Submission #322273

#TimeUsernameProblemLanguageResultExecution timeMemory
322273dolphingarlicSwap (BOI16_swap)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define FOR(i, x, y) for (int i = x; i < y; i++) typedef pi pair<int, int>; using namespace std; map<pi,int> bes; int n, p[MX]; int get(int ind, int y) { if (bes.count({ind,y})) return bes[{ind,y}]; if (2*ind > n) return ind; if (2*ind+1 > n) { if (y > p[2*ind]) return 2*ind; return ind; } if (y < min(p[2*ind],p[2*ind+1])) return bes[{ind,y}] = ind; if (p[2*ind] < min(y,p[2*ind+1])) return bes[{ind,y}] = get(2*ind,y); int mn = min(y,p[2*ind]); if (get(2*ind,mn) < get(2*ind+1,mn)) { if (mn == y) return bes[{ind,y}] = get(2*ind,y); return bes[{ind,y}] = get(2*ind+1,y); } else { if (mn == y) return bes[{ind,y}] = get(2*ind+1,y); return bes[{ind,y}] = get(2*ind,y); } } void solve(int ind) { if (2*ind > n) return; if (2*ind+1 > n) { if (p[ind] > p[2*ind]) swap(p[ind],p[2*ind]); return; } if (p[ind] < min(p[2*ind],p[2*ind+1])) { } else if (p[2*ind] < min(p[ind],p[2*ind+1])) { swap(p[2*ind],p[ind]); } else { int mn = min(p[ind],p[2*ind]), mx = max(p[ind],p[2*ind]); p[ind] = p[2*ind+1]; if (get(2*ind,mn) < get(2*ind+1,mn)) { p[2*ind] = mn, p[2*ind+1] = mx; } else { p[2*ind] = mx, p[2*ind+1] = mn; } } solve(ind+1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; FOR(i,1,n+1) cin >> p[i]; solve(1); FOR(i,1,n+1) cout << p[i] << " "; }

Compilation message (stderr)

swap.cpp:3:9: error: 'pi' does not name a type
    3 | typedef pi pair<int, int>;
      |         ^~
swap.cpp:6:5: error: 'pi' was not declared in this scope
    6 | map<pi,int> bes;
      |     ^~
swap.cpp:6:11: error: template argument 1 is invalid
    6 | map<pi,int> bes;
      |           ^
swap.cpp:6:11: error: template argument 3 is invalid
swap.cpp:6:11: error: template argument 4 is invalid
swap.cpp:7:10: error: 'MX' was not declared in this scope
    7 | int n, p[MX];
      |          ^~
swap.cpp: In function 'int get(int, int)':
swap.cpp:10:13: error: request for member 'count' in 'bes', which is of non-class type 'int'
   10 |     if (bes.count({ind,y})) return bes[{ind,y}];
      |             ^~~~~
swap.cpp:10:47: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   10 |     if (bes.count({ind,y})) return bes[{ind,y}];
      |                                               ^
swap.cpp:13:17: error: 'p' was not declared in this scope
   13 |         if (y > p[2*ind]) return 2*ind;
      |                 ^
swap.cpp:16:17: error: 'p' was not declared in this scope
   16 |     if (y < min(p[2*ind],p[2*ind+1])) return bes[{ind,y}] = ind;
      |                 ^
swap.cpp:16:57: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   16 |     if (y < min(p[2*ind],p[2*ind+1])) return bes[{ind,y}] = ind;
      |                                                         ^
swap.cpp:17:9: error: 'p' was not declared in this scope
   17 |     if (p[2*ind] < min(y,p[2*ind+1])) return bes[{ind,y}] = get(2*ind,y);
      |         ^
swap.cpp:17:57: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   17 |     if (p[2*ind] < min(y,p[2*ind+1])) return bes[{ind,y}] = get(2*ind,y);
      |                                                         ^
swap.cpp:18:20: error: 'p' was not declared in this scope
   18 |     int mn = min(y,p[2*ind]);
      |                    ^
swap.cpp:20:40: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   20 |         if (mn == y) return bes[{ind,y}] = get(2*ind,y);
      |                                        ^
swap.cpp:21:27: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   21 |         return bes[{ind,y}] = get(2*ind+1,y);
      |                           ^
swap.cpp:23:40: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   23 |         if (mn == y) return bes[{ind,y}] = get(2*ind+1,y);
      |                                        ^
swap.cpp:24:27: error: invalid types 'int[<brace-enclosed initializer list>]' for array subscript
   24 |         return bes[{ind,y}] = get(2*ind,y);
      |                           ^
swap.cpp: In function 'void solve(int)':
swap.cpp:31:13: error: 'p' was not declared in this scope
   31 |         if (p[ind] > p[2*ind]) swap(p[ind],p[2*ind]);
      |             ^
swap.cpp:35:9: error: 'p' was not declared in this scope
   35 |     if (p[ind] < min(p[2*ind],p[2*ind+1])) {
      |         ^
swap.cpp:44:41: error: 'mx' was not declared in this scope; did you mean 'mn'?
   44 |             p[2*ind] = mn, p[2*ind+1] = mx;
      |                                         ^~
      |                                         mn
swap.cpp:46:24: error: 'mx' was not declared in this scope; did you mean 'mn'?
   46 |             p[2*ind] = mx, p[2*ind+1] = mn;
      |                        ^~
      |                        mn
swap.cpp: In function 'int main()':
swap.cpp:55:25: error: 'p' was not declared in this scope
   55 |     FOR(i,1,n+1) cin >> p[i];
      |                         ^
swap.cpp:57:26: error: 'p' was not declared in this scope
   57 |     FOR(i,1,n+1) cout << p[i] << " ";
      |                          ^