QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67226#5098. 第一代图灵机crazy_sea0 501ms62076kbC++141.9kb2022-12-10 10:50:482022-12-10 10:50:52

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-10 10:50:52]
  • Judged
  • Verdict: 0
  • Time: 501ms
  • Memory: 62076kb
  • [2022-12-10 10:50:48]
  • Submitted

answer

#include<cstdio>
#include<algorithm>
#include<set>
#define ll long long
#define upb upper_bound
#define ls (now<<1)
#define rs (now<<1|1)
#define mid ((l+r)>>1)
using namespace std;
const int N=8e5+10;
int n,m,Q;
ll s[N],tr[N];
int mx[N],lst[N],a[N],c[N],L,R,K;
ll getans(int l,int r,int now,int c)
{
	if(l==r) return s[l]-s[max(lst[l],c)];
	if(mx[ls]>c) return max(getans(l,mid,ls,c),tr[rs]);
	else return max(getans(mid+1,r,rs,c),s[mid]-s[c]);
}
void init(int w,int now)
{
	tr[now]=s[w]-s[w-1];
	mx[now]=lst[w];
}
void update(int l,int r,int now)
{
	tr[now]=max(tr[ls],getans(mid+1,r,rs,max(l-1,mx[ls])));
	mx[now]=max(mx[ls],mx[rs]);
}
void build(int l,int r,int now)
{
	if(l==r) {init(l,now);return;}
	build(l,mid,ls),build(mid+1,r,rs);
	update(l,r,now);
}
void modify(int l,int r,int now,int w)
{
	if(l==r) {init(l,now);return;}
	if(w<=mid) modify(l,mid,ls,w);
	else modify(mid+1,r,rs,w);
	update(l,r,now);
}
ll query(int l,int r,int now)
{
	if(l>R||r<L) return 0;
	if(L<=l&&r<=R)
	{
		K=max(K,mx[now]);
		return getans(l,r,now,K);
	}
	return max(query(l,mid,ls),query(mid+1,r,rs));
}
set<int> t[N];
int main()
{
	scanf("%d%d%d",&n,&m,&Q);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),s[i]=s[i-1]+a[i];
	for(int i=1;i<=n;i++) scanf("%d",&c[i]),t[c[i]].insert(i);
	for(int i=1;i<=m;i++) t[i].insert(0),t[i].insert(n+1);
	for(int i=1;i<=n;i++) lst[i]=*(--t[c[i]].upb(i-1));
	build(1,n,1);
	int x,y,op;
	while(Q--)
	{
		scanf("%d",&op);
		if(op==1)
		{
			scanf("%d%d",&L,&R),K=L-1;
			printf("%lld\n",query(1,n,1));
		}
		else
		{
			scanf("%d%d",&x,&y);
			if(c[x]==y) continue;
			int z=c[x],w1=*t[z].upb(x),w2=*t[y].upb(x),w3=*(--t[y].upb(x));
			c[x]=y,t[z].erase(x),t[y].insert(x);
			if(w1!=n+1) lst[w1]=lst[x],modify(1,n,1,w1);
			if(w2!=n+1) lst[w2]=x,modify(1,n,1,w2);
			lst[x]=w3,modify(1,n,1,x);
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 24ms
memory: 41100kb

input:

5000 200 5000
2315 3433 1793 4621 4627 4561 289 4399 3822 2392 392 4581 2643 2441 4572 4649 2981 3094 4206 2057 761 2516 2849 3509 3033 658 4965 3316 3269 4284 4961 753 1187 2515 1377 1725 4743 4761 3823 3464 4859 989 2401 953 875 1481 2181 103 2067 2625 3296 4721 61 3843 1607 997 4385 1284 4299 441...

output:

428064
136303
33803
294132
667560
10703
126242
133456
226461
47758
65135
136303
191744
54584
22795
85513
127706
176412
33448
144071
31813
587282
2491
39374
648685
467419
437547
36751
28882
60848
26397
36111
42726
84987
384889
52918
61542
130905
19512
26617
986501
963740
65135
52175
114253
14564
3478...

result:

wrong answer 1st lines differ - expected: '118571', found: '428064'

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 501ms
memory: 60016kb

input:

200000 10 200000
55651 97298 108697 86619 60721 199951 10610 162267 154301 138848 39191 18605 101369 57073 34977 101576 71252 143401 89587 160521 166491 38442 150761 35579 25571 121311 38033 38483 144639 41401 179161 54872 157905 137601 46863 187656 171901 43715 41036 150741 69057 102031 130561 4772...

output:

242546
802019
229042
323913
729415
1627157
256863
217872
203242
1503001
311029
140161
516607
1047265
158540
19201
236910
426385
532646
473600
413874
604105
246378
150601
301985
325155
184001
145708
438050
314732
5370489
533461
615003
420311
55121
777515
634189
66608
603604
565801
310703
248417
39340...

result:

wrong answer 1st lines differ - expected: '1232419', found: '242546'

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 308ms
memory: 62076kb

input:

200000 20000 200000
30681 32496 35471 48191 159123 69792 120915 150673 187226 158493 36275 26856 107976 124777 145229 69745 183961 14497 144808 153612 185893 137681 66417 46802 19345 113322 168046 128149 191001 135433 13201 139214 59489 81178 42343 163158 110121 119201 97501 53079 158755 192241 1132...

output:

4243072171
40482194
30554521
2082574765
390788837
56203008
1920624457
18795858
511066957
18562653
125441385
11314060
922532359
131381006
1497576554
1880621346
1499148856
1179797825
3144714126
121834492
407987493
135097633
1222673668
145723094
374831370
37815948
117859830
165942412
943937033
27002806...

result:

wrong answer 1st lines differ - expected: '46702944', found: '4243072171'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%