QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#516578 | #5504. Flower Garden | bai_hong | ML | 1603ms | 139500kb | C++14 | 3.6kb | 2024-08-12 19:07:28 | 2024-08-12 19:07:28 |
Judging History
answer
//Shirosaki Hana kawaii
#include<bits/stdc++.h>
const int QaQ=4e6+5;
const int QWQ=8e5+5;
using namespace std;
using ll=long long;
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar())
if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar())
x=(x<<1)+(x<<3)+(ch^48);
return x*f;
}
int dfn[QWQ],low[QWQ],scc[QWQ],w[QWQ],Cnd,now;
int T,n,m,cnt,head[QWQ],Tnd,Dnd,tot,rev[QWQ];
bool ins[QWQ],is[QWQ],chs[QWQ]; int du[QWQ];
stack<int> stk; queue<int> q; bool vis[QWQ];
struct node{ int to,next; } E[QaQ];
vector<int> e[QWQ],g[QWQ];
inline void append(int x,int y){
E[++cnt]={y,head[x]},head[x]=cnt;
}
inline void add(int u,int v){
append(u,v),append(v+Dnd,u+Dnd);
}
#define mid (l+r>>1)
void make(int k,int l,int r){
if (l==r){
rev[l]=k,is[k]=1;
append(k,k+Dnd);
append(k+Dnd,k);
Tnd=max(Tnd,k+Dnd);
return ;
}
make(k<<1,l,mid),make(k<<1|1,mid+1,r);
add(k,k<<1),add(k,k<<1|1);
}
void change(int k,int l,int r,int ll,int rr,bool tp){
if (ll<=l&&rr>=r){
if (!tp) append(Tnd,k);
else append(k+Dnd,Tnd);
return ;
}
if (ll<=mid) change(k<<1,l,mid,ll,rr,tp);
if (mid<rr) change(k<<1|1,mid+1,r,ll,rr,tp);
}
inline void Edd(int l1,int r1,int l2,int r2){
change(1,1,3*n,l1,r1,1);
change(1,1,3*n,l2,r2,0);
}
void tarjan(int u){
low[u]=dfn[u]=++tot;
stk.push(u),ins[u]=1;
for (int i=head[u],v;i;i=E[i].next)
if (!dfn[v=E[i].to])
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]){
scc[u]=++Cnd,w[Cnd]+=is[u];
while (stk.top()!=u){
w[Cnd]+=is[stk.top()];
scc[stk.top()]=Cnd;
ins[stk.top()]=0;
stk.pop();
}
ins[u]=0,stk.pop();
}
}
inline void out(){
puts("TAK");
for (int i=1;i<=3*n;i++)
putchar(chs[scc[rev[i]]] ? 'F':'R');
puts("");
}
inline bool ckbig(int s){
for (int i=1;i<=Cnd;i++) chs[i]=0;
q.push(s),now=w[s],chs[s]=1;
while (!q.empty()){
int u=q.front(); q.pop();
for (int v:e[u]) if (!chs[v])
chs[v]=1,now+=w[v],q.push(v);
}
if (n<=now&&now<=2*n) out();
return n<=now&&now<=2*n;
}
inline void clean(){
while(q.size())q.pop();
for (int i=1;i<=Tnd;i++)
dfn[i]=scc[i]=ins[i]=head[i]=rev[i]=is[i]=0;
for (int i=1;i<=Cnd;i++)
g[i].clear(),e[i].clear(),w[i]=chs[i]=du[i]=0;
Tnd=cnt=tot=Cnd=0,Dnd=12*n;
}
signed main(){
for (T=read();T--;){
n=read(),m=read(),clean();
make(1,1,3*n);
for (int i=1;i<=m;i++){
int l1=read(),r1=read();
int l2=read(),r2=read();
++Tnd,Edd(l1,r1,l2,r2);
}
for (int i=1;i<=Tnd;i++)
if (!dfn[i]) tarjan(i);
for (int u=1;u<=Tnd;u++)
for (int i=head[u],v;i;i=E[i].next)
if (scc[u]!=scc[v=E[i].to])
e[scc[u]].push_back(scc[v]),
g[scc[v]].push_back(scc[u]),du[scc[u]]++;
bool ok=0; vector<int> st;
for (int i=1;i<=Cnd;i++){
if (w[i]>2*n){ puts("NIE"),ok=1; break; }
if (w[i]>=n) st.push_back(i);
}
if (ok) continue;
if (!st.size()){
for (int i=1;i<=Cnd;i++)
if (!du[i]) q.push(i); now=0;
while (!q.empty()){
int u=q.front(); q.pop();
now+=w[u],chs[u]=1;
if (now>=n) break;
for (int v:g[u])
if (!--du[v]) q.push(v);
} out(); continue;
}
while (st.size()){
ok=ckbig(st.back()); if (ok) break;
for (int i=1;i<=Cnd;i++) vis[i]=chs[i]=0;
q.push(st.back()),vis[st.back()]=1;
while (!q.empty()){
int u=q.front(); q.pop();
for (int v:g[u]) q.push(v),vis[v]=1;
} now=0;
for (int i=1;i<=Cnd;i++)
if (!vis[i]) now+=w[i],chs[i]=1;
if (now>=n){ out(),ok=1; break; }
st.pop_back();
}
if (!ok) puts("NIE");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 55412kb
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 RFF NIE
result:
ok good!
Test #2:
score: 0
Accepted
time: 1603ms
memory: 116760kb
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: 1385ms
memory: 139500kb
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: 1280ms
memory: 128920kb
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: 0
Accepted
time: 266ms
memory: 53584kb
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 RFF NIE TAK RFF TAK FFR NIE TAK RFRRRFRRFRRF TAK RFRFFFRRRRRR NIE TAK FFFFRRRFRRRRRRR TAK FRRFRRRRFRRF TAK FFRRRRRRRRFF TAK FFFFFRRRRRRRRRR TAK FRRRRRFRFRRF TAK FFRRFFRRRRRRRRF NIE TAK RFFFRRRRRRRF NIE TAK RRFFFRRFF NIE TAK RRFFFRRRR TAK RRRRFFRRFRRF TAK RRFFRFRFFFFFRFF TAK RRRRRRFFFRRF NIE TAK ...
result:
ok good!
Test #6:
score: -100
Memory Limit Exceeded
input:
10 33333 99999 60859 99999 1 60858 78724 99999 1 78723 42986 99999 1 42985 35108 99999 1 35107 63158 99999 1 63157 86977 99999 1 86976 13576 99999 1 13575 48277 99999 1 48276 89102 99999 1 89101 92657 99999 1 92656 25093 99999 1 25092 2353 99999 1 2352 81748 99999 1 81747 51216 99999 1 51215 75815 9...