QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471492 | #5504. Flower Garden | DEMONKILLER | WA | 11ms | 119624kb | C++14 | 3.7kb | 2024-07-10 21:35:53 | 2024-07-10 21:35:54 |
Judging History
answer
#include<bits/stdc++.h>
#define N 2000010
#define lc p<<1
#define rc p<<1|1
using namespace std;
struct node{
int to,next;
}edge[N<<1];
int T,n,q,len,l,r,x,y,cnt,tot,top,num,sum,it,qh,qt,h[N],deg[N],siz[N],be[N],stk[N],dfn[N],low[N],head[N],T1[N],T2[N];
bool ans,ins[N],vis[N];
vector<int> G[N],g[N];
void Clear(){
for(int i=1;i<=tot;i++)head[i]=siz[i]=be[i]=dfn[i]=low[i]=ins[i]=vis[i]=0;
for(int i=1;i<=num;i++)G[i].clear(),g[i].clear();
cnt=top=num=it=0;
}
void add(int from,int to){
edge[++cnt]={to,head[from]};
head[from]=cnt;
}
void build(int p,int l,int r){
if(l==r){
T1[p]=T2[p]=l;
return ;
}
int mid=(l+r)>>1;
T1[p]=++tot,T2[p]=++tot;
build(lc,l,mid),build(rc,mid+1,r);
add(T1[lc],T1[p]),add(T1[rc],T1[p]);
add(T2[p],T2[lc]),add(T2[p],T2[rc]);
}
void add1(int p,int l,int r,int L,int R,int t){
if(L<=l&&r<=R){
add(T1[p],t);
return ;
}
int mid=(l+r)>>1;
if(L<=mid)add1(lc,l,mid,L,R,t);
if(R>mid)add1(rc,mid+1,r,L,R,t);
}
void add2(int p,int l,int r,int L,int R,int t){
if(L<=l&&r<=R){
add(t,T2[p]);
return ;
}
int mid=(l+r)>>1;
if(L<=mid)add2(lc,l,mid,L,R,t);
if(R>mid)add2(rc,mid+1,r,L,R,t);
}
void tarjan(int now){
dfn[now]=low[now]=++it;
ins[now]=1,stk[++top]=now;
for(int i=head[now];i;i=edge[i].next){
if(!dfn[edge[i].to]){
tarjan(edge[i].to);
low[now]=min(low[now],low[edge[i].to]);
}
else if(ins[edge[i].to])low[now]=min(low[now],dfn[edge[i].to]);
}
if(dfn[now]==low[now]){
num++;
int u;
do{
u=stk[top--];
ins[u]=0;
be[u]=num;
}while(u!=now);
}
}
void print(){
puts("TAK");
for(int i=1;i<=len;i++)
putchar(vis[be[i]]?'F':'R');
puts("");
}
void solve(){
scanf("%d%d",&n,&q);
len=3*n,tot=len;
build(1,1,len);
for(int i=1;i<=q;i++){
scanf("%d%d%d%d",&l,&r,&x,&y);
++tot;
add1(1,1,len,l,r,tot);
add2(1,1,len,x,y,tot);
}
for(int i=1;i<=tot;i++)if(!dfn[i])tarjan(i);
for(int i=1;i<=len;i++)siz[be[i]]++;
for(int i=1;i<=num;i++)cout<<siz[i]<<endl;
for(int u=1;u<=tot;u++)
for(int i=head[u];i;i=edge[i].next){
if(be[u]!=be[edge[i].to]){
G[be[u]].push_back(be[edge[i].to]);
g[be[edge[i].to]].push_back(be[u]);
}
}
qh=1,qt=sum=0;
for(int i=1;i<=num;i++){
deg[i]=G[i].size();
if(!deg[i])h[++qt]=i;
}
while(qh<=qt){
int now=h[qh++];
if(siz[now]>=n)continue;
sum+=siz[now];
vis[now]=1;
if(sum>=n&&sum<=n*2){
print();
return ;
}
for(int i:g[now]){
deg[i]--;
if(!deg[i])h[++qt]=i;
}
}
for(int u=1;u<=num;u++)
if(siz[u]>=n){
qh=1,qt=sum=0;
for(int i=1;i<=num;i++){
vis[i]=0;
deg[i]=g[i].size();
if(!deg[i])h[++qt]=i;
}
vis[u]=1;
while(qh<=qt){
int now=h[qh++];
for(int i:G[now]){
vis[i]|=vis[now];
deg[i]--;
if(!deg[i])h[++qt]=i;
}
}
for(int i=1;i<=num;i++)
if(!vis[i])sum+=siz[i];
if(sum>=n&&sum<=n*2){
print();
return ;
}
}
puts("NIE");
}
int main(){
scanf("%d",&T);
while(T--){
solve();
Clear();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 119624kb
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:
0 1 0 0 0 1 0 1 0 0 TAK RRF 0 0 3 0 0 NIE
result:
wrong answer zla odpowiedz!