QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#75835#5302. Useful Algorithm275307894aRE 32ms110540kbC++141.9kb2023-02-06 12:45:472023-02-06 12:45:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-06 12:45:50]
  • 评测
  • 测评结果:RE
  • 用时:32ms
  • 内存:110540kb
  • [2023-02-06 12:45:47]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define PB push_back
using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned ll;
using namespace std;const int N=1e5+5,M=16+5,K=2e3+5,mod=924844033,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,m,q,W[N],C[N],D[N],P1[M],P2[M][N],Xi[M][N];ll x,y,z,LA;
ll GA(){LA=0;for(int i=1;i<=m;i++) LA=max(LA,1ll*P1[i]*W[i]);return LA;}
multiset<int> f[M][N];
void CG(int p,int x){
	int i,j,B=(1<<(p+1)/2),S=1<<p;
	Xi[p][x]=-INF;for(i=0;i<B;i++) if(!f[p][x*B+i].empty())Xi[p][x]=max(Xi[p][x],*f[p][x*B+i].rbegin());
	if(x>=S/B/2) x=S/B-1-x;
  	P2[p][x]=0;int Mx=-INF;for(i=1;i<B;i++) {
 		if(!f[p][(S/B-1-x)*B+B-i].empty()) Mx=max(Mx,*f[p][(S/B-1-x)*B+B-i].rbegin());
		if(!f[p][i+x*B].empty()) P2[p][x]=max(P2[p][x],Mx+*f[p][i+x*B].rbegin());
	}
	for(i=0;i<B;i++) if(f[p][i+x*B].size()>=2&&(i+x*B)*2>=S) P2[p][x]=max(P2[p][x],*f[p][i+x*B].rbegin()+*(++f[p][i+x*B].rbegin()));
	P1[p]=0;for(i=0;i<S/B/2;i++) P1[p]=max(P1[p],P2[p][i]);
	Mx=-INF;
	for(i=1;i<S/B;i++){
		Mx=max(Mx,Xi[p][S/B-i]);
		P1[p]=max(P1[p],Mx+Xi[p][i]); 
	}
}
void Ins(int p,int x,int y){f[p][x].insert(y);CG(p,x>>(p+1)/2);}
void Del(int p,int x,int y){f[p][x].erase(f[p][x].LB(y));CG(p,x>>(p+1)/2);}
int main(){
	int i,j;scanf("%d%d%d",&n,&m,&q);for(i=1;i<=m;i++) scanf("%d",&W[i]);for(i=1;i<=n;i++) scanf("%d",&C[i]);for(i=1;i<=n;i++) scanf("%d",&D[i]);
	Me(Xi,-0x3f);for(j=1;j<=m;j++) for(i=1;i<=n;i++) Ins(j,C[i]&((1<<j)-1),D[i]);
	printf("%lld\n",GA());
	while(q--) {
		scanf("%lld%lld%lld",&x,&y,&z);x^=LA;y^=LA;z^=LA;
		for(i=1;i<=m;i++) Del(i,C[x]&((1<<i)-1),D[x]);C[x]=y;D[x]=z;for(i=1;i<=m;i++) Ins(i,C[x]&((1<<i)-1),D[x]);
		printf("%lld\n",GA());
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 32ms
memory: 110540kb

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: