Submission #571217

#TimeUsernameProblemLanguageResultExecution timeMemory
571217AdnanboiAddk (eJOI21_addk)C++14
0 / 100
8 ms2788 KiB
#include <bits/stdc++.h> using namespace std; #define N 10000 #define ll long long vector<long long> tree(2*N,0); long long n; void build(vector<long long> lista){ for(long long i=0;i<n;i++){ tree[n+i]=lista[i]; } for (long long i=n-1;i>0;i--){ tree[i]=tree[i<<1]+tree[i<<1 | 1]; } } void update(long long p, long long value){ tree[p]=value; p+=n; tree[p]=value; for(p/=2;p>0;p/=2){ tree[p]=tree[2*p]+tree[p*2+1]; } } long long sum(long long l, long long r){ long long res = 0; for (l+=n,r+=n;l<r;l>>=1,r>>=1) { if (l&1) res += tree[l++]; if (r&1) res += tree[--r]; } return res; } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(NULL); long long q,k; cin>>n>>k; vector<long long> lista(n); for(long long i=0;i<n;i++){ cin>>lista[i]; } build(lista); cin>>q; for(long long i=0;i<q;i++){ long long c; cin>>c; if(c==1){ long long a; cin>>a; long long first=tree[a+n-1]; long long b=a; for(long long i=0;i<k-1;i++){ long long d=b; cin>>b; update(d-1,tree[b-1+n]); } update(b-1,first); } else if(c==2){ long long a,b,m; cin>>a>>b>>m; long long f=0; for(long long j=a;j<=b-m+1;j++){ f+=sum(j-1,j+m-1); } cout<<f<<'\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...