QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#261798 | #5504. Flower Garden | six-floor-slip-liu | WA | 11ms | 79320kb | C++14 | 4.2kb | 2023-11-23 11:06:41 | 2023-11-23 11:06:42 |
Judging History
answer
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define forup(i,s,e) for(int i=(s);i<=(e);i++)
#define fordown(i,s,e) for(int i=(s);i>=(e);i--)
using namespace std;
using pii=pair<int,int>;
#define fi first
#define se second
#define mkp make_pair
#define gc getchar()
inline int read(){
int x=0,f=1;char c;
while(!isdigit(c=gc)) if(c=='-') f=-1;
while(isdigit(c)){x=(x<<3)+(x<<1)+(c^48);c=gc;}
return x*f;
}
#undef gc
const int N=123456,inf=0x3f3f3f3f;
int n,q,cntn;
struct edge{
int v,nxt;
}e[12345678];
int head[N*9*2],cnte;
void adde(int u,int v){
e[++cnte]=edge{v,head[u]};head[u]=cnte;
}
int dfn[N*9*2],low[N*9*2],Tm,blg[N*9*2],csc,ist[N*9*2];
stack<int> stk;
int col[N*9*2],sz[N*9*2];
vector<pii> sve;
void Tarjan(int x){
low[x]=dfn[x]=++Tm;
stk.push(x);ist[x]=1;
for(int i=head[x];i;i=e[i].nxt){
int v=e[i].v;
if(!dfn[v]){
Tarjan(v);
low[x]=min(low[x],low[v]);
}else if(ist[v]){
low[x]=min(low[x],low[v]);
}
}
if(dfn[x]==low[x]){
++csc;sz[csc]=col[csc]=0;
while(stk.top()!=x){
int u=stk.top();
ist[u]=0;
blg[u]=csc;
if(u<=n*3){
++sz[csc];
}
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].v;
if(low[v]==low[u]) continue;
sve.push_back(mkp(u,v));
}
stk.pop();
}
int u=stk.top();
ist[u]=0;
blg[u]=csc;
if(u<=n*3){
++sz[csc];
}
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].v;
if(low[v]==low[u]) continue;
sve.push_back(mkp(u,v));
}
stk.pop();
}
}
int newnode(){
++cntn;
head[cntn]=0;
dfn[cntn]=low[cntn]=blg[cntn]=ist[cntn]=0;
return cntn;
}
struct SegTree{
#define mid ((l+r)>>1)
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
int num[N<<2],co,tp;
void New(int id){
num[id]=newnode();
if(tp==0){
adde(num[id>>1],num[id]);
}else{
adde(num[id],num[id>>1]);
}
}
void Build(int l=1,int r=3*n,int id=1){
if(l==r){
num[id]=l+co*(n*3);
if(tp==0){
adde(num[id>>1],num[id]);
}else{
adde(num[id],num[id>>1]);
}
return;
}
if(id>1) New(id);
Build(lson);Build(rson);
}
void init(int _co,int _tp){
co=_co;tp=_tp;
num[1]=newnode();
Build();
}
void Link(int L,int R,int X,int l=1,int r=3*n,int id=1){
if(L<=l&&r<=R){
adde(X,num[id]);
if(tp==0){
}else{
adde(num[id],X);
}
return;
}
if(L<=mid) Link(L,R,X,lson);
if(mid< R) Link(L,R,X,rson);
}
};
SegTree t[2][2];
namespace ANS{
vector<int> e[N*9*2];
int deg[N*9*2];
vector<int> seq;
int dfs(int x){
int res=sz[x];
col[x]=0;
for(auto i:e[x]){
if(!col[i]) continue;
res+=dfs(i);
}
return res;
}
bool work2(){
forup(i,1,csc){
col[i]=1;
}
forup(i,1,csc){
if(sz[i]>n){
return dfs(i)<=n*2;
}
}
return false;
}
void work(){
for(auto i:sve){
int u=i.fi,v=i.se;
int fu=blg[u],fv=blg[v];
if(fu==fv) continue;
e[fu].push_back(fv);
++deg[fv];
}
vector<int> vec,v1;
forup(i,1,csc){
if(deg[i]==0){
vec.push_back(i);
}
}
while(vec.size()){
v1.clear();
for(auto u:vec){
if(sz[u]!=0) seq.push_back(u);
for(auto v:e[u]){
--deg[v];
if(deg[v]==0&&sz[v]<=n) v1.push_back(v);
}
}
vec=v1;
}
int sum=0;
for(auto i:seq){
sum+=sz[i];
col[i]=1;
if(sum>=n){
break;
}
}
if(sum>=n&&sum<=n*2){
puts("TAK");
}else{
if(work2()){
puts("TAK");
}else{
puts("NIE");
return;
}
}
forup(i,1,n*3){
putchar(col[blg[i]]?'R':'F');
}
puts("");
}
}
void solve(){
n=read();q=read();
cnte=0;cntn=n*6;
forup(i,1,n*6){
head[i]=0;
dfn[i]=low[i]=blg[i]=ist[i]=0;
}
forup(i,0,1){
forup(j,0,1){
t[i][j].init(i,j);
}
}
forup(i,1,q){
int l1=read(),r1=read(),l2=read(),r2=read();
int nw=newnode();
t[1][1].Link(l1,r1,nw);t[1][0].Link(l2,r2,nw);
nw=newnode();
t[0][1].Link(l2,r2,nw);t[0][0].Link(l1,r1,nw);
}
sve.clear();
Tm=csc=0;
forup(i,1,cntn){
if(!dfn[i]) Tarjan(i);
}
forup(i,1,csc){
if(sz[i]>n*2){
puts("NIE");
return;
}
}
ANS::work();
}
signed main(){
int t=read();
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 79320kb
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!