제출 #931797

#제출 시각아이디문제언어결과실행 시간메모리
931797Arp밀림 점프 (APIO21_jumps)C++17
컴파일 에러
0 ms0 KiB
const int N = 2e5+10; const int K = 18; const int INF = 1e9; int up[K][N], mvr[K][N], mvl[K][N], h[N], idx[N], lh[N], rh[N], n; int sp[K][N], lg[N]; int que(int l, int r) { int i=lg[r-l+1]; return max(sp[i][l], sp[i][r-(1<<i)+1]); } void init(int N, std::vector<int> H) { n=N; for (int i=0; i<n; ++i) h[i+1]=H[i], idx[h[i+1]]=i+1; h[0]=INF-1, h[n+1]=INF; stack<int> st; st.push(0); for (int i=1; i<=n; ++i) { while (h[st.top()] <= h[i]) st.pop(); assert(!st.empty()); lh[i]=st.top(), st.push(i); } st=stack<int>(); for (int i=1; i<=n; ++i) sp[0][i]=h[i]; for (int j=1; j<K; ++j) { for (int i=1; i+(1<<(j-1))<=n; ++i) sp[j][i]=max(sp[j-1][i], sp[j-1][i+(1<<(j-1))]); } lg[1]=0; for (int i=2; i<N; ++i) lg[i]=lg[i/2]+1; st.push(n+1); for (int i=n; i>=1; --i) { while (h[st.top()] <= h[i]) st.pop(); assert(!st.empty()); rh[i]=st.top(), st.push(i); } // assume A=B, C=D for testing reasons for (int i=n; i>=1; --i) { int j=idx[i]; int r=rh[j], l=lh[j]; assert(h[l] > h[j] && h[j] < h[r]); if (h[l] > h[r]) up[0][j]=l; else up[0][j]=r; for (int k=1; k<K; ++k) up[k][j]=up[k-1][up[k-1][j]]; } for (int k=0; k<K; ++k) mvr[k][n+1]=n+1; for (int i=n; i>=1; --i) { int j=idx[i]; mvr[0][j]=rh[j]; for (int k=1; k<K; ++k) mvr[k][j]=mvr[k-1][mvr[k-1][j]]; } for (int i=n; i>=1; --i) { int j=idx[i]; mvl[0][j]=lh[j]; for (int k=1; k<K; ++k) mvl[k][j]=mvl[k-1][mvl[k-1][j]]; } } int minimum_jumps(int a,int b,int c,int d){ a ++,b ++; c ++,d ++; // if(one) return c - b; int m2 = c; int mxv = que(c,d); for(int i = c + 1;i <= d;i ++){ if(h[i] > h[m2]) m2 = i; } int m1 = -1; for(int i = b;i >= a;i--){ if(h[i] > arr[m2]){ break; }else{ m1 = i; } } if(m1 == -1) return -1; int x = m1; int ans = 0; while (true) { int u=up[0][x]; // if (u < c && rh[u] < c && h[u] < mxv) x=u, ans+=(1<<j); if(u < c && rh[x] < c && h[u] < arr[m2]){ x = u; ans +=1; }else{ break; } } // if (up[0][x] < c && h[up[0][x]] < mxv && rh[x] < c) x=up[0][x], ++ans; while(true) { int u=rh[x]; if (u < c) x=u, ans+=1; else break; } if (rh[x] >= c && rh[x] <= d) return ans+1; return -1; }

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

jumps.cpp: In function 'int que(int, int)':
jumps.cpp:11:12: error: 'max' was not declared in this scope
   11 |     return max(sp[i][l], sp[i][r-(1<<i)+1]);
      |            ^~~
jumps.cpp: At global scope:
jumps.cpp:14:18: error: 'std::vector' has not been declared
   14 | void init(int N, std::vector<int> H) {
      |                  ^~~
jumps.cpp:14:29: error: expected ',' or '...' before '<' token
   14 | void init(int N, std::vector<int> H) {
      |                             ^
jumps.cpp: In function 'void init(int, int)':
jumps.cpp:16:36: error: 'H' was not declared in this scope
   16 |     for (int i=0; i<n; ++i) h[i+1]=H[i], idx[h[i+1]]=i+1;
      |                                    ^
jumps.cpp:19:5: error: 'stack' was not declared in this scope
   19 |     stack<int> st; st.push(0);
      |     ^~~~~
jumps.cpp:19:11: error: expected primary-expression before 'int'
   19 |     stack<int> st; st.push(0);
      |           ^~~
jumps.cpp:19:20: error: 'st' was not declared in this scope; did you mean 'sp'?
   19 |     stack<int> st; st.push(0);
      |                    ^~
      |                    sp
jumps.cpp:23:9: error: 'assert' was not declared in this scope
   23 |         assert(!st.empty());
      |         ^~~~~~
jumps.cpp:1:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
  +++ |+#include <cassert>
    1 | 
jumps.cpp:25:16: error: expected primary-expression before 'int'
   25 |     } st=stack<int>();
      |                ^~~
jumps.cpp:29:54: error: 'max' was not declared in this scope
   29 |         for (int i=1; i+(1<<(j-1))<=n; ++i) sp[j][i]=max(sp[j-1][i], sp[j-1][i+(1<<(j-1))]);
      |                                                      ^~~
jumps.cpp:38:9: error: 'assert' was not declared in this scope
   38 |         assert(!st.empty());
      |         ^~~~~~
jumps.cpp:38:9: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
jumps.cpp:47:9: error: 'assert' was not declared in this scope
   47 |         assert(h[l] > h[j] && h[j] < h[r]);
      |         ^~~~~~
jumps.cpp:47:9: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:81:15: error: 'arr' was not declared in this scope
   81 |     if(h[i] > arr[m2]){
      |               ^~~
jumps.cpp:93:39: error: 'arr' was not declared in this scope
   93 |       if(u < c && rh[x] < c && h[u] < arr[m2]){
      |                                       ^~~
jumps.cpp:75:7: warning: unused variable 'mxv' [-Wunused-variable]
   75 |   int mxv = que(c,d);
      |       ^~~