QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111576#5504. Flower GardenAK_DreamWA 3353ms104900kbC++142.5kb2023-06-07 16:38:182023-06-07 16:38:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-07 16:38:21]
  • 评测
  • 测评结果:WA
  • 用时:3353ms
  • 内存:104900kb
  • [2023-06-07 16:38:18]
  • 提交

answer

#include <bits/stdc++.h>
#define N 1000005
#define pb push_back 
using namespace std;

template <typename T>
inline void read(T &num) {
	T x = 0, ff = 1; char ch = getchar();
	for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') ff = -1;
	for (; ch <= '9' && ch >= '0'; ch = getchar()) x = (x<<3)+(x<<1)+(ch^'0');
	num = x * ff; 
}

int n, Q, tot;
int lc[N], rc[N];
int dfn[N], low[N], stk[N], in[N], col[N], siz[N], top, tme, scc;
vector<int> E[N];

void build(int &p, int l, int r, int tp) {
	if (l == r) return p = l, void();
	p = ++tot; E[p].clear(); 
	int mid = (l+r)>>1;
	build(lc[p],l,mid,tp); build(rc[p],mid+1,r,tp);
	if (!tp) E[lc[p]].pb(p), E[rc[p]].pb(p);
	else E[p].pb(lc[p]), E[p].pb(rc[p]); 
}
void qry(int p, int l, int r, int x, int y, int v, int tp) {
	if (x <= l && r <= y) {
		if (!tp) E[p].pb(v); else E[v].pb(p);
		return;
	}
	int mid = (l+r)>>1;
	if (x <= mid) qry(lc[p],l,mid,x,y,v,tp);
	if (mid < y) qry(rc[p],mid+1,r,x,y,v,tp);
}

void tarjan(int x) {
	dfn[x] = low[x] = ++tme;
	stk[++top] = x; in[x] = 1;
	for (auto y : E[x]) {
		if (!dfn[y]) tarjan(y), low[x] = min(low[x], low[y]);
		else if (in[y]) low[x] = min(low[x], dfn[y]);
	}
	if (dfn[x] == low[x]) {
		int z = 0; siz[++scc] = 0;
		do {
			z = stk[top--];
			in[z] = 0; col[z] = scc;
			if (z <= n) ++siz[scc];
		} while (z != x);
	}
}
void dfs(int x, int &sum) {
	if (x <= n) ++sum;
	dfn[x] = 0;
	for (auto y : E[x]) if (dfn[y]) dfs(y, sum);
}

void solve() {
	read(n); read(Q); n *= 3;
	tot = n; 
	for (int i = 1; i <= n; i++) E[i].clear();
	int rt0 = 0, rt1 = 0;
	build(rt0,1,n,0); build(rt1,1,n,1);
	while (Q--) {
		int l, r, x, y; read(l); read(r); read(x); read(y);
		int t = ++tot; E[t].clear();
		qry(rt0,1,n,l,r,t,0); qry(rt1,1,n,x,y,t,1); 
	}
	for (int i = 1; i <= tot; i++) dfn[i] = 0;
	tme = scc = 0;
	for (int i = 1; i <= tot; i++) if (!dfn[i]) tarjan(i);
	int k = 0, sum = 0;
	for (int i = 1; i <= scc; i++) {
		sum += siz[i];
		if (sum >= n/3) {
			if (sum <= 2*n/3) k = i; 
			else k = -i;
			break;
		}
	}
	if (k > 0) {
		puts("TAK"); sum = 0;
		for (int i = 1; i <= n; i++) putchar(col[i]<=k?'F':'R'), sum += (col[i]<=k);
		putchar('\n'); return;
	}
	k = -k;
	for (int i = 1; i <= tot; i++) if (col[i] == k) {
		sum = 0; dfs(i, sum);
		if (sum > 2*n/3) { puts("NIE"); return; }
		puts("TAK"); sum = 0;
		for (int j = 1; j <= n; j++) putchar(!dfn[j]?'F':'R'), sum += (!dfn[j]);
		putchar('\n'); return;
	}
}

int main() {
	int ttt; read(ttt);
	while (ttt--) solve();	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 41328kb

input:

2
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1

output:

TAK
RRF
NIE

result:

ok good!

Test #2:

score: 0
Accepted
time: 3353ms
memory: 104900kb

input:

10
33333 100000
28701 40192 93418 95143
95902 97908 78378 78461
36823 44196 22268 23996
23977 24786 33315 48829
83965 90411 4923 8445
20235 21177 32543 47454
29598 35414 72477 73049
2014 12632 42163 46466
64305 65518 98825 99552
32331 41625 92772 96224
26500 54122 76990 77126
18249 20335 31165 36080...

output:

NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE

result:

ok good!

Test #3:

score: 0
Accepted
time: 2002ms
memory: 94552kb

input:

10
33333 100000
15207 33614 66276 66276
97173 97173 67589 73960
19673 36626 65207 65207
89825 98169 27079 27079
56067 56966 7560 7560
18170 35477 18752 18752
32621 36748 34460 34460
61595 61700 14117 14117
32395 36710 9064 9064
13172 13172 1728 4640
40462 41878 47171 47171
76965 82414 5767 5767
9225...

output:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

ok good!

Test #4:

score: 0
Accepted
time: 1954ms
memory: 94796kb

input:

10
33333 100000
2646 2646 6430 6446
82226 82231 15128 15132
877 877 85831 88474
51389 79196 37573 37573
38030 38030 14248 14280
63032 68489 81074 81074
46468 46468 7403 7487
19864 20058 97979 97979
71640 71833 8558 8558
12121 12434 82481 82481
32901 32901 1899 2162
65312 77886 75969 75974
87983 8798...

output:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFRRFFFFRFFRRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

ok good!

Test #5:

score: -100
Wrong Answer
time: 255ms
memory: 42196kb

input:

87005
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1
1 1
1 3 2 3
1 2
1 1 2 2
2 2 1 1
1 2
1 3 1 1
1 1 1 3
4 20
3 5 6 12
4 5 7 11
1 1 2 2
3 4 7 12
3 5 10 10
3 5 8 8
4 4 9 11
4 4 7 7
1 1 9 10
3 4 6 9
3 5 11 12
3 3 7 9
3 5 2 2
4 5 2 2
1 1 7 11
1 1 10 10
3 5 7 8
4 4 2 2
1 1 2 2
4 5 8 10
4 12
11 ...

output:

TAK
RRF
NIE
TAK
RFF
TAK
FFR
NIE
TAK
RFRRRRFRFFRR
TAK
FFRRFFRRRRRR
NIE
TAK
FFFFRRRRRFRRRRR
TAK
FRRRRRRRFFFR
TAK
FFFRRRRRRRRF
TAK
FFFFFRRRRRRRRRR
TAK
FFRRRRRRRRFF
TAK
FFRRFFFRRRRRRRR
NIE
TAK
FFFFRRRRRRRR
NIE
TAK
FRFFFRRFF
NIE
TAK
FFFRRRRRR
TAK
RRRRRRFFFRRF
TAK
RRFFRFRFFFFFRFF
TAK
RRRRRRRFFFFR
NIE
TAK
...

result:

wrong answer zla odpowiedz!