QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99113#5504. Flower GardenMaverikWA 3170ms352104kbC++174.7kb2023-04-21 11:07:472023-04-21 11:07:49

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:07:49]
  • 评测
  • 测评结果:WA
  • 用时:3170ms
  • 内存:352104kb
  • [2023-04-21 11:07:47]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int maxn=2e6+10;
#define ls (p<<1)
#define rs (p<<1|1)
#define mid ((t[p].l+t[p].r)>>1)
int n,Q,m;
int val[maxn],deg[maxn],ans[maxn];
int dfn[maxn],low[maxn],num,scn,sccval[maxn],bl[maxn];
vector<int>scc[maxn];
bool ins[maxn],vis[maxn];
stack<int>stk;
vector<int>e[maxn],g[maxn],ung[maxn];
inline void dadd(int x,int y){e[x].pb(y),e[y].pb(x);}
inline void add(int x,int y){e[x].pb(y);}
int idin[maxn],idout[maxn],idx;
struct Segment_In
{
    int up;
    struct node{int l,r;}t[maxn];
    inline void build(int p,int l,int r)
    {
        t[p].l=l,t[p].r=r;
        if(l==r) return idin[l]=p+up,void();
        add(p+up,ls+up),add(p+up,rs+up);
        build(ls,l,mid),build(rs,mid+1,r);
    }
    inline void addin(int p,int l,int r,int fm)
    {
        if(l<=t[p].l && t[p].r<=r) return add(fm,p+up);
        if(l<=mid) addin(ls,l,r,fm);
        if(r>mid) addin(rs,l,r,fm);
    }
    inline void buildin()
    {up=idx;build(1,1,m);idx+=5;}
}in;
struct Segment_Out
{
    int up;
    struct node{int l,r;}t[maxn];
    inline void build(int p,int l,int r)
    {
        t[p].l=l,t[p].r=r;
        if(l==r) return idout[l]=p+up,add(idin[l],l),add(l,idout[l]),void();
        add(ls+up,p+up),add(rs+up,p+up);
        build(ls,l,mid),build(rs,mid+1,r);
    }
    inline void addout(int p,int l,int r,int to)
    {
        if(l<=t[p].l && t[p].r<=r) return add(p+up,to);
        if(l<=mid) addout(ls,l,r,to);
        if(r>mid) addout(rs,l,r,to);
    }
    inline void buildout()
    {up=idx;build(1,1,m);idx+=5;}
}out;
inline void addseg(int l1,int r1,int l2,int r2){idx++;out.addout(1,l1,r1,idx),in.addin(1,l2,r2,idx);}
#undef ls
#undef rs
#undef mid


inline void tarjan(int x)
{
    dfn[x]=low[x]=++num,stk.push(x),ins[x]=1;
    for(auto y:e[x])
        if(!dfn[y]) tarjan(y),low[x]=min(low[x],low[y]);
        else if(ins[y]) low[x]=min(low[x],dfn[y]);
    if(dfn[x]==low[x])
    {
        scn++;int y;
        do
        {
            y=stk.top();stk.pop();ins[y]=0;
            scc[scn].pb(y);bl[y]=scn,sccval[scn]+=val[y];
        }while(x!=y);
    }
}
inline void printans()
{
    cout<<"TAK"<<'\n';
    for(int i=1;i<=m;i++) 
        if(ans[i]) cout<<"F";
        else cout<<"R";
    cout<<'\n';
}
inline void init()
{
    for(int i=0;i<maxn;i++)
    {
        e[i].clear(),g[i].clear(),ung[i].clear(),scc[i].clear();
        vis[i]=ins[i]=dfn[i]=low[i]=bl[i]=val[i]=sccval[i]=ans[i]=deg[i]=0;
        idin[i]=idout[i]=0;
    }
    idx=n=m=Q=num=scn=0;
    memset(in.t,0x00,sizeof(in.t));
    memset(out.t,0x00,sizeof(out.t));
    while(!stk.empty()) stk.pop();
}
inline void solve()
{
    cin>>n>>Q,idx=m=3*n;
    in.buildin(),out.buildout();
    for(int i=1,a,b,c,d;i<=Q;i++) cin>>a>>b>>c>>d,addseg(a,b,c,d);
    for(int i=1;i<=m;i++) val[i]=1;
    for(int i=1;i<=idx;i++) if(!dfn[i]) tarjan(i);
    for(int x=1;x<=idx;x++) for(auto y:e[x]) if(bl[y]!=bl[x])
        g[bl[x]].pb(bl[y]),deg[bl[y]]++,ung[bl[y]].pb(bl[x]);
    vector<int>res;
    for(int i=1;i<=scn;i++) if(sccval[i]>=n)
    {
        queue<int>q;
        for(int j=1;j<=m;j++) vis[j]=0;
        res.clear();q.push(i),vis[i]=1;
        while(!q.empty())
        {
            int x=q.front();q.pop();
            for(auto ele:scc[x]) if(ele<=m) res.pb(ele);
            for(auto y:g[x]) if(!vis[y]) q.push(y),vis[y]=1;
        }
        if(res.size()<=2*n) 
        {
            for(auto ele:res) ans[ele]=1;
            return printans(),init(),void();
        }
        
        for(int j=1;j<=m;j++) vis[j]=0;
        res.clear();q.push(i),vis[i]=1;
        while(!q.empty())
        {
            int x=q.front();q.pop();
            for(auto ele:scc[x]) if(ele<=m) res.pb(ele);
            for(auto y:ung[x]) if(!vis[y]) q.push(y),vis[y]=1; 
        }
        if(res.size()<=2*n) 
        {
            for(auto ele:res) ans[ele]=1;
            return printans(),init(),void();
        }  
    }
    
    queue<int>q;res.clear();
    for(int i=1;i<=scn;i++) if(!deg[i]) q.push(i);
    vector<int>tops;
    while(!q.empty())
    {
        int x=q.front();q.pop();tops.pb(x);
        for(auto y:g[x]) if(--deg[y]==0) q.push(y);
    }
    for(auto e:tops)
    {
        for(auto ele:scc[e]) if(ele<=m) res.pb(ele);
        if(n<=res.size() && res.size()<=2*n)
        {
            for(int i=1;i<=m;i++) ans[i]=1;
            for(auto ele:res) ans[ele]=0;
            return printans(),init(),void();
        } 
    }
    cout<<"NIE"<<'\n';init();
}
signed main()
{
    ios::sync_with_stdio(false);cin.tie(NULL);
    int Testcase;cin>>Testcase;
    while(Testcase--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 117ms
memory: 296368kb

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: 3170ms
memory: 352104kb

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: 2680ms
memory: 348468kb

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:

NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE

result:

wrong answer zla odpowiedz!