제출 #282662

#제출 시각아이디문제언어결과실행 시간메모리
282662Haunted_Cpp자리 배치 (IOI18_seats)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; struct SegmentTree { vector<int> mn, mx; const int n; SegmentTree(const vector<int> &arr) : n(arr.size()) { mn = mx = vector<int>(2 * n); for (int i = 0; i < n; i++) mn[i + n] = mx[i + n] = arr[i]; for (int i = n - 1; i > 0; i--) { mn[i] = min(mn[i << 1], mn[i << 1 | 1]); mx[i] = max(mx[i << 1], mx[i << 1 | 1]); } } void modify(int where, int delta) { where += n; mn[where] = mx[where] = delta; for (; delta > 1; delta >>= 1) { mn[where >> 1] = min(mn[where], mn[where ^ 1]); mx[where >> 1] = max(mx[where], mx[where ^ 1]); } } pair<int, int> rmq(int l, int r) { pair<int, int> res = {INF, -INF}; l += n; r += n; res.first = min(res.first, mn[l]); res.first = min(res.first, mn[r]); res.second = max(res.second, mx[l]); res.second = max(res.second, mx[r]); for(; l <= r; l >>= 1, r >>= 1) { if (l & 1) { res.first = min(res.first, mn[l]); res.second = max(res.second, mx[l]); ++l; } if (r & 1 ^ 1) { res.first = min(res.first, mn[r]); res.second = max(res.second, mx[r]); --r; } } return res; } }; int H, W; vector<int> R, C; SegmentTree *rows, *cols; void give_initial_chart(int H, int W, vector<int> R, vector<int> C) { ::H = H; ::W = W; ::R = R; ::C = C; rows = new SegmentTree(R); cols = new SegmentTree(C); } int swap_seats(int a, int b) { swap(R[a], R[b]); swap(C[a], C[b]); rows -> modify(a, R[a]); rows -> modify(b, R[b]); cols -> modify(a, C[a]); cols -> modify(b, C[b]); int idx = 0, res = 0; while(idx < H * W) { tie(R_min, R_max) = rows -> query(0, idx); tie(C_min, C_max) = cols -> query(0, idx); int score = (R_max - R_min + 1) * (C_max - C_min + 1); if (score == idx + 1) { ++res; ++idx; } else { idx = score - 1; } } return res; }

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

seats.cpp: In member function 'std::pair<int, int> SegmentTree::rmq(int, int)':
seats.cpp:39:13: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   39 |       if (r & 1 ^ 1) {
      |           ~~^~~
seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:69:9: error: 'R_min' was not declared in this scope
   69 |     tie(R_min, R_max) = rows -> query(0, idx);
      |         ^~~~~
seats.cpp:69:16: error: 'R_max' was not declared in this scope
   69 |     tie(R_min, R_max) = rows -> query(0, idx);
      |                ^~~~~
seats.cpp:69:33: error: 'struct SegmentTree' has no member named 'query'
   69 |     tie(R_min, R_max) = rows -> query(0, idx);
      |                                 ^~~~~
seats.cpp:70:9: error: 'C_min' was not declared in this scope
   70 |     tie(C_min, C_max) = cols -> query(0, idx);
      |         ^~~~~
seats.cpp:70:16: error: 'C_max' was not declared in this scope
   70 |     tie(C_min, C_max) = cols -> query(0, idx);
      |                ^~~~~
seats.cpp:70:33: error: 'struct SegmentTree' has no member named 'query'
   70 |     tie(C_min, C_max) = cols -> query(0, idx);
      |                                 ^~~~~