Submission #574343

#TimeUsernameProblemLanguageResultExecution timeMemory
574343Trisanu_DasArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
 
const int N = 2e5 + 5;
 
int n, fenwick[N];
queue<int> shoes_lt[N], shoes_rt[n];
 
void upd(int i, int val) {
    for(int j = i; j <= n; j += j & (-j)) fenwick[i] += val;
}
 
int get(int i){
    int val = 0;
    for(int j = i; j > 0; j -= j & (-j)) val += fenwick[i];
    return val;
}
 
ll count_swaps(vector<int> s) {
    n = s.size();
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        int temp = s[i - 1];
        if(temp < 0) {
            temp *= -1;
            if(shoes_rt[temp].size()) {
                int other = shoes_rt[temp].front(); shoes_rt[temp].pop(); ans += get(i) - get(other - 1); upd(other, 1);
            }
            else {
                shoes_lt[temp].push(i); upd(i, 1);
            }
        }
        else {
            if(shoes_lt[temp].size()) {
                int other = shoes_lt[temp].front(); shoes_lt[temp].pop(); ans += get(i) - get(other);upd(other,1);
            }
            else {
                shoes_rt[temp].push(i);upd(i, 1);
            }
        }
    }
    return ans;
}

Compilation message (stderr)

shoes.cpp:9:35: error: array bound is not an integer constant before ']' token
    9 | queue<int> shoes_lt[N], shoes_rt[n];
      |                                   ^
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:28:16: error: 'shoes_rt' was not declared in this scope; did you mean 'shoes_lt'?
   28 |             if(shoes_rt[temp].size()) {
      |                ^~~~~~~~
      |                shoes_lt
shoes.cpp:40:17: error: 'shoes_rt' was not declared in this scope; did you mean 'shoes_lt'?
   40 |                 shoes_rt[temp].push(i);upd(i, 1);
      |                 ^~~~~~~~
      |                 shoes_lt