This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY 10000000
#define mod 100000000
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mid (start+end)/2
int pre[100005],tree[400005],lazy[400005];
vector<int> v;
inline void push(int node,int start,int end){
if(lazy[node]==0)return ;
tree[node]+=lazy[node]*(end-start+1);
if(start!=end){
lazy[node*2]+=lazy[node];
lazy[node*2+1]+=lazy[node];
}
lazy[node]=0;
}
inline void build(int node,int start,int end){
lazy[node]=0;
if(start>end)return ;
if(start==end){tree[node]=pre[start];return;}
build(node*2,start,mid),build(node*2+1,mid+1,end);
tree[node]=tree[node*2]+tree[node*2+1];
}
inline int query(int node,int start,int end,int l,int r){
if(start>end || start>r || end<l)return 0;
push(node,start,end);
if(start>=l && end<=r)return tree[node];
return query(node*2,start,mid,l,r)+query(node*2+1,mid+1,end,l,r);
}
inline void update(int node,int start,int end,int l,int r,int val){
push(node,start,end);
if(start>end || start>r || end<l)return ;
if(start>=l && end<=r){
lazy[node]+=val;
push(node,start,end);
return ;
}
update(node*2,start,mid,l,r,val),update(node*2+1,mid+1,end,l,r,val);
tree[node]=tree[node*2]+tree[node*2+1];
}
int32_t main(){
faster
int n,k,deg;cin>>n>>k;
int dizi[n+1];
dizi[0]=0;
for(int i=1;i<=n;i++){
cin>>dizi[i];
}
for(int i=1;i<=n;i++){
pre[i]=pre[i-1]+dizi[i];
}
build(1,1,n);
int q;cin>>q;
while(q--){
int ty;cin>>ty;
if(ty==1){
for(int i=0;i<k;i++){
cin>>deg;
v.push_back(deg);
}
update(1,1,n,v[0],v[k-1]-1,-dizi[v[0]]);
int gec=dizi[v[0]];
for(int i=1;i<v.size();i++){
update(1,1,n,v[i-1],v[i]-1,dizi[v[i]]);
dizi[v[i-1]]=dizi[v[i]];
}
dizi[v[k-1]]=gec;
v.clear();
}
else{
int l,r,m;cin>>l>>r>>m;
int cev=query(1,1,n,1,r)-query(1,1,n,1,l+m-2);
if(l-2>0)deg=query(1,1,n,1,l-2);
else deg=0;
cev-=query(1,1,n,1,r-m)-deg;
cout<<cev<<'\n';
}
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:70:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i=1;i<v.size();i++){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |