心路歷程
預計得分:\(100 + 100 + 100 = 300\)
實際得分:\(100 +100 +100 = 300\)
學OI兩年終於AK了一次qwq(雖然題目炒雞水。。)
紀念一下這令人激動的時刻。。
8點開始考,9:40就都拍上了。。可見題目確實水。。然後又去做了做另一套
Sol
T1
題目中給的兩個數組沒啥卵用,都是可以直接求的
然後離散化+樹狀數組就完了
#include<cstdio> #include<algorithm> #include<iostream> #define lb(x) (x & (-x)) #define LL long long using namespace std; const LL MAXN = 1e6 + 10; inline LL read() { char c = getchar(); LL x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } LL N, f[MAXN], g[MAXN], a[MAXN], mod; LL add(LL x, LL y) { if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y; } LL mul(LL x, LL y) { return 1ll * x * y % mod; } LL fp(LL a, LL p) { LL base = 1; while(p) { if(p & 1) base = mul(base, a); a = mul(a, a); p >>= 1; } return base; } LL date[MAXN], num; void Des() { sort(date + 1, date + num + 1); num = unique(date + 1, date + num + 1) - date - 1; for(LL i = 1; i <= N; i++) f[i] = lower_bound(date + 1, date + num + 1, f[i]) - date, g[i] = lower_bound(date + 1, date + num + 1, g[i]) - date; } LL T[MAXN]; void Add(LL x, LL val) { while(x <= num) T[x] += val, x += lb(x); } LL Query(LL x) { LL ans = 0; while(x) ans += T[x], x -= lb(x); return ans; } int main() { freopen("calc.in", "r", stdin); freopen("calc.out", "w", stdout); N = read(); mod = read(); for(LL i = 1; i <= N; i++) a[i] = read(), f[i] = fp(i, a[i]), g[i] = fp(a[i], i), date[++num] = f[i], date[++num] = g[i]; Des(); LL ans = 0; for(LL i = N; i >= 1; i--) { ans += Query(f[i] - 1); Add(g[i], 1); } cout << ans; return 0; }
T2
這題比較interesting啊。
我是先做的T3再回來做的T2
首先二分答案
很顯然的一個貪心是從左往右掃,如果遇到一個不合法的點\(i\),那麼升級\(i + R\)處的炮臺。。
和暴力拍了10000多組沒錯誤。。贏了
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #define LL long long using namespace std; const LL MAXN = 2e6; inline LL read() { char c = getchar(); LL x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } LL N, R; LL tag[MAXN], s[MAXN], a[MAXN], b[MAXN], K; bool check(LL val) { memset(tag, 0, sizeof(tag)); LL now = 0, res = K, flag = 1; for(LL i = 1; i <= N; i++) { now += tag[i]; a[i] += now; if(a[i] < val) now += val - a[i], tag[i + 2 * R + 1] -= val - a[i], res -= val - a[i]; if(res < 0) {flag = 0; break;} } memcpy(a, b, sizeof(a)); return flag; } LL Query(LL l, LL r) { r = min(r, N); if(l < 0) return s[r]; return s[r] - s[l]; } int main() { freopen("game.in", "r", stdin); freopen("game.out", "w", stdout); N = read(); R = read(); K = read(); for(LL i = 1; i <= N; i++) a[i] = read(), s[i] = s[i - 1] + a[i]; for(LL i = 1; i <= N; i++) a[i] = Query(i - R - 1, i + R); for(LL i = 1; i <= N; i++) b[i] = a[i]; LL l = 0, r = 3e18, ans = 0; while(l <= r) { LL mid = (l + r) >> 1; if(check(mid)) l = mid + 1, ans = mid; else r = mid - 1; } cout << ans; return 0; }
T3
出題人還能再套路一點麼。。
首先把詢問離線後從小到大排序
合併的時候用帶權並查集維護一下
#include<cstdio> #include<algorithm> #include<cstring> #include<vector> #define Pair pair<LL, LL> #define MP make_pair #define fi first #define se second #define LL long long using namespace std; const LL MAXN = 1e6 + 10, INF = 1e9 + 10; inline LL read() { char c = getchar(); LL x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } LL N, M, Q, cnt, fa[MAXN], w[MAXN], ans, out[MAXN]; struct Edge { LL u, v, w; bool operator < (const Edge &rhs) const { return w < rhs.w; } }E[MAXN]; Pair q[MAXN]; LL find(LL x) { return fa[x] == x ? fa[x] : fa[x] = find(fa[x]); } void AddEdge(LL i) { LL x = E[i].u, y = E[i].v, v = E[i].w; LL fx = find(x), fy = find(y); if(fx == fy) w[fx] += v, ans = max(ans, w[fx]); else { fa[fx] = fy; w[fy] += v + w[fx]; w[fx] = 0; ans = max(ans, w[fy]); } } int main() { freopen("graph.in", "r", stdin); freopen("graph.out", "w", stdout); N = read(); M = read(); Q = read(); for(LL i = 1; i <= N; i++) fa[i] = i; for(LL i = 1; i <= M; i++) E[i].u = read(), E[i].v = read(), E[i].w = read(); sort(E + 1, E + M + 1); for(LL i = 1; i <= Q; i++) q[i] = MP(read(), i); sort(q + 1, q + Q + 1); LL j = 1; for(LL i = 1; i <= Q; i++) { while(j <= M && E[j].w <= q[i].fi) AddEdge(j++); out[q[i].se] = ans; } for(LL i = 1; i <= Q; i++) printf("%I64d\n", out[i]); return 0; }