QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#67322#5098. 第一代图灵机crazy_sea0 986ms71660kbC++142.2kb2022-12-10 11:46:492022-12-10 11:46: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 11:46:52]
  • Judged
  • Verdict: 0
  • Time: 986ms
  • Memory: 71660kb
  • [2022-12-10 11:46:49]
  • 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)
		{
			ll s=getans(l,r,now,K);
			K=max(K,mx[now]);
			return s;
		}
		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: 7ms
memory: 27112kb

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
402328
667560
628229
631912
803350
226461
210951
222019
136303
906095
661079
96641
1189273
818244
304232
277635
144071
1253911
587282
533499
39374
648685
467419
437547
102096
244579
294828
501619
83427
42726
1186202
459079
364365
701570
466602
359998
60947
1770070
1562495
182379
...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 986ms
memory: 67076kb

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:

540380
1425989
871101
323913
729415
1627157
4612047
592360
2615196
1503001
577109
322147
1576307
7176654
326113
1440417
1036974
1058438
1788996
473600
1386019
673652
366022
1126507
2540938
1313667
2917932
1507124
438050
314732
5370489
1467955
780325
2457145
2124159
1111202
823787
3403081
831091
1119...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 695ms
memory: 71660kb

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
931158568
2082574765
750333254
9534839833
1920624457
6476878769
2613354590
947390860
125441385
547086620
937474897
1655645026
1497576554
1880621346
1499148856
2889489926
3144714126
4642609744
407987493
413184755
1578832124
1694960013
801823540
939754008
306512764
165942412
9439...

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%