Submission #775175

# Submission time Handle Problem Language Result Execution time Memory
775175 2023-07-06T08:31:06 Z tranminhthang2907 Addk (eJOI21_addk) C++14
0 / 100
672 ms 2768 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef vector<vi> vvi;
int n,k;
template<typename IteratorType> void print(IteratorType first,IteratorType last){
	while(first != last){
		cout<<*first<<' ';
		first++;
	}
}
vector<ll> st,arr;
void build(int id,int l,int r){
	if(l==r){
		st[id] = arr[l];
		return;
	}
	int mid = (l+r)>>1;
	build(2*id,l,mid);
	build(2*id+1,mid+1,r);
	st[id] = st[2*id] + st[2*id+1];
}
void update(int id,int l,int r,int i,ll val){
	if(l>i || i>r) return;
	if(l==r){
		st[id] = val;
		return;
	}
	int mid = (l+r)/2;
	update(2*id,l,mid,i,val);
	update(2*id+1,mid+1,r,i,val);
	st[id] = (st[2*id] + st[2*id+1]);
}
ll query(int id,int l,int r,int u,int v){
	if(l>v || r<u || l>r) return 0;
	if(l>=u && r<=v){
		return st[id];
	}
	int mid = (l+r)/2;
	ll a = query(2*id,l,mid,u,v);
	ll b = query(2*id+1,mid+1,r,u,v);
	return a+b;
}
signed main(){
	cin>>n>>k;
	arr.resize(n+1); st.resize(4*(n+1));
	for(int i=1;i<=n;++i){
		cin>>arr[i];
	}
	build(1,1,n);
	vector<int> change(k+1);
	int q,l,r,m; cin>>q;
	while(q-->0){
		int cmd; cin>>cmd;
		if(cmd==1){
			for(int i=0;i<k;++i){
				cin>>change[i];
			}
			ll temp = arr[change[0]];
			for(int i=0;i<k-1;++i){
				arr[change[i]] = arr[change[i+1]];
				update(1,1,n,change[i],arr[change[i]]);
			}
			arr[change[k-1]] = temp;
			update(1,1,n,change[k-1],arr[change[k-1]]);
		}
		else{
			cin>>l>>r>>m;
			ll res = 0, h = query(1,1,n,l,r);
			int p1 = l, p2 = r;
			while(p1<=p2 && p2 - l +1 >= m){
				res += h;
				h -= arr[p1] + arr[p2];
				p1++, p2--;
			}
			cout<<res<<'\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 154 ms 1304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 672 ms 2768 KB Output isn't correct
2 Halted 0 ms 0 KB -