답안 #1069242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069242 2024-08-21T18:01:59 Z raduv Fountain (eJOI20_fountain) C++14
100 / 100
115 ms 17232 KB
#include <bits/stdc++.h>
#define pi pair<int, int>
const int MAXN = 100'000;
const int LOG = 18;
using namespace std;
int rmq[LOG + 1][MAXN + 1];
int cap[LOG + 1][MAXN + 1];
pi stiva[MAXN + 1];
int ns;
int main()
{
    int n, q, i, diam, p, a, b;
    scanf("%d%d", &n, &q);
    for( i = 1; i <= n; i++ ){
      scanf("%d%d", &diam, &cap[0][i]);
      while(ns > 0 && diam > stiva[ns].first)
        rmq[0][stiva[ns--].second] = i;
      stiva[++ns] = {diam, i};
    }
    while(ns > 0)
      rmq[0][stiva[ns--].second] = i;
    for ( p = 1; p <= LOG; p++ ){
      for( i = 1; i <= n; i++ ){
        rmq[p][i] = rmq[p - 1][rmq[p - 1][i]];
        cap[p][i] = cap[p - 1][i] + cap[p - 1][rmq[p - 1][i]];
      }
    }
    while(q--){
      scanf("%d%d", &a, &b);
      for( i = LOG; i >= 0; i-- ){
        if(cap[i][a] < b){
          b -= cap[i][a];
          a = rmq[i][a];
        }
      }
      printf("%d\n", a);
    }
    return 0;
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
fountain.cpp:15:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |       scanf("%d%d", &diam, &cap[0][i]);
      |       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:29:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |       scanf("%d%d", &a, &b);
      |       ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 16144 KB Output is correct
2 Correct 90 ms 15696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 1 ms 8796 KB Output is correct
7 Correct 1 ms 8796 KB Output is correct
8 Correct 81 ms 16144 KB Output is correct
9 Correct 90 ms 15696 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 52 ms 10440 KB Output is correct
12 Correct 115 ms 16976 KB Output is correct
13 Correct 106 ms 16980 KB Output is correct
14 Correct 66 ms 16980 KB Output is correct
15 Correct 58 ms 17232 KB Output is correct