昨天晚上zyf神犇问我的题,虽然我太弱参加不了APIO但也做一做吧。
用小数据拍了无数次总是查不出错来,交上去就WA,后来用国内数据测发现是主席树上区间相减的值没有用long long存,小数据真是没用啊QuQ
手残不加long long毁一生
交上去还是WA,最后发现没有把windows下的I64d改成linux下的lld==
因为这个贡献了两次Wrong Answer,,,好像第一次还爆内存了?比赛时这么手残就得滚粗了QAQ
#include<cstdio> #include<cstring> #include<algorithm> #define read(x) x=getint() using namespace std; const int N = 100003; int getint() { int k = 0, fh = 1; char c = getchar(); for(; c < '0' || c > '9'; c = getchar()) if (c == '-') fh = -1; for(; c >= '0' && c <= '9'; c = getchar()) k = k * 10 + c - '0'; return k * fh; } struct node1 { int b, c, l, id; } Q[N]; struct node2 { int l, r, s; long long sc; }T[N * 30]; int S[N], n, m, point[N], nxt[N], to[N], cnt = 0, rt = 0, L[N], R[N], H[N]; int root[N], CL[N]; void ins(int x, int y) {nxt[++cnt] = point[x]; to[cnt] = y; point[x] = cnt;} void dfs(int x) { S[++cnt] = x; L[x] = cnt; for(int i = point[x]; i; i = nxt[i]) dfs(to[i]); R[x] = cnt; } bool cmp(node1 X, node1 Y) {return X.c < Y.c;} void update(int l, int r, int &pos, int key) { T[++cnt] = T[pos]; pos = cnt; ++T[pos].s; T[pos].sc += Q[key].c; if (l == r) return; int mid = (l + r) >> 1; if (key <= mid) update(l, mid, T[pos].l, key); else update(mid + 1, r, T[pos].r, key); } long long Query(int l, int r, int x, int y, int key) { if (l == r) { if (T[y].sc - T[x].sc <= key) return T[y].s - T[x].s; else return key / Q[l].c; } int mid = (l + r) >> 1; long long su = T[T[y].l].sc - T[T[x].l].sc; if (su >= key) return Query(l, mid, T[x].l, T[y].l, key); else return T[T[y].l].s - T[T[x].l].s + Query(mid + 1, r, T[x].r, T[y].r, key - su); } int main() { read(n); read(m); for(int i = 1; i <= n; ++i) read(Q[i].b), read(Q[i].c), read(Q[i].l), Q[i].id = i, CL[i] = Q[i].l; for(int i = 1; i <= n; ++i) if (Q[i].b == 0) rt = i; else ins(Q[i].b, i); cnt = 0; dfs(rt); sort(Q + 1, Q + n + 1, cmp); for(int i = 1; i <= n; ++i) H[Q[i].id] = i; cnt = 0; // for(int i = 1; i <= n; ++i) printf("%d %d ", L[i], R[i]); // for(int i = 1; i <= n; ++i) printf("!! %d ", H[i]); // for(int i = 1; i <= n; ++i) printf("!! %d ", Q[H[i]].c); for(int i = 1; i <= n; ++i) { root[i] = root[i - 1]; update(1, n, root[i], H[S[i]]); // printf("HHH %d ", S[i]); // printf("!!! %d ", H[S[i]]); } // for(int i = 1; i <= n ;++i) printf("%I64d ", T[root[i]].sc); puts(""); long long ans = 0; for(int i = 1; i <= n; ++i) ans = max(ans, CL[i] * Query(1, n, root[L[i] - 1], root[R[i]], m)); printf("%lld ", ans); // for(int i = 1; i <= n; ++i) printf("%d %d ", L[i], R[i]); return 0; }
没有删掉愚蠢的调试信息,,,