Submission #578498

#TimeUsernameProblemLanguageResultExecution timeMemory
578498alireza_kavianiPort Facility (JOI17_port_facility)C++17
100 / 100
4106 ms265480 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define SZ(x) ll(x.size()) #define lc id << 1 #define rc lc | 1 const ll MAXN = 2e6 + 10; const ll LOG = 22; const ll INF = 8e18; const ll MOD = 1e9 + 7; //998244353; //1e9 + 9; int n , cnt , ans = 1 , A[MAXN] , B[MAXN] , mark[MAXN]; pii seg[2][MAXN << 2]; vector<pii> vec[2]; void modify(int ind , int pos , pii val , int id = 1 , int l = 0 , int r = 2 * n){ if(r - l == 1){ seg[ind][id] = val; return; } int mid = l + r >> 1; if(pos < mid) modify(ind , pos , val , lc , l , mid); else modify(ind , pos , val , rc , mid , r); seg[ind][id] = min(seg[ind][lc] , seg[ind][rc]); } pii get(int ind , int ql , int qr , int id = 1 , int l = 0 , int r = 2 * n){ if(qr <= l || r <= ql) return {MOD, MOD}; if(ql <= l && r <= qr) return seg[ind][id]; int mid = l + r >> 1; return min(get(ind , ql , qr , lc , l , mid), get(ind , ql , qr , rc , mid , r)); } void DFS(int v , int col){ mark[v] = 1; modify(0 , B[v] , {MOD , v}); modify(1 , A[v] , {MOD , v}); vec[col].push_back({A[v] , B[v]}); while(1){ pii u = get(0 , A[v] , B[v]); if(u.X > A[v]) break; DFS(u.Y , 1 - col); } while(1){ pii u = get(1 , A[v] , B[v]); if(-u.X < B[v]) break; DFS(u.Y , 1 - col); } } void check(vector<pii> vec){ set<int> st; sort(all(vec)); for(pii i : vec){ auto it = st.lower_bound(i.X); if(it != st.end() && (*it) <= i.Y){ cout << 0 << endl; exit(0); } st.insert(i.Y); } } int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); fill(seg[0] , seg[0] + MAXN * 4 , pii(MOD , MOD)); fill(seg[1] , seg[1] + MAXN * 4 , pii(MOD , MOD)); cin >> n; for(int i = 0 ; i < n ; i++){ cin >> A[i] >> B[i]; A[i]--; B[i]--; modify(0 , B[i] , {A[i] , i}); modify(1 , A[i] , {-B[i] , i}); } for(int i = 0 ; i < n ; i++){ if(!mark[i]){ DFS(i , 0); cnt++; } } check(vec[0]); check(vec[1]); for(int i = 0 ; i < cnt ; i++){ ans = ans * 2 % MOD; } cout << ans << endl; return 0; } /* */

Compilation message (stderr)

port_facility.cpp: In function 'void modify(int, int, pii, int, int, int)':
port_facility.cpp:31:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |  int mid = l + r >> 1;
      |            ~~^~~
port_facility.cpp: In function 'pii get(int, int, int, int, int, int)':
port_facility.cpp:40:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |  int mid = l + r >> 1;
      |            ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...