QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#67141#5098. 第一代图灵机NATURAL60 483ms13828kbC++142.9kb2022-12-10 09:57:062022-12-10 09:57:09

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 09:57:09]
  • Judged
  • Verdict: 0
  • Time: 483ms
  • Memory: 13828kb
  • [2022-12-10 09:57:06]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
inline int qread()
{
	int a=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){a=(a*10)+(ch^48);ch=getchar();}
	return a*f;
}
int n,m,q,a[200010],col[200010],cz[200010][3],b[400010];
int cl,c[200010],st[450],ed[450],l,r,vis[200010];
int len[200010],cx,xk;
long long pre[200010],an[200010],ans,sum[450];
inline void F(int h)
{
	int pos=cz[h][1],co=cz[h][2];
	col[pos]=co;
	cx=max(pos-m,1);
	l=r=cx;
	vis[col[cx]]=1;
	ans=a[cx];
	for(int i=cx;i<=pos;++i)
	{
		while(r<=n&&!vis[col[r+1]])
		{
			++r;
			++vis[col[r]];
			ans+=a[r];
		}
		an[i]=ans;
		len[i]=r-l+1;
		--vis[col[l]];
		ans-=a[l];
		++l;
	}
	for(int i=c[cx];i<=c[pos];++i)
	{
		sum[i]=0;
		for(int j=st[i];j<=ed[i];++j)sum[i]=max(sum[i],an[j]);
	} 
	while(l<=r)
	{
		--vis[col[l]];
		++l;
	}
	return ;
}
inline int find(int ll,int rr)
{
	int mid,R=rr;
	while(ll<rr)
	{
		mid=(ll+rr)>>1;
		if(mid+len[mid]-1<R)ll=mid+1;
		else rr=mid;
	}
	return ll-1;
}
inline void Qr(int ll,int rr)
{
	if(ll>rr)return ;
	ans=0;
	if(c[ll]==c[rr])for(int i=ll;i<=rr;++i)ans=max(ans,an[i]);
	else
	{
		for(int i=ll;i<=ed[c[ll]];++i)ans=max(an[i],ans);
		for(int i=c[ll]+1;i<c[rr];++i)ans=max(ans,sum[i]);
		for(int i=ed[c[rr]];i<=rr;++i)ans=max(an[i],ans);
	}
	return ;
}
inline void Q(int h)
{
	l=cz[h][1],r=cz[h][2];
	int mid=find(l,r);
	ans=0;
//	Qr(l,mid);
//	ans=max(ans,pre[r]-pre[mid]);
for(int i=l;i<=ed[c[l]];++i)
{
	if(i+len[i]-1<=r)ans=max(ans,an[i]);
	else ans=max(ans,pre[r]-pre[i-1]);
}l=ed[c[l]]+1;
for(int i=l;i<st[c[r]];++i)
{
	if(ed[c[i]]+len[ed[c[i]]]-1<=r)ans=max(ans,sum[i]),i=ed[c[i]];
	else if(i+len[i]-1<=r)ans=max(ans,an[i]);
	else ans=max(ans,pre[r]-pre[i-1]);
}
for(int i=st[c[r]];i<=r;++i)
{
	if(i+len[i]-1<=r)ans=max(ans,an[i]);
	else ans=max(ans,pre[r]-pre[i-1]);
}
	printf("%lld\n",ans);
	return ;
}
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	n=qread();
	cl=sqrt(n)+1;
	m=qread();
	q=qread();
	for(int i=1;i<=n;++i)a[i]=qread(),c[i]=(i-1)/cl+1,ed[c[i]]=i,pre[i]=pre[i-1]+a[i];
	for(int i=1;i<=n;++i)b[i]=col[i]=qread();
	m=n;
	for(int i=1;i<=q;++i)
	{
		cz[i][0]=qread();
		cz[i][1]=qread();
		cz[i][2]=qread();
		if(cz[i][0]==2) b[++m]=cz[i][2];
	}
	sort(b+1,b+1+m);
	m=unique(b+1,b+1+m)-b-1;
	for(int i=n;i;--i)col[i]=lower_bound(b+1,b+1+m,col[i])-b,st[c[i]]=i;
	for(int i=1;i<=q;++i)if(cz[i][0]==2)cz[i][2]=lower_bound(b+1,b+1+m,cz[i][2])-b;
	l=r=1;
	++vis[col[1]];
	ans=a[1];
	for(int i=1;i<=n;++i)
	{
		while(r<n&&!vis[col[r+1]])
		{
			++r;
			++vis[col[r]];
			ans+=a[r];
		}
		an[i]=ans;
		len[i]=r-l+1;
		sum[c[i]]=max(sum[c[i]],an[i]);
		--vis[col[l]];
		ans-=a[l];
		++l;
	}
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=q;++i)
	{
		if(cz[i][0]==1)Q(i);
		else F(i);
	}
	return 0;
}


詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 4520kb

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:

79590
82967
73997
79590
95154
48725
68356
82967
82967
82967
79590
82967
79590
82967
84007
63111
53606
95154
73642
79590
82967
95154
82967
39374
82967
89208
99923
82967
82967
77192
67533
56075
82967
82967
82967
82967
82967
76436
82967
26617
82967
73997
82967
79590
86780
82967
71458
76436
60731
82967
...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 300ms
memory: 13828kb

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:

1013029
981403
1088761
1181726
1019022
1013029
1013029
1013029
1013029
1013029
933725
1112602
1013029
1013029
1167757
1013029
1081599
692746
1013029
1013029
1013029
995648
869967
875030
1013029
854668
1013029
924176
945731
927956
860041
1013029
1013029
817465
869967
1016087
854113
855326
1030453
985...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 483ms
memory: 13592kb

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:

46018625
46018625
33772147
33772147
28740908
38565907
33518574
46018625
46018625
46018625
25259743
34976888
46018625
46018625
38565907
34075904
33772147
34075904
46018625
46018625
46018625
38565907
46018625
24857502
46018625
33772147
46018625
22585357
46018625
38565907
38565907
32190071
46018625
460...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%