Submission #547331

#TimeUsernameProblemLanguageResultExecution timeMemory
547331sidonPyramid Base (IOI08_pyramid_base)C++17
70 / 100
5040 ms112236 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int Z = 4e5+1; const ll INF = 1e18; int sL, sR; ll sV; struct SegmentTree { int l, r; ll v {}, add {}; SegmentTree *L, *R; SegmentTree(int lv, int rv) : l(lv), r(rv) { if(r - l > 1) { int m = (l + r) / 2; L = new SegmentTree(l, m); R = new SegmentTree(m, r); } } void rangeAdd(int lv, int rv, ll val) { sL = lv, sR = rv + 1, sV = val; rangeAdd(); } void rangeAdd() { if(sR <= l || r <= sL) return; if(sL <= l && r <= sR) { add += sV; v += sV; return; } L->rangeAdd(); R->rangeAdd(); v = min(L->v, R->v) + add; } void clear() { if(r - l > 1) L->clear(), R->clear(); add = v = 0; } }; int M, N, B, P; ll C[Z]; array<int, 4> a[Z]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> M >> B >> P; for(int i = 0; i < P; ++i) { for(int j : {0, 2, 1, 3}) cin >> a[i][j]; cin >> C[i]; } a[P] = {0, 0, 1, M}; C[P++] = INF; a[P] = {N+1, N+1, 1, M}; C[P++] = INF; int byX[2][P]; for(int i = 0; i < 2; ++i) { iota(byX[i], byX[i] + P, 0); sort(byX[i], byX[i] + P, [&](const int &x, const int &y) { return a[x][i] < a[y][i]; }); } SegmentTree* st = new SegmentTree(1, M + 1); int x = 0; for(int y = 1<<20; y /= 2; ) if(x + y <= min(M, N)) { x ^= y; bool ok = 0; st->rangeAdd(M - x + 2, M, INF); for(int i {}, j {}; i < P && !ok; ++i) { while(j < P && a[byX[1][j]][1] + x < a[byX[0][i]][0]) { int u = byX[1][j++]; st->rangeAdd(a[u][2] - x + 1, a[u][3], -C[u]); } if(i && a[byX[0][i-1]][0] != a[byX[0][i]][0]) ok = st->v <= B; int u = byX[0][i]; st->rangeAdd(a[u][2] - x + 1, a[u][3], C[u]); } st->clear(); if(!ok) x ^= y; } cout << x; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...