QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#67307#5098. 第一代图灵机crazy_sea0 904ms71936kbC++142.2kb2022-12-10 11:39:532022-12-10 11:41:00

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 11:41:00]
  • Judged
  • Verdict: 0
  • Time: 904ms
  • Memory: 71936kb
  • [2022-12-10 11:39:53]
  • 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;
struct seg
{
	ll s[N],tr[N],tr1[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),tr1[now]);
		else return max(getans(mid+1,r,rs,c),s[mid]-s[c]);
	}
	void init(int w,int now)
	{
		tr[now]=s[w]-s[lst[w]];
		mx[now]=lst[w];
	}
	void update(int l,int r,int now)
	{
		tr1[now]=getans(mid+1,r,rs,mx[ls]);
		tr[now]=max(tr[ls],tr1[now]);
		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>>2];
	void modify(int x,int y)
	{
		if(c[x]==y) return;
		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);
	}
	void init()
	{
		for(int i=1;i<=n;i++) s[i]=s[i-1]+a[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);
	}
	ll query(int l,int r)
	{
		L=l,R=r,K=l-1;
		return query(1,n,1);
	}
}t1,t2;
int main()
{
	int x,y,op;
	scanf("%d%d%d",&n,&m,&Q);
	for(int i=1;i<=n;i++) scanf("%d",&x),t1.a[i]=t2.a[n-i+1]=x;
	for(int i=1;i<=n;i++) scanf("%d",&x),t1.c[i]=t2.c[n-i+1]=x;
	t1.init(),t2.init();
	while(Q--)
	{
		scanf("%d",&op);
		if(op==1) scanf("%d%d",&x,&y),
			printf("%lld\n",max(t1.query(x,y),t2.query(n-y+1,n-x+1)));
		else scanf("%d%d",&x,&y),t1.modify(x,y),t2.modify(n-x+1,y);
	}
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 11ms
memory: 28860kb

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
44845
294132
667560
53615
126242
803350
226461
65997
65135
136303
268342
661079
66425
88213
378494
176412
277635
144071
69433
587282
533499
39374
648685
467419
437547
58213
49370
75784
54682
70394
42726
1186202
384889
364365
61542
130905
359998
60947
986501
963740
65135
136904
114253
1...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 904ms
memory: 67080kb

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:

394441
802019
229042
323913
729415
1627157
2153200
592360
203242
1503001
577109
322147
678015
7176654
326113
1440417
378168
655664
1788996
473600
497166
673652
246378
319691
301985
522717
2917932
1507124
438050
314732
5370489
548820
780325
775223
627863
777515
634189
3403081
831091
565801
426251
999...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 584ms
memory: 71936kb

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
1460479167
30554521
2082574765
750333254
967303100
1920624457
393724087
1241035093
38654027
125441385
547086620
937474897
619521997
1497576554
1880621346
1499148856
1179797825
3144714126
316501822
407987493
413184755
1565209203
1694960013
374831370
376018064
306512764
165942412
943937033
...

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%