QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99056#5504. Flower GardenAcestarCompile Error//C++144.6kb2023-04-21 09:57:002023-04-21 09:57:12

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 09:57:12]
  • 评测
  • [2023-04-21 09:57:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,m,t,lim,cnt,a[N],head[N],tot,sz[N],s[N],low[N],dfn[N],id[N],p[N],num,sum,tim;
bool vis[N],ans[N];
vector<int>son[N],g[N],re[N];
struct o{
    int ne,to;
}e[N*40];
inline void add(int x,int y){
    // cout<<x<<' '<<y<<'\n';
    e[++tot].ne=head[x];
    head[x]=tot;
    e[tot].to=y;
}
inline void build1(int x,int l,int r){
    if(l==r){
        a[x]=l,cnt=max(cnt,x);return;
    }
    int mid=(l+r)>>1;
    add(x<<1,x),add(x<<1|1,x);
    build1(x<<1,l,mid),build1(x<<1|1,mid+1,r);
}
inline void build2(int x,int l,int r){
    id[x]=x;
    if(l==r)return;
    id[x]+=cnt;
    int mid=(l+r)>>1;
    build2(x<<1,l,mid),build2(x<<1|1,mid+1,r);
    add(id[x],id[x<<1]),add(id[x],id[x<<1|1]);
}
inline void add1(int x,int l,int r,int ql,int qr){
    if(l>qr||r<ql)return;
    if(l>=ql&&r<=qr){
        add(x,cnt);return;
    }
    int mid=(l+r)>>1;
    add1(x<<1,l,mid,ql,qr),add1(x<<1|1,mid+1,r,ql,qr);
}
inline void add2(int x,int l,int r,int ql,int qr){
    if(l>qr||r<ql)return;
    if(l>=ql&&r<=qr){
        add(cnt,id[x]);return;
    }
    int mid=(l+r)>>1;
    add2(x<<1,l,mid,ql,qr),add2(x<<1|1,mid+1,r,ql,qr);
}
inline void tarjan(int x){
    low[x]=dfn[x]=++tim,s[++num]=x,vis[x]=1;
    for(int i=head[x];i;i=e[i].ne){
        int to=e[i].to;
        if(!dfn[to]){
            tarjan(to);
            low[x]=min(low[x],low[to]);
        }else if(vis[to])low[x]=min(low[x],dfn[to]);
    }
    if(low[x]==dfn[x]){
        sum++;
        while(s[num+1]!=x){
            p[s[num]]=sum;
            if(a[s[num]])g[sum].emplace_back(a[s[num]]),sz[sum]++;
            vis[s[num--]]=0;
        }
    }
}
inline void clear(){
    for(int i=1;i<=cnt;i++)id[i]=ans[i]=vis[i]=a[i]=head[i]=p[i]=low[i]=dfn[i]=sz[i]=0,son[i].clear(),g[i].clear(),re[i].clear();
    tot=cnt=sum=tim=num=0;
}
inline bool bfs1(int x){
    queue<int>q;for(int i=1;i<=sum;i++)vis[i]=0;
    q.push(x);int sum=0;vis[x]=1;
    while(q.size()){
        int x=q.front();q.pop();
        sum+=sz[x];
        for(int to:son[x]){
            if(vis[to])continue;
            q.push(to),vis[to]=1;
        }
    }
    return sum<=lim+lim;
}
inline bool bfs2(int x){
    queue<int>q;for(int i=1;i<=sum;i++)vis[i]=0;
    q.push(x);int sum=0;vis[x]=1;
    while(q.size()){
        int x=q.front();q.pop();
        sum+=sz[x];
        for(int to:re[x]){
            if(vis[to])continue;
            q.push(to),vis[to]=1;
        }
    }
    return sum<=lim+lim;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n>>m;
        lim=n;n*=3;
        build1(1,1,n),build2(1,1,n);
        cnt<<=1;cnt-=n;
        for(int i=1;i<=m;i++){
            int l,r,ql,qr;
            cin>>l>>r>>ql>>qr;cnt++;
            add1(1,1,n,l,r),add2(1,1,n,ql,qr);
        }
        for(int i=1;i<=cnt;i++)if(!dfn[i])tarjan(i);
        for(int x=1;x<=cnt;x++){
            for(int i=head[x];i;i=e[i].ne){
                int to=e[i].to;
                if(p[to]!=p[x])son[p[x]].emplace_back(p[to]),re[p[to]].emplace_back(p[x]);
            }
        }
        int pp=0,np=0;
        for(int i=1;i<=sum;i++){
            if(sz[i]>=lim){
                if(!np)np=i;
                else pp=i;
            }
        }
        if(sz[np]>lim+lim){
            cout<<"NIE"<<'\n';clear();continue;
        }
        if((np&&bfs1(np))||(pp&&bfs1(pp))){
            cout<<"TAK"<<'\n';
            for(int i=1;i<=sum;i++){
                if(!vis[i])continue;
                for(int x:g[i])ans[x]=1;
            }
            for(int i=1;i<=n;i++)cout<<(ans[i]?'F':'R');
            cout<<'\n';
            clear();continue;
        }else if((np&&bfs2(np))||(pp&&bfs2(pp))){
            cout<<"TAK"<<'\n';
            for(int i=1;i<=sum;i++){
                if(!vis[i])continue;
                for(int x:g[i])ans[x]=1;
            }
            for(int i=1;i<=n;i++)cout<<(ans[i]?'R':'F');
            cout<<'\n';
            clear();continue;
        }
        int res=0,np=0;
        for(int i=1;i<=sum;i++){
            res+=sz[i];
            if(res>=lim&&res<=lim+lim){
                np=i;break;
            }
        }
        if(np){
            for(int i=1;i<=np;i++){
                for(int x:g[i])ans[x]=1;
            }
            cout<<"TAK"<<'\n';
            for(int i=1;i<=n;i++)cout<<(ans[i]?'F':'R');
            cout<<'\n';
            clear();continue;
        }
        cout<<"NIE"<<'\n';
        clear();
    }
    return 0;
}

/*
1
1 3
1 1 2 2
2 2 3 3
3 3 1 1
*/

Details

answer.code: In function ‘int main()’:
answer.code:146:19: error: redeclaration of ‘int np’
  146 |         int res=0,np=0;
      |                   ^~
answer.code:117:18: note: ‘int np’ previously declared here
  117 |         int pp=0,np=0;
      |                  ^~