제출 #1157285

#제출 시각아이디문제언어결과실행 시간메모리
1157285coolsentenceidontrememberElection (BOI18_election)C++20
컴파일 에러
0 ms0 KiB
void upd(const int &id, const int &l, const int &r, const int &p, const int &v) { // std::cout << l << r << '\n'; if (l == r) { st[id] = {v, v}; return; } int m = (l + r) >> 1; if (p <= m) upd(id << 1, l, m, p, v); else upd(id << 1 | 1, m + 1, r, p, v); st[id] = combine(st[id << 1], st[id << 1 | 1]); return; } std::pair<int, int> get(const int &id, const int &l, const int &r, const int &u, const int &v) { if (r < u || l > v) return std::pair<int, int>(0, 0); if (l >= u && r <= v) return st[id]; int m = (l + r) >> 1; return combine(get(id << 1, l, m, u, v), get(id << 1 | 1, m + 1, r, u, v)); } int main() { setIO(); int n; std::cin >> n; st = std::vector<std::pair<int, int>>((n << 2) + 1); for (int i = 1; i <= n; i++) { char c; std::cin >> c; vote.push_back((c == 'C') ? 1 : -1); } int q; std::cin >> q; for (int i = 1; i <= q; i++) { int l, r; std::cin >> l >> r; query.push_back({--l, --r, i - 1}); } std::sort(query.begin(), query.end(), [&](const std::array<int, 3> &a, const std::array<int, 3> &b) { return a[0] > b[0]; }); std::vector<int> ans(q); int border = n - 1; std::vector<int> cur; for (const std::array<int, 3> &a : query) { int l = a[0], r = a[1], id = a[2]; while (border >= l) { if (vote[border] == -1) { cur.push_back(border); } else { upd(1, 0, n - 1, border, 1); if (!cur.empty()) { int x = cur.back(); upd(1, 0, n - 1, x, -1); cur.pop_back(); } } border--; } ans[id] = std::upper_bound(cur.rbegin(), cur.rend(), r) - cur.rbegin() - get(1, 0, n - 1, l, r).ss; } for (int i = 0; i < q; i++) { std::cout << ans[i] << '\n'; } }

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

election.cpp: In function 'void upd(const int&, const int&, const int&, const int&, const int&)':
election.cpp:5:5: error: 'st' was not declared in this scope; did you mean 'std'?
    5 |     st[id] = {v, v};
      |     ^~
      |     std
election.cpp:13:3: error: 'st' was not declared in this scope; did you mean 'std'?
   13 |   st[id] = combine(st[id << 1], st[id << 1 | 1]);
      |   ^~
      |   std
election.cpp:13:12: error: 'combine' was not declared in this scope
   13 |   st[id] = combine(st[id << 1], st[id << 1 | 1]);
      |            ^~~~~~~
election.cpp: At global scope:
election.cpp:17:6: error: 'pair' in namespace 'std' does not name a template type
   17 | std::pair<int, int> get(const int &id, const int &l, const int &r, const int &u,
      |      ^~~~
election.cpp:1:1: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
  +++ |+#include <utility>
    1 | void upd(const int &id, const int &l, const int &r, const int &p,
election.cpp: In function 'int main()':
election.cpp:27:3: error: 'setIO' was not declared in this scope
   27 |   setIO();
      |   ^~~~~
election.cpp:29:8: error: 'cin' is not a member of 'std'
   29 |   std::cin >> n;
      |        ^~~
election.cpp:1:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
  +++ |+#include <iostream>
    1 | void upd(const int &id, const int &l, const int &r, const int &p,
election.cpp:30:3: error: 'st' was not declared in this scope; did you mean 'std'?
   30 |   st = std::vector<std::pair<int, int>>((n << 2) + 1);
      |   ^~
      |   std
election.cpp:30:13: error: 'vector' is not a member of 'std'
   30 |   st = std::vector<std::pair<int, int>>((n << 2) + 1);
      |             ^~~~~~
election.cpp:1:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
  +++ |+#include <vector>
    1 | void upd(const int &id, const int &l, const int &r, const int &p,
election.cpp:30:25: error: 'pair' is not a member of 'std'
   30 |   st = std::vector<std::pair<int, int>>((n << 2) + 1);
      |                         ^~~~
election.cpp:30:25: note: 'std::pair' is defined in header '<utility>'; did you forget to '#include <utility>'?
election.cpp:30:30: error: expected primary-expression before 'int'
   30 |   st = std::vector<std::pair<int, int>>((n << 2) + 1);
      |                              ^~~
election.cpp:33:10: error: 'cin' is not a member of 'std'
   33 |     std::cin >> c;
      |          ^~~
election.cpp:33:10: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
election.cpp:34:5: error: 'vote' was not declared in this scope
   34 |     vote.push_back((c == 'C') ? 1 : -1);
      |     ^~~~
election.cpp:37:8: error: 'cin' is not a member of 'std'
   37 |   std::cin >> q;
      |        ^~~
election.cpp:37:8: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
election.cpp:40:10: error: 'cin' is not a member of 'std'
   40 |     std::cin >> l >> r;
      |          ^~~
election.cpp:40:10: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
election.cpp:41:5: error: 'query' was not declared in this scope
   41 |     query.push_back({--l, --r, i - 1});
      |     ^~~~~
election.cpp:43:8: error: 'sort' is not a member of 'std'
   43 |   std::sort(query.begin(), query.end(),
      |        ^~~~
election.cpp:43:13: error: 'query' was not declared in this scope
   43 |   std::sort(query.begin(), query.end(),
      |             ^~~~~
election.cpp:44:28: error: 'array' in namespace 'std' does not name a template type
   44 |             [&](const std::array<int, 3> &a, const std::array<int, 3> &b) {
      |                            ^~~~~
election.cpp:1:1: note: 'std::array' is defined in header '<array>'; did you forget to '#include <array>'?
  +++ |+#include <array>
    1 | void upd(const int &id, const int &l, const int &r, const int &p,
election.cpp: In lambda function:
election.cpp:46:15: error: expected '{' before ';' token
   46 |             });
      |               ^
election.cpp: In function 'int main()':
election.cpp:46:15: error: expected ')' before ';' token
   46 |             });
      |               ^
      |               )
election.cpp:43:12: note: to match this '('
   43 |   std::sort(query.begin(), query.end(),
      |            ^
election.cpp:47:8: error: 'vector' is not a member of 'std'
   47 |   std::vector<int> ans(q);
      |        ^~~~~~
election.cpp:47:8: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
election.cpp:47:15: error: expected primary-expression before 'int'
   47 |   std::vector<int> ans(q);
      |               ^~~
election.cpp:49:8: error: 'vector' is not a member of 'std'
   49 |   std::vector<int> cur;
      |        ^~~~~~
election.cpp:49:8: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
election.cpp:49:15: error: expected primary-expression before 'int'
   49 |   std::vector<int> cur;
      |               ^~~
election.cpp:50:19: error: 'array' in namespace 'std' does not name a template type
   50 |   for (const std::array<int, 3> &a : query) {
      |                   ^~~~~
election.cpp:50:14: note: 'std::array' is defined in header '<array>'; did you forget to '#include <array>'?
   50 |   for (const std::array<int, 3> &a : query) {
      |              ^~~
election.cpp:67:4: error: expected ';' before 'for'
   67 |   }
      |    ^
      |    ;
   68 |   for (int i = 0; i < q; i++) {
      |   ~~~
election.cpp:68:3: error: expected primary-expression before 'for'
   68 |   for (int i = 0; i < q; i++) {
      |   ^~~
election.cpp:67:4: error: expected ';' before 'for'
   67 |   }
      |    ^
      |    ;
   68 |   for (int i = 0; i < q; i++) {
      |   ~~~
election.cpp:68:3: error: expected primary-expression before 'for'
   68 |   for (int i = 0; i < q; i++) {
      |   ^~~
election.cpp:67:4: error: expected ')' before 'for'
   67 |   }
      |    ^
      |    )
   68 |   for (int i = 0; i < q; i++) {
      |   ~~~
election.cpp:50:7: note: to match this '('
   50 |   for (const std::array<int, 3> &a : query) {
      |       ^
election.cpp:69:10: error: 'cout' is not a member of 'std'
   69 |     std::cout << ans[i] << '\n';
      |          ^~~~
election.cpp:69:10: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
election.cpp:69:18: error: 'ans' was not declared in this scope
   69 |     std::cout << ans[i] << '\n';
      |                  ^~~