QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#75850#5302. Useful Algorithm275307894aTL 50ms110816kbC++141.8kb2023-02-06 13:35:222023-02-06 13:35:25

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 13:35:25]
  • 评测
  • 测评结果:TL
  • 用时:50ms
  • 内存:110816kb
  • [2023-02-06 13:35:22]
  • 提交

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/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-i-x*B].empty()) Mx=max(Mx,*f[p][S-i-x*B].rbegin());
		if(!f[p][i+x*B].empty()) P2[p][x]=max(P2[p][x],Mx+*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/2);}
void Del(int p,int x,int y){f[p][x].erase(f[p][x].LB(y));CG(p,x>>p/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;cerr<<x<<' '<<y<<' '<<z<<'\n';
		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());
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 20ms
memory: 110544kb

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: 0
Accepted
time: 24ms
memory: 110300kb

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:

1786020431157499328
1496424903210009136
981667153012455664
981667153012455664
817082674424719944
1083086338546577104
1186096888772143904
1186096888772143904
1186096888772143904
768437095486384888
848350340146561056

result:

ok 11 numbers

Test #3:

score: 0
Accepted
time: 30ms
memory: 110396kb

input:

100 5 100
90634477 839424973 368714032 715789796 976912516
14 25 23 26 21 6 18 25 13 16 1 11 6 19 23 30 20 16 9 5 15 14 18 25 20 21 16 20 1 17 5 20 29 21 23 30 14 21 16 25 0 10 30 15 5 18 20 15 16 14 8 13 25 3 19 1 28 25 20 4 25 31 13 22 21 5 4 27 24 0 3 25 14 9 25 27 6 31 23 17 22 0 20 14 20 20 10 ...

output:

1948430837606303184
1925731571920031664
1925731571920031664
1918610389626725016
1918610389626725016
1912989537852540976
1912989537852540976
1943875008041762216
1880564337285514332
1872790752298860048
1872790752298860048
1872790752298860048
1860886514497440896
1840781733071162176
1840781733071162176
...

result:

ok 101 numbers

Test #4:

score: 0
Accepted
time: 17ms
memory: 110664kb

input:

200 10 200
686225366 625898088 889833199 755030970 349397678 32982490 273727441 273558302 259659090 988780410
764 308 833 222 75 641 80 22 298 315 295 545 284 459 960 884 566 848 491 631 930 542 972 519 28 570 603 1013 120 480 482 900 538 1022 131 1007 380 694 176 737 172 480 945 763 459 389 34 593 ...

output:

1976367332381717700
1976367332381717700
1976367332381717700
1919420428070056950
1896682288410976680
1851396613326110610
1848014565081016770
1848014565081016770
1844553517236285570
1844515090263211740
1839357062871524190
1835762131192937760
1831576340926210500
1820368528821786240
1813214370325218480
...

result:

ok 201 numbers

Test #5:

score: 0
Accepted
time: 50ms
memory: 110816kb

input:

1000 10 1000
634018763 100170818 567660357 254302610 840960097 802296108 283969325 368515437 441547602 397000462
612 405 890 783 513 253 461 140 625 8 464 401 1011 271 27 355 794 222 734 246 846 310 88 374 330 844 353 706 415 584 993 492 816 456 342 954 436 90 339 808 56 517 1019 996 922 705 138 209...

output:

1681866301913143852
1681866301913143852
1680999430153635088
1676312717485049238
1674196766011546180
1673931937585479716
1673454371483675162
1672867243418513254
1672867243418513254
1672867243418513254
1672669252819036156
1671478710655473838
1671478710655473838
1665328148837561252
1665328148837561252
...

result:

ok 1001 numbers

Test #6:

score: -100
Time Limit Exceeded

input:

100000 16 100000
427137788 524903900 786287591 199228679 318168922 101722889 789810886 488566259 846829249 575667147 767258103 63802528 801156446 519047646 781774765 555029219
4621 48336 12816 52645 55523 30344 27584 3940 41894 60346 15947 30387 19024 31860 33462 13493 28048 58004 12794 7590 22857 6...

output:

1693617423394106504
1693589359472794644
1693492085043791263
1693480115112356648
1693470840638421600
1693453134285654259
1693444900564866232
1693444900564866232
1693416918785991525
1693393685178715961
1693387980090065448
1693380527992674248
1693380527992674248
1693380527992674248
1693380527992674248
...

result: