Submission #1279052

#TimeUsernameProblemLanguageResultExecution timeMemory
1279052gazizmadi11Arranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "shoes.h" #define pb push_back // #define pf push_front // #define F first // #define S second // #define all(v) v.begin(),v.end() // #define pii pair<int,int> #define tm (tl+tr)/2 #define TL v+v, tl, tm #define TR v+v+1, tm+1, tr #define DA l <= tl && tr <= r #define NE r < tl || tr < l // #define double long double // #define int long long s using namespace std; const int N=2e5+7; // const int mod=998244353; // const int inf=2e9; int n; int t[N*4]; int get(int x, int v=1, int tl=1, int tr=n){ if(tl == tr)return t[v]; if(x <= tm)return get(x, TL)+t[v]; else return get(x, TR)+t[v]; } void upd(int l, int r, int v=1, int tl=1, int tr=n){ if(DA){ t[v]++; return; } if(NE)return; upd(l, r, TL); upd(l, r, TR); } long long count_swaps(vector<int>S){ n=s.size(); vector<int>a; vector<int>b; long long ans=0; for(int i=0; i < S.size(); i++){ int x = S[i]; if(x > 0){ if(a[x].size()){ ans+=i+1-a[x].back()-1-get(a[x].back()); upd(a[x].back(), i+1); a[x].pop_back(); } else b[x].pb(i+1); } else{ x=abs(x); if(b[x].size()){ ans+=i+1-b[x].back()-get(b[x].back()); upd(b[x].back(), i+1); b[x].pop_back(); } else a[x].pb(i+1); } } return ans; } // void solve(){ // } // signed main(){ // ios_base::sync_with_stdio(0); // cin.tie(0); // int dioz=1; // cin >> dioz; // while(dioz--)solve(); // return 0; // }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:39:7: error: 's' was not declared in this scope
   39 |     n=s.size();
      |       ^
shoes.cpp:46:21: error: request for member 'size' in 'a.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   46 |             if(a[x].size()){
      |                     ^~~~
shoes.cpp:47:31: error: request for member 'back' in 'a.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   47 |                 ans+=i+1-a[x].back()-1-get(a[x].back());
      |                               ^~~~
shoes.cpp:47:49: error: request for member 'back' in 'a.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   47 |                 ans+=i+1-a[x].back()-1-get(a[x].back());
      |                                                 ^~~~
shoes.cpp:48:26: error: request for member 'back' in 'a.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   48 |                 upd(a[x].back(), i+1);
      |                          ^~~~
shoes.cpp:49:22: error: request for member 'pop_back' in 'a.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   49 |                 a[x].pop_back();
      |                      ^~~~~~~~
shoes.cpp:3:12: error: request for member 'push_back' in 'b.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
    3 | #define pb push_back
      |            ^~~~~~~~~
shoes.cpp:51:23: note: in expansion of macro 'pb'
   51 |             else b[x].pb(i+1);
      |                       ^~
shoes.cpp:55:21: error: request for member 'size' in 'b.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   55 |             if(b[x].size()){
      |                     ^~~~
shoes.cpp:56:31: error: request for member 'back' in 'b.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   56 |                 ans+=i+1-b[x].back()-get(b[x].back());
      |                               ^~~~
shoes.cpp:56:47: error: request for member 'back' in 'b.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   56 |                 ans+=i+1-b[x].back()-get(b[x].back());
      |                                               ^~~~
shoes.cpp:57:26: error: request for member 'back' in 'b.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   57 |                 upd(b[x].back(), i+1);
      |                          ^~~~
shoes.cpp:58:22: error: request for member 'pop_back' in 'b.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   58 |                 b[x].pop_back();
      |                      ^~~~~~~~
shoes.cpp:3:12: error: request for member 'push_back' in 'a.std::vector<int>::operator[](((std::vector<int>::size_type)x))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
    3 | #define pb push_back
      |            ^~~~~~~~~
shoes.cpp:60:23: note: in expansion of macro 'pb'
   60 |             else a[x].pb(i+1);
      |                       ^~