Submission #553122

#TimeUsernameProblemLanguageResultExecution timeMemory
553122fuad27Addk (eJOI21_addk)C++17
100 / 100
324 ms8012 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 100'010; vector<ll> fen1(MAXN, 0); vector<ll> fen2(MAXN, 0); void update(vector<ll> &bit, ll in, ll val) { while(in < MAXN) { bit[in]+=val; in+=in&(-in); } } long long query(vector<ll> &bit, ll in) { ll sum = 0; while(in > 0) { sum+=bit[in]; in-=in&(-in); } return sum; } int main () { int n, k; cin >> n >> k; long long arr[n+1]; //, prefix1[n+1] = {0}, prefix2[n+1] = {0}; for(int i = 1;i<=n;i++) { cin >> arr[i]; update(fen1, i, arr[i]); update(fen2, i, arr[i]*i); //prefix1[i] = prefix1[i-1] + arr[i]; //prefix2[i] = prefix2[i-1] + arr[i]*i; } int q; cin >> q; while(q--) { int type; cin >> type; if(type == 1) { ll change[k]; for(int i= 0;i<k;i++) { cin >> change[i]; update(fen1, change[i], -arr[change[i]]); update(fen2, change[i], -change[i]*arr[change[i]]); } reverse(change, change+k); long long prev = arr[change[k-1]]; for(int i = 0;i<k;i++) { swap(prev, arr[change[i]]); update(fen1, change[i], arr[change[i]]); update(fen2, change[i], arr[change[i]]*change[i]); } } else { int ans = 0; int l, r, m; cin >> l >> r >> m; m = min(r-l-m + 2, m); long long a = (query(fen2, l+m-1) - query(fen2, l-1))-(query(fen1,l+m-1) - query(fen1, l-1))*(l-1); long long b = (query(fen1, r-m) - query(fen1, l+m-1))*m; long long c = (query(fen1, r) - query(fen1, r-m))*(r+1) - (query(fen2, r) - query(fen2, r-m)); cout<<a+b+c<<endl; } } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:60:8: warning: unused variable 'ans' [-Wunused-variable]
   60 |    int ans = 0;
      |        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...