QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#77180 | #5504. Flower Garden | 18Michael | WA | 4ms | 31644kb | C++14 | 3.9kb | 2023-02-13 08:26:36 | 2023-02-13 08:26:38 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
#define LL long long
#define inf 0x3f3f3f3f
using namespace std;
const int MxV=1200002,MxE=50000002,MxN=100002,MxQ=100002;
int n,n2,n3,q,t,edge_t,dfn_t,st_t,rt_t,cnt,e_t,Test_num;
int a[MxQ],b[MxQ],c[MxQ],d[MxQ],val[MxV],la[MxV],num[MxN],dfn[MxV],low[MxV],rt[MxV],st[MxV],sum[MxV],lae[MxV],from[MxE],deg[MxV];
bool ins[MxV],u[MxV];
vector<int> vec;
vector<int> vec2[MxV];
queue<int> Q,ept;
struct aaa
{
int to,nx;
}edge[MxE],e[MxE];
template<class T>void read(T &x)
{
x=0;int f=0;char ch=getchar();
while(ch<'0' || ch>'9')f|=(ch=='-'),ch=getchar();
while(ch>='0' && ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
x=f? -x:x;return ;
}
inline void add_edge(int x,int y)
{
edge[++edge_t]=(aaa){y,la[x]},la[from[edge_t]=x]=edge_t;
}
inline void add_e(int x,int y)
{
if(x^y)e[++e_t]=(aaa){y,lae[x]},lae[x]=e_t;
}
inline int get(int x)
{
return x+(MxV>>1);
}
inline int newnode()
{
return ++t,la[t]=val[t]=dfn[t]=rt[t]=la[get(t)]=val[get(t)]=dfn[get(t)]=rt[get(t)]=0,t;
}
inline void Add(int x,int y)
{
add_edge(x,y),add_edge(get(y),get(x));
}
inline int lson(int x)
{
return (x<<1);
}
inline int rson(int x)
{
return ((x<<1)|1);
}
inline void build(int k,int l,int r)
{
if(l==r)return (void)(val[num[l]=k]=val[get(k)]=1);
int mid=((l+r)>>1),ls=lson(k),rs=rson(k);
build(ls,l,mid),build(rs,mid+1,r),Add(k,ls),Add(k,rs);
}
inline void build2(int k,int l,int r)
{
if(l==r)return ;
int mid=((l+r)>>1),ls=lson(k),rs=rson(k);
build2(ls,l,mid),build2(rs,mid+1,r),Add(k,ls),Add(k,rs);
}
inline void add(int k,int l,int r,int l1,int r1,int x)
{
if(l>=l1 && r<=r1)return Add(x,k);
int mid=((l+r)>>1),ls=lson(k),rs=rson(k);
if(l1<=mid)add(ls,l,mid,l1,r1,x);
if(r1>mid)add(rs,mid+1,r,l1,r1,x);
}
inline void add2(int k,int l,int r,int l1,int r1,int x)
{
if(l>=l1 && r<=r1)return Add(k,x);
int mid=((l+r)>>1),ls=lson(k),rs=rson(k);
if(l1<=mid)add2(ls,l,mid,l1,r1,x);
if(r1>mid)add2(rs,mid+1,r,l1,r1,x);
}
inline void Tarjan(int x)
{
dfn[x]=low[x]=(++dfn_t),ins[st[++st_t]=x]=1;
for(int i=la[x],v;i;i=edge[i].nx)
{
v=edge[i].to;
if(!dfn[v])Tarjan(v),low[x]=min(low[x],low[v]);
else if(ins[v])low[x]=min(low[x],dfn[v]);
}
if(x==low[x])for(sum[++rt_t]=0,vec2[rt_t].clear();st[st_t+1]!=x;--st_t)rt[st[st_t]]=rt_t,sum[rt_t]+=val[st[st_t]],vec2[rt_t].push_back(st[st_t]);
}
inline void print()
{
puts("TAK");
for(int i=1;i<=n3;++i)putchar(u[num[i]]? 'F':'R');
puts("");
}
inline void solve1()
{
//cerr<<"solve1\n";
e_t=cnt=0,Q=ept;
for(int i=1;i<=t;++i)deg[i]=deg[get(i)]=0;
for(int i=1;i<=edge_t;++i)add_e(rt[from[i]],rt[edge[i].to]);
for(int i=1;i<=rt_t;++i)if(!deg[i])Q.push(i),ins[i]=1;else ins[i]=0;
for(int i=1;i<=n3;++i)u[i]=1;
for(int p;Q.size();)
{
p=Q.front(),cnt+=sum[p];
for(int i=0;i<vec2[p].size();++i)u[vec2[p][i]]=1;
if(cnt>=n && cnt<=n2)return print();
for(int i=0;i<vec2[p].size();++i)for(int i=la[vec2[p][i]],v;i;i=edge[i].nx)if(!(--deg[rt[v=edge[i].to]]) && !ins[rt[v]])Q.push(rt[v]),ins[rt[v]]=1;
}
}
inline void dfs(int x)
{
u[x]=1,cnt+=sum[x];
for(int i=la[x],v;i;i=edge[i].nx)if(!u[v=edge[i].to])dfs(v);
}
inline void solve2()
{
//cerr<<"solve2\n";
for(int i=0;i<vec.size();++i)
{
for(int j=1;j<=t;++j)u[j]=u[get(j)]=0;
cnt=0,dfs(vec[i]);
if(cnt>=n && cnt<=n2)return print();
}
puts("NIE");
}
inline void solve()
{
for(read(n),read(q),n2=(n<<1),n3=n*3,edge_t=dfn_t=rt_t=t=0,vec.clear();t<=(n3<<2);newnode());
build(1,1,n3),build2(1,1,n3);
for(int i=1;i<=q;++i)read(a[i]),read(b[i]),read(c[i]),read(d[i]),add(1,1,n3,a[i],b[i],newnode()),add2(1,1,n3,c[i],d[i],t);
for(int i=1;i<=t;++i)
{
if(!dfn[i])Tarjan(i);
if(!dfn[get(i)])Tarjan(get(i));
}
for(int i=1;i<=rt_t;++i)if(sum[i]>n)vec.push_back(i);
if(!vec.size())solve1();
else solve2();
}
int main()
{
read(Test_num);
while(Test_num--)solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 31644kb
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!