QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#471886#5504. Flower Gardenmsk_samaWA 2257ms187576kbC++203.1kb2024-07-11 10:56:122024-07-11 10:56:12

Judging History

你现在查看的是最新测评结果

  • [2024-07-11 10:56:12]
  • 评测
  • 测评结果:WA
  • 用时:2257ms
  • 内存:187576kb
  • [2024-07-11 10:56:12]
  • 提交

answer

#include <bits/stdc++.h>
#define MISAKA main
#define ll long long
using namespace std;
inline int read(){
    char ch=getchar();int f=1,x=0;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
const double eps=1e-9;
const int N=8e6+10,inf=1e9,mod=998244353;
int n,m,idx=0,w[N],sum[N],dfn[N],low[N],scc[N],s[N],cl[N],deg[N],top=0,cnt=0,tim=0;
vector<int> g[N],G[2][N];queue<int> q;
struct node{int l,r,in,out;}t[N];
void link(int x,int y){g[x].push_back(y);}
void build(int now,int l,int r){
    t[now].l=l,t[now].r=r;int mid=l+r>>1;
    t[now].in=++idx,t[now].out=++idx;
    if(l==r){link(t[now].in,l);link(l,t[now].out);return;}
    build(2*now,l,mid);build(2*now+1,mid+1,r);
    link(t[now].in,t[2*now].in);link(t[now].in,t[2*now+1].in);
    link(t[2*now].out,t[now].out);link(t[2*now+1].out,t[now].out);
}
void link(int now,int l,int r,int x,int tp){
    if(t[now].l>r||t[now].r<l) return;
    if(l<=t[now].l&&t[now].r<=r){
        if(tp) link(x,t[now].in);
        else link(t[now].out,x);
        return;
    }
    link(2*now,l,r,x,tp);link(2*now+1,l,r,x,tp);
}
void tarjan(int u){
	dfn[u]=low[u]=++tim;s[++top]=u;
	for(int v:g[u]){
		if(!dfn[v]){
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}else if(!scc[v])low[u]=min(low[u],dfn[v]);
	}
	if(dfn[u]==low[u]){
		cnt++;
		while(s[top+1]!=u) scc[s[top--]]=cnt;
	}
}
void dfs(int u){cl[u]=1;for(int v:G[1][u])dfs(v);}
void misaka(){
    for(int i=1;i<=idx;i++) g[i].clear(),G[0][i].clear(),G[1][i].clear(),sum[i]=scc[i]=cl[i]=dfn[i]=low[i]=w[i]=deg[i]=0;
    for(int i=1;i<=20*n;i++) t[i]={0,0,0,0};
    n=read(),m=read();top=cnt=tim=0;idx=3*n;
    build(1,1,3*n);
    for(int i=1;i<=3*n;i++) w[i]=1; 
    for(int i=1;i<=m;i++){
        int l1=read(),r1=read(),l2=read(),r2=read();
        int a=++idx;link(1,l1,r1,a,0);link(1,l2,r2,a,1);
    }
    for(int i=1;i<=idx;i++)if(!dfn[i]) tarjan(i);
    for(int i=1;i<=idx;i++) sum[scc[i]]+=w[i];
    for(int i=1;i<=idx;i++)for(int j:g[i]){
        int u=scc[i],v=scc[j];
        if(u==v) continue;deg[u]++;
        G[1][u].push_back(v);
        G[0][v].push_back(u);
    }
    while(!q.empty()) q.pop();
    for(int i=1;i<=cnt;i++)if(!deg[i]) q.push(i);
    int all=0;
    while(!q.empty()){
        int u=q.front();q.pop();
        if(sum[u]>n) continue;
        cl[u]=1;all+=sum[u];
        if(all>=n) break;
        for(int v:G[0][u]){
            deg[v]--;
            if(!deg[v]) q.push(v);
        }
    }
    if(all>=n){
        puts("TAK");
        for(int i=1;i<=3*n;i++) putchar(cl[scc[i]]?'F':'R');
        puts("");return;
    }
    for(int id=1;id<=cnt;id++)if(sum[id]>n){
        for(int i=1;i<=cnt;i++) cl[i]=0;
        all=0;dfs(id);
        for(int i=1;i<=cnt;i++) all+=sum[i]*cl[i];
        if(all<=2*n){
            puts("TAK");
            for(int i=1;i<=3*n;i++) putchar(cl[scc[i]]?'F':'R');
            puts("");return;
        }
    }
    puts("NIE");
}
signed MISAKA(){
    int T=read();
    while(T--) misaka();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 18ms
memory: 20160kb

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: 2162ms
memory: 129788kb

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: 2257ms
memory: 187576kb

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: 2156ms
memory: 168736kb

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: 293ms
memory: 20036kb

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
FRRRFRRRRRRRFFF
TAK
RRRRRRFFFRRF
NIE
TAK
...

result:

wrong answer zla odpowiedz!