Submission #1025182

#TimeUsernameProblemLanguageResultExecution timeMemory
1025182marAddk (eJOI21_addk)C++14
100 / 100
1988 ms7912 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { int n,k; cin >> n >> k; vector<int>v(n+1); vector<ll>ps(n+1); ps[0] = 0; for(int i = 1;i <= n;i++){ cin >> v[i]; ps[i] = ps[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 += ps[rr] + res2[rr] - (ps[ll] + res2[ll]); ll++; rr--; } cout << sum << "\n"; }else{ vector<int> ind(k); for(int j= 0;j < k;j++){ cin >> ind[j]; } for(int j = 0;j < k-1;j++){ int diff = v[ind[j+1]] - v[ind[j]]; res[ind[j]] += diff; res[ind[j+1]] -= diff; int temp = v[ind[j]]; v[ind[j]] = v[ind[j+1]]; v[ind[j+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...