제출 #651964

#제출 시각아이디문제언어결과실행 시간메모리
651964LoboPort Facility (JOI17_port_facility)C++17
10 / 100
1385 ms448 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 = 2e6+10; const int mod = 1e9+7; int n, a[maxn], b[maxn], bit[maxn]; int ds[maxn], dsz[maxn]; pair<int,int> c[maxn]; int find(int v) { if(v == ds[v]) return v; return ds[v] = find(ds[v]); } void join(int u, int v) { u = find(u); v = find(v); if(u == v) return; if(dsz[u] < dsz[v]) swap(u,v); dsz[u]+= dsz[v]; ds[v] = u; } void attb1(int pos, int val) { for(int i = pos; i <= 2*n; i+= i&-i) bit[i] = max(bit[i],val); } int qryb1(int pos) { int val = 0; for(int i = pos; i > 0; i-= i&-i) val = max(val,bit[i]); return val; } void solve() { cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; c[i] = mp(a[i],b[i]); } sort(c+1,c+1+n); for(int i = 1; i <= n; i++) { a[i] = c[i].fr; b[i] = c[i].sc; ds[i] = i; dsz[i] = 1; } // The graph will not be bipartite only if there exist some b1 < b2 < b3 // set<int> stb1; // for(int i = 1; i <= n; i++) { // stb1.insert(b[i]); // auto it = stb1.find(b[i]); // if(it != stb1.begin()) { // int b1 = *prev(it); // // adiciona o par b1,b[i] // attb1(b[i],b1); // } // // If the max b1 with b2 < b[i] is > a[i], I found it // if(qryb1(b[i]-1) > a[i]) { // cout << 0 << endl; // return; // } // } for(int i = 1; i <= n; i++) { for(int j = i+1; j <= n; j++) { for(int k = j+1; k <= n; k++) { if(b[i] < b[j] && a[k] < b[i] && b[k] > b[j]) { cout << 0 << endl; return; } } } } for(int i = 1; i <= n; i++) { for(int j = 1; j < i; j++) { if(a[i] < b[j] && b[j] < b[i]) join(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...