이 제출은 이전 버전의 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;
vector<ll> v[N];
set<pll> s;
void DFS(ll nd,ll pa){
for(auto i:v[nd]){
if(i==pa)continue;
col[i]=3-col[nd];
DFS(i,nd);
}
}
ll F(ll l,ll r){
auto t=s.lwb(mp(l,0));
if(t==s.end()||t->X>r)return 0;
return t->Y;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
REP1(i,n){
cin>>x[i]>>y[i];
ed.pb(mp(mp(x[i],y[i]),i));
}
sort(ed.begin(),ed.end());
for(auto i:ed){
ll id=F(i.X.X,i.X.Y);
//cout<<i.X.X<<" "<<i.X.Y<<" "<<id<<"\n";
s.insert(mp(i.X.Y,i.Y));
if(!id)continue;
v[id].pb(i.Y);v[i.Y].pb(id);
}
REP1(i,n){
if(!col[i]){
ans=ans*2%MOD;
col[i]=1;
DFS(i,0);
}
}
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... |