QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#385274#5441. Quartz Collectionwsc2008WA 1ms4068kbC++142.1kb2024-04-10 17:09:472024-04-10 17:09:47

Judging History

你现在查看的是最新测评结果

  • [2024-04-10 17:09:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4068kb
  • [2024-04-10 17:09:47]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
inline ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=4e5+9;
mt19937 rnd(time(0));
ll n,m,a[N],b[N];
struct EquilibriumTree{
	ll rt,rd[N],val[N],tot,sum[4][N],sz[N],ls[N],rs[N];
	ll Nd(ll v){
		ll x=++tot;
		rd[x]=rnd(),sz[x]=1,val[x]=v;
		sum[0][x]=val[x];
		return x;
	}
	void Pushup(ll x){
		sz[x]=sz[ls[x]]+sz[rs[x]]+1;
		rep(i,0,3)sum[x][i]=(sum[ls[x]][i]+sum[rs[x]][((i-sz[ls[x]]-1)%4+4)%4]+(sz[x]%4==i)*val[x]);
	}
	void Split(ll x,ll v,ll&L,ll&R){
		if(!x)return L=0,R=0,void();
		if(val[x]<=v)L=x,Split(rs[x],v,rs[x],R);
		else R=x,Split(ls[x],v,L,ls[x]);
		Pushup(x);
	}
	ll Merge(ll x,ll y){
		if(!x||!y)return x|y;
		if(rd[x]<rd[y]){
			rs[x]=Merge(rs[x],y);
			Pushup(x);
			return x;
		}
		else {
			ls[y]=Merge(x,ls[y]);
			Pushup(y);
			return y;
		}
	}
	void Ins(ll x){
		ll L=0,R=0;
		Split(rt,x,L,R);
		rt=Merge(Merge(L,Nd(x)),R);
	}
	void Del(ll x){
		ll L=0,R=0,p=0;
		Split(rt,x-1,L,R);
		Split(R,x,p,R);
		rt=Merge(Merge(L,Merge(ls[p],rs[p])),R);
	}
}T1,T2;
ll S;
void calc(){
	ll res=S+T1.sum[T1.rt][0]+T1.sum[T1.rt][1];
	if(T1.sz[T1.rt]&1)res+=T2.sum[T2.rt][0]+T2.sum[T2.rt][3];
	else res+=T2.sum[T2.rt][1]+T2.sum[T2.rt][2];
	write(res),putchar('\n');
}
bool Med;
int main(){
	cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
	n=read(),m=read();
	rep(i,1,n)a[i]=read(),b[i]=read(),S+=b[i];
	rep(i,1,n){
		ll d=b[i]-a[i];
		if(d>=0)T1.Ins(-d);
		else T2.Ins(-d);
	}
	calc();
	while(m--){
		ll i=read(),x=read(),y=read();
		S-=a[i];
		ll d=b[i]-a[i];
		if(d>=0)T1.Del(-d);
		else T2.Del(-d);
		a[i]=x,b[i]=y;
		d=b[i]-a[i];
		if(d>=0)T1.Ins(-d);
		else T2.Ins(-d);
		calc();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4068kb

input:

4 5
2 4
5 7
1 7
2 1
4 5 2
1 6 2
4 4 3
2 1 3
3 6 6

output:

11
9
6
8
19
15

result:

wrong answer 1st numbers differ - expected: '13', found: '11'