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>
#define int long long
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << "\n", exit(0);
#define pii pair<int, int>
#define pll pair<long long, long long>
#define endl "\n"
using namespace std;
typedef long long ll;
// typedef __int128_t lll;
typedef long double ld;
const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
const int LG = 30;
int n, m, k, tmp, t, tmp2, tmp3, tmp4, u, v, w, flag, q, ans, N, res, pre_ans;
pii arr[MAXN];
/* BIT */
int fen[2][MAXN];
inline void upd(int ind, int x, int y) {
for (x++; x<MAXN; x+=x&-x) fen[ind][x] += y;
}
inline int get(int ind, int x) {
int res = 0;
for (x++; x>0; x-=x&-x) res += fen[ind][x];
return res;
}
/* BIT */
int32_t main() {
#ifdef LOCAL
freopen("inp.in", "r", stdin);
freopen("res.out", "w", stdout);
#else
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
cin >> n;
for (int i=1; i<=n; i++) {
cin >> arr[i].S >> arr[i].F;
}
sort(arr+1, arr+n+1);
ans = 1;
for (int i=1; i<=n; i++) {
u = arr[i].S; v = arr[i].F;
tmp = get(0, u);
tmp2 = get(1, u);
if (!tmp && !tmp2) ans = (ans+ans)%MOD;
if (tmp && tmp2) kill(0);
if (tmp) upd(1, u, 1), upd(1, v+1, -1);
else upd(0, u, 1), upd(0, v+1, -1);
}
cout << ans << endl;
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... |