Submission #877064

#TimeUsernameProblemLanguageResultExecution timeMemory
877064raul2008487Arranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include "shoes.h"
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
const int sz = 2e5+5;
ll Tree[sz];
void add(ll pos, ll val){
    for(ll i = pos; i<sz ; i += (i & (-i))){
        Tree[i] += val;
    }
}
ll get(ll pos){
    ll rx = 0;
    for(ll i = pos; i>0; i -= (i & (-i))){
        rx += Tree[i];
    }
    return rx;
}
ll ask(ll l, ll r){
    return get(r) - get(l-1);
}
long long count_swaps(vector<int> s) {
	ll n = s.size(), i, j, ans = 0;
	set<pair<ll,ll>> c;
	for(i=0;i<n;i++){
        c.in({s[i], i});
        add(i+1, 1);
	}
    while(s.size()){
        auto x = s.begin();
        pair<ll,ll> fr = (*x);
        auto f = c.lower_bound({-fr.fi, fr.se});
        ll pr = (*f).se;
        if(pr > (fr.se + 1)){
            ans += ask(fr.se+2, pr);
        }
        if(pr.fi > 0){
            ans++;
        }
        add(fr.fi+1, -1);
        add(pr+1, -1);
        s.erase(x);
        s.erase(f);
    }
    return ans;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:30:11: error: 'class std::set<std::pair<long long int, long long int> >' has no member named 'in'
   30 |         c.in({s[i], i});
      |           ^~
shoes.cpp:35:27: error: conversion from 'int' to non-scalar type 'std::pair<long long int, long long int>' requested
   35 |         pair<ll,ll> fr = (*x);
      |                          ~^~~
shoes.cpp:6:12: error: request for member 'first' in 'pr', which is of non-class type 'long long int'
    6 | #define fi first
      |            ^~~~~
shoes.cpp:41:15: note: in expansion of macro 'fi'
   41 |         if(pr.fi > 0){
      |               ^~
shoes.cpp:47:18: error: no matching function for call to 'std::vector<int>::erase(std::_Rb_tree_const_iterator<std::pair<long long int, long long int> >&)'
   47 |         s.erase(f);
      |                  ^
In file included from /usr/include/c++/10/vector:67,
                 from shoes.h:5,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1430:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator]'
 1430 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/10/bits/stl_vector.h:1430:28: note:   no known conversion for argument 1 from 'std::_Rb_tree_const_iterator<std::pair<long long int, long long int> >' to 'std::vector<int>::const_iterator'
 1430 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1457:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::const_iterator, std::vector<_Tp, _Alloc>::const_iterator) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = std::vector<int>::iterator; std::vector<_Tp, _Alloc>::const_iterator = std::vector<int>::const_iterator]'
 1457 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/10/bits/stl_vector.h:1457:7: note:   candidate expects 2 arguments, 1 provided
shoes.cpp:27:22: warning: unused variable 'j' [-Wunused-variable]
   27 |  ll n = s.size(), i, j, ans = 0;
      |                      ^