QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471506 | #5504. Flower Garden | peter | RE | 0ms | 24160kb | C++14 | 3.8kb | 2024-07-10 21:40:21 | 2024-07-10 21:40:22 |
Judging History
answer
// Problem: I - Flower Garden
// Contest: Virtual Judge - 2024-07-10 贪心与构造
// URL: https://vjudge.net/contest/639440#problem/I
// Memory Limit: 1014 MB
// Time Limit: 30000 ms
#include <bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
struct edge{
int to,nxt;
}e[maxn],g[maxn];
int head[maxn],len,headg[maxn],leng,cnt=0;
int n,q,tim,tot;
int dfn[maxn],low[maxn];
int blgs[maxn],sz[maxn];
bool inst[maxn];
stack<int> st;
inline void init(){
for(int i=1;i<=15*n+q;i++){
head[i]=headg[i]=-1;
dfn[i]=low[i]=blgs[i]=sz[i]=0;
inst[i]=0;
}
len=leng=tim=tot=0;
}
void addedge(int u,int v){
e[++len].to=v;
e[len].nxt=head[u];
head[u]=len;
}
void addg(int u,int v){
g[++leng].to=v;
g[leng].nxt=headg[u];
headg[u]=leng;
}
void add(int u,int v){
addedge(u,v);
addg(v,u);
}
struct Tree{
int tr[maxn<<2];
void build(int now,int l,int r,int op){
if(l==r){
tr[now]=l;
return;
}
tr[now]=++cnt;
// printf("%d %d %d %d : %d\n",now,l,r,op,tr[now]);
int mid=(l+r)>>1;
build(now<<1,l,mid,op);
build(now<<1|1,mid+1,r,op);
if(!op){
add(tr[now<<1],tr[now]);
add(tr[now<<1|1],tr[now]);
// printf("pp%d %d\nkk%d %d\n",tr[now<<1],tr[now],tr[now<<1|1],tr[now]);
}else{
add(tr[now],tr[now<<1]);
add(tr[now],tr[now<<1|1]);
// printf("pp%d %d\nkk%d %d\n",tr[now],tr[now<<1],tr[now],tr[now<<1|1]);
}
}
void update(int now,int l,int r,int ql,int qr,int k,int op){
if(ql<=l&&qr>=r){
if(!op) add(tr[now],k);
else add(k,tr[now]);
return;
}
int mid=(l+r)>>1;
if(ql<=mid) update(now<<1,l,mid,ql,qr,k,op);
if(qr>mid) update(now<<1|1,mid+1,r,ql,qr,k,op);
}
}t1,t2;
void tarjan(int u){
// fflush(stdout);
dfn[u]=low[u]=++tim;
st.push(u);
inst[u]=1;
for(int i=head[u];i!=-1;i=e[i].nxt){
int v=e[i].to;
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}else if(inst[v]) low[u]=min(low[u],dfn[v]);
}
// printf("pp%d %d %d\n",u,dfn[u],low[u]);
if(low[u]==dfn[u]){
tot++;
int x;
do{
x=st.top();
// printf("%d %d\n",x,u);
// fflush(stdout);
inst[x]=0;
st.pop();
blgs[x]=tot;
sz[tot]+=(x<=3*n);
}while(x!=u);
}
}
int res[maxn];
int dfs(int u,int op){
if(res[u]) return 0;
// printf("%d : %d\n",op,u);
if(u<=3*n) res[u]=1;
int tt=(u<=3*n);
if(!op){
for(int i=head[u];i!=-1;i=e[i].nxt){
int v=e[i].to;
tt+=dfs(v,op);
}
}else{
for(int i=headg[u];i!=-1;i=g[i].nxt){
int v=g[i].to;
tt+=dfs(v,op);
}
}
return tt;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
tim=tot=0;
scanf("%d %d",&n,&q);
init();
cnt=3*n;
t1.build(1,1,3*n,0);
t2.build(1,1,3*n,1);
while(q--){
int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
cnt++;
t1.update(1,1,3*n,a,b,cnt,0);
t2.update(1,1,3*n,c,d,cnt,1);
}
for(int i=1;i<=cnt;i++){
if(!dfn[i]) tarjan(i);
}
int now=0;
bool flag=0;
for(int i=1;i<=tot;i++){
now+=sz[i];
if(now>2*n){
// puts("here");
int p;
for(int j=1;j<=3*n;j++){
if(blgs[j]==i){
p=j;
break;
}
}
for(int j=1;j<=3*n;j++) res[j]=0;
if(dfs(p,1)<=2*n){//R 0 F 1
puts("TAK");
flag=1;
for(int j=1;j<=3*n;j++){
if(res[j]) putchar('R');
else putchar('F');
}
puts("");
break;
}
for(int j=1;j<=3*n;j++) res[j]=0;
if(dfs(p,0)<=2*n){
puts("TAK");
flag=1;
for(int j=1;j<=3*n;j++){
if(res[j]) putchar('F');
else putchar('R');
}
puts("");
break;
}
break;
}else if(now>=n){
flag=1;
puts("TAK");
for(int j=1;j<=3*n;j++){
if(blgs[j]<=i) putchar('F');
else putchar('R');
}
puts("");
break;
}
}
if(flag) continue;
puts("NIE");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 24160kb
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: -100
Runtime Error
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...