제출 #671754

#제출 시각아이디문제언어결과실행 시간메모리
671754stevancvPort Facility (JOI17_port_facility)C++14
100 / 100
1542 ms287424 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 1e6 + 2; const int mod = 1e9 + 7; struct Node { pair<int, int> mn, mx; Node() { mn = {mod, -1}; mx = {-mod, -1}; } Node(int a, int b, int c, int d) { mn = {a, b}; mx = {c, d}; } }st[8 * N]; Node Combine(Node a, Node b) { Node c = Node(); c.mn = min(a.mn, b.mn); c.mx = max(a.mx, b.mx); return c; } pair<int, int> a[2 * N]; void Init(int node, int l, int r) { if (l == r) { st[node] = Node(a[l].first, a[l].second, a[l].first, a[l].second); return; } int mid = l + r >> 1; Init(2 * node, l, mid); Init(2 * node + 1, mid + 1, r); st[node] = Combine(st[2 * node], st[2 * node + 1]); } Node Get(int node, int l, int r, int ql, int qr) { if (r < ql || qr < l || ql > qr) return Node(); if (ql <= l && r <= qr) return st[node]; int mid = l + r >> 1; return Combine(Get(2 * node, l, mid, ql, qr), Get(2 * node + 1, mid + 1, r, ql, qr)); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> l(n), r(n); for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; l[i] -= 1; r[i] -= 1; a[l[i]] = {r[i], i}; a[r[i]] = {l[i], i}; } Init(1, 0, 2 * n - 1); vector<vector<int>> g(n); for (int i = 0; i < n; i++) { Node h = Get(1, 0, 2 * n - 1, l[i] + 1, r[i] - 1); if (h.mn.first < l[i]) { g[i].push_back(h.mn.second); g[h.mn.second].push_back(i); } if (r[i] < h.mx.first) { g[i].push_back(h.mx.second); g[h.mx.second].push_back(i); } } vector<int> col(n, -1); function<void(int, int)> Dfs = [&] (int s, int t) { col[s] = t; for (int u : g[s]) { if (col[u] == -1) Dfs(u, 1 - t); else if (col[u] == col[s]) { cout << 0 << en; exit(0); } } }; int ans = 1; for (int i = 0; i < n; i++) { if (col[i] == -1) { Dfs(i, 0); ans *= 2; if (ans >= mod) ans -= mod; } } cout << ans << en; return 0; }

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

port_facility.cpp: In function 'void Init(int, int, int)':
port_facility.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     int mid = l + r >> 1;
      |               ~~^~~
port_facility.cpp: In function 'Node Get(int, int, int, int, int)':
port_facility.cpp:41:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |     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...