제출 #963672

#제출 시각아이디문제언어결과실행 시간메모리
963672CookiePort Facility (JOI17_port_facility)C++14
0 / 100
2 ms2652 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; #define sz(a) (int)a.size() #define ALL(v) v.begin(), v.end() #define ALLR(v) v.rbegin(), v.rend() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> #define mpp make_pair const ld PI = 3.14159265359, prec = 1e-9;; //using u128 = __uint128_t; //const int x[4] = {1, 0, -1, 0}; //const int y[4] = {0, -1, 0, 1}; const ll mod = 1e9 + 7, pr = 31; const int mxn = 1e5 + 5, mxq = 1e5 + 5, sq = 500, mxv = 5e4 + 1; //const int base = (1 <<18); const ll inf = 1e9 + 5, neg = -69420, inf2 = 1e14; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // have fun! //JOIIIIIIIIIIIIIII int n; int c[mxn + 1]; pii p[mxn + 1]; vt<int>adj[mxn + 1]; bool bad = 0, used[mxn + 1]; void dfs(int s){ for(auto i: adj[s]){ if(c[i] == -1){ c[i] = c[s] ^ 1; dfs(i); }else if(c[i] != (c[s] ^ 1))bad = 1; } } void solve(){ cin >> n; for(int i = 1; i <= n; i++)cin >> p[i].fi >> p[i].se; sort(p + 1, p + n + 1); set<int>s; for(int i = 1; i <= n; i++){ auto it = s.lower_bound(p[i].fi); if(it == s.end() || *it > p[i].se){ used[i] = 1; s.insert(p[i].se); } } s.clear(); for(int i = 1; i <= n; i++){ if(!used[i]){ auto it = s.lower_bound(p[i].fi); if(it == s.end() || *it > p[i].se){ s.insert(p[i].se); }else{ cout << 0; return; } } } for(int i = 1; i <= n; i++){ for(int j = i + 1; j <= n; j++){ if(p[j].fi < p[i].se && p[i].se < p[j].se){ adj[i].pb(j); adj[j].pb(i); } } } ll ans = 1; for(int i = 1; i <= n; i++)c[i] = -1; for(int i = 1; i <= n; i++){ if(c[i] == -1){ c[i] = 1; dfs(i); ans = (ans * 2) % mod; } } if(bad){ cout << 0; return; } cout << ans; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("DATA.inp", "r", stdin); //freopen("DATA.out", "w", stdout); int tt; tt = 1; while(tt--){ solve(); } return(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...