제출 #1046466

#제출 시각아이디문제언어결과실행 시간메모리
1046466Dalek_of_RiviaArranging Shoes (IOI19_shoes)C++17
컴파일 에러
0 ms0 KiB
#include "shoes.h" using namespace std; vector<vector<int>> G; int H[270000]; void build(int n){ G.clear(); vector<int> v; v.clear(); G.push_back(v); for(int i=1; i<=n; i++){ G.push_back(v); G[i].push_back(2*i); G[i].push_back(2*i+1); H[i]=0; } for(int i=n+1; i>0; i--){ G.push_back(v); H[i+n]=0; } } void actualizar(int s, int nodo, int n){ if(G[nodo].size()>0){ int u=(n+1)/2; if(s>=u){ H[2*nodo]++; actualizar(s-u, 2*nodo+1, n-u); }else{ actualizar(s, 2*nodo, u); } } } int evaluar(int s, int nodo, int n){ if(G[nodo].size()>0){ int u=(n+1)/2; if(s>=u){ return H[nodo]+evaluar(s-u, 2*nodo+1, n-u); }else{ return H[nodo]+evaluar(s, 2*nodo, u); } } return H[nodo]; } long long count_swaps(vector<int> s) { map<int, queue<int>> m; map<int, bool> b; long long ans = 0; int N = s.size(); for(int i=0; i<N; i++){ int K = abs(s[i]); if(!m[K].empty()){ if(s[i]>0){ if(b[K]){ m[K].push(i); }else{ ans+=i-m[K].front()-1; s[i]=-1; s[m[K].front()]=i+1; m[K].pop(); } }else{ if(!b[K]){ m[K].push(i); }else{ ans+=i-m[K].front()+1; s[i]=-1; s[m[K].front()]=i+1; m[K].pop(); } } }else{ m[K].push(i); b[K]=(s[i]>0); } } ans/=2; cout<<ans<<endl; int P=1; int ka=N; while(ka>0){ ka=ka/2; P*=2; } build(P); for(int i=0; i<N; i++){ if(s[i]!=-1){ ans+=evaluar(s[i], 1, P); actualizar(s[i], 1, P); } } return ans; } /*int main(){ ios::sync_with_stdio(0); cin.tie(nullptr); int T; cin>>T; for(int dalekofrivia=T; dalekofrivia>0; dalekofrivia--){ int n; cin>>n; vector<int> s; for(int i=0; i<2*n; i++){ int u; cin>>u; s.push_back(u); } cout<<count_swaps(s)<<endl; } return 0; }*/

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:50:6: error: 'map' was not declared in this scope
   50 |      map<int, queue<int>> m;
      |      ^~~
shoes.cpp:2:1: note: 'std::map' is defined in header '<map>'; did you forget to '#include <map>'?
    1 |     #include "shoes.h"
  +++ |+#include <map>
    2 | 
shoes.cpp:50:10: error: expected primary-expression before 'int'
   50 |      map<int, queue<int>> m;
      |          ^~~
shoes.cpp:51:13: error: expected primary-expression before 'int'
   51 |         map<int, bool> b;
      |             ^~~
shoes.cpp:55:21: error: 'abs' was not declared in this scope; did you mean 'ans'?
   55 |             int K = abs(s[i]);
      |                     ^~~
      |                     ans
shoes.cpp:56:17: error: 'm' was not declared in this scope
   56 |             if(!m[K].empty()){
      |                 ^
shoes.cpp:58:24: error: 'b' was not declared in this scope
   58 |                     if(b[K]){
      |                        ^
shoes.cpp:67:25: error: 'b' was not declared in this scope
   67 |                     if(!b[K]){
      |                         ^
shoes.cpp:78:17: error: 'b' was not declared in this scope
   78 |                 b[K]=(s[i]>0);
      |                 ^
shoes.cpp:82:9: error: 'cout' was not declared in this scope
   82 |         cout<<ans<<endl;
      |         ^~~~
shoes.cpp:2:1: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 |     #include "shoes.h"
  +++ |+#include <iostream>
    2 | 
shoes.cpp:82:20: error: 'endl' was not declared in this scope
   82 |         cout<<ans<<endl;
      |                    ^~~~
shoes.cpp:2:1: note: 'std::endl' is defined in header '<ostream>'; did you forget to '#include <ostream>'?
    1 |     #include "shoes.h"
  +++ |+#include <ostream>
    2 |