이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e6+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
set<ll> ck[3],idx;
ll n,x[N],y[N],g[N],col[N],ans=1;
vector<pair<pll,ll> > ed;
void DFS(ll nd){
for(ll i=*idx.lwb(x[nd]);i<y[nd];i=*idx.lwb(i+1)){
ll tmp=0;
if(x[g[i]]&&y[g[i]]>y[nd])tmp=g[i];
if(y[g[i]]&&x[g[i]]<x[nd])tmp=g[i];
if(!tmp)continue;
col[tmp]=3-col[nd];
idx.erase(x[tmp]);idx.erase(y[tmp]);
DFS(tmp);
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
srand(clock());
cin>>n;
idx.insert(2*n+1);idx.insert(0);
REP1(i,n){
idx.insert(i*2-1);idx.insert(i*2);
cin>>x[i]>>y[i];
ed.pb(mp(mp(x[i],y[i]),i));
g[x[i]]=g[y[i]]=i;
}
random_shuffle(ed.begin(),ed.end());
for(auto i:ed){
if(!col[i.Y]){
ans=ans*2%MOD;
col[i.Y]=1;
idx.erase(i.X.X);idx.erase(i.X.Y);
DFS(i.Y);
}
}
sort(ed.begin(),ed.end());
for(auto i:ed){
int ty=col[i.Y];
if(ck[ty].lwb(i.X.X)!=ck[ty].end()&&*ck[ty].lwb(i.X.X)<i.X.Y){
cout<<"0\n";return 0;
}
ck[ty].insert(i.X.Y);
}
cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |