QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#523870 | #5504. Flower Garden | z | WA | 1862ms | 144536kb | C++14 | 3.1kb | 2024-08-18 20:39:05 | 2024-08-18 20:39:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int testNum,n,Q;
int ptNum,colNum,dfNum;
int t1[N],t2[N];
int sta[N],top;
bool vis[N],ins[N];
int dfn[N],low[N],col[N];
int out[N],num[N];
vector<int>G[N],T[N],R[N];
void add(int x,int y){
G[x].push_back(y);
}
void Add(int x,int y){
T[x].push_back(y);
R[y].push_back(x);
++out[x];
}
void build(int k,int l,int r){
if(l==r) {t1[k]=t2[k]=l;return;}
t1[k]=++ptNum,t2[k]=++ptNum;
int mid=l+r>>1;
build(k*2,l,mid);
build(k*2+1,mid+1,r);
add(t1[k*2],t1[k]);
add(t1[k*2+1],t1[k]);
add(t2[k],t2[k*2]);
add(t2[k],t2[k*2+1]);
}
void add1(int k,int l,int r,int x,int y,int v){
if(x<=l&&r<=y) {
add(t1[k],v);
return;
}
int mid=l+r>>1;
if(x<=mid) add1(k*2,l,mid,x,y,v);
if(y>mid) add1(k*2+1,mid+1,r,x,y,v);
}
void add2(int k,int l,int r,int x,int y,int v){
if(x<=l&&r<=y){
add(v,t2[k]);
return;
}
int mid=l+r>>1;
if(x<=mid) add2(k*2,l,mid,x,y,v);
if(y>mid) add2(k*2+1,mid+1,r,x,y,v);
}
void tarjan(int u){
dfn[u]=low[u]=++dfNum;
ins[u]=1;
sta[++top]=u;
for(int v:G[u]){
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}else if(ins[v]) low[u]=min(low[u],dfn[v]);
}
if(low[u]==dfn[u]){
int t;
++colNum;
do{
t=sta[top--];
ins[t]=0;
if(t<=n*3) ++num[colNum];
col[t]=colNum;
}while(t!=u);
}
}
void init(){
for(int i=1;i<=ptNum;i++) G[i].clear(),low[i]=dfn[i]=col[i]=0;
for(int i=1;i<=colNum;i++) T[i].clear(),R[i].clear(),out[i]=num[i]=0,vis[i]=0;
ptNum=colNum=dfNum=0;
}
int main(){
scanf("%d",&testNum);
while(testNum--){
scanf("%d%d",&n,&Q);
init();
ptNum=n*3;
build(1,1,n*3);
int a,b,c,d;
while(Q--){
scanf("%d%d%d%d",&a,&b,&c,&d);
++ptNum;
add1(1,1,n*3,a,b,ptNum);
add2(1,1,n*3,c,d,ptNum);
}
for(int i=1;i<=ptNum;i++) if(!dfn[i]) tarjan(i);
for(int i=1;i<=ptNum;i++){
for(int j:G[i])
if(col[i]!=col[j]) Add(col[i],col[j]);
}
queue<int> q;
for(int i=1;i<=colNum;i++)
if(!out[i]) q.push(i);
int now=0;
bool f=0;
while(!q.empty()){
int u=q.front();q.pop();
if(now+num[u]>n*2) continue;
now+=num[u];
vis[u]=1;
if(now>=n&&now<=n*2){
f=1;
while(!q.empty()) q.pop();
break;
}
for(int v:R[u])
if(!--out[v]) q.push(v);
}
for(int i=1;!f&&i<=colNum;i++)
if(num[i]>=n){
for(int j=1;j<=colNum;j++) vis[j]=0;
now=0;
q.push(i);
while(!q.empty()){
int u=q.front();q.pop();
now+=num[u];
vis[u]=1;
for(int v:T[u]) if(!vis[v]) q.push(v);
}
if(now<=n*2) {f=1;break;}
}
if(!f){
puts("NIE");
continue;
}
puts("TAK");
for(int i=1;i<=n*3;i++)
if(vis[col[i]]) putchar('F');
else putchar('R');
putchar('\n');
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 51116kb
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: 1862ms
memory: 111980kb
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: 0
Accepted
time: 1805ms
memory: 144536kb
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:
ok good!
Test #4:
score: 0
Accepted
time: 1651ms
memory: 131968kb
input:
10 33333 100000 2646 2646 6430 6446 82226 82231 15128 15132 877 877 85831 88474 51389 79196 37573 37573 38030 38030 14248 14280 63032 68489 81074 81074 46468 46468 7403 7487 19864 20058 97979 97979 71640 71833 8558 8558 12121 12434 82481 82481 32901 32901 1899 2162 65312 77886 75969 75974 87983 8798...
output:
TAK FFFFFFFFFFFFFFFFFFFFFFFFFFFFFRRFFFFRFFRRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...
result:
ok good!
Test #5:
score: -100
Wrong Answer
time: 355ms
memory: 50824kb
input:
87005 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 1 1 1 3 2 3 1 2 1 1 2 2 2 2 1 1 1 2 1 3 1 1 1 1 1 3 4 20 3 5 6 12 4 5 7 11 1 1 2 2 3 4 7 12 3 5 10 10 3 5 8 8 4 4 9 11 4 4 7 7 1 1 9 10 3 4 6 9 3 5 11 12 3 3 7 9 3 5 2 2 4 5 2 2 1 1 7 11 1 1 10 10 3 5 7 8 4 4 2 2 1 1 2 2 4 5 8 10 4 12 11 ...
output:
TAK RRF NIE TAK RFF TAK RRF NIE TAK RFRRRFRRFRRF TAK RFRFFFRRRRRR NIE TAK FFFFRRRFRRRRRRR TAK FRRFRRRRFRRF TAK FFRRRRRRRRFF TAK FFFFFRRRRRRRRRR TAK FRRRRRFRFRRF TAK FFRRFFRRRRRRRRF NIE TAK RFFFRRRRRRRF NIE TAK RRFFFRRFF NIE TAK RRFFFRRRR TAK RRRRFFRRFRRF TAK FRRRFRRRRRRFFRF TAK RRRRRRFFFRRF NIE TAK ...
result:
wrong answer zla odpowiedz!