QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#99342#5504. Flower GardenFanch100WA 9778ms269172kbC++145.1kb2023-04-21 21:58:552023-04-21 21:58:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-21 21:58:59]
  • 评测
  • 测评结果:WA
  • 用时:9778ms
  • 内存:269172kb
  • [2023-04-21 21:58:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int RN = 100010;
const int N = 500010;
const int M = N*10;
int n, Q;
int head[N], pre[M], ver[M], tot, from[M];
void add(int x,int y){
    ver[++tot]=y; pre[tot]=head[x]; head[x]=tot; from[tot]=x;
//    if (tot>=M-10000) printf("tot=%d\n",tot);
//    printf("x=%d y=%d\n",x,y);
}
int idx;
int spl[N];
int w[N];
int ls[N], rs[N];
void build(int &p,int l,int r,bool z){
    if (l==r) {
        if (!w[l]) w[l]=++idx, spl[idx]=l;
        p=w[l];
        return;
    }
    p=++idx;
//    printf("p=%d l=%d r=%d\n",p,l,r);
    int mid=(l+r)>>1;
    build(ls[p],l,mid,z); build(rs[p],mid+1,r,z);
    if (!(z&1)) add(ls[p],p),add(rs[p],p);
    else add(p,ls[p]),add(p,rs[p]);
}
void update(int p,int l,int r,int pl,int pr,int d,bool z){
    if (l<=pl && pr<=r){
        if (!(z&1)) add(p,d);
        else add(d,p);
        return;
    }
    int mid=(pl+pr)>>1;
    if (mid>=l) update(ls[p],l,r,pl,mid,d,z);
    if (mid+1<=r) update(rs[p],l,r,mid+1,pr,d,z);
}
int dfn[N], low[N], tp, st[N], top, scc[N], sc, siz[N];
bool ins[N];
vector<int> inc[N];
void tarjan(int x){
    dfn[x]=low[x]=++tp;
    st[++top]=x; ins[x]=1;
    for (int i=head[x]; i; i=pre[i]){
        int v=ver[i];
        if (!dfn[v]){
            tarjan(v);
            low[x]=min(low[x],low[v]);
        }
        else if (ins[v]) low[x]=min(low[x],dfn[v]);
    }
    if (dfn[x]==low[x]){
        sc++;
        while(1){
            int qh=st[top--];
            scc[qh]=sc;
            if (spl[qh]) siz[sc]++, inc[sc].push_back(spl[qh]);
            ins[qh]=0;
            if (qh==x) break;
        }
    }
}
vector<int> G0[N], G1[N];
set<pair<int,int> > s;
int dg[N];
bool vis[N];
vector<int> ans;
int bfs(int x){
    for (int i=1;i<=sc;++i) vis[i]=0; ans.clear();
    queue<int> q;
    q.push(x);
    while(q.size()){
        int x=q.front(); q.pop();
        if (vis[x]) continue;
        vis[x]=1;
        for (int i : inc[x]) ans.push_back(i);
        for (int v : G0[x]) q.push(v);
    }
    if (ans.size()<=n/3*2) return 0;
//    for (int i=1;i<=sc;++i) vis[i]=0; ans.clear();
    vis[x]=0;
    q.push(x);
    while(q.size()){
        int x=q.front(); q.pop();
        if (vis[x]) continue;
        vis[x]=1;
        for (int i : inc[x]) ans.push_back(i);
        for (int v : G1[x]) q.push(v);
    }
    if (ans.size()<=n/3*2) return 1;
    return 2;
}
void clear(){for (int i=1;i<=idx;++i) dfn[i]=dg[i]=spl[i]=w[i]=siz[i]=head[i]=0, G0[i].clear(), G1[i].clear(), inc[i].clear(); tp=0; tot=0; idx=0; sc=0; s.clear();}
bool anss[N], flag;
void solve(){

    cin>>n>>Q; n*=3;
    int nn=n/3;
    tot=0; idx=0;
    int rt0=0, rt1=0;
    build(rt0,1,n,0);
    build(rt1,1,n,1);
//    printf("tot=%d\n",tot);
    while(Q--){
        int l1,r1,l2,r2; cin>>l1>>r1>>l2>>r2;
//        if (Q==100000-1 && l1==15207) flag=1;
        ++idx;
        update(rt0,l1,r1,1,n,idx,0);
        update(rt1,l2,r2,1,n,idx,1);
//        printf("l=%d r=%d l=%d r=%d\n",l1,r1,l2,r2);
    }
//    printf("idx=%d tot=%d\n",idx,tot);
    for (int i=1;i<=idx;++i){
        if (!dfn[i]) tarjan(i);
    }
//    puts("Yes");
    for (int i=1;i<=tot;++i){
        if (scc[from[i]]!=scc[ver[i]]){
            int x=scc[from[i]], y=scc[ver[i]];

            if (s.find({x,y})!=s.end()) continue;
            s.insert({x,y});
            G0[y].push_back(x); G1[x].push_back(y);
            dg[y]++;
//            printf("un x=%d y=%d dg=%d\n",x,y,dg[y]);
        }
    }
//    for (int i=1;i<=idx;++i) printf("i=%d sc=%d\n",i,scc[i]);
//    for (int i=1;i<=sc;++i) {
//        printf("i=%d dg=%d siz=%d\n",i,dg[i],siz[i]);
//        for (int j : inc[i]) printf("%d ",j); puts("");
//    }
    for (int i=1;i<=sc;++i){
        if (siz[i]>2*nn){
            puts("NIE");
            clear();
            return;
        }
        if (siz[i]>=nn){
            int tmp=bfs(i);
            if (tmp!=2){
                puts("TAK");
//                printf("tmp=%d i=%d\n",tmp,i);
                for (int j=1;j<=n;++j) anss[j]=(tmp^1);
                for (int j : ans) anss[j]=tmp;
                for (int j=1;j<=n;++j) printf(anss[j]?"F":"R"); puts("");
                clear();
                return;
            }
        }
    }
//    puts("Yes");
    for (int i=1;i<=n;++i) anss[i]=1;
    queue<int> q; ans.clear();
    for (int i=1;i<=sc;++i){
        if (!dg[i]) q.push(i);
    }
    while(q.size()){
        int x=q.front(); q.pop();
//        printf("x=%d\n",x);
        for (int i : inc[x]) ans.push_back(i);
        if (ans.size()>=nn && ans.size()<=nn*2){
            puts("TAK");
//            clear();
            for (int j : ans) anss[j]=0;
            for (int j=1;j<=n;++j) printf(anss[j]?"F":"R"); puts("");
            return;
        }
        for (int v : G1[x]){
            if ((--dg[v])==0) q.push(v);
        }
    }
//    for (int i=1;i<=sc;++i) printf("dg=%d\n",dg[i]);
    clear();
    puts("NIE");
}
int main(){
//    freopen("data.in","r",stdin);
    int t; cin>>t;
    while(t--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 54640kb

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: 3186ms
memory: 120340kb

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: -100
Wrong Answer
time: 9778ms
memory: 269172kb

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:

wrong answer zla odpowiedz!