# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
958796 |
2024-04-06T17:02:44 Z |
Acanikolic |
Addk (eJOI21_addk) |
C++14 |
|
1428 ms |
11212 KB |
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1e5 + 10;
const int mod = 998244353;
long long st[N * 4];
long long lazy[N * 4];
void push(int node,int tl,int tr) {
st[node] += 1ll * (tr - tl + 1) * lazy[node];
if(tl != tr) {
lazy[node * 2] += lazy[node];
lazy[node * 2 + 1] += lazy[node];
}
lazy[node] = 0;
}
void modify(int node,int tl,int tr,int l,int r,long long val) {
push(node,tl,tr);
if(tl > r || tr < l) return;
if(tl >= l && tr <= r) {
lazy[node] += val;
push(node,tl,tr);
return;
}
push(node,tl,tr);
int mid = (tl + tr) / 2;
modify(node * 2,tl,mid,l,r,val);
modify(node * 2 + 1,mid + 1,tr,l,r,val);
st[node] = st[node * 2] + st[node * 2 + 1];
}
long long get(int node,int tl,int tr,int l,int r) {
push(node,tl,tr);
if(tl > r || tr < l) return 0ll;
if(tl >= l && tr <= r) return st[node];
int mid = (tl + tr) / 2;
return get(node * 2,tl,mid,l,r) + get(node * 2 + 1,mid + 1,tr,l,r);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin >> n >> k;
vector<int>a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
vector<long long>pref(n + 1);
for(int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i];
for(int i = 1; i <= n; i++) modify(1,1,n,i,i,pref[i]);
int q;
cin >> q;
while(q--) {
int type;
cin >> type;
if(type == 1) {
vector<int>b(k + 1),c(k + 1);
for(int i = 1; i <= k; i++) cin >> b[i];
for(int i = 1; i <= k - 1; i++) c[i] = b[i + 1];
c[k] = b[1];
vector<int>cpy = a;
for(int i = 1; i <= k; i++) {
cpy[b[i]] = a[c[i]];
modify(1,1,n,c[i],n,-a[c[i]]);
modify(1,1,n,b[i],n,a[c[i]]);
}
a = cpy;
}else {
int l,r,m;
long long res = 0;
cin >> l >> r >> m;
int L = l + m - 1;
if(L <= r) res += get(1,1,n,1,r);
if(L <= r) res -= get(1,1,n,1,L - 1);
//if(L <= r) res += Pref[r] - Pref[L - 1];
int R = r - m + 1;
if(R >= l) res -= get(1,1,n,1,R - 1);
//if(R >= l) res -= Pref[R - 1];
//if(R >= l && l >= 2) res += Pref[l - 2];
if(R >= l && l >= 2) res += get(1,1,n,1,l - 2);
cout << res << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
3 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2652 KB |
Output is correct |
5 |
Correct |
6 ms |
2684 KB |
Output is correct |
6 |
Correct |
7 ms |
2652 KB |
Output is correct |
7 |
Correct |
7 ms |
2652 KB |
Output is correct |
8 |
Correct |
8 ms |
2756 KB |
Output is correct |
9 |
Correct |
13 ms |
4804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
5244 KB |
Output is correct |
2 |
Correct |
46 ms |
5544 KB |
Output is correct |
3 |
Correct |
81 ms |
5804 KB |
Output is correct |
4 |
Correct |
144 ms |
7732 KB |
Output is correct |
5 |
Correct |
237 ms |
8552 KB |
Output is correct |
6 |
Correct |
428 ms |
8476 KB |
Output is correct |
7 |
Correct |
429 ms |
8308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
294 ms |
5996 KB |
Output is correct |
2 |
Correct |
323 ms |
7812 KB |
Output is correct |
3 |
Correct |
1428 ms |
8600 KB |
Output is correct |
4 |
Correct |
285 ms |
11212 KB |
Output is correct |