제출 #1067393

#제출 시각아이디문제언어결과실행 시간메모리
1067393IgnutThe Big Prize (IOI17_prize)C++17
컴파일 에러
0 ms0 KiB
// Ignut #include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> ask(int i); int Q = 0; struct SegmentTree { vector<int> t; void Init(int n) { t.assign(4 * n, 0); } void Add(int v, int l, int r, int pos) { t[v] ++; if (l == r) return; int mid = l + (r - l) / 2; if (pos <= mid) Add(v * 2, l, mid, pos); else Add(v * 2 + 1, mid + 1, r, pos); } int Sum(int v, int l, int r, int ql, int qr) { if (l > qr || ql > r) return 0; if (l >= ql && r <= qr) return t[v]; int mid = l + (r - l) / 2; return Sum(v * 2, l, mid, ql, qr) + Sum(v * 2 + 1, mid + 1, r, ql, qr); } }; int n; int cntHave = 0; SegmentTree st[10]; map<int, int> index; void Inc(int lvl, int pos) { if (!index.count(lvl)) { st[cntHave].Init(n); index[lvl] = cntHave ++; } st[index[lvl]].Add(1, 0, n - 1, pos); } int Get(int lvl, int l, int r) { if (!index.count(lvl)) return 0; return st[index[lvl]].Sum(1, 0, n - 1, l, r); } int find_best(int nn) { n = nn; int L = -1; while (L < n - 1) { int lo = L + 1, hi = n - 1; while (lo < hi) { int mid = lo + (hi - lo) / 2; Q ++; if (Q == 10000) { Q /= 0; } vector<int> vec = ask(mid); if (vec[0] + vec[1] == 0) return mid; int lvl = vec[0] + vec[1]; int comp = 0; for (auto [a, b] : index) if (a < lvl) comp += Get(a, 0, mid - 1); Inc(lvl, mid); if (vec[0] > comp) hi = mid - 1; else { lo = mid + 1; } } // cout << "lo = " << lo << '\n'; Q ++; if (Q == 10000) { Q /= 0; } vector<int> vec = ask(lo); if (vec[0] + vec[1] == 0) return lo; int lvl = vec[0] + vec[1]; Inc(lvl, lo); L = lo; } return n - 1; } /* 8 3 2 3 1 3 3 2 3 */

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

prize.cpp:42:15: error: 'std::map<int, int> index' redeclared as different kind of entity
   42 | map<int, int> index;
      |               ^~~~~
In file included from /usr/include/string.h:432,
                 from /usr/include/c++/10/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:48,
                 from prize.cpp:3:
/usr/include/strings.h:61:1: note: previous declaration 'const char* index(const char*, int)'
   61 | index (const char *__s, int __c) __THROW
      | ^~~~~
prize.cpp: In function 'void Inc(int, int)':
prize.cpp:45:13: error: overloaded function with no contextual type information
   45 |  if (!index.count(lvl)) {
      |             ^~~~~
prize.cpp:47:8: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   47 |   index[lvl] = cntHave ++;
      |        ^
prize.cpp:49:10: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   49 |  st[index[lvl]].Add(1, 0, n - 1, pos);
      |          ^
prize.cpp: In function 'int Get(int, int, int)':
prize.cpp:53:13: error: overloaded function with no contextual type information
   53 |  if (!index.count(lvl)) return 0;
      |             ^~~~~
prize.cpp:54:17: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   54 |  return st[index[lvl]].Sum(1, 0, n - 1, l, r);
      |                 ^
prize.cpp: In function 'int find_best(int)':
prize.cpp:66:7: warning: division by zero [-Wdiv-by-zero]
   66 |     Q /= 0;
      |     ~~^~~~
prize.cpp:73:23: error: unable to deduce 'auto&&' from 'index'
   73 |    for (auto [a, b] : index) if (a < lvl) comp += Get(a, 0, mid - 1);
      |                       ^~~~~
prize.cpp:73:23: note:   couldn't deduce template parameter 'auto'
prize.cpp:84:6: warning: division by zero [-Wdiv-by-zero]
   84 |    Q /= 0;
      |    ~~^~~~