제출 #168692

#제출 시각아이디문제언어결과실행 시간메모리
168692maruiiPort Facility (JOI17_port_facility)C++14
78 / 100
6163 ms921160 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; #define ff first #define ss second const int mod = 1e9 + 7; int mp(int x, int a) { if (a == 0) return 1; int ret = mp(x, a >> 1); if (a & 1) return 1ll * ret * ret % mod * x % mod; return 1ll * ret * ret % mod; } int N; pii P[1000005]; int idx[2000005]; const int SIZE = 1 << 21; struct ST { set<int> A[2 * SIZE]; void insert(int x, int v) { for (x += SIZE; x; x >>= 1) A[x].insert(v); } void erase(int x, int v) { for (x += SIZE; x; x >>= 1) A[x].erase(v); } vector<int> query(int s, int e, int a, int b) { vector<int> ret; for (s += SIZE, e += SIZE; s <= e; s >>= 1, e >>= 1) { if ( s & 1) { auto i = A[s].lower_bound(a); auto j = A[s].lower_bound(b); for (; i != j; ++i) ret.push_back(idx[*i]); s++; } if (~e & 1) { auto i = A[e].lower_bound(a); auto j = A[e].lower_bound(b); for (; i != j; ++i) ret.push_back(idx[*i]); e--; } } return ret; } } seg; bool vis[1000005], C[1000005]; vector<int> A, B; void dfs(int x) { if (C[x]) A.push_back(x); else B.push_back(x); vis[x] = 1; auto v = seg.query(P[x].ff, P[x].ss, 0, P[x].ff); auto u = seg.query(P[x].ss, 2 * N, P[x].ff, P[x].ss); for (auto i : v) seg.erase(P[i].ss, P[i].ff); for (auto i : u) seg.erase(P[i].ss, P[i].ff); for (auto i : v) C[i] = C[x] ^ 1, dfs(i); for (auto i : u) C[i] = C[x] ^ 1, dfs(i); } int main() { cin >> N; for (int i = 0; i < N; ++i) { int a, b; cin >> a >> b; P[i] = {a, b}; } sort(P, P + N); for (int i = 0; i < N; ++i) seg.insert(P[i].ss, P[i].ff), idx[P[i].ff] = i; int cnt = 0; for (int i = N - 1; i >= 0; --i) { if (vis[i]) continue; cnt++; seg.erase(P[i].ss, P[i].ff); dfs(i); } priority_queue<int, vector<int>, greater<int> > pq; sort(A.begin(), A.end()); sort(B.begin(), B.end()); for (auto i : A) { while (pq.size() && pq.top() < P[i].ff) pq.pop(); if (pq.size() && pq.top() < P[i].ss) return !printf("0"); pq.push(P[i].ss); } while (pq.size()) pq.pop(); for (auto i : B) { while (pq.size() && pq.top() < P[i].ff) pq.pop(); if (pq.size() && pq.top() < P[i].ss) return !printf("0"); pq.push(P[i].ss); } cout << mp(2, cnt); return 0; }

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

port_facility.cpp: In function 'int mp(int, int)':
port_facility.cpp:7:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if (a == 0) return 1; int ret = mp(x, a >> 1); if (a & 1) return 1ll * ret * ret % mod * x % mod;
  ^~
port_facility.cpp:7:24: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if (a == 0) return 1; int ret = mp(x, a >> 1); if (a & 1) return 1ll * ret * ret % mod * x % mod;
                        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...