結果
問題 | No.865 24時間降水量 |
ユーザー | bond_cmprog |
提出日時 | 2019-08-16 22:55:55 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,717 bytes |
コンパイル時間 | 2,051 ms |
コンパイル使用メモリ | 181,604 KB |
実行使用メモリ | 19,188 KB |
最終ジャッジ日時 | 2024-09-22 20:23:50 |
合計ジャッジ時間 | 6,653 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | TLE | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
ソースコード
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0;i < n;i++) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()) #define VRSORT(v) sort(v.rbegin(), v.rend()) #define ll long long #define pb(a) push_back(a) #define INF 1000000000 #define LINF 3e18+7 #define MOD 1000000007 using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; typedef vector<unsigned int>vec; typedef vector<vec> mat; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;}; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const double PI = acos(-1.0); const double EPS = 1e-10; template<class Monoid, class Action> struct LazySegTree { using FuncMonoid = function< Monoid(Monoid, Monoid) >; using FuncAction = function< void(Monoid&, Action) >; using FuncLazy = function< void(Action&, Action) >; FuncMonoid FM; FuncAction FA; FuncLazy FL; Monoid UNITY_MONOID; Action UNITY_LAZY; int SIZE, HEIGHT; vector<Monoid> dat; vector<Action> lazy; LazySegTree() { } LazySegTree(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl, const Monoid &unity_monoid, const Action &unity_lazy) : FM(fm), FA(fa), FL(fl), UNITY_MONOID(unity_monoid), UNITY_LAZY(unity_lazy) { SIZE = 1; HEIGHT = 0; while (SIZE < n) SIZE <<= 1, ++HEIGHT; dat.assign(SIZE * 2, UNITY_MONOID); lazy.assign(SIZE * 2, UNITY_LAZY); } void init(int n, const FuncMonoid fm, const FuncAction fa, const FuncLazy fl, const Monoid &unity_monoid, const Action &unity_lazy) { FM = fm; FA = fa; FL = fl; UNITY_MONOID = unity_monoid; UNITY_LAZY = unity_lazy; SIZE = 1; HEIGHT = 0; while (SIZE < n) SIZE <<= 1, ++HEIGHT; dat.assign(SIZE * 2, UNITY_MONOID); lazy.assign(SIZE * 2, UNITY_LAZY); } /* set, a is 0-indexed */ void set(int a, const Monoid &v) { dat[a + SIZE] = v; } void build() { for (int k = SIZE - 1; k > 0; --k) dat[k] = FM(dat[k*2], dat[k*2+1]); } /* update [a, b) */ inline void evaluate(int k) { if (lazy[k] == UNITY_LAZY) return; if (k < SIZE) FL(lazy[k*2], lazy[k]), FL(lazy[k*2+1], lazy[k]); FA(dat[k], lazy[k]); lazy[k] = UNITY_LAZY; } inline void update(int a, int b, const Action &v, int k, int l, int r) { evaluate(k); if (a <= l && r <= b) FL(lazy[k], v), evaluate(k); else if (a < r && l < b) { update(a, b, v, k*2, l, (l+r)>>1), update(a, b, v, k*2+1, (l+r)>>1, r); dat[k] = FM(dat[k*2], dat[k*2+1]); } } inline void update(int a, int b, const Action &v) { update(a, b, v, 1, 0, SIZE); } /* get [a, b) */ inline Monoid get(int a, int b, int k, int l, int r) { evaluate(k); if (a <= l && r <= b) return dat[k]; else if (a < r && l < b) return FM(get(a, b, k*2, l, (l+r)>>1), get(a, b, k*2+1, (l+r)>>1, r)); else return UNITY_MONOID; } inline Monoid get(int a, int b) { return get(a, b, 1, 0, SIZE); } inline Monoid operator [] (int a) { return get(a, a+1); } /* debug */ void print() { for (int i = 0; i < SIZE; ++i) { cout << (*this)[i]; if (i != SIZE) cout << ","; } cout << endl; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; auto fm = [](long long a, long long b) { return max(a,b); }; auto fa = [](long long &a, long long d) { a = a + d; }; auto fl = [](long long &d, long long e) { d = d + e; }; LazySegTree<long long, long long> seg(N+1, fm, fa, fl, 0, 0); vector<int> A(N); REP(i,N) cin >> A[i]; for(int i=1;i<N;i++){ A[i] += A[i-1]; if(i>24) A[i] -= A[i-24]; } REP(i,N) seg.update(i,i+1,A[i]); int Q; cin >> Q; REP(i,Q){ int T, V; cin >> T >> V; T--; if(T==0) seg.update(T,T+24,V-seg.get(T,T+1)); else seg.update(T,T+24,V-(seg.get(T,T+1)-seg.get(T-1,T))); ll res = 0; for(int i=max(0,T-24);i<=min(T+24,N);i++){ if(i==0) res = max(res, seg.get(i,i+25)); else res = max(res, seg.get(i+24,i+25) - seg.get(i,i-1)); } cout << res << endl; //if(i==1) break; } //REP(i,N) cout << seg.get(i,i+1) << " "; }