제출 #400500

#제출 시각아이디문제언어결과실행 시간메모리
400500rondojimFountain (eJOI20_fountain)C++17
30 / 100
215 ms15508 KiB
#include <stdio.h> #include <vector> #include <algorithm> #include <stack> using namespace std; const int MAXN = 1e5 + 5, INF = 1e9, MAXL = 18; int N, Q, sum[MAXN][MAXL], anc[MAXN][MAXL]; int D[MAXN], V[MAXN], R, C, result; stack<int> S; int main(){ scanf("%d %d", &N, &Q); for(int i=1; i<=N; ++i) scanf("%d %d", &D[i], &V[i]); D[N + 1] = INF; S.push(N + 1); for(int i=N; i>=1; --i){ while(!S.empty() && D[i] > D[S.top()]) S.pop(); int p = S.top(); anc[i][0] = p, sum[i][0] = V[i] + V[p]; S.push(i); } for(int j=1; j<MAXL; ++j) for(int i=1; i<=N; ++i) if(anc[i][j - 1]){ anc[i][j] = anc[anc[i][j - 1]][j - 1]; sum[i][j] = sum[i][j - 1] + sum[anc[i][j - 1]][j - 1] - V[anc[i][j - 1]]; } while(Q--){ scanf("%d %d", &R, &C); result = R; for(int j=MAXL-1; j>=0; --j) if(anc[result][j] && sum[result][j] < C){ C = C - sum[result][j] + V[anc[result][j]]; result = anc[result][j]; } if(V[result] < C) result = anc[result][0]; printf("%d\n", (result == N + 1) ? 0 : result); } return 0; }

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

fountain.cpp: In function 'int main()':
fountain.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |  scanf("%d %d", &N, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~
fountain.cpp:16:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  for(int i=1; i<=N; ++i) scanf("%d %d", &D[i], &V[i]);
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |   scanf("%d %d", &R, &C);
      |   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...