Submission #656179

#TimeUsernameProblemLanguageResultExecution timeMemory
656179ilia_rrPort Facility (JOI17_port_facility)C++17
0 / 100
2 ms468 KiB
// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ // Written by Ilia Rahbar // #pragma GCC optimize ("O3,no-stack-protector,unroll-loops,fast-math") // #pragma GCC target ("abm,bmi,bmi2,tbm,avx2") #include <bits/stdc++.h> using namespace std; #define int int64_t #define ai(x) array <int, x> #define F first #define S second const int MOD = 1e9 + 7, N = 1e6 + 100; ai(2) a[N]; int n, d[N], l[N * 2], vs[N], c, ans = 1; set <int> s; set <int> :: iterator itr; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; sort(a, a+n); for (int i = 0; i < n; i++) { l[a[i][0]] = i+1; l[a[i][1]] = i+1; } for (int i = 1; i <= n * 2; i++) { if (vs[l[i]]) { s.erase(l[i]); if (!d[l[i]]) { d[l[i]] = 1; c++; } itr = s.end(); while (s.size()) { itr--; if (*itr < l[i]) break; if (d[*itr] && d[*itr] != 3 - d[l[i]]) { assert(0); cout << 0; return 0; } d[*itr] = 3 - d[l[i]]; if (itr == s.begin()) break; } } else { vs[l[i]] = 1; s.insert(l[i]); } } for (int i = 0; i < c; i++) ans = (ans * 2) % MOD; cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...