QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#470960 | #5504. Flower Garden | czc | WA | 1003ms | 102452kb | C++23 | 4.3kb | 2024-07-10 17:02:44 | 2024-07-10 17:02:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int maxn=1e5+5;
struct tree{
int id1,id2;
}T[maxn<<2];
int tot;
vector<int> G[maxn<<3];
#define lc (rt<<1)
#define rc (rt<<1|1)
int h[maxn<<3],vs[maxn<<3];
inline void build(int rt,int l,int r){
if(l==r){
T[rt].id1=T[rt].id2=++tot;
G[tot].clear();
h[tot]=l;
vs[tot]=1;
return ;
}
T[rt].id1=++tot,vs[tot]=0,h[tot]=0;
T[rt].id2=++tot,vs[tot]=0,h[tot]=0;
G[T[rt].id1].clear();
G[T[rt].id2].clear();
int mid=(l+r)>>1;
build(lc,l,mid);
build(rc,mid+1,r);
G[T[rt].id1].push_back(T[lc].id1),G[T[rt].id1].push_back(T[rc].id1);
G[T[lc].id2].push_back(T[rt].id2),G[T[rc].id2].push_back(T[rt].id2);
}
vector<int> v1,v2;
inline void ask(int rt,int l,int r,int L,int R,int op){
if(L<=l && r<=R){
if(op) v1.push_back(T[rt].id1);
else v2.push_back(T[rt].id2);
return ;
}
int mid=(l+r)>>1;
if(L<=mid) ask(lc,l,mid,L,R,op);
else ask(rc,mid+1,r,L,R,op);
}
int dfn[maxn<<3],low[maxn<<3],instack[maxn<<3],scc[maxn<<3],col,tt;
stack<int> st;
inline void Tarjan(int x){
dfn[x]=low[x]=++tt;
st.push(x);
instack[x]=1;
for(auto y:G[x]){
if(!dfn[y]){
Tarjan(y);
low[x]=min(low[x],low[y]);
}
else if(instack[y]) low[x]=min(low[x],dfn[y]);
}
if(dfn[x]==low[x]){
col++;
scc[x]=col,instack[x]=0;
while(st.top()!=x){
scc[st.top()]=col;
instack[st.top()]=0;
st.pop();
}
st.pop();
}
}
int Ans[maxn];
vector<int> G2[maxn<<3],G3[maxn<<3];
int ind[maxn<<3],cd[maxn<<3],siz[maxn<<3],vvv[maxn<<3];
vector<int> vv[maxn<<3];
inline void solve(){
scanf("%d%d",&n,&m);
tot=0;
build(1,1,n*3);
for(int i=1,l1,r1,l2,r2;i<=m;i++){
scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
v1.clear(),v2.clear();
ask(1,1,n*3,l1,r1,1);
ask(1,1,n*3,l2,r2,0);
for(auto x:v2){
for(auto y:v1){
G[x].push_back(y);
}
}
}
while(!st.empty()) st.pop();
for(int i=1;i<=tot;i++) dfn[i]=low[i]=instack[i]=scc[i]=0;
col=tt=0;
for(int i=1;i<=tot;i++)
if(!dfn[i]) Tarjan(i);
for(int i=1;i<=n*3;i++) Ans[i]=0;;
for(int i=1;i<=col;i++) vv[i].clear(),ind[i]=0,G2[i].clear(),siz[i]=0,cd[i]=0,vvv[i]=0,G3[i].clear();
for(int i=1;i<=tot;i++){
assert(1<=scc[i] && scc[i]<=col);
siz[scc[i]]+=vs[i];
if(vs[i]){
vv[scc[i]].push_back(h[i]);
}
assert(siz[scc[i]]==(int)vv[scc[i]].size());
for(auto j:G[i]){
if(scc[i]!=scc[j]){
G2[scc[i]].push_back(scc[j]);
G3[scc[j]].push_back(scc[i]);
ind[scc[j]]++,cd[scc[i]]++;
}
}
}
int ps=0;
for(int i=1;i<=col;i++){
if(siz[i]>2*n){
printf("NIE\n");
return ;
}
if(siz[i]>n+1){
ps=i;
break;
}
}
if(!ps){
//乱选
queue<int> q;
int ans=0;
for(int i=1;i<=col;i++)
if(!cd[i]) q.push(i);
for(int i=1;i<=n*3;i++) assert(Ans[i]==0);
while(!q.empty()){
int x=q.front();
assert(x>=1 && x<=col);
q.pop();
ans+=siz[x];
for(auto y:vv[x]) Ans[y]=1;
assert(siz[x]==(int)vv[x].size());
if(ans>=n) break;
for(auto y:G3[x]){
cd[y]--;
if(!cd[y]) q.push(y);
}
}
puts("TAK");
int ctt=0;
for(int i=1;i<=n*3;i++){
if(Ans[i]) printf("R"),ctt++;
else printf("F");
}
assert(ans==ctt);
assert(n<=ctt && ctt<=2*n);
puts("");
return ;
}
else{
//考虑选 pos
int ans=0;
queue<int> q;
q.push(ps);
vvv[ps]=1;
while(!q.empty()){
int x=q.front();
q.pop();
ans+=siz[x];
for(auto y:vv[x]) Ans[y]=1;
for(auto y:G2[x]){
if(!vvv[y]){
vvv[y]=1;
q.push(y);
}
}
}
if(ans<=2*n){
puts("TAK");
int ctt=0;
for(int i=1;i<=n*3;i++){
if(Ans[i]) printf("R"),ctt++;
else printf("F");
}
assert(n<=ctt && ctt<=2*n);
puts("");
return ;
}
for(int i=1;i<=n*3;i++) Ans[i]=0;
//考虑不选
ans=0;
for(int i=1;i<=col;i++)
if(!cd[i]) q.push(i);
while(!q.empty()){
int x=q.front();
q.pop();
if(x==ps) continue;
ans+=siz[x];
for(auto y:vv[x]) Ans[y]=1;
for(auto y:G3[x]){
cd[y]--;
if(!cd[y]) q.push(y);
}
}
if(ans>=n){
int ctt=0;
puts("TAK");
for(int i=1;i<=n*3;i++){
if(Ans[i]) printf("R"),ctt++;
else printf("F");
}
puts("");
assert(n<=ctt && ctt<=2*n);
return ;
}
}
puts("NIE");
}
int main(){
int T;
scanf("%d",&T);
while(T--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 26292kb
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 RFF NIE
result:
ok good!
Test #2:
score: 0
Accepted
time: 670ms
memory: 70824kb
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: 1003ms
memory: 102452kb
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...
result:
wrong answer odpowiedz nie spelnia wymogow!