QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#77268#5504. Flower Gardenvme50AC ✓6439ms147260kbC++143.0kb2023-02-13 20:51:452023-02-13 20:54:08

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-13 20:54:08]
  • 评测
  • 测评结果:AC
  • 用时:6439ms
  • 内存:147260kb
  • [2023-02-13 20:51:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define N 500005
#define LIM 10000005
#define mid ((l+r)/2)
#define pb push_back
//#define gc() (P1==P2 && (P2=(P1=buf)+fread(buf,1,LIM,stdin),P1==P2)?EOF:*P1++)
#define gc getchar
char buf[LIM],*P1=buf,*P2=buf;
int T,n,m,cntV,dfn[N],low[N],st[N],bl[N];bool vs[N];
struct Seg {int u1,u2;}sg[N];vector<int> e1[N],e2[N],vc[N];
int rd()
{
    int res=0;char c=0;while(!isdigit(c)) c=gc();
    while(isdigit(c)) res=res*10+(c-48),c=gc();return res;
}
void build(int p,int l,int r)
{
    if(l==r) {sg[p]=(Seg) {l,l};return;}sg[p].u1=++cntV;sg[p].u2=++cntV;
    build(p*2,l,mid);build(p*2+1,mid+1,r);
    e1[sg[p].u1].pb(sg[p*2].u1);e1[sg[p].u1].pb(sg[p*2+1].u1);
    e1[sg[p*2].u2].pb(sg[p].u2);e1[sg[p*2+1].u2].pb(sg[p].u2);
}
void ins1(int p,int l,int r,int qL,int qR,int u)
{
    if(l>=qL && r<=qR) {e1[u].pb(sg[p].u1);return;}
    if(qL<=mid) ins1(p*2,l,mid,qL,qR,u);if(qR>mid) ins1(p*2+1,mid+1,r,qL,qR,u);
}
void ins2(int p,int l,int r,int qL,int qR,int u)
{
    if(l>=qL && r<=qR) {e1[sg[p].u2].pb(u);return;}
    if(qL<=mid) ins2(p*2,l,mid,qL,qR,u);if(qR>mid) ins2(p*2+1,mid+1,r,qL,qR,u);
}
void Tarjan(int u)
{
    dfn[u]=low[u]=++dfn[0];st[++st[0]]=u;
    for(auto v:e1[u]) if(!dfn[v]) Tarjan(v),low[u]=min(low[u],low[v]);
        else if(!bl[v]) low[u]=min(low[u],dfn[v]);
    if(dfn[u]==low[u])
    {bl[u]=++bl[0];while(st[st[0]]!=u) bl[st[st[0]--]]=bl[0];--st[0];}
}
void dfs1(int u) {if(vs[u]) return;vs[u]=1;for(auto v:e1[u]) dfs1(v);}
void dfs2(int u) {if(vs[u]) return;vs[u]=1;for(auto v:e2[u]) dfs2(v);}
void slv()
{
    for(int i=1;i<=cntV+m;++i) e1[i].clear(),e2[i].clear(),vc[i].clear();
    n=rd();m=rd();cntV=n*3;build(1,1,n*3);memset(dfn,0,sizeof(int)*(cntV+m+5));
    memset(bl,0,sizeof(int)*(cntV+m+5));memset(vs,0,sizeof(bool)*(cntV+m+5));
    for(int i=1,l1,r1,l2,r2;i<=m;++i)
    {
        l1=rd();r1=rd();l2=rd();r2=rd();
        ins1(1,1,n*3,l1,r1,cntV+i);ins2(1,1,n*3,l2,r2,cntV+i);
    }for(int i=1;i<=cntV+m;++i) for(auto j:e1[i]) e2[j].pb(i);
    for(int i=1;i<=cntV+m;++i) if(!dfn[i]) Tarjan(i);
    for(int i=1;i<=n*3;++i) vc[bl[i]].pb(i);
    for(int i=1,t;i<=bl[0];++i) if(vc[i].size()>=n)
    {
        t=0;dfs1(vc[i][0]);for(int j=1;j<=n*3;++j) if(vs[j]) ++t;
        if(t<=n*2)
        {
            printf("TAK\n");
            for(int j=1;j<=n*3;++j) putchar(vs[j]?'R':'F');putchar('\n');return;
        }t=0;memset(vs,0,sizeof(bool)*(cntV+m+5));dfs2(vc[i][0]);
        for(int j=1;j<=n*3;++j) if(vs[j]) ++t;
        if(t<=n*2)
        {
            printf("TAK\n");
            for(int j=1;j<=n*3;++j) putchar(vs[j]?'F':'R');putchar('\n');return;
        }printf("NIE\n");return;
    }
    for(int i=1,t=0;i<=bl[0];++i)
    {
        t+=vc[i].size();for(auto j:vc[i]) vs[j]=1;
        if(t>=n)
        {
            printf("TAK\n");
            for(int i=1;i<=n*3;++i) putchar(vs[i]?'R':'F');putchar('\n');return;
        }
    }
}
int main() {T=rd();while(T--) slv();return 0;}

详细

Test #1:

score: 100
Accepted
time: 15ms
memory: 38760kb

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: 6439ms
memory: 147260kb

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: 4134ms
memory: 125692kb

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: 4087ms
memory: 129628kb

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: 0
Accepted
time: 288ms
memory: 38568kb

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
RFF
NIE
TAK
RFF
TAK
RRF
NIE
TAK
RFRRRFFFFFFF
TAK
RFFFFFFFFRRR
NIE
TAK
RRFFRFFFFFFFFRR
TAK
FRRFRRFFFFFF
TAK
FFFFRRRRFFFF
TAK
RFFFFFFFFFFRRRR
TAK
RRRRFFFFFFFF
TAK
RRRRRFFFFFFFFFF
NIE
TAK
RFFFRRFRFFFF
NIE
TAK
RRFFFRRFF
NIE
TAK
FFFFFRRRF
TAK
RRRRFFFFFFFF
TAK
FRRRFRRRRRRFFFF
TAK
RRRRFFFFFFFF
NIE
TAK
...

result:

ok good!

Test #6:

score: 0
Accepted
time: 3126ms
memory: 114912kb

input:

10
33333 99999
60859 99999 1 60858
78724 99999 1 78723
42986 99999 1 42985
35108 99999 1 35107
63158 99999 1 63157
86977 99999 1 86976
13576 99999 1 13575
48277 99999 1 48276
89102 99999 1 89101
92657 99999 1 92656
25093 99999 1 25092
2353 99999 1 2352
81748 99999 1 81747
51216 99999 1 51215
75815 9...

output:

NIE
TAK
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR...

result:

ok good!