제출 #566362

#제출 시각아이디문제언어결과실행 시간메모리
566362lorenzoferrariThe Big Prize (IOI17_prize)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "prize.h" using namespace std; int mx_cnt; int answer = -1; map<int, array<int, 2>> memo; map<int, set<int>> found; array<int, 2> askme(int i) { array<int, 2> ans; if (memo.find(i) != memo.end()) { ans[0] = memo[i][0]; ans[1] = memo[i][1]; } else { auto v = ask(i); ans[0] = v[0]; ans[1] = v[1]; } memo[i] = {ans[0], ans[1]}; found[ans[0] + ans[1]].insert(i); if (ans[0] + ans[1] == 0) answer = i; return ans; } int count(int i) { return askme(i)[0] + askme(i)[1]; } bool makes_sense(int l, int r) { for (auto& ss : found) { if (ss.first == mx_cnt) continue; auto& s = ss.second; auto il = s.lower_bound(l); auto ir = s.lower_bound(r); if (il == s.begin()) continue; if (ir == s.end()) continue; il = prev(il); if (ir) if (ask(*ir)[0] - ask(*il)[0] == 0) return false; } return true; } void findall(int l, int r) { // assume t[l] = t[r] = v if (!makes_sense(l, r)) return; int cnt = askme(r)[0] - askme(l)[0]; if (cnt <= 0) return; if (answer != -1) return; int m = (l + r) / 2; int lm = m, rm = m; while (count(lm) != count(l)) { if (answer != -1) return; --lm; } while (count(rm) != count(l)) { if (answer != -1) return; ++rm; } findall(l, lm); findall(rm, r); } int find_best(int n) { srand(time(NULL)); for (int i = 0; i < 600; ++i) mx_cnt = max(mx_cnt, count(rand() % n)); int l = 0; while (count(l) != mx_cnt) ++l; int r = n-1; while (count(r) != mx_cnt) --r; findall(l, r); return answer; } #ifdef LORENZO int main() { cout << "insert n: "; fflush(stdout); int n; cin >> n; cout << "answer: " << find_best(n) << endl; } #endif

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

prize.cpp: In function 'bool makes_sense(int, int)':
prize.cpp:36:9: error: could not convert 'ir' from 'std::_Rb_tree_const_iterator<int>' to 'bool'
   36 |     if (ir)
      |         ^~
      |         |
      |         std::_Rb_tree_const_iterator<int>