Submission #877061

#TimeUsernameProblemLanguageResultExecution timeMemory
877061raul2008487Arranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#include "shoes.h"
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using nemaspce std;
const int sz = 2e5+5;
ll Tree[sz];
void add(ll pos, ll val){
    for(ll i = pos; i<n ; 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:8:7: error: expected nested-name-specifier before 'nemaspce'
    8 | using nemaspce std;
      |       ^~~~~~~~
shoes.cpp: In function 'void add(long long int, long long int)':
shoes.cpp:12:23: error: 'n' was not declared in this scope
   12 |     for(ll i = pos; i<n ; i += (i & (-i))){
      |                       ^
shoes.cpp: At global scope:
shoes.cpp:26:23: error: 'long long int count_swaps' redeclared as different kind of entity
   26 | long long count_swaps(vector<int> s) {
      |                       ^~~~~~
In file included from shoes.cpp:2:
shoes.h:7:11: note: previous declaration 'long long int count_swaps(std::vector<int>)'
    7 | long long count_swaps(std::vector<int> S);
      |           ^~~~~~~~~~~
shoes.cpp:26:23: error: 'vector' was not declared in this scope
   26 | long long count_swaps(vector<int> s) {
      |                       ^~~~~~
shoes.cpp:26:23: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from shoes.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
shoes.cpp:26:30: error: expected primary-expression before 'int'
   26 | long long count_swaps(vector<int> s) {
      |                              ^~~