QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#99110 | #5504. Flower Garden | Maverik | WA | 2833ms | 310724kb | C++17 | 4.7kb | 2023-04-21 11:05:32 | 2023-04-21 11:05:36 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int maxn=2e6+10;
#define ls (p<<1)
#define rs (p<<1|1)
#define mid ((t[p].l+t[p].r)>>1)
int n,Q,m;
int val[maxn],deg[maxn],ans[maxn];
int dfn[maxn],low[maxn],num,scn,sccval[maxn],bl[maxn];
vector<int>scc[maxn];
bool ins[maxn],vis[maxn];
stack<int>stk;
vector<int>e[maxn],g[maxn],ung[maxn];
inline void dadd(int x,int y){e[x].pb(y),e[y].pb(x);}
inline void add(int x,int y){e[x].pb(y);}
int idin[maxn],idout[maxn],idx;
struct Segment_In
{
int up;
struct node{int l,r;}t[maxn];
inline void build(int p,int l,int r)
{
t[p].l=l,t[p].r=r;
if(l==r) return idin[l]=p+up,void();
add(p+up,ls+up),add(p+up,rs+up);
build(ls,l,mid),build(rs,mid+1,r);
}
inline void addin(int p,int l,int r,int fm)
{
if(l<=t[p].l && t[p].r<=r) return add(fm,p+up);
if(l<=mid) addin(ls,l,r,fm);
if(r>mid) addin(rs,l,r,fm);
}
inline void buildin()
{up=idx;build(1,1,m);idx+=5;}
}in;
struct Segment_Out
{
int up;
struct node{int l,r;}t[maxn];
inline void build(int p,int l,int r)
{
t[p].l=l,t[p].r=r;
if(l==r) return idout[l]=p+up,add(idin[l],l),add(l,idout[l]),void();
add(ls+up,p+up),add(rs+up,p+up);
build(ls,l,mid),build(rs,mid+1,r);
}
inline void addout(int p,int l,int r,int to)
{
if(l<=t[p].l && t[p].r<=r) return add(p+up,to);
if(l<=mid) addout(ls,l,r,to);
if(r>mid) addout(rs,l,r,to);
}
inline void buildout()
{up=idx;build(1,1,m);idx+=5;}
}out;
inline void addseg(int l1,int r1,int l2,int r2){idx++;out.addout(1,l1,r1,idx),in.addin(1,l2,r2,idx);}
#undef ls
#undef rs
#undef mid
inline void tarjan(int x)
{
dfn[x]=low[x]=++num,stk.push(x),ins[x]=1;
for(auto y:e[x])
if(!dfn[y]) tarjan(y),low[x]=min(low[x],low[y]);
else if(ins[y]) low[x]=min(low[x],dfn[y]);
if(dfn[x]==low[x])
{
scn++;int y;
do
{
y=stk.top();stk.pop();ins[y]=0;
scc[scn].pb(y);bl[y]=scn,sccval[scn]+=val[y];
}while(x!=y);
}
}
inline void printans()
{
cout<<"TAK"<<'\n';
for(int i=1;i<=m;i++)
if(ans[i]) cout<<"F";
else cout<<"R";
cout<<'\n';
}
inline void init()
{
for(int i=0;i<=idx;i++)
{
e[i].clear(),g[i].clear(),ung[i].clear(),scc[i].clear();
vis[i]=ins[i]=dfn[i]=low[i]=bl[i]=val[i]=sccval[i]=ans[i]=deg[i]=0;
idin[i]=idout[i]=0;
}
idx=n=m=Q=num=scn=0;
memset(in.t,0x00,sizeof(in.t));
memset(out.t,0x00,sizeof(out.t));
while(!stk.empty()) stk.pop();
}
inline void solve()
{
cin>>n>>Q,idx=m=3*n;
in.buildin(),out.buildout();
for(int i=1,a,b,c,d;i<=Q;i++) cin>>a>>b>>c>>d,addseg(a,b,c,d);
for(int i=1;i<=m;i++) val[i]=1;
for(int i=1;i<=idx;i++) if(!dfn[i]) tarjan(i);
for(int x=1;x<=idx;x++) for(auto y:e[x]) if(bl[y]!=bl[x])
g[bl[x]].pb(bl[y]),deg[bl[y]]++,ung[bl[y]].pb(bl[x]);
vector<int>res;
for(int i=1;i<=scn;i++) if(sccval[i]>=n)
{
queue<int>q;
for(int j=1;j<=m;j++) vis[j]=0;
res.clear();q.push(i),vis[i]=1;
while(!q.empty())
{
int x=q.front();q.pop();
for(auto ele:scc[x]) if(ele<=m) res.pb(ele);
for(auto y:g[x]) if(!vis[y]) q.push(y),vis[y]=1;
}
if(res.size()<=2*n)
{
for(auto ele:res) ans[ele]=1;
return printans(),init(),void();
}
for(int j=1;j<=m;j++) vis[j]=0;
res.clear();q.push(i),vis[i]=1;
while(!q.empty())
{
int x=q.front();q.pop();
for(auto ele:scc[x]) if(ele<=m) res.pb(ele);
for(auto y:ung[x]) if(!vis[y]) q.push(y),vis[y]=1;
}
if(res.size()<=2*n)
{
for(auto ele:res) ans[ele]=1;
return printans(),init(),void();
}
}
queue<int>q;res.clear();
for(int i=1;i<=scn;i++) if(!deg[i]) q.push(i);
vector<int>tops;
while(!q.empty())
{
int x=q.front();q.pop();tops.pb(x);
for(auto y:g[x]) if(--deg[y]==0) q.push(y);
}
for(auto e:tops)
{
for(auto ele:scc[e]) if(ele<=m) res.pb(ele);
if(n<=res.size() && res.size()<=2*n)
{
for(int i=1;i<=m;i++) ans[i]=1;
for(auto ele:res) ans[ele]=0;
return printans(),init(),void();
}
}
cout<<"NIE"<<'\n';init();
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(NULL);
int Testcase;cin>>Testcase;
while(Testcase--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 56ms
memory: 224076kb
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: -100
Wrong Answer
time: 2833ms
memory: 310724kb
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 TAK FRRRRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRRRRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRRRRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRRRRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRRRRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRRRRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFRRFR...
result:
wrong answer zla odpowiedz!