제출 #747516

#제출 시각아이디문제언어결과실행 시간메모리
747516baluteshihMizuyokan 2 (JOI23_mizuyokan2)C++14
0 / 100
81 ms3108 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define X first #define Y second #define SZ(a) ((int)a.size()) #define ALL(v) v.begin(), v.end() #define pb push_back const int L = 70; int arr[250005], lft[250005], tmp[250005]; int main() { ios::sync_with_stdio(0), cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> arr[i]; auto update = [&](int i) { lft[i] = 0; ll cur = 0; for (int j = i; j > 0 && j > i - L; --j) { cur += arr[j]; if (cur > max(arr[j - 1], arr[i + 1])) { lft[i] = j; break; } } }; for (int i = 1; i <= n; ++i) update(i); int q; cin >> q; for (int i = 1; i <= q; ++i) { int x, y, a, b; cin >> x >> y >> a >> b; arr[x] = y; for (int j = max(1, x - 1); j <= n && j <= x + L; ++j) update(j); int ans = 1; ll cur = 0; for (int j = a + 1; j < b && j <= a + L; ++j) { tmp[j] = lft[j]; if (cur > arr[j + 1]) lft[j] = max(lft[j], a + 1); cur += arr[j]; } tmp[b] = lft[b], lft[b] = 0, cur = 0; for (int j = b; j > a && j > b - L; --j) { cur += arr[j]; if (j == a + 1 || cur > arr[j - 1]) { lft[b] = j; break; } } pii one = pll(a - 1, -1); pii two = pll(a, 0); for (int j = a + 1; j <= b; ++j) { if (lft[j] - 1 > one.X) one.X = j, one.Y += 2; if (lft[j] - 1 > two.X) two.X = j, two.Y += 2; if (j == b) ans = max({ans, one.Y, two.Y}); else ans = max({ans, one.Y + 1, two.Y + 1}); } for (int j = a + 1; j <= b && j <= a + L; ++j) lft[j] = tmp[j]; lft[b] = tmp[b]; cout << ans << "\n"; } }
#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...