Submission #289866

#TimeUsernameProblemLanguageResultExecution timeMemory
289866Bill_00Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include <shoes.h> #include <bits/stdc++.h> using namespace std; queue<int> l[200005], r[200005]; long long s[200005]; int a[200005]; int n; long long tree[1000005]; void add(int i, int x) { while(i <= 2 * n) { s[i] += x; i += (i & (-i)); } } long long sum(int i) { long long res = 0; while(i > 0) { res += s[i]; i -= (i & (-i)); } return res; } long long count_swaps(vector<int> b) { n = b.size() / 2; for(i = 1; i <= 2 * n; i++) a[i] = b[i - 1]; int i, j; long long ans = 0; cin >> n; for(i = 1; i <= 2 * n; i++) { cin >> a[i]; if(a[i] > 0) r[a[i]].push(i); else l[-a[i]].push(i); } for(i = 1; i <= 2 * n; i++) add(i, 1); for(i = 1; i <= 2 * n; i++) if(sum(i) - sum(i - 1)){ if(a[i] < 0) { int id; id = r[-a[i]].front(); ans += sum(id) - sum(i) - 1; add(id, -1); l[-a[i]].pop(); r[-a[i]].pop(); } else { int id; id = l[a[i]].front(); ans += sum(id) - sum(i); add(id, -1); l[a[i]].pop(); r[a[i]].pop(); } } return ans; } /* 6 -2 2 2 -2 -2 2 */

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:31:6: error: 'i' was not declared in this scope
   31 |  for(i = 1; i <= 2 * n; i++) a[i] = b[i - 1];
      |      ^
shoes.cpp:32:9: warning: unused variable 'j' [-Wunused-variable]
   32 |  int i, j;
      |         ^