QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#87619#5302. Useful Algorithmzsj6315RE 38ms163064kbC++142.6kb2023-03-13 21:30:482023-03-13 21:30:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-13 21:30:52]
  • 评测
  • 测评结果:RE
  • 用时:38ms
  • 内存:163064kb
  • [2023-03-13 21:30:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define mod 998244353
#define N 100005
#define M 17
#define inf 0x3f3f3f3f
int n,m,Q,w[N],c[N],d[N];
ll lastans;

//DS
multiset<int> A[M][N],B[M][N];
struct SGT1{
	struct SGT{
		int ans,mxa,mxb;
	}t[1<<(M+1)];
	int Max(int a,int b){
		return a<b?b:a;
	}
	void pushup(int nd){
		t[nd].mxa=Max(t[nd<<1].mxa,t[nd<<1|1].mxa);
		t[nd].mxb=Max(t[nd<<1].mxb,t[nd<<1|1].mxb);
		t[nd].ans=Max(Max(t[nd<<1].ans,t[nd<<1|1].ans),t[nd<<1].mxb+t[nd<<1|1].mxa);
	}
	void build(int nd,int l,int r){
		if(l==r){
			t[nd].mxa=t[nd].mxb=t[nd].ans=-inf;
			return;
		}
		else{
			int mid=(l+r)>>1;
			build(nd<<1,l,mid);
			build(nd<<1|1,mid+1,r);
		}
	}
	void updatea(int nd,int l,int r,int x,int aa){
		if(l==r){
			t[nd].mxa=aa;
			return;
		}
		else{
			int mid=(l+r)>>1;
			if(x<=mid)updatea(nd<<1,l,mid,x,aa);
			else  updatea(nd<<1|1,mid+1,r,x,aa);
			pushup(nd);
		}
	}
	void updateb(int nd,int l,int r,int x,int bb){
		if(l==r){
			t[nd].mxb=bb;
			return;
		}
		else{
			int mid=(l+r)>>1;
			if(x<=mid)updateb(nd<<1,l,mid,x,bb);
			else  updateb(nd<<1|1,mid+1,r,x,bb);
			pushup(nd);
		}
	}
	int findmx(){
		return t[1].ans;
	}
}T[M];

void addA(int k,int a,int b,int op){
	if(op==1)A[k][a].insert(b);
	else A[k][a].erase(A[k][a].find(b));
	if(A[k][a].size())T[k].updatea(1,1,(1<<k),a,*A[k][a].rbegin());
	else T[k].updatea(1,1,(1<<k),a,-inf);
}
void addB(int k,int a,int b,int op){
	if(op==1)B[k][a].insert(b);
	else B[k][a].erase(B[k][a].find(b));
	if(B[k][a].size())T[k].updateb(1,1,(1<<k),a,*B[k][a].rbegin());
	else T[k].updateb(1,1,(1<<k),a,-inf);
}
void ins(int a,int b,int op){
	fr(i,1,m){
		int ag=a&((1<<i)-1);
		addA(i,ag+1,b,op),addB(i,(1<<i)-ag,b,op);
	}
}
ll Query(){
	ll res=0;
	fr(i,1,m)res=max(res,1ll*T[i].findmx()*w[i]);
	return res;
}

int readi(){
	int s=0;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')s=s*10+c-'0',c=getchar();
	return s;
}
int readl(){
	ll s=0;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')s=s*10+c-'0',c=getchar();
	return s;
}
int main(){
	n=readi(),m=readi(),Q=readi();
	fr(i,1,m)T[i].build(1,1,(1<<i));
	fr(i,1,m)w[i]=readi();
	fr(i,1,n)c[i]=readi();
	fr(i,1,n)d[i]=readi();
	fr(i,1,n)ins(c[i],d[i],1);
	printf("%lld\n",lastans=Query());
	while(Q--){
		ll x=readl()^lastans,u=readl()^lastans,v=readl()^lastans;
		ins(c[x],d[x],-1);
		ins(c[x]=u,d[x]=v,1);
		printf("%lld\n",lastans=Query());
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 38ms
memory: 163064kb

input:

5 3 3
1 2 4
0 0 1 2 7
10 10 5 3 1
27 24 29
20 16 19
13 8 9

output:

24
16
8
0

result:

ok 4 number(s): "24 16 8 0"

Test #2:

score: -100
Runtime Error

input:

10 3 10
927067928 939794644 439925712
4 7 6 2 4 2 0 7 0 7
207761141 796144622 434713413 101162902 804840394 950218456 666995722 154361380 192946720 522277478
1786020431157499334 1786020431157499335 1786020431397722754
1496424903210009138 1496424903210009136 1496424902707960940
981667153012455665 981...

output:


result: