QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#470880#5504. Flower GardenMathew_MiaoRE 1751ms209728kbC++235.0kb2024-07-10 16:48:302024-07-10 16:48:30

Judging History

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

  • [2024-07-10 16:48:30]
  • 评测
  • 测评结果:RE
  • 用时:1751ms
  • 内存:209728kb
  • [2024-07-10 16:48:30]
  • 提交

answer

#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<string>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1e5+10;
const int MAXM=1.2e6+10;
const int INF=0x3f3f3f3f;
const long long LINF=0x3f3f3f3f3f3f3f3f;
int n,q;
int idx=0;
basic_string <int> gr[MAXM];
inline void add_edge(int x,int y){
    gr[x].push_back(y);
}
namespace segtree{
    int L[MAXN*4],R[MAXN*4];
    int s[MAXN*4],t[MAXN*4];
    #define ls(x) (x<<1)
    #define rs(x) (x<<1|1)
    void build(int l,int r,int x){
        L[x]=l;
        R[x]=r;
        if(l==r){
            s[x]=l;
            t[x]=l;
            return ;
        }
        idx++;
        s[x]=idx;
        idx++;
        t[x]=idx;
        int mid=(l+r)>>1;
        build(l,mid,ls(x));
        build(mid+1,r,rs(x));
        add_edge(s[ls(x)],s[x]);
        add_edge(s[rs(x)],s[x]);
        add_edge(t[x],t[ls(x)]);
        add_edge(t[x],t[rs(x)]);
    }
    inline void build(){
        build(1,n*3,1);
    }
    void edge(int ql,int qr,int to,int x){
        int l=L[x],r=R[x];
        if(ql<=l&&r<=qr){
            if(to>0){
                add_edge(s[x],to);
            }
            else{
                add_edge(-to,t[x]);
            }
            return ;
        }
        if(qr<l||r<ql){
            return ;
        }
        edge(ql,qr,to,ls(x));
        edge(ql,qr,to,rs(x));
    }
    inline void edge(int ql,int qr,int to){
        edge(ql,qr,to,1);
    }
}
int dfc=0,cnt=0;
int dfn[MAXM],low[MAXM];
int col[MAXM],siz[MAXM];
int top=0;
int st[MAXM];
bool inst[MAXM];
void tarjan(int x){
    dfc++;
    dfn[x]=dfc;
    low[x]=dfc;
    top++;
    st[top]=x;
    inst[x]=true;
    for(int to:gr[x])
    {
        if(!dfn[to]){
            tarjan(to);
            low[x]=min(low[x],low[to]);
        }
        else if(inst[to]){
            low[x]=min(low[x],dfn[to]);
        }
    }
    if(low[x]==dfn[x]){
        cnt++;
        while(st[top]^x)
        {
            col[st[top]]=cnt;
            siz[cnt]+=(st[top]<=n*3);
            inst[st[top]]=false;
            top--;
        }
        top--;
        col[x]=cnt;
        siz[cnt]+=(x<=n*3);
        inst[x]=false;
    }
}
int out[MAXM];
basic_string <int> tr[MAXM],fr[MAXM];
inline void add_tr(int x,int y){
    tr[x].push_back(y);
    fr[y].push_back(x);
    out[x]++;
}
inline void tarjan(){
    dfc=0;
    top=0;
    for(int i=1;i<=idx;i++)
    {
        if(!dfn[i]){
            tarjan(i);
        }
    }
    for(int i=1;i<=idx;i++)
    {
        for(int to:gr[i])
        {
            if(col[i]^col[to]){
                add_tr(col[i],col[to]);
            }
        }
    }
}
bool vis[MAXM];
inline bool topo(){
    memset(vis,false,sizeof(int)*(cnt+1));
    queue <int> q;
    for(int i=1;i<=cnt;i++)
    {
        if(!out[i]){
            q.push(i);
        }
    }
    int sum=0;
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        if(siz[x]>n){
            continue;
        }
        vis[x]=true;
        sum+=siz[x];
        if(sum>=n){
            return true;
        }
        for(int f:fr[x])
        {
            out[f]--;
            if(!out[f]){
                q.push(f);
            }
        }
    }
    return false;
}
int dfs(int x){
    if(vis[x]){
        return 0;
    }
    vis[x]=true;
    int res=siz[x];
    for(int to:tr[x])
    {
        res+=dfs(to);
    }
    return res;
}
inline bool check(){
    for(int i=1;i<=cnt;i++)
    {
        if(siz[i]>n){
            memset(vis,false,sizeof(int)*(cnt+1));
            if(dfs(i)<=2*n){
                return true;
            }
        }
    }
    return false;
}
inline void solve(){
    scanf("%d%d",&n,&q);
    idx=n*3;
    segtree::build();
    for(int i=1;i<=q;i++)
    {
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        idx++;
        int to=idx;
        segtree::edge(a,b,to);
        segtree::edge(c,d,-to);
    }
    tarjan();
    if(topo()||check()){
        puts("TAK");
        for(int i=1;i<=n*3;i++)
        {
            if(vis[col[i]]){
                putchar('F');
            }
            else{
                putchar('R');
            }
        }
        putchar('\n');
        return ;
    }
    puts("NIE");
}
inline void clear(){
    memset(dfn,0,sizeof(int)*(idx+1));
    memset(low,0,sizeof(int)*(idx+1));
    memset(col,0,sizeof(int)*(idx+1));
    for(int i=1;i<=idx;i++)
    {
        gr[i].clear();
    }
    memset(siz,0,sizeof(int)*(cnt+1));
    memset(out,0,sizeof(int)*(cnt+1));
    for(int i=1;i<=cnt;i++)
    {
        tr[i].clear();
        fr[i].clear();
    }
    idx=0;
    cnt=0;
}
signed main(){
    int t;
    scanf("%d",&t);
    while(t--)
    {
        solve();
        clear();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 124252kb

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: 1638ms
memory: 181072kb

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: 1751ms
memory: 209728kb

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: 1608ms
memory: 200720kb

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: 405ms
memory: 129548kb

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:

ok good!

Test #6:

score: -100
Runtime Error

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: