Submission #1130613

#TimeUsernameProblemLanguageResultExecution timeMemory
1130613lopkusAddk (eJOI21_addk)C++20
92 / 100
104 ms5492 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 5; struct segtree{ int t[4*N]; int query(int v,int tl,int tr,int l,int r){ if(tl>r||tr<l)return 0; if(tl>=l&&tr<=r)return t[v]; int tm=(tl+tr)/2; return (query(v*2,tl,tm,l,r)+query(v*2+1,tm+1,tr,l,r)); } void update(int v,int tl,int tr,int index,int value){ if(tl==tr)t[v]=value; else { int tm=(tl+tr)/2; if(index<=tm)update(v*2,tl,tm,index,value); else update(v*2+1,tm+1,tr,index,value); t[v]=(t[v*2]+t[v*2+1]); } } }seg; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> a(n + 1); for(int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> pref(n + 1, 0); for(int i = 1; i <= n; i++) { pref[i] = pref[i - 1] + a[i]; seg.update(1, 1, n, i, pref[i]); } int q; cin >> q; while(q--) { int o; cin >> o; if(o == 1) { vector<int> b(k + 1); for(int i = 1; i <= k; i++) { cin >> b[i]; } } else { int l, r, m; cin >> l >> r >> m; // l + m - 1 <= r // l <= r - m + 1 // max(r - m + 1, r) - seg.get(l - 1) //cout << seg.query(1, 1, n, r - m + 1, r) - seg.query(1, 1, n, l - 1, l - 1) << "\n"; int sol1 = 0; int sol2 = 0; // l + m - 1 <= r // r >= l + m - 1 /* for(int i = l + m - 1; i <= r; i++) { sol1 += pref[i]; } // l + m - 1 <= r // l <= r - m + 1 for(int i = l - 1; i <= r - m; i++) { sol2 += pref[i]; }*/ cout << seg.query(1, 1, n, l + m - 1, r) - seg.query(1, 1, n, l - 1, r - m) << "\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...