# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1025182 |
2024-07-16T17:10:50 Z |
mar |
Addk (eJOI21_addk) |
C++14 |
|
1988 ms |
7912 KB |
#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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
492 KB |
Output is correct |
4 |
Correct |
8 ms |
600 KB |
Output is correct |
5 |
Correct |
9 ms |
348 KB |
Output is correct |
6 |
Correct |
13 ms |
568 KB |
Output is correct |
7 |
Correct |
16 ms |
560 KB |
Output is correct |
8 |
Correct |
20 ms |
512 KB |
Output is correct |
9 |
Correct |
33 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
960 KB |
Output is correct |
2 |
Correct |
187 ms |
1364 KB |
Output is correct |
3 |
Correct |
325 ms |
1620 KB |
Output is correct |
4 |
Correct |
914 ms |
2744 KB |
Output is correct |
5 |
Correct |
1457 ms |
3748 KB |
Output is correct |
6 |
Correct |
1360 ms |
3664 KB |
Output is correct |
7 |
Correct |
1241 ms |
3600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
858 ms |
2152 KB |
Output is correct |
2 |
Correct |
1463 ms |
5340 KB |
Output is correct |
3 |
Correct |
1988 ms |
7912 KB |
Output is correct |
4 |
Correct |
1958 ms |
6484 KB |
Output is correct |