QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#493141#9155. 集合LinkWish100 ✓529ms237556kbC++143.8kb2024-07-26 19:59:262024-07-26 19:59:26

Judging History

你现在查看的是最新测评结果

  • [2024-07-26 19:59:26]
  • 评测
  • 测评结果:100
  • 用时:529ms
  • 内存:237556kb
  • [2024-07-26 19:59:26]
  • 提交

answer

//Linkwish's code
#include<bits/stdc++.h>
#define endl '\n'
#define si static inline
#define mp make_pair
#define fi first
#define se second
using namespace std;typedef long long ll;typedef __int128 li;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;typedef const int ci;
typedef const ll cl;const int iinf=INT_MAX;const ll linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}

namespace LinkWish{

	ci N=200005,M=600005,U=1000005;

	int n,m,Q;
	int a[2][N][3];
	int note[2][N][3];
	
	vector<pii> que[N];
	bool ans[U];


	vector<int> pos[2][M];
	int las[2][M];

	struct OP{
		int r,fl,c;
		inline OP(int x,int y,int z){r=x,fl=y,c=z;}
	};
	vector<OP> chg[N];
	int cur[2][M];

	int nf[3],nn[3],nv[3];
	si void update(int c,int x,int lim,ci fl){
		auto &np=pos[fl][c];

		int tf[3],tv[3],tn[3];
		bool suc[3]={0,0,0};
		for(int i=0;i<3;i++){
			int nc=a[fl^1][x][i],xb=note[fl^1][x][i],res=-1;
			for(int j=0;j<3;j++){
				if(nc==nv[j]){
					int las=pos[fl^1][nc][xb-1];
					if(las==np[lim-1])res=nf[j],suc[j]=1;
					else res=las+1;
				}
			}
			if(res==-1){
				if(xb)res=pos[fl^1][nc][xb-1]+1;
				else res=1;
				if(lim)gmax(res,np[lim-1]+1);
				else gmax(res,1);
			}
			int nxt=n+1;
			if(xb!=(int)pos[fl^1][nc].size()-1)gmin(nxt,pos[fl^1][nc][xb+1]);
			if(lim<(int)np.size()-1)gmin(nxt,np[lim+1]);
			tf[i]=res,tv[i]=nc,tn[i]=nxt;
		}
		for(int i=0;i<3;i++){
			if(!suc[i]&&~nf[i]){
				chg[nf[i]].emplace_back(nn[i],fl,c);
				chg[nn[i]].emplace_back(-1,fl,c);
				chg[nf[i]].emplace_back(nn[i],fl^1,nv[i]);
				chg[nn[i]].emplace_back(-1,fl^1,nv[i]);
			}
		}
		memcpy(nf,tf,sizeof tf),memcpy(nv,tv,sizeof tv),memcpy(nn,tn,sizeof tn);
	}

	bool fit[2][M],vis[2][M];
	vector<pii> dis[N];
	int amt[2][M],tt[2];
	void mian(){
		cin>>n>>m>>Q;
		for(int i=0;i<2;i++)
			for(int j=1;j<=n;j++)
				for(int k=0;k<3;k++)
					cin>>a[i][j][k],note[i][j][k]=pos[i][a[i][j][k]].size(),pos[i][a[i][j][k]].push_back(j);

		for(int j=1;j<=m;j++){
			memset(nf,-1,sizeof nf),memset(nv,-1,sizeof nv),memset(nn,-1,sizeof nn);
			for(int k=0;k<(int)pos[0][j].size();k++)update(j,pos[0][j][k],k,0);
			for(int i=0;i<3;i++){
				chg[nf[i]].emplace_back(nn[i],0,j);
				chg[nn[i]].emplace_back(-1,0,j);
				chg[nf[i]].emplace_back(nn[i],1,nv[i]);
				chg[nn[i]].emplace_back(-1,1,nv[i]);
			}
		}

		for(int i=1,l,r;i<=Q;i++)cin>>l>>r,que[r].emplace_back(l,i);

		for(int i=1,j=0;i<=n;i++){
			for(int k=0;k<2;k++){
				for(int l=0;l<3;l++){
					las[k][a[k][i][l]]=i;
					if(!(amt[k][a[k][i][l]]++))tt[k]++;
				}
			}

			vector<pii> chk;
			for(OP k:chg[i]){
				if(k.r<0&&!vis[k.fl][k.c]&&cur[k.fl][k.c]<=i&&las[k.fl][k.c]>=j)
					vis[k.fl][k.c]=1,chk.emplace_back(k.fl,k.c),dis[las[k.fl][k.c]].emplace_back(k.fl,k.c);
			}
			int got=0;
			while((got<(int)chk.size()||tt[0]!=tt[1])&&j<i){
				for(pii k:dis[j])
					if(vis[k.fi][k.se]&&!fit[k.fi][k.se])
						got++,fit[k.fi][k.se]=1;

				if(j){
					for(int k=0;k<2;k++)
						for(int l=0;l<3;l++)
							if(!(--amt[k][a[k][j][l]]))tt[k]--;
				}
				
				j++;
				for(OP k:chg[j]){
					gmax(cur[k.fl][k.c],k.r);
					if(k.r>i&&vis[k.fl][k.c]&&!fit[k.fl][k.c])got++,fit[k.fl][k.c]=1;
				}
			}
			for(pii k:que[i])ans[k.se]=(k.fi>=j);

			for(pii k:chk)vis[k.fi][k.se]=fit[k.fi][k.se]=0,dis[las[k.fi][k.se]].clear();
		}

		for(int i=1;i<=Q;i++){
			if(ans[i])cout<<"Yes\n";
			else cout<<"No\n";
		}
	}

}

signed main(){
	#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	LinkWish::mian();
	#ifdef LOCAL
	cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl;
	#endif
	return 0;
}

Details


Pretests

Pretest #1:

score: 5
Accepted
time: 7ms
memory: 62964kb

Pretest #2:

score: 5
Accepted
time: 3ms
memory: 62956kb

Pretest #3:

score: 5
Accepted
time: 0ms
memory: 65012kb

Pretest #4:

score: 5
Accepted
time: 7ms
memory: 63048kb

Pretest #5:

score: 5
Accepted
time: 0ms
memory: 63052kb

Pretest #6:

score: 5
Accepted
time: 8ms
memory: 62952kb

Pretest #7:

score: 5
Accepted
time: 7ms
memory: 63076kb

Pretest #8:

score: 5
Accepted
time: 3ms
memory: 63032kb

Pretest #9:

score: 5
Accepted
time: 32ms
memory: 64948kb

Pretest #10:

score: 5
Accepted
time: 28ms
memory: 65016kb

Pretest #11:

score: 5
Accepted
time: 153ms
memory: 108872kb

Pretest #12:

score: 5
Accepted
time: 221ms
memory: 131012kb

Pretest #13:

score: 5
Accepted
time: 10ms
memory: 63780kb

Pretest #14:

score: 5
Accepted
time: 13ms
memory: 64668kb

Pretest #15:

score: 5
Accepted
time: 116ms
memory: 75012kb

Pretest #16:

score: 5
Accepted
time: 112ms
memory: 75932kb

Pretest #17:

score: 5
Accepted
time: 27ms
memory: 72828kb

Pretest #18:

score: 5
Accepted
time: 36ms
memory: 82008kb

Pretest #19:

score: 5
Accepted
time: 416ms
memory: 149252kb

Pretest #20:

score: 5
Accepted
time: 529ms
memory: 234380kb

Final Tests

Test #1:

score: 5
Accepted
time: 0ms
memory: 62952kb

Test #2:

score: 5
Accepted
time: 7ms
memory: 64952kb

Test #3:

score: 5
Accepted
time: 3ms
memory: 65004kb

Test #4:

score: 5
Accepted
time: 5ms
memory: 63200kb

Test #5:

score: 5
Accepted
time: 0ms
memory: 62980kb

Test #6:

score: 5
Accepted
time: 3ms
memory: 63000kb

Test #7:

score: 5
Accepted
time: 0ms
memory: 63016kb

Test #8:

score: 5
Accepted
time: 7ms
memory: 63288kb

Test #9:

score: 5
Accepted
time: 17ms
memory: 64900kb

Test #10:

score: 5
Accepted
time: 23ms
memory: 64988kb

Test #11:

score: 5
Accepted
time: 154ms
memory: 108876kb

Test #12:

score: 5
Accepted
time: 214ms
memory: 133440kb

Test #13:

score: 5
Accepted
time: 0ms
memory: 63784kb

Test #14:

score: 5
Accepted
time: 11ms
memory: 64600kb

Test #15:

score: 5
Accepted
time: 110ms
memory: 74972kb

Test #16:

score: 5
Accepted
time: 111ms
memory: 75608kb

Test #17:

score: 5
Accepted
time: 19ms
memory: 72720kb

Test #18:

score: 5
Accepted
time: 24ms
memory: 83900kb

Test #19:

score: 5
Accepted
time: 382ms
memory: 149744kb

Test #20:

score: 5
Accepted
time: 501ms
memory: 237556kb

Extra Test:

score: 0
Extra Test Passed