QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#390323#5098. 第一代图灵机onlycre0 396ms42208kbC++142.5kb2024-04-15 11:52:322024-04-15 11:52:33

Judging History

This is the latest submission verdict.

  • [2024-04-15 11:52:33]
  • Judged
  • Verdict: 0
  • Time: 396ms
  • Memory: 42208kb
  • [2024-04-15 11:52:32]
  • Submitted

answer

#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rpe(i,x) for(int i=_he[x];i;i=_ne[i])
#define lb(x) (x&(-x))
using namespace std;
typedef long long LL;
typedef pair<int,LL>pil;
const int N=2e5+10;

int pre[N],c[N],n,m,Q;
LL s[N];
namespace T{
	int pmx[N<<2];
	LL dat[N<<2],F[N<<2];
	LL solve(int p,int l,int r,int x)
	{
		if(l==r)return s[l]-s[max(x,pre[l])];
		int mid=(l+r)>>1;
		if(x>pmx[p<<1])return max(s[mid]-s[x],solve(p<<1|1,mid+1,r,x));
		return max(solve(p<<1,l,mid,x),F[p<<1|1]);
	}
	void pup(int p,int mid,int r)
	{
		pmx[p]=max(pmx[p<<1],pmx[p<<1|1]);
		F[p<<1|1]=solve(p<<1|1,mid+1,r,pmx[p<<1]);
		dat[p]=max(dat[p<<1],F[p<<1|1]);
	}
	void build(int p,int l,int r)
	{
		if(l==r)return dat[p]=s[l]-s[pmx[p]=pre[l]],void();
		int mid=(l+r)>>1;
		build(p<<1,l,mid),build(p<<1|1,mid+1,r);
		pup(p,mid,r);
	}
	void mdf(int p,int l,int r,int pos,int v)
	{
		if(l==r)return pmx[p]=v,void();
		int mid=(l+r)>>1;
		pos<=mid?mdf(p<<1,l,mid,pos,v):mdf(p<<1|1,mid+1,r,pos,v);
		pup(p,mid,r);
	}
	pil ask(int p,int l,int r,int tl,int tr,int x)
	{
		if(l>=tl&&r<=tr)return {max(x,pmx[p]),solve(p,l,r,x)};
		int mid=(l+r)>>1;
		if(tl<=mid&&tr>mid)
		{
			pil L=ask(p<<1,l,mid,tl,tr,x),R=ask(p<<1|1,mid+1,r,tl,tr,max(x,L.first));
			return {max(L.first,R.first),max(L.second,R.second)};
		}
		return tl<=mid?ask(p<<1,l,mid,tl,tr,x):ask(p<<1|1,mid+1,r,tl,tr,x);
	}
}

set<int>S[N];
int t[N];
void add(int x,int v){for(;x<=n;x+=lb(x))t[x]=max(t[x],v);}
int qry(int x){int res=0;for(;x;x-=lb(x))res=max(res,t[x]);return res;}
int main()
{
	//freopen("ex_machine2.in","r",stdin);
	scanf("%d%d%d",&n,&m,&Q);
	rep(i,1,n)scanf("%lld",&s[i]),s[i]+=s[i-1];
	rep(i,1,n)
	{
		scanf("%d",&c[i]);
		if(!S[c[i]].empty())pre[i]=*prev(S[c[i]].end()),add(i,pre[i]);
		S[c[i]].insert(i);
	}
	T::build(1,1,n);
	rep(i,1,Q)
	{
		int opt,x,y;scanf("%d%d%d",&opt,&x,&y);
		if(opt==1){printf("%lld qwq\n",T::ask(1,1,n,x,y,x).second);}
		else
		{
			if(c[x]==y)continue;
			S[c[x]].erase(x);
			auto it=S[c[x]].lower_bound(x);
			if(it!=S[c[x]].end())
			{
				if(it==S[c[x]].begin())pre[*it]=0;
				else pre[*it]=*prev(it);
				T::mdf(1,1,n,*it,pre[*it]);
			}
			
			it=S[y].lower_bound(x);
			if(it!=S[y].end())
			{
				pre[*it]=x;
				T::mdf(1,1,n,*it,x);
			}
			if(it==S[y].begin())pre[x]=0;
			else pre[x]=*prev(it);
			T::mdf(1,1,n,x,pre[x]);
			
			c[x]=y;
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 23304kb

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:

118571 qwq
90725 qwq
79596 qwq
95154 qwq
95154 qwq
94493 qwq
72411 qwq
100567 qwq
100567 qwq
100567 qwq
100567 qwq
90725 qwq
100567 qwq
100567 qwq
90725 qwq
118571 qwq
94493 qwq
95154 qwq
58191 qwq
118571 qwq
100567 qwq
100567 qwq
100567 qwq
36813 qwq
89208 qwq
118571 qwq
99923 qwq
100567 qwq
100567...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 396ms
memory: 42208kb

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:

1232419 qwq
1222519 qwq
1232419 qwq
1232419 qwq
1232419 qwq
1232419 qwq
1232419 qwq
1232419 qwq
1232419 qwq
1232419 qwq
1040511 qwq
1148070 qwq
1232419 qwq
1232419 qwq
1232419 qwq
1232419 qwq
1206368 qwq
1206368 qwq
1232419 qwq
1232419 qwq
1232419 qwq
1222519 qwq
1167757 qwq
1206368 qwq
1214212 qwq
...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 254ms
memory: 42204kb

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:

46702944 qwq
46702944 qwq
38383720 qwq
38615532 qwq
38615532 qwq
42801975 qwq
39035571 qwq
46702944 qwq
46702944 qwq
46702944 qwq
27438528 qwq
38402892 qwq
46702944 qwq
46702944 qwq
42801975 qwq
42323113 qwq
39035571 qwq
42323113 qwq
46702944 qwq
46702944 qwq
46702944 qwq
41821993 qwq
46702944 qwq
3...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%