Submission #571798

#TimeUsernameProblemLanguageResultExecution timeMemory
571798AdnanboiAddk (eJOI21_addk)C++14
36 / 100
2084 ms17488 KiB
#include <bits/stdc++.h> using namespace std; #define N 1000000 #define ll long long vector<ll> tree(2*N,0); ll n; void build(vector<ll> lista){ for(int i=0;i<n;i++){ tree[n+i]=lista[i]; } for (int i=n-1;i>0;i--){ tree[i]=tree[i<<1]+tree[i<<1 | 1]; } } void update(int p, ll value){ p+=n; tree[p]=value; } ll sum2(int m, int begin, int end){ ll result=0; ll constantres=0; begin+=n; end+=n; for(int i=begin-1;i<begin+m-1;i++){ result+=tree[i]; } constantres=result; for(int i=begin;i<end-m+1;i++){ constantres-=tree[i-1]; constantres+=tree[i+m-1]; result+=constantres; } return result; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); ll q,k; cin>>n>>k; vector<ll> lista(n); for(int i=0;i<n;i++){ cin>>lista[i]; } build(lista); cin>>q; for(int i=0;i<q;i++){ short c; cin>>c; if(c==1){ int a; cin>>a; int first=tree[a+n-1]; int b=a; for(int i=0;i<k-1;i++){ int d=b; cin>>b; update(d-1,tree[b-1+n]); } update(b-1,first); } else if(c==2){ int a,b,m; cin>>a>>b>>m; cout<<sum2(m,a,b)<<'\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...