Submission #311283

#TimeUsernameProblemLanguageResultExecution timeMemory
311283saarang123Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "bits/stdc++.h" using namespace std; const int N = 2e5 + 2; ll tree[N], n; queue<int> l[N], r[N]; void upd(int x, int val) { for(; x <= n; x += (x & -x)) tree[x] += val; } int sum(int x) { if(x <= 0) return 0; int ans = 0; for(; x > 0; x -= (x & -x)) ans += tree[x]; return ans; } int qry(int l, int r) { return sum(r) - sum(l - 1); }; long long count_swaps(vector<int> a) { n = a.size(); int i, j; for(i = 0; i < n; i++) { if(a[i] > 0) l[a[i]].push(i + 1); else r[-a[i]].push(i + 1); } ll ans = 0; for(i = 0; i < n; i++) { if(a[i] > 0) { if(l[a[i]].front() != i + 1) continue; l[a[i]].pop(); int id = r[a[i]].front(); r[a[i]].pop(); ans += (id - i - 1 - qry(i + 1, id)); //cout << i << " " << a[i] << " " << id - i - qry(i + 1, id) << endl; upd(id, 1); } else { if(r[-a[i]].front() != i + 1) continue; r[-a[i]].pop(); int id = l[-a[i]].front(); l[-a[i]].pop(); ans += (id - i - 2 - qry(i + 1, id)); //cout << i << " " << a[i] << " " << id - i - 1 - qry(i + 1, id) << endl; upd(id, 1); } } return ans; } /* signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); int i,j; cin >> n; vector<int> a(2 * n); for(auto &x : a) cin >> x; cout << count_swaps(a) << endl; return 0; }*/

Compilation message (stderr)

shoes.cpp:4:1: error: 'll' does not name a type
    4 | ll tree[N], n;
      | ^~
shoes.cpp: In function 'void upd(int, int)':
shoes.cpp:8:16: error: 'n' was not declared in this scope
    8 |     for(; x <= n; x += (x & -x))
      |                ^
shoes.cpp:9:9: error: 'tree' was not declared in this scope; did you mean 'free'?
    9 |         tree[x] += val;
      |         ^~~~
      |         free
shoes.cpp: In function 'int sum(int)':
shoes.cpp:16:16: error: 'tree' was not declared in this scope; did you mean 'free'?
   16 |         ans += tree[x];
      |                ^~~~
      |                free
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:23:5: error: 'n' was not declared in this scope
   23 |     n = a.size(); int i, j;
      |     ^
shoes.cpp:28:5: error: 'll' was not declared in this scope; did you mean 'l'?
   28 |     ll ans = 0;
      |     ^~
      |     l
shoes.cpp:34:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   34 |             ans += (id - i - 1 - qry(i + 1, id));
      |             ^~~
      |             abs
shoes.cpp:42:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   42 |             ans += (id - i - 2 - qry(i + 1, id));
      |             ^~~
      |             abs
shoes.cpp:47:12: error: 'ans' was not declared in this scope; did you mean 'abs'?
   47 |     return ans;
      |            ^~~
      |            abs
shoes.cpp:23:26: warning: unused variable 'j' [-Wunused-variable]
   23 |     n = a.size(); int i, j;
      |                          ^