Submission #69351

#TimeUsernameProblemLanguageResultExecution timeMemory
69351Just_Solve_The_ProblemPort Facility (JOI17_port_facility)C++11
100 / 100
2173 ms624352 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define ll long long #define pii pair < int, int > #define fr first #define sc second #define mk make_pair #define sz(s) (int)s.size() #define all(s) s.begin(), s.end() #define OK puts("ok"); #define whatis(x) cerr << #x << " = " << x << endl; #define pause system("pause"); const int N = (int)2e6 + 7; const int inf = (int)1e9 + 7; int mod = (int)1e9 + 7; pii ar[N]; int pr[N], used[N]; int ans; map < int, int > mp; int mult(int a, int b) { return (a * 1LL * b) % mod; } int getpar(int a) { if (pr[a] == a) return a; return pr[a] = getpar(pr[a]); } void connect(int a, int b) { a = getpar(a); b = getpar(b); if (a != b) { pr[a] = b; } } main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d", &ar[i].fr, &ar[i].sc); } iota(pr, pr + n + n + 2, 0); sort(ar, ar + n); int ans = 1; for (int i = 0; i < n; i++) { auto fir = mp.lower_bound(ar[i].fr), sec = mp.lower_bound(ar[i].sc); while (fir != sec) { connect(i, (fir -> sc) + n); connect(i + n, fir -> sc); if (getpar((--sec) -> sc) == getpar(fir -> sc)) break; fir++; sec++; } mp[ar[i].sc] = i; } for (int i = 0; i < n; i++) { if (getpar(i) == getpar(i + n)) ans = 0; else used[getpar(i)] = used[getpar(i + n)] = 1; } for (int i = 0; i < n; i++) { if (used[i]) { ans = mult(ans, 2); } } cout << ans; }

Compilation message (stderr)

port_facility.cpp:44:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
port_facility.cpp: In function 'int main()':
port_facility.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
   ~~~~~^~~~~~~~~~
port_facility.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &ar[i].fr, &ar[i].sc);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...