이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<long long,long long>pii;
typedef array<int,5>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
inline pii combine(pii a, pii b){
if(a.first>b.first){
return a;
}
else return b;
}
struct node{
int s,e,m;
node *l,*r;
pii v;
node(int ss, int ee):s(ss),e(ee),m((s+e)>>1){
if(s!=e){
l=new node(s,m);
r=new node(m+1,e);
v=combine(l->v,r->v);
}
else{
v={0,s};
}
}
void upd(int x, pii y){
if(s==e){
v=y;
return;
}
if(x<=m) l->upd(x,y);
else r->upd(x,y);
v=combine(l->v,r->v);
}
pii query(int x, int y){
if(x<=s&&y>=e){
return v;
}
if(y<=m) return l->query(x,y);
if(x>m) return r->query(x,y);
return combine(l->query(x,m),r->query(m+1,y));
}
};
vector<int>adj[1000005];
int visited[1000005];
bool amos=true;
const int mod=1e9+7;
void dfs(int index, int col){
visited[index]=col;
for(auto it:adj[index]){
if(visited[it]&&visited[it]==visited[index]) amos=false;
else if(!visited[it]){
dfs(it,3-col);
}
}
}
void solve(){
int n;
cin >> n;
pii arr[n];
for(int x=0;x<n;x++){
cin >> arr[x].first >> arr[x].second;
}
sort(arr,arr+n);
node st(0,2*n+5);
for(int x=0;x<n;x++){
st.upd(arr[x].first,{arr[x].second,x});
}
for(int x=0;x<n;x++){
vector<pii>undo;
st.upd(arr[x].first,{0,x});
while(1){
pii hold=st.query(arr[x].first,arr[x].second);
if(hold.first<=arr[x].second) break;
adj[x].push_back(hold.second);
adj[hold.second].push_back(x);
//show2(x,x,hold.second,hold.second);
st.upd(arr[hold.second].first,{0,hold.second});
undo.push_back(hold);
}
for(auto it:undo){
st.upd(arr[it.second].first,{arr[it.second].second,it.second});
}
}
int counter=1;
for(int x=0;x<n;x++){
if(!visited[x]){
dfs(x,1);
counter=(counter*2)%mod;
}
}
if(!amos){
cout << 0;
}
else cout << counter;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//freopen("in.txt","r",stdin);
//cin >> t;
while(t--){
solve();
}
}
# | 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... |