Submission #767680

#TimeUsernameProblemLanguageResultExecution timeMemory
767680ono_de206Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; #define in insert #define all(x) x.begin(),x.end() #define pb push_back #define eb emplace_back #define ff first #define ss second // #define int long long typedef long long ll; typedef vector<int> vi; typedef set<int> si; typedef multiset<int> msi; typedef pair<int, int> pii; typedef vector<pii> vpii; const int mxn = 1e5 + 10; int a[mxn], fn[mxn], n; queue<pair<int, int>> q[mxn][3]; void add(int i, int val) { for(; i; i -= (i & -i)) { fn[i] += val; } } int get(int i) { int ret = 0; for(; i <= n; i += (i & -i)) { ret += fn[i]; } return ret; } long long count_swaps(vector<int> s) { n = (int)s.size() * 2; for(int i = 1; i <= n; i++) { a[i] = s[i - 1]; } int ret = 0; for(int i = 1; i <= n; i++) { if(a[i] > 0) { if(q[a[i]][0].size()) { int lst = q[a[i]][0].front(); q[a[i]][0].pop(); ans += (i - lst - 1) - (get(i) - get(lst)); add(i, -1); add(lst, 1); } else { q[a[i]][1].push(i); } } else { if(q[a[i]][1].size()) { int lst = q[a[i]][1].front(); q[a[i]][1].pop(); ans += (i - lst) - (get(i) - get(lst)); add(i, -1); add(lst, 1); } else { q[a[i]][0].push(i); } } } return ret; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:48:31: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int' in initialization
   48 |     int lst = q[a[i]][0].front();
      |               ~~~~~~~~~~~~~~~~^~
      |                               |
      |                               __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type {aka std::pair<int, int>}
shoes.cpp:50:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   50 |     ans += (i - lst - 1) - (get(i) - get(lst));
      |     ^~~
      |     abs
shoes.cpp:54:22: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(int&)'
   54 |     q[a[i]][1].push(i);
      |                      ^
In file included from /usr/include/c++/10/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from shoes.cpp:2:
/usr/include/c++/10/bits/stl_queue.h:265:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]'
  265 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:265:30: note:   no known conversion for argument 1 from 'int' to 'const value_type&' {aka 'const std::pair<int, int>&'}
  265 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_queue.h:270:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(std::queue<_Tp, _Sequence>::value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]'
  270 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:270:25: note:   no known conversion for argument 1 from 'int' to 'std::queue<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  270 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
shoes.cpp:58:31: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int' in initialization
   58 |     int lst = q[a[i]][1].front();
      |               ~~~~~~~~~~~~~~~~^~
      |                               |
      |                               __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type {aka std::pair<int, int>}
shoes.cpp:60:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   60 |     ans += (i - lst) - (get(i) - get(lst));
      |     ^~~
      |     abs
shoes.cpp:64:22: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(int&)'
   64 |     q[a[i]][0].push(i);
      |                      ^
In file included from /usr/include/c++/10/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from shoes.cpp:2:
/usr/include/c++/10/bits/stl_queue.h:265:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]'
  265 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:265:30: note:   no known conversion for argument 1 from 'int' to 'const value_type&' {aka 'const std::pair<int, int>&'}
  265 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_queue.h:270:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(std::queue<_Tp, _Sequence>::value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<int, int>]'
  270 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:270:25: note:   no known conversion for argument 1 from 'int' to 'std::queue<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  270 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~