Submission #68309

#TimeUsernameProblemLanguageResultExecution timeMemory
68309realityPort Facility (JOI17_port_facility)C++17
100 / 100
2785 ms585136 KiB
#include "bits/stdc++.h" using namespace std; #define fi first #define se second #define ll long long #define dbg(v) cerr<<#v<<" = "<<v<<'\n' #define vi vector<int> #define vl vector <ll> #define pii pair<int,int> #define vii vector < pii > #define mp make_pair #define db long double #define pb push_back #define all(s) s.begin(),s.end() template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;} template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;} template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;} template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;} const int N = 2e6 + 5; const int mod = 1e9 + 7; int n; int color[N]; vi g[N]; int f[N]; int get(int k) { return f[k] == k ? k : f[k] = get(f[k]); } int main(void) { ios_base::sync_with_stdio(0); cin>>n; int ans = 1; vii e(n); for (auto & it : e) cin>>it.fi>>it.se; sort(all(e)); for (int i = 0;i < n + n;++i) f[i] = i; map < int , int > M; for (int i = 0;i < n;++i) { auto l = M.lower_bound(e[i].fi); auto r = M.lower_bound(e[i].se); if (!M.empty()) { int lst; if (r != M.begin()) { --r; lst = get(r->se); ++r; } else { lst = get(r->se); } while (l != r) { f[get(l->se + n)] = get(i); f[get(l->se)] = get(i + n); if (get(l->se) == get(lst)) break; ++l; } } M[e[i].se] = i; } set < int > ss; for (int i = 0;i < n;++i) if (get(i) == get(i + n)) ans = 0; for (int i = 0;i < n + n;++i) ss.insert(get(i)); for (int i = 0;i < ss.size();i += 2) ans = (ans * 2) % mod; cout << ans << '\n'; return 0; }

Compilation message (stderr)

port_facility.cpp: In function 'int main()':
port_facility.cpp:67:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0;i < ss.size();i += 2)
                    ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...