QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#261742 | #5504. Flower Garden | six-floor-slip-liu | RE | 7483ms | 224208kb | C++14 | 4.4kb | 2023-11-23 10:00:02 | 2023-11-23 10:00:02 |
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);
#ifdef DEBUG
printf("%d %d %d||\n",l,r,num[id]);
#endif
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 ans[N];
void work(){
for(auto i:sve){
int u=i.fi,v=i.se;
int fu=blg[u],fv=blg[v];
if(fu==fv) continue;
#ifdef DEBUG
printf("%d %d\n",fu,fv);
#endif
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){
// printf("%d\n",u);
if(sz[u]!=0) seq.push_back(u);
for(auto v:e[u]){
--deg[v];
if(deg[v]==0) v1.push_back(v);
}
}
vec=v1;
sort(vec.begin(),vec.end(),[&](int a,int b){
return sz[a]<sz[b];
});
}
int sum=0;
#ifdef DEBUG
forup(i,1,cntn){
printf("%d|",blg[i]);
}
puts("");
#endif
for(auto i:seq){
#ifdef DEBUG
printf("%d|",i);
#endif
sum+=sz[i];
col[i]=1;
if(sum>=n){
break;
}
}
#ifdef DEBUG
puts("");
#endif
if(sum<=n*2){
puts("TAK");
}else{
puts("NIE");
return;
}
forup(i,1,n*3){
ans[i]=col[blg[i]];
}
forup(i,1,n*3){
putchar(ans[i]?'F':'R');
}
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);
}
}
#ifdef DEBUG
printf("%d||\n",cntn);
#endif
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();
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();
}
}
/*
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 81436kb
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: 0
Accepted
time: 7483ms
memory: 224208kb
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 NIE NIE NIE NIE NIE NIE NIE NIE NIE
result:
ok good!
Test #3:
score: -100
Runtime Error
input:
10 33333 100000 15207 33614 66276 66276 97173 97173 67589 73960 19673 36626 65207 65207 89825 98169 27079 27079 56067 56966 7560 7560 18170 35477 18752 18752 32621 36748 34460 34460 61595 61700 14117 14117 32395 36710 9064 9064 13172 13172 1728 4640 40462 41878 47171 47171 76965 82414 5767 5767 9225...
output:
TAK FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...