Submission #914208

#TimeUsernameProblemLanguageResultExecution timeMemory
914208PieArmyAddk (eJOI21_addk)C++17
100 / 100
212 ms12672 KiB
#include <bits/stdc++.h> using namespace std; template<typename X, typename Y> istream& operator>>(istream& in, pair<X,Y> &pr) {return in>>pr.first>>pr.second;} template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr) {return os<<pr.first<<" "<<pr.second;} template<typename X> istream& operator>>(istream& in, vector<X> &arr) {for(auto &it : arr) in>>it; return in;} template<typename X> ostream& operator<<(ostream& os, vector<X> arr) {for(auto &it : arr) os<<it<<" "; return os;} mt19937 rng(chrono::high_resolution_clock().now().time_since_epoch().count()); typedef long long ll; #define yem(re) (1ll<<(ll(re))) #define endl '\n' #define pb push_back #define int ll #define mid ((left+right)/2) #define L(emanuelLasker,joseRaulCapablanca,anatolyKarpov) for(int emanuelLasker=(joseRaulCapablanca);emanuelLasker<=(anatolyKarpov);emanuelLasker++) #define R(magnusCarlsen,paulMorphy,bobbyFischer) for(int magnusCarlsen=(paulMorphy);magnusCarlsen>=(bobbyFischer);magnusCarlsen--) #define cint(vladimirKramnik) int vladimirKramnik;cin>>vladimirKramnik #define inf (2000000000000000005) #define sc second #define fr first #define Bismillahirrahmanirrahim ios_base::sync_with_stdio(false);cin.tie(NULL); #define cinarr(mikhailTal) for(auto &garryKasparov:mikhailTal)cin>>garryKasparov; #define all(mustafaKemalAtaturk) mustafaKemalAtaturk.begin(),mustafaKemalAtaturk.end() vector<int>arr; struct Seg{ int n; vector<int>tree; Seg(int N){ n=N; tree.resize(n*4); } void build(bool coklu=false,int node=1,int left=0,int right=-1){ if(right==-1)right=n-1; if(left==right){ tree[node]=arr[left]; if(coklu)tree[node]*=left+1; return; } build(coklu,node*2,left,mid); build(coklu,node*2+1,mid+1,right); tree[node]=tree[node*2]+tree[node*2+1]; return; } void update(int tar,int x,bool coklu=false){ int node=1,left=0,right=n-1; while(left<right){ tree[node]+=x-arr[tar]; if(coklu)tree[node]+=(x-arr[tar])*tar; node*=2; if(tar>mid){left=mid+1;node++;} else right=mid; } tree[node]=x; if(coklu)tree[node]*=tar+1; return; } int query(int l,int r,int node=1,int left=0,int right=-1){ if(right==-1)right=n-1; if(l>r)return 0; if(l>right||r<left)return 0; if(l<=left&&r>=right)return tree[node]; return query(l,r,node*2,left,mid)+query(l,r,node*2+1,mid+1,right); } }; void code(){ int n,k;cin>>n>>k; arr.resize(n);cin>>arr; Seg B(n); Seg C(n); B.build(); C.build(true); int q;cin>>q; while(q--){ int typ;cin>>typ; if(typ==1){ int up[k];cinarr(up); for(int &x:up)x--; for(int i=0;i<k-1;i++){ B.update(up[i],arr[up[i+1]]); C.update(up[i],arr[up[i+1]],true); } B.update(up[k-1],arr[up[0]]); C.update(up[k-1],arr[up[0]],true); int bas=arr[up[0]]; for(int i=0;i<k-1;i++) arr[up[i]]=arr[up[i+1]]; arr[up[k-1]]=bas; } else{ int l,r,m;cin>>l>>r>>m; l--;r--; if(r-l+3>=m*2){ int ans=B.query(l+m-1,r-m+1)*m; if(m==1){cout<<ans<<endl;continue;} ans+=C.query(l,l+m-2)-(B.query(l,l+m-2)*l); ans+=(B.query(r-m+2,r)*(r+2))-C.query(r-m+2,r); cout<<ans<<endl; } else{ int ans=B.query(r-m+1,l+m-1)*(r-l+2-m); if(m==1||m==r-l+1){cout<<ans<<endl;continue;} ans+=C.query(l,r-m)-(B.query(l,r-m)*l); ans+=(B.query(l+m,r)*(r+2))-C.query(l+m,r); cout<<ans<<endl; } } } } int32_t main(){ Bismillahirrahmanirrahim int t=1; bool usaco=0; if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} if(!t)cin>>t; while(t--){code();cout<<endl;} return 0; }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:116:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |     if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |               ~~~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:116:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |     if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...