Submission #848123

#TimeUsernameProblemLanguageResultExecution timeMemory
848123JoksimKaktusAddk (eJOI21_addk)C++17
92 / 100
2058 ms3996 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int n,k; cin >> n >> k; vector <int> v(n+1); vector <long long> pre(n+1); pre[0] = 0; for(int i = 1;i <= n;i++){ cin >> v[i]; pre[i] = pre[i-1] + v[i]; } int q; cin >> q; bool fix = false; vector <int> res(n+1,0); vector <int> res2(n+1,0); int mini = n; int maxi = 0; for(int i = 0;i < q;i++){ int qu,l,r,m; cin >> qu; if(qu == 2){ cin >> l >> r >> m; int rr = r; int ll = l-1; long long sum = 0; if(fix){ for(int j = mini;j <= maxi;j++){ res2[j] += res[j-1] + res[j]; res[j] += res[j-1]; res[j-1] = 0; } res[maxi] = 0; fix = false; mini = n; maxi = 0; } for(int j = 0; j < min(m,(r-l)+2-m);j++){ sum += pre[rr] + res2[rr] - (pre[ll] + res2[ll]); ll++; rr--; } cout << sum << "\n"; }else{ vector <int> ind(k); for(int ii = 0;ii < k;ii++){ cin >> ind[ii]; } for(int ii = 0;ii < k-1;ii++){ int diff = v[ind[ii+1]] - v[ind[ii]]; res[ind[ii]] += diff; res[ind[ii+1]] -= diff; int temp = v[ind[ii]]; v[ind[ii]] = v[ind[ii+1]]; v[ind[ii+1]] = temp; } fix = true; mini = min (mini,ind[0]); maxi = max(maxi, ind[k-1]); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...