# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
775095 |
2023-07-06T07:32:22 Z |
vjudge1 |
Addk (eJOI21_addk) |
C++17 |
|
670 ms |
2792 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vi;
typedef vector<vi> vvi;
int n,k;
template<typename IteratorType> void print(IteratorType first,IteratorType last){
while(first != last){
cout<<*first<<' ';
first++;
}
}
vector<int> st,arr;
void build(int id,int l,int r){
if(l==r){
st[id] = arr[l];
return;
}
int mid = (l+r)>>1;
build(2*id,l,mid);
build(2*id+1,mid+1,r);
st[id] = st[2*id] + st[2*id+1];
}
void update(int id,int l,int r,int u,int v,int val){
if(l>v || r<u || l>r) return;
if(l>=u && r<=v){
st[id] = val;
return;
}
int mid = (l+r)>>1;
update(2*id,l,mid,u,v,val);
update(2*id+1,mid+1,r,u,v,val);
st[id] = st[2*id] + st[2*id+1];
}
int query(int id,int l,int r,int u,int v){
if(l>v || r<u || l>r) return 0;
if(l>=u && r<=v){
return st[id];
}
int mid = (l+r)>>1;
int a = query(2*id,l,mid,u,v);
int b = query(2*id+1,mid+1,r,u,v);
return a+b;
}
signed main(){
cin>>n>>k;
arr.resize(n+1); st.resize(4*(n+1));
for(int i=1;i<=n;++i){
cin>>arr[i];
}
build(1,1,n);
vector<int> change(k+1);
int q,l,r,m; cin>>q;
while(q-->0){
int cmd; cin>>cmd;
if(cmd==1){
for(int i=1;i<=k;++i){
cin>>change[i];
}
for(int i=1;i<=k;++i){
update(1,1,n,change[i],change[i],arr[change[(i+1)%n]]);
}
int temp = arr[change[1]];
for(int i=1;i<k;++i){
arr[change[i]] = arr[change[(i+1)%n]];
}
arr[change[k]] = temp;
//print(arr.begin()+1,arr.end()); cout<<'\n';
}
else{
cin>>l>>r>>m;
int res = query(1,1,n,l,r), h = res;
int p1 = l, p2 = r;
while(p1<p2 && p2 - l +1 >= m){
h -= arr[p1] + arr[p2];
res += h;
p1++, p2--;
}
cout<<res<<'\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
136 ms |
1272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
670 ms |
2792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |