Submission #445871

#TimeUsernameProblemLanguageResultExecution timeMemory
445871JerryLiu06Pyramid Base (IOI08_pyramid_base)C++17
85 / 100
1787 ms139800 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<str>; using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; #define mp make_pair #define f first #define s second #define sz(x) (int)(x).size() #define bg(x) begin(x) #define all(x) bg(x), end(x) #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define R0F(i, a) ROF(i, 0, a) #define EACH(a, x) for (auto& a : x) ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<class T> void remDup(vector<T>& v) { sor(v); v.erase(unique(all(v)), v.end()); } const int MOD = 1e9 + 7; const int MX = 1e6 + 10; const ll INF = 1e18; int M, N, B, P; struct Subtask2 { vector<array<int, 3>> ST[MX], EN[MX]; int tree[4 * MX], lazy[4 * MX]; void pushdown(int x, int l, int r) { if (lazy[x] == 0) return ; tree[x] += lazy[x]; if (l < r) { F0R(i, 2) lazy[2 * x + i] += lazy[x]; } lazy[x] = 0; } void update(int x, int l, int r, int tl, int tr, int val) { int mid = (l + r) / 2; pushdown(x, l, r); if (l > tr || r < tl) return ; if (tl <= l && r <= tr) { lazy[x] = val; pushdown(x, l, r); return ; } update(2 * x, l, mid, tl, tr, val); update(2 * x + 1, mid + 1, r, tl, tr, val); tree[x] = min(tree[2 * x], tree[2 * x + 1]); } void init() { F0R(i, P) { int X1, Y1, X2, Y2, C; cin >> X1 >> Y1 >> X2 >> Y2 >> C; ST[X1].pb({Y1, Y2, C}); EN[X2 + 1].pb({Y1, Y2, -C}); } } int solve() { int low = 0; int high = min(M, N); int res = 0; while (low <= high) { int mid = (low + high) / 2; F0R(i, 4 * N) tree[i] = 0, lazy[i] = 0; update(1, 1, N, N - mid + 2, N, MOD); FOR(i, 1, mid) EACH(C, ST[i]) update(1, 1, N, max(1, C[0] - mid + 1), C[1], C[2]); bool valid = false; FOR(i, 1, M - mid + 2) { EACH(C, ST[i + mid - 1]) update(1, 1, N, max(1, C[0] - mid + 1), C[1], C[2]); EACH(C, EN[i]) update(1, 1, N, max(1, C[0] - mid + 1), C[1], C[2]); valid = tree[1] <= B; if (valid) break; } if (valid) low = mid + 1, res = mid; else high = mid - 1; } return res; } }; struct Subtask3 { vector<array<int, 2>> ST[MX], EN[MX]; struct Node { int L, R, ans; } tree[4 * MX]; int lazy[4 * MX]; void comb(int x, int l, int r) { int mid = (l + r) / 2; int LL = tree[2 * x].L, LR = tree[2 * x].R, LA = tree[2 * x].ans; int RL = tree[2 * x + 1].L, RR = tree[2 * x + 1].R, RA = tree[2 * x + 1].ans; if (lazy[2 * x]) LL = LR = LA = 0; if (lazy[2 * x + 1]) RL = RR = RA = 0; tree[x].ans = max({LA, RA, LR + RL}); tree[x].L = LL == mid - l + 1 ? (LL + RL) : LL; tree[x].R = RR == r - mid ? (RR + LR) : RR; } void build(int x, int l, int r) { int mid = (l + r) / 2; if (l == r) { tree[x].L = tree[x].R = tree[x].ans = 1; return ; } build(2 * x, l, mid); build(2 * x + 1, mid + 1, r); comb(x, l, r); } void update(int x, int l, int r, int tl, int tr, int val) { int mid = (l + r) / 2; if (l > tr || r < tl) return ; if (tl <= l && r <= tr) { lazy[x] += val; return ; } update(2 * x, l, mid, tl, tr, val); update(2 * x + 1, mid + 1, r, tl, tr, val); comb(x, l, r); } void init() { F0R(i, P) { int X1, Y1, X2, Y2, C; cin >> X1 >> Y1 >> X2 >> Y2 >> C; ST[X1].pb({Y1, Y2}); EN[X2 + 1].pb({Y1, Y2}); } } int solve() { int ans = 0; int R = 1; build(1, 1, N); FOR(L, 1, M + 1) { EACH(C, EN[L]) update(1, 1, N, C[0], C[1], -1); while (R <= M && (lazy[1] ? 0 : tree[1].ans) >= R - L) { ckmax(ans, R - L); EACH(C, ST[R]) update(1, 1, N, C[0], C[1], 1); R++; } // ckmax(ans, R - L); } return ans; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> M >> N >> B >> P; if (B) { Subtask2 S; S.init(); cout << S.solve(); } else { Subtask3 S; S.init(); cout << S.solve(); } }

Compilation message (stderr)

pyramid_base.cpp: In member function 'void Subtask2::pushdown(int, int, int)':
pyramid_base.cpp:65:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   65 |         if (lazy[x] == 0) return ; tree[x] += lazy[x];
      |         ^~
pyramid_base.cpp:65:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   65 |         if (lazy[x] == 0) return ; tree[x] += lazy[x];
      |                                    ^~~~
pyramid_base.cpp: In member function 'int Subtask2::solve()':
pyramid_base.cpp:41:22: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   41 | #define FOR(i, a, b) for (int i = (a); i < (b); i++)
      |                      ^~~
pyramid_base.cpp:42:19: note: in expansion of macro 'FOR'
   42 | #define F0R(i, a) FOR(i, 0, a)
      |                   ^~~
pyramid_base.cpp:86:13: note: in expansion of macro 'F0R'
   86 |             F0R(i, 4 * N) tree[i] = 0, lazy[i] = 0; update(1, 1, N, N - mid + 2, N, MOD);
      |             ^~~
pyramid_base.cpp:86:53: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   86 |             F0R(i, 4 * N) tree[i] = 0, lazy[i] = 0; update(1, 1, N, N - mid + 2, N, MOD);
      |                                                     ^~~~~~
pyramid_base.cpp: In member function 'void Subtask3::comb(int, int, int)':
pyramid_base.cpp:112:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  112 |         if (lazy[2 * x]) LL = LR = LA = 0; if (lazy[2 * x + 1]) RL = RR = RA = 0;
      |         ^~
pyramid_base.cpp:112:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  112 |         if (lazy[2 * x]) LL = LR = LA = 0; if (lazy[2 * x + 1]) RL = RR = RA = 0;
      |                                            ^~
pyramid_base.cpp: In member function 'void Subtask3::update(int, int, int, int, int, int)':
pyramid_base.cpp:122:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  122 |         if (l > tr || r < tl) return ; if (tl <= l && r <= tr) { lazy[x] += val; return ; }
      |         ^~
pyramid_base.cpp:122:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  122 |         if (l > tr || r < tl) return ; if (tl <= l && r <= tr) { lazy[x] += val; return ; }
      |                                        ^~
pyramid_base.cpp: In member function 'int Subtask3::solve()':
pyramid_base.cpp:45:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   45 | #define EACH(a, x) for (auto& a : x)
      |                    ^~~
pyramid_base.cpp:142:17: note: in expansion of macro 'EACH'
  142 |                 EACH(C, ST[R]) update(1, 1, N, C[0], C[1], 1); R++;
      |                 ^~~~
pyramid_base.cpp:142:64: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  142 |                 EACH(C, ST[R]) update(1, 1, N, C[0], C[1], 1); R++;
      |                                                                ^
#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...