QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#472585#5504. Flower Gardenzhao_daodaoWA 8ms112384kbC++143.4kb2024-07-11 17:19:472024-07-11 17:19:49

Judging History

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

  • [2024-07-11 17:19:49]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:112384kb
  • [2024-07-11 17:19:47]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=1e6+5;
int T=-1;
#define ls(x) ((x)<<1)
#define rs(x) ((x)<<1|1)
struct Tree{
    #define in(x) tr[x].in
    #define out(x) tr[x].out
    int in,out;
}tr[MAXN];int tot;
basic_string<int>V[MAXN];
inline void add(int u,int v){V[u].push_back(v);}
inline void build(int l,int r,int q){
    if(l==r){
        in(q)=out(q)=l;
        return ;
    }
    int mid=l+r>>1;
    in(q)=++tot,out(q)=++tot;
    build(l,mid,ls(q)),build(mid+1,r,rs(q));
    add(in(q),in(ls(q))),add(in(q),in(rs(q)));
    add(out(ls(q)),out(q)),add(out(rs(q)),out(q));
}
inline void update(int l,int r,int ql,int qr,int q,int x,bool opt){
    if(ql<=l&&r<=qr){
        if(opt)add(x,out(q));
        else add(in(q),x);
        return ;
    }int mid=l+r>>1;
    if(ql<=mid)update(l,mid,ql,qr,ls(q),x,opt);
    if(mid<qr)update(mid+1,r,ql,qr,rs(q),x,opt);
}
int n,q;
int dfn[MAXN],low[MAXN],dfscnt;
int scc[MAXN],siz[MAXN],sc;
int instk[MAXN],stk[MAXN],tp;
inline void tarjan(int u){
    dfn[u]=low[u]=++dfscnt;
    instk[stk[++tp]=u]=1;
    for(int v:V[u]){
        if(!dfn[v]){
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }else if(instk[v]){
            low[u]=min(low[u],dfn[v]);
        }
    }
    if(dfn[u]==low[u]){
        sc++;
        while(stk[tp]!=u){
            scc[stk[tp]]=sc;
            instk[stk[tp--]]=0;
        }
        scc[stk[tp]]=sc;
        instk[stk[tp--]]=0;
    }
}
basic_string<int>G[2][MAXN];
int deg[MAXN],col[MAXN];
inline void dfs(int u){
    col[u]=1;
    for(int v:G[1][u])if(!col[v])
        dfs(v);
}
signed main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    if(T==-1)cin>>T;
    for(int i=1;i<=tot;i++)dfn[i]=low[i]=scc[i]=siz[i]=instk[i]=stk[i]=deg[i]=col[i]=0;
    for(int i=1;i<=tot;i++)V[i].clear(),G[0][i].clear(),G[1][i].clear();
    tot=dfscnt=sc=tp=0;
    cin>>n>>q;tot=3*n;
    build(1,3*n,1);
    for(int i=1,a_,b_,c_,d_;i<=q;i++){
        cin>>a_>>b_>>c_>>d_;
        int now=++tot;
        update(1,3*n,a_,b_,1,now,0);
        update(1,3*n,c_,d_,1,now,1);
    }
    for(int i=1;i<=tot;i++)if(!dfn[i])tarjan(i);
    for(int i=1;i<=3*n;i++)siz[scc[i]]++;
    for(int u=1;u<=tot;u++)for(int v:V[u])
        if(scc[u]!=scc[v]){
            G[1][scc[u]].push_back(scc[v]);
            G[0][scc[v]].push_back(scc[u]);
            deg[scc[v]]++;
        }
    queue<int>q;
    for(int i=1;i<=sc;i++)if(!deg[i])q.push(i);
    int all=0;
    while(!q.empty()){
        int u=q.front();q.pop();
        if(siz[u]>n)continue;
        col[u]=1,all+=siz[u];
        if(all>=n)break;
        for(int v:G[0][u])if(!--deg[v])q.push(v);
    }
    if(all>=n){
        cout<<"TAK\n";
        for(int i=1;i<=3*n;i++)
            if(col[scc[i]])cout<<'F';
            else cout<<'R';
        cout<<"\n";
        if(--T)main();else exit(0);
    }
    for(int _=1;_<=sc;_++)if(siz[_]>=n){
        for(int i=1;i<=sc;i++)col[i]=0;
        all=0;dfs(_);
        for(int i=1;i<=sc;i++)all+=col[i]*siz[i];
        if(all<=2*n){
            cout<<"TAK\n";
            for(int i=1;i<=3*n;i++)
                if(col[scc[i]])cout<<'F';
                else cout<<'R';
        cout<<"\n";
            if(--T)main();else exit(0);
        }
    }
    cout<<"NIE\n";
    if(--T)main();else exit(0);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 112384kb

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
RFR
NIE

result:

wrong answer odpowiedz nie spelnia wymogow!