제출 #670858

#제출 시각아이디문제언어결과실행 시간메모리
670858stevancvPort Facility (JOI17_port_facility)C++14
0 / 100
0 ms328 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 PST { int st[21 * N], lc[21 * N], rc[21 * N], root[N], tsz; void Add(int &c, int pc, int l, int r, int x) { c = ++tsz; st[c] = st[pc] + 1; lc[c] = lc[pc]; rc[c] = rc[pc]; if (l == r) return; int mid = l + r >> 1; if (x <= mid) Add(lc[c], lc[pc], l, mid, x); else Add(rc[c], rc[pc], mid + 1, r, x); } int Get(int c, int l, int r, int ql, int qr) { if (r < ql || qr < l) return 0; if (ql <= l && r <= qr) return st[c]; int mid = l + r >> 1; return Get(lc[c], l, mid, ql, qr) + Get(rc[c], mid + 1, r, ql, qr); } }pst[2]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<array<int, 2>> a(n); for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; } sort(a.begin(), a.end(), [&] (array<int, 2> i, array<int, 2> j) { return i[1] < j[1]; }); vector<int> b(n); iota(b.begin(), b.end(), 0); for (int i = 0; i < n; i++) { int l = 0, r = i - 1; while (l <= r) { int mid = l + r >> 1; if (a[i][0] < a[mid][1]) { r = mid - 1; b[i] = mid; } else l = mid + 1; } } int ans = 1; for (int i = 0; i < n; i++) { int x = 0, y = 0; if (i > 0) { pst[0].root[i] = pst[0].root[i - 1]; pst[1].root[i] = pst[1].root[i - 1]; x += pst[0].Get(pst[0].root[i - 1], 1, 2 * n, 1, a[i][0]); y += pst[1].Get(pst[1].root[i - 1], 1, 2 * n, 1, a[i][0]); } if (b[i] > 0) { x -= pst[0].Get(pst[0].root[b[i] - 1], 1, 2 * n, 1, a[i][0]); y -= pst[1].Get(pst[1].root[b[i] - 1], 1, 2 * n, 1, a[i][0]); } if (x == 0 && y == 0) { ans *= 2; if (ans >= mod) ans -= mod; pst[0].Add(pst[0].root[i], pst[0].root[i - 1], 1, 2 * n, a[i][0]); } else if (x > 0 && y > 0) { cout << 0 << en; return 0; } else if (x > 0) pst[1].Add(pst[1].root[i], pst[1].root[i - 1], 1, 2 * n, a[i][0]); else pst[0].Add(pst[0].root[i], pst[0].root[i - 1], 1, 2 * n, a[i][0]); } cout << ans << en; return 0; }

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

port_facility.cpp: In member function 'void PST::Add(int&, int, int, int, int)':
port_facility.cpp:16:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   16 |         int mid = l + r >> 1;
      |                   ~~^~~
port_facility.cpp: In member function 'int PST::Get(int, int, int, int, int)':
port_facility.cpp:23:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |         int mid = l + r >> 1;
      |                   ~~^~~
port_facility.cpp: In function 'int main()':
port_facility.cpp:44:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |             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...