11.4 解題報告
阿新 • • 發佈:2020-11-04
\[\huge\texttt{11.4 解題報告}
\]目錄
在模 \(998244353\) 意義下的值。
概述
詳細資訊
題號 | T1 | T2 | T3 | T4 | 合計 |
---|---|---|---|---|---|
用時 | 20min | 1h 20min | 30min | 40min | 2h 50min |
估分 | 100 | 100 | 40 | 100 | 340 |
實際 | 100 | 80 | 40 | 100 | 320 |
爆零小技巧
stl map
的常數很大!
解題報告
T1 大空魔術
T2 夜桜街道
Description
長為 \(n\) 的序列,對於每個 \(i\),求分別以 \([1, i]\) 為右端點的順序對個數之和除以 \(i\)
Solution
1.離散化。
2.開值域樹狀陣列對每個位置求順序對。
3.統計字首和。
4.計算答案。
Code
#include <cstdio> #include <map> #include <set> #include <iostream> #include <cmath> #include <algorithm> #define LL long long const LL Mod = 998244353; const int Maxn = 1e6 + 5; using namespace std; int n; LL a[Maxn], s[Maxn]; int rank[Maxn]; struct lsh { LL data; int idx; } b[Maxn]; bool cmp(lsh a10, lsh a20) { return a10.data < a20.data; } namespace Math { LL qpow(LL b, LL p) { LL res = 1LL; while(p) res *= ((p & 1LL) ? b : 1LL), res %= Mod, b *= b, b %= Mod, p >>= 1; return res; } LL inv(LL t) {return qpow(t, Mod - 2) % Mod;} LL div(LL t, LL d) {return 1LL * t * inv(d) % Mod;} } namespace Read { template<typename _Temp> inline _Temp read() { _Temp fh = 1, w = 0; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) if(ch == '-') fh = -1; for(; isdigit(ch); ch = getchar()) w = (w << 3) + (w << 1) + (ch ^ '0'); return fh * w; } } using namespace Math; using namespace Read; struct T_array { #define g(t) -t&t LL arr[Maxn]; inline void add(int t,LL x) { while(t <= n) { arr[t] += x; arr[t] %= Mod; t+=g(t); } } inline LL ask(int t) { LL x = 0; while(t) { x += arr[t]; x %= Mod; t -= g(t); } return x; } #undef lb } T; LL ans; int main() { //freopen("b.in", "r", stdin); //freopen("b.out", "w", stdout); n = read<int>(); for(register int i = 1; i <= n; ++i) { a[i] = read<LL>(); b[i].data = a[i]; b[i].idx = i; } sort(b + 1, b + n + 1, cmp); b[0].idx = 0; b[0].data = -1; rank[0] = 0; for(register int i = 1; i <= n; ++i) { if(b[i].data == b[i - 1].data) rank[b[i].idx] = rank[b[i - 1].idx]; else rank[b[i].idx] = rank[b[i - 1].idx] + 1; } for(register int i = 1; i <= n; ++i) { T.add(rank[i], 1); s[i] = (s[i - 1] % Mod) + (T.ask(rank[i] - 1)); s[i] %= Mod; ans += 1LL * s[i] * inv((LL)i) % Mod; ans %= Mod; } printf("%lld", ans); //fclose(stdin); fclose(stdout); return 0; }
T3 科學世紀
Solution
列舉 \(q\) 在 \([2, \sqrt{q}]\) 內的所有因子。
除這個因子直到 \(i\)