제출 #820769

#제출 시각아이디문제언어결과실행 시간메모리
820769vjudge1The Big Prize (IOI17_prize)C++17
0 / 100
90 ms7732 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; struct fenwick { vector<int> v; fenwick(int N) : v(N + 1, 0) {} void upd(int x, int g) { while (x < v.size()) { v[x] += g; x += x & -x; } } int get(int x) { int res = 0; while (x > 0) { res += v[x]; x -= x & -x; } return res; } }; int find_best(int n) { #define fi first #define se second vector<int> to_ask; queue<pair<int, int>> q; fenwick tree(n + 10); q.push({0, n - 1}); while (!q.empty()) { auto p = q.front(); q.pop(); if (p.fi > p.se) { continue; } int m = (p.fi + p.se) / 2; to_ask.push_back(m); q.push({p.fi, m - 1}); q.push({m + 1, p.se}); } map<int, set<int>> s; auto upd = [&](int sum, int i) -> tuple<int, int> { s[sum].insert(i); auto p = s[sum].find(i); int l = -1, r = -1; if (p != s[sum].begin()) { p--; l = *p; p++; } p++; if (p != s[sum].end()) { r = *p; } return {l, r}; }; vector<vector<int>> asked(n + 1); for (int i: to_ask) { if (tree.get(i + 1) > 0) { continue; } auto ans = ask(i); if (ans[0] + ans[1] == 0) { return i; } asked[i] = ans; auto [l, r] = upd(ans[0] + ans[1], i); if (l != -1 && asked[i][0] - asked[l][0] == i - l - 1) { tree.upd(l + 1, 1); tree.upd(i + 1, -1); } if (r != -1 && asked[r][0] - asked[i][0] == r - i - 1) { tree.upd(i + 1, 1); tree.upd(r + 1, -1); } } }

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

prize.cpp: In member function 'void fenwick::upd(int, int)':
prize.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |         while (x < v.size()) {
      |                ~~^~~~~~~~~~
prize.cpp: In function 'int find_best(int)':
prize.cpp:31:17: warning: control reaches end of non-void function [-Wreturn-type]
   31 |     vector<int> to_ask;
      |                 ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...