This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e6 + 10;
const int MOD = 1e9 + 7;
#define int long long
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
long long bm(long long b, long long p) {
if(p==0) return 1;
long long r = bm(b, p/2);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
struct segment {
int l, r;
};
bool cmp(segment a, segment b) {
return a.l < b.l;
}
vector<int> adj[MAXN];
char c[MAXN];
bool vis[MAXN];
void dfs(int node, char cur) {
c[node] = cur, vis[node] = 1;
for(int x: adj[node]) {
if(!vis[x]) {
dfs(x, (cur == 'A' ? 'B' : 'A'));
}
}
}
void solve(int tc) {
int n;
cin >> n;
segment s[n+1];
for(int i=1; i<=n; i++)cin >> s[i].l >> s[i].r;
sort(s+1, s+n+1, cmp);
for(int i=1; i<=n; i++) {
int lb = i+1, rb = n;
while(lb < rb) {
int mid = (lb+rb+1) >> 1;
if(s[mid].l < s[i].r) {
lb = mid;
}
else {
rb = mid - 1;
}
}
for(int j=i+1; j<=lb; j++) {
if(s[j].l < s[i].r && s[j].r > s[i].r) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
int compo = 0;
for(int i=1; i<=n; i++) {
if(!vis[i]) {
compo++;
dfs(i, 'A');
}
}
for(int i=1; i<=n; i++) {
for(int x: adj[i]) {
if(c[i] == c[x]) {
cout << "0\n"; return;
}
}
}
cout << bm(2, compo) << '\n';
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
/*
3 3
0 1 1 3
1 2 4 1
0 2 3 1
*/
# | 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... |