QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#86789 | #5689. 喵了个喵 II | __stick | RE | 0ms | 0kb | C++14 | 2.8kb | 2023-03-10 22:15:26 | 2023-03-10 22:17:45 |
Judging History
answer
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
using namespace std;
template<typename T>
inline bool cmax(T&x,const T& y){return x<y?x=y,1:0;}
template<typename T>
inline bool cmin(T&x,const T& y){return y<x?x=y,1:0;}
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef unsigned long long ull;
#define sz(x) (int(x.size()))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define em emplace
#define X first
#define Y second
const int mod=998244353;
const int MAXN=2e5+10;
const int S=MAXN*30;
struct edge{int from,v;}e[MAXN*2];
int head[MAXN],cnt,n,m;
inline void add(int u,int v)
{e[++cnt]=(edge){head[u],v},head[u]=cnt;}
#define tree(u) for(int i=head[u],v=e[i].v;i;i=e[i].from,v=e[i].v)
inline void ADD(int u,int v){add(u,v),add(v^1,u^1);}
struct node
{
int l,r,id;
}t[MAXN*30];
#define ls t[p].l
#define rs t[p].r
int tt,id;
void bt(int& p,int l,int r)
{
p=++tt,t[p].id=id++,id++;
if(l==r)return;
int mid=(l+r)>>1;
bt(ls,l,mid),bt(rs,mid+1,r);
}
void update(int& p,int l,int r,int qq,int w)
{
t[++tt]=t[p];
p=tt,t[p].id=id++,id++;
if(l==r)return add(t[p].id,w);
int mid=(l+r)>>1;
if(qq<=mid)update(ls,l,mid,qq,w);
else update(rs,mid+1,r,qq,w);
add(t[p].id,t[ls].id),add(t[p].id,t[rs].id);
}
void ask(int p,int l,int r,int ql,int qr,int w)
{
if(!p)return;
if(ql<=l&&r<=qr)return add(w,t[p].id);
int mid=(l+r)>>1;
if(ql<=mid)ask(ls,l,mid,ql,qr,w);
if(qr >mid)ask(rs,mid+1,r,ql,qr,w);
}
int dfn[S],low[S],F[S];
int c;
void tarjan(int u)
{
static int s[S],top,tt;
s[++top]=u,dfn[u]=low[u]=++tt;
tree(u)
{
if(!dfn[v])tarjan(v),cmin(low[u],low[v]);
else if(!F[v])cmin(low[u],dfn[v]);
}
if(low[u]==dfn[u])
{
F[u]=++c;while(s[top]!=u)F[s[top--]]=c;top--;
}
}
struct op
{
int l,r,id;
inline bool operator<(const op& b)const{return r<b.r;}
}a[MAXN];
vi ve[MAXN];
int rt[MAXN];
char ans[MAXN];
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);cout<<fixed<<setprecision(10);
int n;
cin>>n;
for(int i=1;i<=n*4;i++)
{
int x;cin>>x;
ve[x].eb(i);
}
int tt=0;
for(int i=1;i<=n;i++)
{
a[++tt]={ve[i][0],ve[i][1],id};
a[++tt]={ve[i][2],ve[i][3],id};
id++;
a[++tt]={ve[i][0],ve[i][2],id};
a[++tt]={ve[i][1],ve[i][3],id};
id++;
}
sort(a+1,a+tt+1);
t[0].id=id;id+=2;
for(int i=1;i<=tt;i++)
{
ask(rt[i-1],1,tt,a[i].l,tt,a[i].id);
update(rt[i],1,tt,a[i].l,a[i].id^1);
}
for(int i=0;i<id;i++)if(!dfn[i])tarjan(i);
for(int i=0;i<id;i+=2)if(F[i]==F[i+1])return cout<<"No\n",0;
cout<<"Yes\n";
for(int i=1;i<=tt;i++)if(F[a[i].id]<F[a[i].id^1])
{
ans[a[i].l]='0',ans[a[i].r]='1';
}
cout<<(ans+1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
50000 12725 41478 2443 1096 36968 36898 3393 45898 43154 26629 22985 37972 13935 25628 40196 40293 39791 29109 455 45812 12634 21086 8928 13600 25416 30244 15917 22568 35849 40189 27442 28785 46334 25651 7172 30994 39724 27853 47091 21306 42087 31612 22081 23002 17127 15269 11569 8254 41080 30112 31...