QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#305023 | #5504. Flower Garden | ushg8877 | WA | 2317ms | 171648kb | C++14 | 3.1kb | 2024-01-14 14:33:49 | 2024-01-14 14:33:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
const int MAXN=1e5+5;
int tot,n,q;
vector<int> edg[MAXN<<3],grp[MAXN<<3],rev[MAXN<<3];
int scc[MAXN<<3],val[MAXN<<3],dfn[MAXN<<3],low[MAXN<<3],cnt,snt;
int st[MAXN<<3],d[MAXN<<3],top;bool inq[MAXN<<3],ans[MAXN<<3];
struct segt1{
int rep[MAXN<<2];
void build(int id=1,int l=1,int r=n){
if(l==r){
rep[id]=l;
return;
}
rep[id]=++tot;
int mid=l+r>>1;
build(id<<1,l,mid);build(id<<1|1,mid+1,r);
edg[rep[id<<1]].push_back(rep[id]);
edg[rep[id<<1|1]].push_back(rep[id]);
}
void link(int L,int R,int x,int id=1,int l=1,int r=n){
if(L<=l&&r<=R){
edg[rep[id]].push_back(x);
return;
}
int mid=l+r>>1;
if(L<=mid) link(L,R,x,id<<1,l,mid);
if(mid<R) link(L,R,x,id<<1|1,mid+1,r);
}
}T1;
struct segt2{
int rep[MAXN<<2];
void build(int id=1,int l=1,int r=n){
if(l==r){
rep[id]=l;
return;
}
rep[id]=++tot;
int mid=l+r>>1;
build(id<<1,l,mid);build(id<<1|1,mid+1,r);
edg[rep[id]].push_back(rep[id<<1]);
edg[rep[id]].push_back(rep[id<<1|1]);
}
void link(int L,int R,int x,int id=1,int l=1,int r=n){
if(L<=l&&r<=R){
edg[x].push_back(rep[id]);
return;
}
int mid=l+r>>1;
if(L<=mid) link(L,R,x,id<<1,l,mid);
if(mid<R) link(L,R,x,id<<1|1,mid+1,r);
}
}T2;
void tarjan(int u){
low[u]=dfn[u]=++cnt;
st[++top]=u;inq[u]=true;
for(int v:edg[u]){
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}else if(inq[v]) low[u]=min(low[u],dfn[v]);
}
if(low[u]==dfn[u]){
++snt;
while(st[top+1]!=u){
inq[st[top]]=false;
scc[st[top--]]=snt;
}
}
}
void output(){
cout<<"TAK"<<endl;
for(int i=1;i<=n;i++) cout<<"RF"[ans[scc[i]]];
cout<<endl;
}
void init(){
for(int i=1;i<=tot;i++){
edg[i].clear(),grp[i].clear(),rev[i].clear();
scc[i]=dfn[i]=low[i]=val[i]=0;
st[i]=d[i]=inq[i]=ans[i]=0;
}
cnt=snt=top=tot=0;n=q=0;
}
void solve(){
cin>>n>>q;n*=3;
tot=n;
T1.build();T2.build();
for(int i=1;i<=q;i++){
int x=++tot,y=++tot,a,b,c,d;
cin>>a>>b>>c>>d;
T1.link(a,b,x);T2.link(c,d,y);
edg[x].push_back(y);
}
cnt=0;
for(int i=1;i<=tot;i++) if(!dfn[i]) tarjan(i);
for(int i=1;i<=n;i++) val[scc[i]]++;
for(int i=1;i<=tot;i++) for(int j:edg[i]) if(scc[i]!=scc[j])
grp[scc[i]].push_back(scc[j]),rev[scc[j]].push_back(scc[i]);
for(int i=1;i<=snt;i++) d[i]=grp[i].size();
queue<int> q;
for(int i=1;i<=snt;i++) if(d[i]==0&&val[i]<=n/3) q.push(i);
int sum=0;
while(!q.empty()){
int u=q.front();q.pop();
sum+=val[u];ans[u]=true;
if(sum>=n/3) return output(),init();
for(int v:rev[u]) if(--d[v]==0&&val[v]<=n/3) q.push(v);
}
for(int i=1;i<=snt;i++) if(d[i]>=n/3){
for(int i=1;i<=snt;i++) ans[i]=false;
while(!q.empty()) q.pop();
sum=0;q.push(i);ans[i]=true;
while(!q.empty()){
int u=q.front();q.pop();
sum+=val[u];
for(int v:grp[u]) if(!ans[v]){
ans[v]=true;
q.push(v);
}
}
if(sum<=2*n/3) return output(),init();
}
cout<<"NIE"<<endl;
return init();
}
int main(){
ios::sync_with_stdio(false);
int _;cin>>_;
while(_--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 59828kb
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: 2317ms
memory: 138100kb
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
Wrong Answer
time: 2236ms
memory: 171648kb
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:
NIE TAK RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...
result:
wrong answer zla odpowiedz!