Submission #476962

#TimeUsernameProblemLanguageResultExecution timeMemory
476962David_MAddk (eJOI21_addk)C++14
100 / 100
236 ms10464 KiB
#include <bits/stdc++.h> #define ll long long #define F first #define S second #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define FF first.first #define FS first.second #define pb push_back using namespace std; const ll N=1000006, INF=1e18, P=998244353; ll q=1, n, m, x, y, z, l, r, k, t, a[N], b[N], f[N], ans, o, u, Ans[N]; pair<ll, ll> T[N]; void upd(int x, ll val, int v=1, int L=1, int R=n){ int M=L+R>>1; if(L==R){T[v]={val,val*x};return;} if(x<=M)upd(x, val, v<<1, L, M); else upd(x, val, v<<1|1, M+1, R); T[v]={T[v<<1].F+T[v<<1|1].F, T[v<<1].S+T[v<<1|1].S}; } ll get(int l, int r, int v=1, int L=1, int R=n){ if(R<l || L>r)return 0; if(L>=l && R<=r)return T[v].S-T[v].F*(l-1); int M=L+R>>1; return get(l, r, v<<1, L, M)+get(l, r, v<<1|1, M+1, R); } main(){ios_base::sync_with_stdio(false), cin.tie(0); cin>>n>>k; for (int i=1; i<=n; i++)cin>>a[i],upd(i,a[i]); cin>>q; b[k]=n+1; while(q--){ cin>>t; if(t==1){ for (int i=0; i<k; i++)cin>>b[i];a[n+1]=a[b[0]]; for (int i=0; i<k; i++)a[b[i]]=a[b[i+1]],upd(b[i],a[b[i]]); }else{ cin>>l>>r>>m; //cout<<l<<" "<<r<<'\n'<<min(r-m+2, l+m)<<" "<<r<<'\n'<<max(r-m+2, l+m)<<" "<<r<<'\n'; cout<<get(l,r)-get(min(r-m+2, l+m),r)-get(max(r-m+2, l+m), r)<<'\n'; } } }

Compilation message (stderr)

Main.cpp: In function 'void upd(int, long long int, int, int, int)':
Main.cpp:17:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   17 |     int M=L+R>>1;
      |           ~^~
Main.cpp: In function 'long long int get(int, int, int, int, int)':
Main.cpp:27:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |     int M=L+R>>1;
      |           ~^~
Main.cpp: At global scope:
Main.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   33 | main(){ios_base::sync_with_stdio(false), cin.tie(0);
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:43:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   43 |             for (int i=0; i<k; i++)cin>>b[i];a[n+1]=a[b[0]];
      |             ^~~
Main.cpp:43:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   43 |             for (int i=0; i<k; i++)cin>>b[i];a[n+1]=a[b[0]];
      |                                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...