Submission #165302

#TimeUsernameProblemLanguageResultExecution timeMemory
165302Segtree고대 책들 (IOI17_books)C++14
Compilation error
0 ms0 KiB
#include<iostream> #include<algorithm> #include<vector> #include"books.h" using namespace std; typedef long long ll; #define chmin(a,b) a=min(a,b) #define chmax(a,b) a=max(a,b) #define N 1000010 ll minimum_walk(vector<int> p,int s){ int n=p.size(); ll sum=0; for(int i=0;i<n;i++)sum+=abs(i-p[i]); if(sum==0)return 0; bool vis[N]; for(int i=0;i<n;i++)vis[i]=0; vector<pair<int,int> >v; bool th=0; for(int i=0;i<n;i++){ if(vis[i])continue; ll x=i; ll mi=1e17,ma=-1e17; while(1){ chmin(mi,x); chmax(ma,x); vis[x]=1; x=p[x]; if(x==i)break; } if(mi!=ma){ v.push_back(make_pair(mi,ma)); if(mi<=s&&s<=ma)th=1; } } if(th==0)v.push_back(make_pair(s,s)); sort(v.begin(),v.end()); vector<P> nv; int rnd=-1; for(int i=0;i<v.size();i++){ if(rnd<v[i].second){ nv.push_back(v[i]); rnd=v[i].second; } } v=nv; ll bef=v[0].first; for(int i=0;i<v.size();i++){ if(~rnd&&rnd<v[i].first){ v.push_back(make_pair(bef,rnd)); bef=v[i].first; sum+=2*(v[i].first-rnd); } chmax(rnd,v[i].second); } if(th==1){ int mi=1e9; for(int i=0;i<v.size();i++){ chmin(mi,abs(s-v[i].first)); chmin(mi,abs(s-v[i].second)); } if(mi==1e9)return 0; if(mi==0)cout<<1/0<<endl; //sum+=mi*2; } return sum; }

Compilation message (stderr)

books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:37:12: error: 'P' was not declared in this scope
     vector<P> nv;
            ^
books.cpp:37:13: error: template argument 1 is invalid
     vector<P> nv;
             ^
books.cpp:37:13: error: template argument 2 is invalid
books.cpp:39:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();i++){
                 ~^~~~~~~~~
books.cpp:41:9: error: request for member 'push_back' in 'nv', which is of non-class type 'int'
      nv.push_back(v[i]);
         ^~~~~~~~~
books.cpp:45:7: error: no match for 'operator=' (operand types are 'std::vector<std::pair<int, int> >' and 'int')
     v=nv;
       ^~
In file included from /usr/include/c++/7/vector:69:0,
                 from books.cpp:3:
/usr/include/c++/7/bits/vector.tcc:179:5: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]
     vector<_Tp, _Alloc>::
     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/7/bits/vector.tcc:179:5: note:   no known conversion for argument 1 from 'int' to 'const std::vector<std::pair<int, int> >&'
In file included from /usr/include/c++/7/vector:64:0,
                 from books.cpp:3:
/usr/include/c++/7/bits/stl_vector.h:461:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]
       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
       ^~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:461:7: note:   no known conversion for argument 1 from 'int' to 'std::vector<std::pair<int, int> >&&'
/usr/include/c++/7/bits/stl_vector.h:482:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]
       operator=(initializer_list<value_type> __l)
       ^~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:482:7: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<std::pair<int, int> >'
books.cpp:47:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.size();i++){
                 ~^~~~~~~~~
books.cpp:57:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size();i++){
              ~^~~~~~~~~
books.cpp:62:18: warning: division by zero [-Wdiv-by-zero]
  if(mi==0)cout<<1/0<<endl;
                 ~^~