QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#99112#5504. Flower GardenMaverikAC ✓3298ms258248kbC++174.7kb2023-04-21 11:06:322023-04-21 11:06:36

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 11:06:36]
  • 评测
  • 测评结果:AC
  • 用时:3298ms
  • 内存:258248kb
  • [2023-04-21 11:06:32]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
int T,n,m,cnt,ecnt,go[30000010],adj[1200010],nxt[30000010],dfncnt,dfn[1200010],low[1200010],ins[1200010],wo[1200010],d[1200010],scccnt,scc[1200010],sccwo[1200010],tpcnt,tp[1200010],ans[1200010],vis[1200010];
pair<int,int> to[1200010];
stack<int> s;
queue<int> q;
vector<int> ok,fed[1200010],sed[1200010],sc[1200010];
struct node { int a,b,c,d;} op[100010];
void add_(int u,int v) { go[++ecnt]=v, nxt[ecnt]=adj[u], adj[u]=ecnt;}
void build_(int k,int l,int r,int opt) {
    if (opt==1) to[k].first=++cnt;
    else to[k].second=++cnt;
    if (k!=1) {
        if (opt==1) add_(to[k].first,to[k/2].first);
        else add_(to[k/2].second,to[k].second);
    }
    if (l==r) {
        if (opt==1) add_(l,to[k].first);
        else add_(to[k].second,l);
        return;
    }
    int mid=(l+r)>>1;
    build_(k<<1,l,mid,opt), build_(k<<1|1,mid+1,r,opt);
}
void turn_add_(int k,int l,int r,int lpos,int rpos,int opt,int kl) {
    if (lpos<=l&&r<=rpos) {
        if (opt==1) add_(to[k].first,kl);
        else add_(kl,to[k].second);
        return;
    }
    int mid=(l+r)>>1;
    if (lpos<=mid) turn_add_(k<<1,l,mid,lpos,rpos,opt,kl);
    if (mid<rpos) turn_add_(k<<1|1,mid+1,r,lpos,rpos,opt,kl);
}
void tarjan_(int x) {
    s.push(x), ins[x]=1, low[x]=dfn[x]=++dfncnt;
    for (int i=adj[x];i;i=nxt[i]) 
        if (!dfn[go[i]]) tarjan_(go[i]), low[x]=min(low[x],low[go[i]]);
        else if (ins[go[i]]) low[x]=min(low[x],dfn[go[i]]);
    if (low[x]!=dfn[x]) return;
    scccnt++;
    while (!s.empty()&&dfn[s.top()]>=dfn[x]) scc[s.top()]=scccnt, sc[scccnt].push_back(s.top()), sccwo[scccnt]+=wo[s.top()], ins[s.top()]=0, s.pop();
}
int main() {
    // freopen("in.in","r",stdin);
    // freopen("out.out","w",stdout);
    
    scanf("%d",&T);

    while (T--) {
        scanf("%d%d",&n,&m);
        for (int i=1;i<=m;i++) scanf("%d%d%d%d",&op[i].a,&op[i].b,&op[i].c,&op[i].d);

        cnt=3*n;
        build_(1,1,3*n,1), build_(1,1,3*n,2);
        for (int i=1;i<=m;i++) turn_add_(1,1,3*n,op[i].a,op[i].b,1,cnt+i), turn_add_(1,1,3*n,op[i].c,op[i].d,2,cnt+i);

        for (int i=1;i<=3*n;i++) wo[i]=1;
        for (int i=1;i<=cnt+m;i++) if (!dfn[i]) tarjan_(i);
        for (int i=1;i<=cnt+m;i++) for (int j=adj[i];j;j=nxt[j]) 
			if (scc[i]!=scc[go[j]]) fed[scc[i]].push_back(scc[go[j]]), sed[scc[go[j]]].push_back(scc[i]), d[scc[go[j]]]++;

        for (int i=1;i<=scccnt;i++) if (sccwo[i]>=n) {
            vector<int> v; 
            ok.clear();
            for (int j=1;j<=scccnt;j++) vis[j]=0;
            v.push_back(i), vis[i]=1;
            while (!v.empty()) {
                int e=v.back(); v.pop_back();
                for (auto o : sc[e]) if (wo[o]) ok.push_back(o);
                for (auto o : fed[e]) if (!vis[o]) vis[o]=1, v.push_back(o);
            }
            if ((int)ok.size()<=2*n) {
                assert((int)ok.size()>=n);
                for (auto o : ok) ans[o]=1;
                goto pos;
            }
            ok.clear();
            for (int j=1;j<=scccnt;j++) vis[j]=0;
            v.push_back(i), vis[i]=1;
            while (!v.empty()) {
                int e=v.back(); v.pop_back();
                for (auto o : sc[e]) if (wo[o]) ok.push_back(o);
                for (auto o : sed[e]) if (!vis[o]) vis[o]=1, v.push_back(o);
            }
            if ((int)ok.size()<=2*n) {
                assert((int)ok.size()>=n);
                for (int j=1;j<=3*n;j++) ans[j]=1;
                for (auto o : ok) ans[o]=0;
                goto pos;
            }
        }
        
        
        
        

        for (int i=1;i<=scccnt;i++) if (!d[i]) q.push(i);
        while (!q.empty()) {
            int e=q.front(); q.pop();
            tp[++tpcnt]=e;
            for (auto o : fed[e]) {
                d[o]--;
                if (!d[o]) q.push(o);
            }
        }
        ok.clear();
        for (int i=1;i<=scccnt;i++) {
            int e=tp[i];
            for (auto o : sc[e]) if (wo[o]) ok.push_back(o);
            if ((int)ok.size()>=n&&(int)ok.size()<=2*n) {
                assert((int)ok.size()>=n);
                for (int j=1;j<=3*n;j++) ans[j]=1;
                for (auto o : ok) ans[o]=0;
                goto pos;
            }
        }

        printf("NIE\n");
        goto pos2;

pos:;
        printf("TAK\n");
        for (int i=1;i<=3*n;i++) printf(ans[i] ? "F" : "R");
        printf("\n");

pos2:;
        for (int i=1;i<=cnt+m;i++) adj[i]=dfn[i]=low[i]=ins[i]=wo[i]=ans[i]=0;
        for (int i=1;i<=scccnt;i++) sccwo[i]=tp[i]=d[i]=0, fed[i].clear(), sed[i].clear(), sc[i].clear();
        scccnt=dfncnt=tpcnt=cnt=ecnt=0;
    }

    return 0;
}

详细

Test #1:

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

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: 3148ms
memory: 185108kb

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: 3298ms
memory: 216308kb

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: 2722ms
memory: 203316kb

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: 661ms
memory: 89200kb

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
FFR
NIE
TAK
RFRRRFFFFFFF
TAK
FFRFFFFFRFRR
NIE
TAK
FFFFRRRFFFFFFRR
TAK
FRRFRRFFFFFF
TAK
FFRFFRFFRRFF
TAK
FFFFFRFFFFFRRRR
TAK
FFRRRRFFFFFF
TAK
RRRRFFFFFFFFFFR
NIE
TAK
FFFFFRRRRFFF
NIE
TAK
RRFFFRRFF
NIE
TAK
FFFFFFRRR
TAK
RRRRFFFFFFFF
TAK
RRFFRFRFFFFFRFF
TAK
FFRRRRFFFFFF
NIE
TAK
...

result:

ok good!

Test #6:

score: 0
Accepted
time: 2875ms
memory: 258248kb

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!