Submission #1071705

# Submission time Handle Problem Language Result Execution time Memory
1071705 2024-08-23T10:14:14 Z vjudge1 Addk (eJOI21_addk) C++17
100 / 100
1752 ms 8528 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define IShowSpeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=1e5+10;
const int K=405;
const int mod=1e9+7;
const ll inf=1e18+228;
const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};
ll h[N],t[4*N];

void build(ll v, ll tl, ll tr)
{
	if(tl==tr) {
		t[v]=h[tl];
		return;
	}
	ll mid = (tl + tr) >> 1;
	build(v+v,tl,mid);
	build(v+v+1,mid+1,tr);
	t[v]=t[v+v]+t[v+v+1];
}

void upd(ll v, ll tl, ll tr, ll pos)
{
	if(tl==tr) {
		t[v]=h[tl];
		return;
	}
	ll mid = (tl + tr) >> 1;
	if(pos<=mid) upd(v+v,tl,mid,pos);
	else upd(v+v+1,mid+1,tr,pos);
	t[v]=t[v+v]+t[v+v+1];
}

ll get(ll v, ll tl, ll tr, ll l, ll r)
{
	if(l<=tl && tr<=r) return t[v];
	if(r<tl || tr<l) return 0;
	ll mid = (tl + tr) >> 1;
	return get(v+v,tl,mid,l,r)+get(v+v+1,mid+1,tr,l,r);
}


int main()
{
	//freopen("closing.in","r",stdin);
	//freopen("closing.out","w",stdout);
	IShowSpeed
	ll tt=1;
	//cin>>tt;
	for(int cas=1;cas<=tt;cas++)
	{
		//for(int i=0;i<=K;i++) bl[i]={0,0};
		//for(int i=1;i<=N-10;i++) h[i]=0;
		//cout<<"Case "<<cas<<":\n";
		ll n,k,q;
		cin>>n>>k;
		for(int i=1;i<=n;i++) cin>>h[i];
		build(1,1,n);
		cin>>q;
		while(q--)
		{
			ll tp;
			cin>>tp;
			if(tp==1) {
				vector<ll>v,lol;
				for(int i=1;i<=k;i++) {
					ll x;
					cin>>x;
					v.pb(x);
					lol.pb(h[x]);
				}
				for(int i=0;i<k;i++)
				{
					if(i==k-1) {
						h[v[i]]=lol[0];
					}
					else {
						h[v[i]]=lol[i+1];
					}
					upd(1,1,n,v[i]);
				}
			}
			else {
				ll l,r,m,s;
				cin>>l>>r>>m;
				s=get(1,1,n,l,r)*m;
				for(int i=l,x=m-1;x>0;i++,x--) s-=h[i]*x;
				for(int i=r,x=m-1;x>0;i--,x--) s-=h[i]*x;
				cout<<s<<"\n";
			}
		}
	}
}
/*
8 3
7 2 5 1 9 3 4 6
3
2 2 7 4
1 2 5 8
2 2 7 3
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 520 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 8 ms 576 KB Output is correct
6 Correct 12 ms 604 KB Output is correct
7 Correct 34 ms 600 KB Output is correct
8 Correct 22 ms 600 KB Output is correct
9 Correct 87 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 249 ms 2880 KB Output is correct
2 Correct 354 ms 3216 KB Output is correct
3 Correct 648 ms 3532 KB Output is correct
4 Correct 1200 ms 4128 KB Output is correct
5 Correct 1752 ms 4756 KB Output is correct
6 Correct 1544 ms 4692 KB Output is correct
7 Correct 1358 ms 4776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 388 ms 3372 KB Output is correct
2 Correct 1161 ms 6708 KB Output is correct
3 Correct 196 ms 8528 KB Output is correct
4 Correct 1685 ms 7492 KB Output is correct