Submission #947733

# Submission time Handle Problem Language Result Execution time Memory
947733 2024-03-17T00:56:46 Z biank Arranging Shoes (IOI19_shoes) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(x) int(x.size())

typedef long long ll;

const int MAX_N = 2e5 + 20;

int ft[MAX_N];

inline int lsb(int i) {
    return i & (-i);
}

void update(int i) {
    i++;
    while (i < MAX_N) {
        ft[i]++;
        i += lsb(i);
    }
}

int query(int i) {
    int s = 0;
    while (i > 0) {
        s += ft[i];
        i -= lsb(i);
    }
    return s;
}

ll count_swaps(vector<int> S) {
	int n = sz(S);
	
	vector<pair<int, int>> pairs;
	map<int, queue<int>> m;
	
	for (int i = 0; i < n; i++) {
		if (!m[S[i]].empty()) {
			pairs.emplace_back(m[S[i]].front(), i);
			m[S[i]].pop();
		} else {
			m[-S[i]].push(i);
		}
	}
	
	ll ans = 0;
	for (auto [x, y] : pairs) {
		if (S[y] < S[x]) {
			swap(x, y);
		}
        for (int p : vector{x, y}) {
            ans += p - query(p);
            update(p);
        }
	}
	return ans;
}

Compilation message

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:50:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |  for (auto [x, y] : pairs) {
      |            ^
shoes.cpp:54:28: error: missing template arguments before '{' token
   54 |         for (int p : vector{x, y}) {
      |                            ^
shoes.cpp:54:28: error: expected ')' before '{' token
   54 |         for (int p : vector{x, y}) {
      |             ~              ^
      |                            )
shoes.cpp:54:29: warning: left operand of comma operator has no effect [-Wunused-value]
   54 |         for (int p : vector{x, y}) {
      |                             ^
shoes.cpp:54:33: error: expected ';' before '}' token
   54 |         for (int p : vector{x, y}) {
      |                                 ^
      |                                 ;
shoes.cpp:54:32: warning: right operand of comma operator has no effect [-Wunused-value]
   54 |         for (int p : vector{x, y}) {
      |                                ^
shoes.cpp:54:18: warning: unused variable 'p' [-Wunused-variable]
   54 |         for (int p : vector{x, y}) {
      |                  ^
shoes.cpp:54:34: error: expected primary-expression before ')' token
   54 |         for (int p : vector{x, y}) {
      |                                  ^