Submission #965277

#TimeUsernameProblemLanguageResultExecution timeMemory
965277modwweAddk (eJOI21_addk)C++17
100 / 100
228 ms12064 KiB
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") #include<bits/stdc++.h> #define int long long //#define ll long long #define down cout<<'\n'; #define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); #define modwwe int t;cin>>t; while(t--) #define bit(i,j) (i>>j&1) #define sobit(a) __builtin_popcountll(a) #define task "test" #define fin(x) freopen(x".inp","r",stdin) #define fou(x) freopen(x".out","w",stdout) #define pb push_back #define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms"; using namespace std; void ngha(); const int mod2=1e9+7; const int mod1=998244353; struct ib { int a; int b; }; struct icd { int a,b; }; struct ic { int a,b,c; }; struct id { int a,b,c,d; }; struct ie { int a,b,c, d,e; }; int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l; int i,s10,s12; int el=29; main() { //#ifndef ONLINE_JUDGE // fin(task),fou(task); //#endif NHP //modwwe // cin>>res; ngha(),down checktime } ib t[400001]; int a[100001]; int b[11]; void build(int node,int l,int r) { if(l==r) { t[node].a=a[l]; t[node].b=a[l]*l; return; } int mid=l+r>>1; build(node<<1,l,mid); build(node<<1|1,mid+1,r); t[node].a=t[node<<1].a+t[node<<1|1].a; t[node].b=t[node<<1].b+t[node<<1|1].b; } void upd(int node,int l,int r,int l1,int r1,int k) { if(l>r1||r<l1) return; if(l>=l1&&r<=r1) { t[node].a=k; t[node].b=k*l; return; } int mid=l+r>>1; upd(node<<1,l,mid,l1,r1,k); upd(node<<1|1,mid+1,r,l1,r1,k); t[node].a=t[node<<1].a+t[node<<1|1].a; t[node].b=t[node<<1].b+t[node<<1|1].b; } ib get(int node,int l,int r,int l1,int r1) { if(l1>r1) return {0,0}; if(l>r1||r<l1) return {0,0}; if(l>=l1&&r<=r1) return {t[node].a,t[node].b}; int mid=l+r>>1; ib xa=get(node<<1,l,mid,l1,r1); ib xb=get(node<<1|1,mid+1,r,l1,r1); return {xa.a+xb.a,xa.b+xb.b}; } void ngha() { cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; build(1,1,n); cin>>m; while(m--) { cin>>dem; if(dem==1) { for(int i=1;i<=k;i++) cin>>b[i]; s2=a[b[1]]; for(int i=2;i<=k;i++) { upd(1,1,n,b[i-1],b[i-1],a[b[i]]); a[b[i-1]]=a[b[i]]; } upd(1,1,n,b[k],b[k],s2); a[b[k]]=s2; } else { cin>>s1>>s4>>mx; s2=s1+mx-1; s3=s4-mx+1; if(s2>s3) swap(s2,s3); s5=0; ib sx=get(1,1,n,s1,s2-1); s5=sx.b-sx.a*(s1-1); sx=get(1,1,n,s2,s3); s6=0; s6+=sx.a*(s2-s1+1); sx=get(1,1,n,s3+1,s4); s7=0; s7+=sx.a*(s4+1)-sx.b; cout<<s5+s6+s7; down } } }

Compilation message (stderr)

Main.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main()
      | ^~~~
Main.cpp: In function 'void build(long long int, long long int, long long int)':
Main.cpp:66:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 |  int mid=l+r>>1;
      |          ~^~
Main.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int, long long int)':
Main.cpp:81:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   81 |       int mid=l+r>>1;
      |               ~^~
Main.cpp: In function 'ib get(long long int, long long int, long long int, long long int, long long int)':
Main.cpp:91:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   91 |  int mid=l+r>>1;
      |          ~^~
Main.cpp: In function 'void ngha()':
Main.cpp:99:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   99 |     for(int i=1;i<=n;i++)
      |     ^~~
Main.cpp:101:10: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  101 |          build(1,1,n);
      |          ^~~~~
Main.cpp:108:8: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  108 |        for(int i=1;i<=k;i++)
      |        ^~~
Main.cpp:110:14: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  110 |              s2=a[b[1]];
      |              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...