#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);
int p1 = l, p2 = r;
while(p1<p2 && p2 - l +1 >= m){
res += query(1,1,n,p1+1,p2-1); //-arr[p1] - arr[p2];
p1++, p2--;
}
cout<<res<<'\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2080 ms |
14096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2065 ms |
79060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |