QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#509942#9155. 集合AdamGS#100 ✓1134ms56816kbC++233.0kb2024-08-08 19:59:202024-08-08 19:59:21

Judging History

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

  • [2024-08-08 19:59:21]
  • 评测
  • 测评结果:100
  • 用时:1134ms
  • 内存:56816kb
  • [2024-08-08 19:59:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7;
struct powrot {
	bool lstczy;
	vector<pair<int,array<int,3>>>P;
};
array<int,3>V[6*LIM];
vector<int>T[LIM];
int nxt[LIM], kiedy[6*LIM], n, m, q, lol;
bool czy=true;
powrot akt;
vector<powrot>zmiany;
// wykonuje x-ta operacje
bool zawiera(int x, int y) {
	bool ok=true;
	rep(i, 3) if(V[x][i]!=-1 || V[y][i]!=-1) ok=false;
	if(ok) return true;
	rep(i, 3) if(V[x][i]==y) return true;
	return false;
}
void usun(int x) {
	rep(xd, 3) if(V[x][xd]!=-1) {
		int i=V[x][xd];
		if(kiedy[i]<lol) {
			akt.P.pb({i, V[i]});
			kiedy[i]=lol;
		}
		rep(j, 3) if(V[i][j]==x) {
			V[i][j]=-1;
			break;
		}
	}
	akt.P.pb({x, V[x]});
	rep(i, 3) V[x][i]=-1;
}
void dodaj_kraw(int x) {
	++lol;
	akt.lstczy=czy;
	akt.P.clear();
	if(czy==false) {
		zmiany.pb(akt);
		return;
	}
	vector<int>A(3), B(3);
	int X[3][3];
	rep(i, 3) rep(j, 3) if(zawiera(T[x][i], T[x][j+3])) X[i][j]=1; else X[i][j]=0;
	rep(i, 3) rep(j, 3) if(X[i][j]) {
		++A[i];
		++B[j];
	}
	sort(all(A));
	sort(all(B));
	if(A!=B || A[0]==0 || B[0]==0 || A==vector<int>{1, 1, 2}) {
		czy=false;
		zmiany.pb(akt);
		return;
	}
	rep(i, 6) usun(T[x][i]);
	rep(i, 3) rep(j, 3) if(X[i][j]) {
		rep(l, 3) if(V[T[x][i]][l]==-1) {
			V[T[x][i]][l]=T[x][j+3];
			break;
		}
		rep(l, 3) if(V[T[x][j+3]][l]==-1) {
			V[T[x][j+3]][l]=T[x][i];
			break;
		}
	}
	zmiany.pb(akt);
}
void rollback() {
	powrot x=zmiany.back(); zmiany.pop_back();
	czy=x.lstczy;
	reverse(all(x.P));
	for(auto i : x.P) V[i.st]=i.nd;
}
void dc(int a, int b, int l, int r) {
	if(a>b) return;
	int mid=(a+b)/2;
	if(b>=l) {
		int x=mid;
		while(x<=r && czy) {
			dodaj_kraw(x);
			++x;
		}
		if(!czy) {
			--x;
			rollback();
		}
		nxt[mid]=x-1;
		for(int i=mid; i<x; ++i) rollback();
		for(int i=mid; i<l; ++i) dodaj_kraw(i);
		dc(a, mid-1, l, nxt[mid]);
		for(int i=mid; i<l; ++i) rollback();
		for(int i=b+1; i<nxt[mid]; ++i) dodaj_kraw(i);
		dc(mid+1, b, nxt[mid], r);
		for(int i=b+1; i<nxt[mid]; ++i) rollback();
		return;
	}
	for(int i=b; i>=mid; --i) dodaj_kraw(i);
	int x=l;
	while(x<=r && czy) {
		dodaj_kraw(x);
		++x;
	}
	if(!czy) {
		--x;
		rollback();
	}
	nxt[mid]=x-1;
	for(int i=x-1; i>=l; --i) rollback();
	dc(a, mid-1, l, nxt[mid]);
	for(int i=mid; i<=b; ++i) rollback();
	for(int i=l; i<x-1; ++i) dodaj_kraw(i);
	dc(mid+1, b, nxt[mid], r);
	for(int i=l; i<x-1; ++i) rollback();
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	rep(i, 6*LIM) rep(j, 3) V[i][j]=-1;
	cin >> n >> m >> q;
	rep(i, n) rep(j, 3) {
		int x;
		cin >> x; --x;
		T[i].pb(x);
	}
	rep(i, n) rep(j, 3) {
		int x;
		cin >> x; --x;
		T[i].pb(x+m);
	}
	dc(0, n-1, 0, n-1);
	while(q--) {
		int l, r;
		cin >> l >> r; --l; --r;
		cout << (nxt[l]>=r?"Yes":"No") << '\n';
	}
}

Details


Pretests

Pretest #1:

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

Pretest #2:

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

Pretest #3:

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

Pretest #4:

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

Pretest #5:

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

Pretest #6:

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

Pretest #7:

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

Pretest #8:

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

Pretest #9:

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

Pretest #10:

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

Pretest #11:

score: 5
Accepted
time: 679ms
memory: 49740kb

Pretest #12:

score: 5
Accepted
time: 603ms
memory: 49968kb

Pretest #13:

score: 5
Accepted
time: 4ms
memory: 19516kb

Pretest #14:

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

Pretest #15:

score: 5
Accepted
time: 105ms
memory: 18268kb

Pretest #16:

score: 5
Accepted
time: 107ms
memory: 20040kb

Pretest #17:

score: 5
Accepted
time: 59ms
memory: 21060kb

Pretest #18:

score: 5
Accepted
time: 84ms
memory: 21204kb

Pretest #19:

score: 5
Accepted
time: 1069ms
memory: 54632kb

Pretest #20:

score: 5
Accepted
time: 1128ms
memory: 55716kb

Final Tests

Test #1:

score: 5
Accepted
time: 4ms
memory: 20896kb

Test #2:

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

Test #3:

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

Test #4:

score: 5
Accepted
time: 2ms
memory: 20536kb

Test #5:

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

Test #6:

score: 5
Accepted
time: 2ms
memory: 18056kb

Test #7:

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

Test #8:

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

Test #9:

score: 5
Accepted
time: 22ms
memory: 20736kb

Test #10:

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

Test #11:

score: 5
Accepted
time: 465ms
memory: 48292kb

Test #12:

score: 5
Accepted
time: 549ms
memory: 47320kb

Test #13:

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

Test #14:

score: 5
Accepted
time: 6ms
memory: 19748kb

Test #15:

score: 5
Accepted
time: 108ms
memory: 18368kb

Test #16:

score: 5
Accepted
time: 106ms
memory: 18156kb

Test #17:

score: 5
Accepted
time: 58ms
memory: 20916kb

Test #18:

score: 5
Accepted
time: 61ms
memory: 23572kb

Test #19:

score: 5
Accepted
time: 821ms
memory: 53480kb

Test #20:

score: 5
Accepted
time: 1134ms
memory: 56816kb

Extra Test:

score: 0
Extra Test Passed