Submission #652485

#TimeUsernameProblemLanguageResultExecution timeMemory
652485LoboPort Facility (JOI17_port_facility)C++17
22 / 100
6021 ms136416 KiB
#include<bits/stdc++.h> using namespace std; const long long inf = (long long) 1e18 + 10; const int inf1 = (int) 1e9 + 10; #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() const int maxn = 1e6+10; const int mod = 1e9+7; int n, a[maxn], b[maxn]; int ds[maxn], dsz[maxn], dsgrp[maxn]; vector<int> dsvec[maxn]; set<int> dsgrpbs[maxn][2]; int find(int v) { if(v == ds[v]) return v; return ds[v] = find(ds[v]); } void createedge(int u, int v) { // an edge from u to v int u1 = u; int v1 = v; int chg = 1; // dsgrp[v] = dsgrp[u]^chg, basically 0 if from the same group and 1 if not u = find(u); v = find(v); if(dsgrp[u1] != dsgrp[u]) chg^= 1; if(dsgrp[v1] != dsgrp[v]) chg^= 1; if(u == v) { if(chg == 1) { // I fail, because they are equal cout << 0 << endl; exit(0); } else { // stop the uniting return; } } if(dsz[u] < dsz[v]) { swap(u,v); swap(u1,v1); } // Now I insert all the ones from v in u ds[v] = u; dsz[u]+= dsz[v]; for(auto id : dsvec[v]) { // Insert id in u as dsgrp[id]^chg dsgrp[id]^= chg; dsgrpbs[u][dsgrp[id]].insert(b[id]); dsvec[u].pb(id); } } void solve() { cin >> n; vector<pair<int,int>> wtfsort; for(int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; wtfsort.pb(mp(a[i],b[i])); } sort(all(wtfsort)); for(int i = 1; i <= n; i++) { a[i] = wtfsort[i-1].fr; b[i] = wtfsort[i-1].sc; ds[i] = i; dsz[i] = 1; dsvec[i].pb(i); dsgrp[i] = 0; dsgrpbs[i][0].insert(b[i]); } for(int i = 1; i <= n; i++) { for(int j = 1; j < i; j++) { if(b[j] > a[i] && b[j] < b[i]) { createedge(i,j); } } } int ans = 1; for(int i = 1; i <= n; i++) { if(find(i) == i) ans = ans*2%mod; } cout << ans << endl; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); int tt = 1; // cin >> tt; while(tt--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...