Submission #775653

#TimeUsernameProblemLanguageResultExecution timeMemory
775653vjudge1Addk (eJOI21_addk)C++14
100 / 100
1313 ms6232 KiB
#include<bits/stdc++.h> using namespace std; #define ll 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<ll> 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 i,ll val){ if(l>i || i>r) return; if(l==r){ st[id] = val; return; } int mid = (l+r)/2; update(2*id,l,mid,i,val); update(2*id+1,mid+1,r,i,val); st[id] = (st[2*id] + st[2*id+1]); } ll 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)/2; ll a = query(2*id,l,mid,u,v); ll 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+2)); for(int i=1;i<=n;++i){ cin>>arr[i]; } build(1,1,n); vector<ll> change(k+1); int q,l,r,m; cin>>q; while(q-->0){ int cmd; cin>>cmd; if(cmd==1){ for(int i=0;i<k;++i){ cin>>change[i]; } ll temp = arr[change[0]]; for(int i=0;i<k-1;++i){ arr[change[i]] = arr[change[i+1]]; update(1,1,n,change[i],arr[change[i]]); } arr[change[k-1]] = temp; update(1,1,n,change[k-1],arr[change[k-1]]); } else if(cmd == 2){ cin>>l>>r>>m; ll ans=0; ll rr=r,lli=l; ll k=query(1,1,n,lli,rr); for(ll i=0;i<m;++i){ ans+=k; k-=arr[lli]; k-=arr[rr]; ++lli; --rr; if(lli>rr||rr<l+m-1){ break; } } cout<<ans<<"\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...