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;
#define finish(x) return cout << x << endl, 0
#define ll long long
const int N = 2000001;
int n, tree[4 * N], mod = 1e9 + 7;
vector <int> a;
void update(int l, int r, int node, int idx, int val){
if(r < l || r < idx || l > idx) return;
if(l == r){
tree[node] += val;
return;
}
int mid = (l + r) / 2;
update(l, mid, 2 * node, idx, val);
update(mid + 1, r, 2 * node + 1, idx, val);
tree[node] = tree[2 * node] + tree[2 * node + 1];
}
int query(int l, int r, int node, int s, int e){
if(r < l || r < s || l > e) return 0;
if(s <= l && r <= e) return tree[node];
int mid = (l + r) / 2;
return query(l, mid, 2 * node, s, e) + query(mid + 1, r, 2 * node + 1, s, e);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
a.resize(2 * n);
vector <int> r(n + 1);
for(int i = 1 ; i <= n ; i++){
int x, y;
cin >> x >> y;
x--; y--;
a[x] = i;
a[y] = -i;
r[i] = y;
}
int ans = 1;
for(auto &i : a){
if(i < 0){
update(0, 2 * n, 1, r[-i], -1);
continue;
}
int b = query(0, 2 * n, 1, 0, r[i]);
if(b >= 2) finish(0);
else if(b == 0){
ans *= 2;
if(ans >= mod) ans -= mod;
}
update(0, 2 * n, 1, r[i], 1);
}
cout << ans << endl;
}
# | 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... |