Submission #931254

#TimeUsernameProblemLanguageResultExecution timeMemory
931254parlimoosPort Facility (JOI17_port_facility)C++14
0 / 100
2 ms16732 KiB
//Be Name KHODA #pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define pp pop_back #define lb lower_bound #define ub upper_bound #define cl clear #define bg begin #define arr(x) array<int , x> #define endl '\n' const int MOD = int(1e9) + 7; int n; vector<arr(2)> a; int h[1000000]; int segl[2][8000001] , segr[2][8000001] , seginf[8000001][2]; int ls[2000000] , rs[2000000] , is[2000000]; set<int> ord; int Mul(int a , int b){ return (1ll * a * b) % MOD; } int Pow(int a , int b){ int res = 1; while(b){ if((b & 1)) res = Mul(res , a); a = Mul(a , a) , b >>= 1; } return res; } void readSeg(int i){ for(int md = 0 ; md < 2 ; md++){ segl[md][i] = max(segl[md][i << 1] , segl[md][(i << 1) | 1]); segr[md][i] = min(segr[md][i << 1] , segr[md][(i << 1) | 1]); } } void buildSeg(int l = 0 , int r = n + n - 1 , int i = 1){ seginf[i][0] = l , seginf[i][1] = r; if(l == r){ is[l] = i; segl[0][i] = ls[l] , segl[1][i] = ls[l]; segr[0][i] = rs[r] , segr[1][i] = rs[r]; }else{ int c = (l + r - 1) >> 1; buildSeg(l , c , (i << 1)) , buildSeg(c + 1 , r , (i << 1) | 1); readSeg(i); } } void updSeg(int md , int l , int r){ int i = is[l]; segl[md][i] = -1; while(i > 1) i >>= 1 , segl[md][i] = max(segl[md][i << 1] , segl[md][(i << 1) | 1]); i = is[r]; segr[md][i] = int(1e9); while(i > 1) i >>= 1 , segr[md][i] = max(segr[md][i << 1] , segr[md][(i << 1) | 1]); } int getMn(int l , int r , int md , int i){ if(seginf[i][0] >= l and seginf[i][1] <= r) return segr[md][i]; if(seginf[i][1] >= l and seginf[i][0] <= r) return min(getMn(l , r , md , i << 1) , getMn(l , r , md , (i << 1) | 1)); return int(1e9); } int getMx(int l , int r , int md , int i){ if(seginf[i][0] >= l and seginf[i][1] <= r) return segl[md][i]; if(seginf[i][1] >= l and seginf[i][0] <= r) return max(getMx(l , r , md , i << 1) , getMx(l , r , md , (i << 1) | 1)); return -1; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> n; fill(&ls[0] , &ls[n + n] , -1) , fill(&rs[0] , &rs[n + n] , int(1e9)) , fill(&h[0] , &h[n + n] , -1); for(int i = 0 ; i < n ; i++){ int l , r; cin >> l >> r; ls[l - 1] = r - 1 , rs[r - 1] = l - 1; ord.insert(l - 1); } buildSeg(); int o = 0; while(!ord.empty()){ queue<int> q; q.push(*ord.bg()) , ord.erase(ord.bg()); h[q.front()] = 0 , o++; updSeg(1 , q.front() , ls[q.front()]); while(!q.empty()){ int l = q.front() , r = ls[l]; q.pop(); while(true){ int d = getMx(l , r , h[l] , 1); if(d <= r) break; if(h[rs[d]] == h[l]){ // cout << l << " " << rs[d] << " : " << h[l] << " " << h[rs[d]] << "|\n"; cout << 0; exit(0); } h[rs[d]] = (h[l] ^ 1); updSeg(h[l] , rs[d] , d); q.push(rs[d]) , ord.erase(rs[d]); } while(true){ int d = getMn(l , r , h[l] , 1); if(d >= l) break; if(h[d] == h[l]){ cout << 0; exit(0); } h[d] = (h[l] ^ 1); updSeg(h[l] , d , ls[d]); q.push(d) , ord.erase(d); } } } cout << Pow(2 , o); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...