QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470809 | #5504. Flower Garden | czc | WA | 678ms | 76388kb | C++23 | 3.9kb | 2024-07-10 16:33:20 | 2024-07-10 16:33:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int maxn=1e5+5;
struct tree{
int id1,id2;
}T[maxn<<2];
int tot;
vector<int> G[maxn<<3];
#define lc (rt<<1)
#define rc (rt<<1|1)
int h[maxn<<3],vs[maxn<<3];
inline void build(int rt,int l,int r){
if(l==r){
T[rt].id1=T[rt].id2=++tot;
G[tot].clear();
h[tot]=l;
vs[tot]=1;
return ;
}
T[rt].id1=++tot,vs[tot]=0;
T[rt].id2=++tot,vs[tot]=0;
G[T[rt].id1].clear();
G[T[rt].id2].clear();
int mid=(l+r)>>1;
build(lc,l,mid);
build(rc,mid+1,r);
G[T[rt].id1].push_back(T[lc].id1),G[T[rt].id1].push_back(T[rc].id1);
G[T[lc].id2].push_back(T[rt].id2),G[T[rc].id2].push_back(T[rt].id2);
}
vector<int> v1,v2;
inline void ask(int rt,int l,int r,int L,int R,int op){
if(L<=l && r<=R){
if(op) v1.push_back(T[rt].id1);
else v2.push_back(T[rt].id2);
return ;
}
int mid=(l+r)>>1;
if(L<=mid) ask(lc,l,mid,L,R,op);
else ask(rc,mid+1,r,L,R,op);
}
int dfn[maxn<<3],low[maxn<<3],instack[maxn<<3],scc[maxn<<3],col,tt;
stack<int> st;
inline void Tarjan(int x){
dfn[x]=low[x]=++tt;
st.push(x);
instack[x]=1;
for(auto y:G[x]){
if(!dfn[y]){
Tarjan(y);
low[x]=min(low[x],low[y]);
}
else if(instack[y]) low[x]=min(low[x],dfn[y]);
}
if(dfn[x]==low[x]){
col++;
scc[x]=col,instack[x]=0;
while(st.top()!=x){
scc[st.top()]=col;
instack[st.top()]=0;
st.pop();
}
st.pop();
}
}
int Ans[maxn];
vector<int> G2[maxn<<3],G3[maxn<<3];
int ind[maxn<<3],cd[maxn<<3],siz[maxn<<3],vvv[maxn<<3];
vector<int> vv[maxn<<3];
inline void solve(){
scanf("%d%d",&n,&m);
tot=0;
build(1,1,n*3);
for(int i=1,l1,r1,l2,r2;i<=m;i++){
scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
v1.clear(),v2.clear();
ask(1,1,n*3,l1,r1,1);
ask(1,1,n*3,l2,r2,0);
for(auto x:v2){
for(auto y:v1){
G[x].push_back(y);
}
}
}
while(!st.empty()) st.pop();
for(int i=1;i<=tot;i++) dfn[i]=low[i]=instack[i]=scc[i]=0;
col=tt=0;
for(int i=1;i<=tot;i++)
if(!dfn[i]) Tarjan(i);
for(int i=1;i<=n*3;i++) Ans[i]=0;
for(int i=1;i<=col;i++) vv[i].clear(),ind[i]=0,G2[i].clear(),siz[i]=0,cd[i]=0,vvv[i]=0;
for(int i=1;i<=tot;i++){
siz[scc[i]]+=vs[i];
if(vs[i]) vv[scc[i]].push_back(h[i]);
for(auto j:G[i]){
if(scc[i]!=scc[j]){
G2[scc[i]].push_back(scc[j]);
G3[scc[j]].push_back(scc[i]);
ind[scc[j]]++,cd[scc[i]]++;
}
}
}
int ps=0;
for(int i=1;i<=col;i++){
if(siz[i]>2*n){
printf("NIE");
return ;
}
if(siz[i]>n+1){
ps=i;
break;
}
}
if(!ps){
//乱选
queue<int> q;
int ans=0;
for(int i=1;i<=col;i++)
if(!cd[i]) q.push(i);
while(!q.empty()){
int x=q.front();
q.pop();
ans+=siz[x];
for(auto y:vv[x]) Ans[y]=1;
if(ans>=n) break;
for(auto y:G3[x]){
cd[y]--;
if(!cd[y]) q.push(y);
}
}
puts("TAK");
for(int i=1;i<=n*3;i++){
if(Ans[i]) printf("R");
else printf("F");
}
puts("");
return ;
}
else{
//考虑选 pos
int ans=0;
queue<int> q;
q.push(ps);
vvv[ps]=1;
while(!q.empty()){
int x=q.front();
q.pop();
ans+=siz[x];
for(auto y:vv[x]) Ans[y]=1;
for(auto y:G2[x]){
if(!vvv[y]){
vvv[y]=1;
q.push(y);
}
}
}
if(ans<=2*n){
puts("TAK");
for(int i=1;i<=n*3;i++){
if(Ans[i]) printf("R");
else printf("F");
}
puts("");
return ;
}
for(int i=1;i<=n*3;i++) Ans[i]=0;
//考虑不选
ans=0;
for(int i=1;i<=col;i++)
if(!cd[i]) q.push(i);
while(!q.empty()){
int x=q.front();
q.pop();
if(x==ps) continue;
ans+=siz[x];
for(auto y:vv[x]) Ans[y]=1;
for(auto y:G3[x]){
cd[y]--;
if(!cd[y]) q.push(y);
}
}
if(ans>=n){
puts("TAK");
for(int i=1;i<=n*3;i++){
if(Ans[i]) printf("R");
else printf("F");
}
puts("");
return ;
}
}
puts("NIE");
}
int main(){
int T;
scanf("%d",&T);
while(T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 26532kb
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: -100
Wrong Answer
time: 678ms
memory: 76388kb
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:
NIENIENIENIENIENIENIENIENIENIE
result:
wrong answer zla odpowiedz!