Submission #289837

#TimeUsernameProblemLanguageResultExecution timeMemory
289837Bill_00Arranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h" int op[100000],tree[300000]; unordered_map<int,int>p; vector<int>lft; void build(int id,int l,int r){ if(l==r){ tree[id]=1; return; } build(id*2,l,(l+r)/2); build(id*2+1,(l+r)/2+1,r); tree[id]=tree[id*2]+tree[id*2+1]; } long long query(int id,int l,int r,int L,int R){ if(r<L || R<l){ return (long long)0; } if(L<=l && r<=R){ return (long long)tree[id]; } return query(id*2,l,(l+r)/2,L,R)+query(id*2+1,(l+r)/2+1,r,L,R); } void update(int id,int l,int r,int index){ if(l==r){ tree[id]=0; return; } if(index<=(l+r)/2){ update(id*2,l,(l+r)/2,index); } else update(id*2+1,(l+r)/2+1,r,index); tree[id]=tree[id*2]+tree[id*2+1]; } long long count_swaps(vector<int> s) { int n=s.size(); for(int i=0;i<s.size();i++){ if(p[-s[i]]!=0){ op[p[-s[i]]-1]=i; p[-s[i]]=0; } else{ p[s[i]]=i+1; lft.push_back(i); } } long long ans=0; build(1,0,n-1); for(int i=0;i<lft.size();i++){ int l=lft[i],r=op[lft[i]]; if(s[l]>0) ans++; ans+=(query(1,0,n-1,l,r)); ans-=2; update(1,0,n-1,r); } return ans; }

Compilation message (stderr)

shoes.cpp:3:1: error: 'unordered_map' does not name a type
    3 | unordered_map<int,int>p;
      | ^~~~~~~~~~~~~
shoes.cpp:4:1: error: 'vector' does not name a type
    4 | vector<int>lft;
      | ^~~~~~
shoes.cpp:34:23: error: 'long long int count_swaps' redeclared as different kind of entity
   34 | long long count_swaps(vector<int> s) {
      |                       ^~~~~~
In file included from shoes.cpp:1:
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:34:23: error: 'vector' was not declared in this scope; did you mean 'std::vector'?
   34 | long long count_swaps(vector<int> s) {
      |                       ^~~~~~
      |                       std::vector
In file included from /usr/include/c++/9/vector:67,
                 from shoes.h:5,
                 from shoes.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:386:11: note: 'std::vector' declared here
  386 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
shoes.cpp:34:30: error: expected primary-expression before 'int'
   34 | long long count_swaps(vector<int> s) {
      |                              ^~~