Submission #475449

# Submission time Handle Problem Language Result Execution time Memory
475449 2021-09-22T14:10:18 Z mosiashvililuka Addk (eJOI21_addk) C++14
0 / 100
63 ms 3644 KB
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,tes,t,k,f[100009],fen[100009],fen2[100009],pas,tp,g[100009],l,r,m;
void upd(long long q, long long w){
	while(q<=100002){
		fen[q]+=w;
		q=q+(q&(-q));
	}
}
void upd2(long long q, long long w){
	while(q<=100002){
		fen2[q]+=w;
		q=q+(q&(-q));
	}
}
long long read(long long q){
	long long sm=0;
	while(q>0){
		sm+=fen[q];
		q=q-(q&(-q));
	}
	return sm;
}
long long read2(long long q){
	long long sm=0;
	while(q>0){
		sm+=fen2[q];
		q=q-(q&(-q));
	}
	return sm;
}
long long calc(long long q, long long w){
	long long sm=0;
	sm=read2(w)-read2(q-1);sm-=(read(w)-read(q-1))*(q-1);
	return sm;
}
long long calc2(long long q, long long w){
	long long sm=0;
	sm=(read(w)-read(q-1))*(w-q+2)-calc(q,w);
	return sm;
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>k;
	for(i=1; i<=a; i++){
		cin>>f[i];
		upd(i,f[i]);
		upd2(i,i*f[i]);
	}
	cin>>tes;
	for(t=1; t<=tes; t++){
		cin>>tp;
		if(tp==2){
			cin>>l>>r>>m;pas=0;
			pas+=calc(l,min((l+r)/2,l+m-1));i=min((l+r)/2,l+m-1)+1;
			pas+=calc2(max((l+r)/2+1,r-m+1),r);j=max((l+r)/2+1,r-m+1)-1;
			if(i>=j){
				pas+=read(j)-read(i-1);
			}
			cout<<pas<<"\n";
		}else{
			for(i=1; i<=k; i++){
				cin>>g[i];
			}
			for(i=1; i<=k; i++){
				if(i==k) j=1; else j=i+1;
				upd(g[i],f[g[j]]-f[g[i]]);
				upd2(g[i],(f[g[j]]-f[g[i]])*g[i]);
			}
			for(i=1; i<k; i++) swap(f[g[i]],f[g[i+1]]);
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 3644 KB Output isn't correct
2 Halted 0 ms 0 KB -