# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
477690 |
2021-10-03T06:13:12 Z |
luka1234 |
Addk (eJOI21_addk) |
C++17 |
|
222 ms |
3584 KB |
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
int n,q,q1;
int t1[400001];
int t2[100001];
int a[100001];
void build(int v,int tl,int tr){
if(tl==tr){
t1[v]=a[tl];
t2[v]=a[tl]*tl;
}
else{
int m=(tl+tr)/2;
build(2*v,tl,m);
build(2*v+1,m+1,tr);
t1[v]=t1[2*v]+t1[2*v+1];
t2[v]=t2[2*v]+t2[2*v+1];
}
}
pair<int,int> get(int v,int tl,int tr,int l,int r){
if(tl==l&&tr==r){
return {t1[v],t2[v]};
}
int m=(tl+tr)/2;
if(r<=m){
return get(2*v,tl,m,l,r);
}
else{
if(l>m){
return get(2*v+1,m+1,tr,l,r);
}
else{
pair<int,int> pir=get(2*v,tl,m,l,m);
pair<int,int> meo=get(2*v+1,m+1,tr,m+1,r);
pair<int,int> mes;
mes.ff=pir.ff+meo.ff;
mes.ss=pir.ss+meo.ss;
return mes;
}
}
}
void update(int v,int tl,int tr,int x,int p){
if(tl==tr){
t1[v]=x;
t2[v]=p*x;
}
else{
int m=(tl+tr)/2;
if(p<=m)
update(2*v,tl,m,x,p);
else
update(2*v+1,m+1,tr,x,p);
t1[v]=t1[2*v]+t1[2*v+1];
t2[v]=t2[2*v]+t2[2*v+1];
}
}
int main(){
cin>>n>>q;
for(int k=1;k<=n;k++)
cin>>a[k];
build(1,1,n);
cin>>q1;
while(q1--){
int x;
cin>>x;
if(x==2){
int l,r,m;
cin>>l>>r>>m;
if(m==1||m==(r-l+1)){
int ans=get(1,1,n,l,r).ff;
cout<<ans<<"\n";
continue;
}
int v=(r-l+1)/2+1;
int m1;
if(m<=v){
m1=m-1;
if(((r-l+1)%2==0)&&(m==v))
m1--;
}
else{
m1=(r-l+1)-m;
}
int pir=0,meo=0,mes=0;
pair<int,int> vv=get(1,1,n,l,l+m1-1);
int f=l-1;
pir=vv.ss-vv.ff*f;
vv=get(1,1,n,r-m1+1,r);
f=r+1;
meo=vv.ff*f-vv.ss;
vv=get(1,1,n,l+m1,r-m1);
int fff=m1+1;
mes=vv.ff*fff;
cout<<pir+meo+mes<<"\n";
}
else{
int b[q+1];
for(int k=1;k<=q;k++)
cin>>b[k];
int f=b[1];
for(int k=1;k<q;k++){
a[b[k]]=a[b[k+1]];
update(1,1,n,a[b[k+1]],b[k]);
}
a[b[q]]=f;
update(1,1,n,f,b[q]);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
71 ms |
1536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
222 ms |
3584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |