제출 #45912

#제출 시각아이디문제언어결과실행 시간메모리
45912golubPort Facility (JOI17_port_facility)C++11
0 / 100
2 ms248 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,sse4") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("unroll-all-loops") #include<cstring> #include<iostream> using namespace std; char buf[(long long)2e9]; size_t p_ = 0; void *operator new(size_t n_) { p_ += n_; return buf + p_ - n_; } void operator delete(void*) {}; #include <bits/stdc++.h> //#define TASK "lca" #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define F first #define S second #define pb push_back //#define int long long #define pii pair<int, int> //typedef long long ll; //typedef long double ld; const int INF = 1e9 + 100; const int MAXN = 1e6 * 2; const int MOD = 1e9 + 7; const double EPS = 1e-12; //ll power(ll x, ll n, ll mod = 1e9 + 7) { // if (n == 0) return 1ll; // if (n & 1ll) return power(x, n - 1ll, mod) * x % mod; // ll tmp = power(x, n >> 1ll, mod); // return (tmp * tmp) % mod; //} // //ll gcd(ll a, ll b) { // if (b == 0) return a; // return gcd (b, a % b); //} // //ll lcm(ll a, ll b) { // return a / gcd(a, b) * b; //} struct seg_max { vector<int> d; int SZ = 1; seg_max(int n = 0) { while(SZ < n) SZ *= 2; d.resize(SZ * 2, -INF); } void update(int x, int dx, int v, int l, int r) { if (x < l || x >= r) return; if (l + 1 >= r) { d[v] = dx; return; } int c = (r + l) / 2; update(x, dx, v * 2 + 1, l, c); update(x, dx, v * 2 + 2, c, r); d[v] = max(d[v * 2 + 1], d[v * 2 + 2]); } void update(int x, int dx) { update(x, dx, 0, 0, SZ); } int query(int ql, int qr, int v, int l, int r) { if (qr <= l || r <= ql) return -INF; if (ql <= l && r <= qr) return d[v]; int c = (l + r) / 2; return max(query(ql, qr, 2 * v + 1, l, c), query(ql, qr, 2 * v + 2, c, r)); } int query(int ql, int qr) { return query(ql, qr, 0, 0, SZ); } }; struct seg_min { vector<int> d; int SZ = 1; seg_min(int n = 0) { while(SZ < n) SZ *= 2; d.resize(SZ * 2, INF); } void update(int x, int dx, int v, int l, int r) { if (x < l || x >= r) return; if (l + 1 >= r) { d[v] = dx; return; } int c = (r + l) / 2; update(x, dx, v * 2 + 1, l, c); update(x, dx, v * 2 + 2, c, r); d[v] = min(d[v * 2 + 1], d[v * 2 + 2]); } void update(int x, int dx) { update(x, dx, 0, 0, SZ); } int query(int ql, int qr, int v, int l, int r) { if (qr <= l || r <= ql) return INF; if (ql <= l && r <= qr) return d[v]; int c = (l + r) / 2; return min(query(ql, qr, 2 * v + 1, l, c), query(ql, qr, 2 * v + 2, c, r)); } int query(int ql, int qr) { return query(ql, qr, 0, 0, SZ); } }; vector<pair<int, int>> a; vector<vector<int>> g; vector<int> used; unordered_map<int, int> num1, num2; seg_max seg_ma(MAXN); seg_min seg_mi(MAXN); void solve(int i, int color = 1) { seg_ma.update(a[i].F, -INF); seg_mi.update(a[i].S, INF); used[i] = color; vector<int> next; int l = a[i].F; int r = a[i].S; int ans = INF; while (ans > r) { ans = seg_ma.query(l, r + 1); if (ans <= r) break; int p = num1[ans]; if (used[p] && used[p] == color) { cout << 0 << '\n'; exit(0); } used[p] = color % 2 + 1; next.pb(p); // if (!used[p]) { // g[i].pb(p); // g[p].pb(i); // // } seg_ma.update(a[p].F, -INF); } ans = -INF; while (ans < l) { ans = seg_mi.query(l, r + 1); if (ans >= l) break; int p = num2[ans]; if (used[p] && used[p] == color) { cout << 0 << '\n'; exit(0); } used[p] = color % 2 + 1; next.pb(p); // if (!used[p]) { // g[i].pb(p); // g[p].pb(i); // // } seg_mi.update(a[p].S, INF); } for (auto x: next) { solve(x, color % 2 + 1); } } void dfs(int v, int color = 1) { used[v] = color; for (auto u: g[v]) { if (u != v && used[u] && used[u] == color) { cout << 0 << "\n"; exit(0); } if (!used[u]) dfs(u, color % 2 + 1); } } int n; int ans = 1ll; signed main() { #ifndef LOCAL #ifdef TASK freopen(TASK".in", "r", stdin); freopen(TASK".out", "w", stdout); #endif #endif #ifdef LOCAL //freopen("/Users/alekseygolub/Desktop/с++/ABS/ABS/input.txt", "r", stdin); #endif iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(924653523); // == SOLUTION == // scanf("%d", &n); a.resize(n); used.resize(n); g.resize(n); for (int i = 0; i < n; i++) { pair<int, int> x; scanf("%d%d", &x.F, &x.S); x.F--; x.S--; a[i] = x; num1[x.S] = i; num2[x.F] = i; seg_ma.update(x.F, x.S); seg_mi.update(x.S, x.F); } for (int i = 0; i < n; i++) { if (!used[i]) { solve(i); ans = ans << 1ll; ans %= MOD; } } // fill(all(used), 0); // for (int i = 0; i < n; i++) { // if (!used[i]) { // dfs(i); // } // } cout << ans << '\n'; }

컴파일 시 표준 에러 (stderr) 메시지

port_facility.cpp: In function 'int main()':
port_facility.cpp:218:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
port_facility.cpp:226:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x.F, &x.S);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...