QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#470363#5504. Flower Garden11d10xyWA 0ms39356kbC++142.3kb2024-07-10 12:12:352024-07-10 12:12:35

Judging History

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

  • [2024-07-10 12:12:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:39356kb
  • [2024-07-10 12:12:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,N,M,dfn[400010],low[400010],bl[400010],stk[400010],vis[400010],tot,tp,idin[100010<<2],idout[100010<<2];
vector<int>G[400010],D[400010],node[400010],ans,tmp;
void upd(){
   if(ans.empty()&&n<=tmp.size()&&tmp.size()<=n*2){
      ans.resize(n*3+1);
      for(int x:tmp)ans[x]=1;
   }
}
void build(int u,int l,int r){
   if(l==r)return idin[u]=idout[u]=l,void();
   int mid=l+r>>1;
   build(u<<1,l,mid),build(u<<1|1,mid+1,r);
   idin[u]=++N,idout[u]=++N;
   G[idin[u]].push_back(idin[u<<1]);
   G[idin[u]].push_back(idin[u<<1|1]);
   G[idout[u<<1]].push_back(idout[u]);
   G[idout[u<<1|1]].push_back(idout[u]);
}
void addin(int u,int l,int r,int L,int R,int x){
   if(L<=l&&r<=R)return G[x].push_back(idin[u]),void();
   int mid=l+r>>1;
   if(L<=mid)addin(u<<1,l,mid,L,R,x);
   if(R>mid)addin(u<<1|1,mid+1,r,L,R,x);
}
void addout(int u,int l,int r,int L,int R,int x){
   if(L<=l&&r<=R)return G[idout[u]].push_back(x),void();
   int mid=l+r>>1;
   if(L<=mid)addout(u<<1,l,mid,L,R,x);
   if(R>mid)addout(u<<1|1,mid+1,r,L,R,x);
}
void tarjan(int u){
   dfn[u]=low[u]=++tot,stk[++tp]=u,vis[u]=1;
   for(int v:G[u])if(!dfn[v])tarjan(v),low[u]=min(low[u],low[v]);
   else if(vis[v])low[u]=min(low[u],dfn[v]);
   if(dfn[u]==low[u]){
      int x,U=++M;
      do{
         x=stk[tp--],vis[x]=0,bl[x]=U;
         if(x<=3*n)node[U].push_back(x),tmp.push_back(x);
         for(int v:G[x])if(bl[v]!=U)D[U].push_back(bl[v]);
      }while(x!=u);
      upd();
   }
}
void dfs(int u){
   tmp.insert(end(tmp),begin(node[u]),end(node[u]));
   vis[u]=1;
   for(int v:D[u])if(!vis[v])dfs(v);
}
void solve(){
   cin>>n>>m,N=n*3;
   build(1,1,n*3);
   for(int a,b,c,d;m--;){
      scanf("%d%d%d%d",&a,&b,&c,&d);
      N++;
      addout(1,1,n*3,a,b,N);
      addin(1,1,n*3,c,d,N);
   } 
   tmp={};
   for(int i=1;i<=N;i++)if(!dfn[i])tarjan(i);
   for(int i=1;ans.empty()&&i<=M;i++)if(node[i].size()>=n){
      tmp={},dfs(i),upd();fill_n(vis+1,M,0);
   }
   if(!ans.empty()){
      puts("TAK");
      for(int i=1;i<=n*3;i++)putchar(ans[i]==0?'F':'R');
      puts("");
   }else puts("NIE");
   for(int i=1;i<=N;i++)G[i]=D[i]=node[i]={},dfn[i]=low[i]=vis[i]=bl[i]=0;
   ans={},M=tot=tp=0;
}
int main(){
   int T;for(cin>>T;T--;)solve();
   return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 39356kb

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
FFR
NIE

result:

wrong answer odpowiedz nie spelnia wymogow!