QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#470991 | #5504. Flower Garden | BINYU | WA | 3444ms | 542680kb | C++14 | 3.0kb | 2024-07-10 17:09:34 | 2024-07-10 17:09:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6,Q = 1e6,M = 3 * N + Q;
int n,m,cntnode,l1,r1,l2,r2;
int dfn[M + 5],cntdfn,cntscc,id[M + 5];
int ins[M + 5],low[M + 5],flag[M + 5],siz[M + 5];
int ls[3 * N + 5],rs[3 * N + 5];
stack <int> s;
vector <int> ee[M + 5],e[M + 5],v[M + 5];
void adde(int u,int v,int op)
{
if(op)swap(u,v);
e[u].push_back(v);
ee[v].push_back(u);
}
int build(int l,int r,int op)
{
if(l == r)return l;
int id = ++cntnode;
int mid = l + r >> 1;
ls[id] = build(l,mid,op);
rs[id] = build(mid + 1,r,op);
adde(id,ls[id],op);adde(id,rs[id],op);
return id;
}
void Adde(int id,int l,int r,int st,int en,int u,int op)
{
if(l >= st&&r <= en)
return adde(u,id,op);
int mid = l + r >> 1;
if(st <= mid)Adde(ls[id],l,mid,st,en,u,op);
if(en > mid)Adde(rs[id],mid + 1,r,st,en,u,op);
}
void tarjan(int u)
{
dfn[u] = low[u] = ++cntdfn;
s.push(u);ins[u] = 1;
for(auto v : e[u])
if(!dfn[v])
tarjan(v),low[u] = min(low[u],low[v]);
else if(ins[v])low[u] = min(low[u],dfn[v]);
if(low[u] == dfn[u])
{
v[++cntscc].push_back(u);
ins[u] = 0;id[u] = cntscc;
while(s.top() != u)
v[cntscc].push_back(s.top()),
ins[s.top()] = 0,id[s.top()] = cntscc,s.pop();
s.pop();
}
}
void write()
{
puts("TAK");
for(int i = 1;i <= 3 * n;i++)
if(flag[id[i]])putchar('R');
else putchar('F');
puts("");
}
void dfs1(int u)
{
flag[u] = 1;
for(auto node : v[u])
for(auto nxt : e[node])
if(!flag[id[nxt]])
dfs1(id[nxt]);
}
void dfs2(int u)
{
flag[u] = 1;
for(auto node : v[u])
for(auto nxt : ee[node])
if(!flag[id[nxt]])
dfs2(id[nxt]);
}
bool Debug;
void solve()
{
scanf("%d %d",&n,&m);
cntnode = 3 * n;cntdfn = 0;cntscc = 0;
int root0 = build(1,3 * n,0);
int root1 = build(1,3 * n,1);
for(int i = 1;i <= m;i++)
{
scanf("%d %d %d %d",&l1,&r1,&l2,&r2);
if(l1 == 15207&&r1 == 33614)Debug = 1;
++cntnode;
Adde(root1,1,3 * n,l1,r1,cntnode,1);
Adde(root0,1,3 * n,l2,r2,cntnode,0);
}
for(int i = 1;i <= cntnode;i++)
if(!dfn[i])tarjan(i);
for(int i = 1;i <= 3 * n;i++)siz[id[i]]++;
int F = 0;
for(int i = 1;i <= cntscc;i++)
if(siz[i] >= n)
{
F = 1;
for(int i = 1;i <= cntscc;i++)flag[i] = 0;
dfs1(i);
int sum = 0;
for(int i = 1;i <= cntscc;i++)
if(flag[i])sum += siz[i];
if(sum <= 2 * n)
{
F = 2;
for(int i = 1;i <= cntscc;i++)flag[i] ^= 1;
write();
break;
}
for(int i = 1;i <= cntscc;i++)flag[i] = 0;
dfs2(i);
sum = 0;
for(int i = 1;i <= cntscc;i++)
if(flag[i])sum += siz[i];
if(sum <= 2 * n)
{
F = 2;
write();
break;
}
}
if(F == 1)puts("NIE");
else if(F == 0)
{
int sum = 0;
for(int i = cntscc;~i;i--)
{
sum += siz[i];
flag[i] = 1;
if(sum >= n)break;
}
write();
}
for(int i = 1;i <= cntnode;i++)e[i].clear(),dfn[i] = 0;
for(int i = 1;i <= cntscc;i++)
flag[i] = 0,v[i].clear(),flag[i] = 0,siz[i] = 0;;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 46ms
memory: 286924kb
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: 3444ms
memory: 542680kb
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: -100
Wrong Answer
time: 2890ms
memory: 464664kb
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:
wrong answer zla odpowiedz!