이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 100005;
int n, qq;
int d[N], c[N];
int p0[N];
vector<int> g[N];
const int m = 18;
int p[N][m];
int s[N][m];
void dfs(int x)
{
    p[x][0] = p0[x];
    s[x][0] = c[x];
    for (int i = 1; i < m; ++i)
    {
        p[x][i] = p[p[x][i - 1]][i - 1];
        s[x][i] = s[x][i - 1] + s[p[x][i - 1]][i - 1];
    }
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        dfs(h);
    }
}
int qry(int x, int v)
{
    for (int i = m - 1; i >= 0; --i)
    {
        if (s[x][i] < v)
        {
            v -= s[x][i];
            x = p[x][i];
        }
    }
    return x;
}
void solv()
{
    cin >> n >> qq;
    for (int i = 1; i <= n; ++i)
        cin >> d[i] >> c[i];
    stack<int> s;
    for (int i = n; i >= 1; --i)
    {
        while (!s.empty() && d[i] >= d[s.top()])
            s.pop();
        if (s.empty())
            p0[i] = 0;
        else
            p0[i] = s.top();
        s.push(i);
    }
    for (int x = 1; x <= n; ++x)
        g[p0[x]].push_back(x);
    dfs(0);
    while (qq--)
    {
        int x, v;
        cin >> x >> v;
        cout << qry(x, v) << "\n";
    }
}
int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    ios_base::sync_with_stdio(false), cin.tie(0);
    int tt = 1;
    //cin >> tt;
    while (tt--)
    {
        solv();
    }
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
fountain.cpp: In function 'void dfs(int)':
fountain.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i = 0; i < g[x].size(); ++i)
      |                     ~~^~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |