QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#99168 | #5504. Flower Garden | fansizhe | WA | 25ms | 73904kb | C++23 | 3.5kb | 2023-04-21 14:14:52 | 2023-04-21 14:14:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m,pnum;
vector<int> edge[1000005];
int dfn[1000005],low[1000005],cnt;
stack<int> st;int ins[1000005];
int col[1000005],tot;
vector<int> e1[1000005],e2[1000005];
int deg[1000005];
int vis[1000005];
int num[1000005];
queue<int> que;
int tot1,tot2;
int ch[1000005][2];
void addedge(int x,int y){edge[x].push_back(y);}
void build1(int k,int l,int r){
if(l==r){
addedge(l,k+n);
return;
}
int mid=l+r>>1;
ch[k][0]=++tot1;build1(ch[k][0],l,mid);
ch[k][1]=++tot1;build1(ch[k][1],mid+1,r);
addedge(ch[k][0]+n,k+n);
addedge(ch[k][1]+n,k+n);
}
void build2(int k,int l,int r){
if(l==r){
addedge(k+n+tot1,l);
return;
}
int mid=l+r>>1;
ch[k][0]=++tot2;build2(ch[k][0],l,mid);
ch[k][1]=++tot2;build2(ch[k][1],mid+1,r);
addedge(k+n+tot1,ch[k][0]+n+tot1);
addedge(k+n+tot1,ch[k][1]+n+tot1);
}
void change1(int k,int l,int r,int x,int y,int z){
if(l>=x&&r<=y){
addedge(k+n,z);
return;
}
int mid=l+r>>1;
if(x<=mid)change1(ch[k][0],l,mid,x,y,z);
if(y>mid)change1(ch[k][1],mid+1,r,x,y,z);
}
void change2(int k,int l,int r,int x,int y,int z){
if(l>=x&&r<=y){
addedge(z,k+n+tot1);
return;
}
int mid=l+r>>1;
if(x<=mid)change2(ch[k][0],l,mid,x,y,z);
if(y>mid)change2(ch[k][1],mid+1,r,x,y,z);
}
void Tarjan(int x){
dfn[x]=low[x]=++cnt;
ins[x]=1;st.push(x);
for(int y:edge[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(low[x]==dfn[x]){
tot++;int y;num[tot]=0;
do{
y=st.top();st.pop();
col[y]=tot;num[tot]+=(y<=n);ins[y]=0;
}while(y!=x);
}
}
int main(){
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
int _;scanf("%d",&_);
while(_--){
scanf("%d%d",&n,&m);n*=3;
tot1=1,tot2=1;
build1(1,1,n);
build2(1,1,n);
for(int i=1;i<=m;i++){
int l1,r1,l2,r2;
scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
change1(1,1,n,l1,r1,tot1+tot2+i);
change2(1,1,n,l2,r2,tot1+tot2+i);
}
pnum=n+tot1+tot2+m;cnt=tot=0;
for(int i=1;i<=pnum;i++)if(!dfn[i])Tarjan(i);
for(int i=1;i<=tot;i++)e1[i].clear(),e2[i].clear(),deg[i]=0;
for(int i=1;i<=pnum;i++)
for(int j:edge[i])if(col[i]!=col[j])
e1[col[i]].push_back(col[j]),e2[col[j]].push_back(col[i]);
int s=0,sum=0;
for(int i=1;i<=tot;i++)if(num[i]>=n/3)s=i;
for(int i=1;i<=tot;i++)vis[i]=0;
if(!s){
for(int i=1;i<=tot;i++)for(int j:e2[i])deg[j]++;
for(int i=1;i<=tot;i++)if(!deg[i])que.push(i);
while(!que.empty()){
int x=que.front();que.pop();
sum+=num[x];vis[x]=1;
if(sum>=n/3)break;
for(int y:e2[x])if(!--deg[y])que.push(y);
}
puts("TAK");
for(int i=1;i<=n;i++)if(vis[col[i]])putchar('F');else putchar('R');puts("");
while(!que.empty())que.pop();
}else{
que.push(s);vis[s]=1;
while(!que.empty()){
int x=que.front();que.pop();
sum+=num[x];
for(int y:e1[x])if(!vis[y])que.push(y),vis[y]=1;
}
if(sum<=n/3*2){
puts("TAK");
for(int i=1;i<=n;i++)if(vis[col[i]])putchar('F');else putchar('R');puts("");
}else{
sum=0;
for(int i=1;i<=tot;i++)vis[i]=0;
que.push(s);vis[s]=1;
while(!que.empty()){
int x=que.front();que.pop();
sum+=num[x];
for(int y:e2[x])if(!vis[y])que.push(y),vis[y]=1;
}
if(sum<=n/3*2){
puts("TAK");
for(int i=1;i<=n;i++)if(vis[col[i]])putchar('F');else putchar('R');puts("");
}else puts("NIE");
}
}
for(int i=1;i<=pnum;i++)edge[i].clear(),dfn[i]=0;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 25ms
memory: 73904kb
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 FRR NIE
result:
wrong answer odpowiedz nie spelnia wymogow!