Submission #342478

#TimeUsernameProblemLanguageResultExecution timeMemory
342478mjhmjh1104The Potion of Great Power (CEOI20_potion)C++14
Compilation error
0 ms0 KiB
#include <map> #include <cmath> #include <algorithm> using namespace std; map<pair<int, int>, vector<int>> m; vector<int> adj[100006]; vector<int> h; void init(int N, int D, int H[]) { for (int i = 0; i < N; i++) h.push_back(H[i]); } void curseChanges(int U, int A[], int B[]) { for (int i = 0; i < U; i++) { int a = A[i], b = B[i]; if (a > b) swap(a, b); m[{ a, b }].push_back(i + 1); adj[a].push_back(b); adj[b].push_back(a); } auto it = m.begin(); while (it != m.end()) { sort(it->second.begin(), it->second.end()); it = next(it); } } struct cmp { operator() (const int &a, const int &b) const { return h[a] < h[b]; } }; int question(int x, int y, int v) { set<int, cmp> adjX, adjY; for (auto &i: adj[x]) { int a = x; int b = i; if (a > b) swap(a, b); auto it = m.find({ a, b }); if (it == m.end()) continue; int la = upper_bound(it->second.begin(), it->second.end(), v) - it->second.begin(); if (la % 2) adjX.insert(i); } for (auto &i: adj[y]) { int a = y; int b = i; if (a > b) swap(a, b); auto it = m.find({ a, b }); if (it == m.end()) continue; int la = upper_bound(it->second.begin(), it->second.end(), v) - it->second.begin(); if (la % 2) adjY.insert(i); } if (adjX.empty() || adjY.empty()) return 1e9; auto i = adjX.begin(); auto j = adjY.begin(); int res = 1e9; while (i != adjX.end() && j != adjY.end()) { res = min(res, abs(h[*i] - h[*j])); if (h[*i] <= h[*j]) i = next(i); else j = next(j); } return res; }

Compilation message (stderr)

potion.cpp:6:21: error: 'vector' was not declared in this scope
    6 | map<pair<int, int>, vector<int>> m;
      |                     ^~~~~~
potion.cpp:4:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    3 | #include <algorithm>
  +++ |+#include <vector>
    4 | using namespace std;
potion.cpp:6:31: error: template argument 2 is invalid
    6 | map<pair<int, int>, vector<int>> m;
      |                               ^~
potion.cpp:6:31: error: template argument 4 is invalid
potion.cpp:7:1: error: 'vector' does not name a type
    7 | vector<int> adj[100006];
      | ^~~~~~
potion.cpp:8:1: error: 'vector' does not name a type
    8 | vector<int> h;
      | ^~~~~~
potion.cpp: In function 'void init(int, int, int*)':
potion.cpp:11:33: error: 'h' was not declared in this scope
   11 |     for (int i = 0; i < N; i++) h.push_back(H[i]);
      |                                 ^
potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:18:19: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   18 |         m[{ a, b }].push_back(i + 1);
      |                   ^
potion.cpp:19:9: error: 'adj' was not declared in this scope
   19 |         adj[a].push_back(b);
      |         ^~~
potion.cpp:22:17: error: request for member 'begin' in 'm', which is of non-class type 'int'
   22 |     auto it = m.begin();
      |                 ^~~~~
potion.cpp:23:20: error: request for member 'end' in 'm', which is of non-class type 'int'
   23 |     while (it != m.end()) {
      |                    ^~~
potion.cpp: At global scope:
potion.cpp:30:45: error: ISO C++ forbids declaration of 'operator()' with no type [-fpermissive]
   30 |     operator() (const int &a, const int &b) const {
      |                                             ^~~~~
potion.cpp: In member function 'int cmp::operator()(const int&, const int&) const':
potion.cpp:31:16: error: 'h' was not declared in this scope
   31 |         return h[a] < h[b];
      |                ^
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:36:5: error: 'set' was not declared in this scope
   36 |     set<int, cmp> adjX, adjY;
      |     ^~~
potion.cpp:4:1: note: 'std::set' is defined in header '<set>'; did you forget to '#include <set>'?
    3 | #include <algorithm>
  +++ |+#include <set>
    4 | using namespace std;
potion.cpp:36:9: error: expected primary-expression before 'int'
   36 |     set<int, cmp> adjX, adjY;
      |         ^~~
potion.cpp:37:19: error: 'adj' was not declared in this scope
   37 |     for (auto &i: adj[x]) {
      |                   ^~~
potion.cpp:41:21: error: request for member 'find' in 'm', which is of non-class type 'int'
   41 |         auto it = m.find({ a, b });
      |                     ^~~~
potion.cpp:42:21: error: request for member 'end' in 'm', which is of non-class type 'int'
   42 |         if (it == m.end()) continue;
      |                     ^~~
potion.cpp:44:21: error: 'adjX' was not declared in this scope
   44 |         if (la % 2) adjX.insert(i);
      |                     ^~~~
potion.cpp:46:19: error: 'adj' was not declared in this scope
   46 |     for (auto &i: adj[y]) {
      |                   ^~~
potion.cpp:50:21: error: request for member 'find' in 'm', which is of non-class type 'int'
   50 |         auto it = m.find({ a, b });
      |                     ^~~~
potion.cpp:51:21: error: request for member 'end' in 'm', which is of non-class type 'int'
   51 |         if (it == m.end()) continue;
      |                     ^~~
potion.cpp:53:21: error: 'adjY' was not declared in this scope
   53 |         if (la % 2) adjY.insert(i);
      |                     ^~~~
potion.cpp:55:9: error: 'adjX' was not declared in this scope
   55 |     if (adjX.empty() || adjY.empty()) return 1e9;
      |         ^~~~
potion.cpp:55:25: error: 'adjY' was not declared in this scope
   55 |     if (adjX.empty() || adjY.empty()) return 1e9;
      |                         ^~~~
potion.cpp:56:14: error: 'adjX' was not declared in this scope
   56 |     auto i = adjX.begin();
      |              ^~~~
potion.cpp:57:14: error: 'adjY' was not declared in this scope
   57 |     auto j = adjY.begin();
      |              ^~~~
potion.cpp:60:28: error: 'h' was not declared in this scope
   60 |         res = min(res, abs(h[*i] - h[*j]));
      |                            ^