제출 #1163251

#제출 시각아이디문제언어결과실행 시간메모리
1163251SzymonKrzywdaFountain (eJOI20_fountain)C++20
컴파일 에러
0 ms0 KiB
#include <iostream>

using ll = long long;
using namespace std;

const int LOGK = 17, MAXN = 1e5 + 7;

int jump[MAXN][LOGK];
int suma[MAXN][LOGK];


int main(){
    int n, q;
    
    cin >> n >> q;

    int a, b;

    vector<pair<int, int>> tab;

    for (int i = 0; i < n; i++){
        cin >> a >> b;
        tab.push_back({a, b});
    }
    tab.push_back({2e9, 2e9});

    vector<int> stos;
    stos.push_back(n);

    for (int i = n - 1; i >= 0; i--){
        while (tab[stos.back()].first <= tab[i].first) stos.pop_back();
        jump[i][0] = stos.back();
        suma[i][0] = tab[stos.back()].second;
        stos.push_back(i);
    }

    jump[n][0] = n;

    for (int k = 1; k < LOGK; k++){
        for (int v = 0; v <= n; v++){
            jump[v][k] = jump[jump[v][k - 1]][k - 1];
            if (jump[v][k] == n) suma[v][k] = 2e9;
            else suma[v][k] = suma[v][k - 1] + suma[jump[v][k - 1]][k - 1];
        }
    }


    while (q--){
        cin >> a >> b;
        a--;

        int aktsuma = tab[a].second;

        for (int k = LOGK - 1; k >= 0; k--){
            if (jump[a][k] == n) continue;
            //cout << k << ' ' << a << ' ' << jump[a][k] << ' ' << aktsuma << ' ' << suma[a][k] << '\n';
            if (aktsuma + suma[a][k] < b){
                aktsuma += suma[a][k];
                a = jump[a][k];
            }
        }
        //cout << a << '\n';

        if (aktsuma < b) a = jump[a][0];
        if (a == n) a = -1;

        cout << a + 1 << '\n';
    }


    return 0;
}

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

fountain.cpp: In function 'int main()':
fountain.cpp:19:5: error: 'vector' was not declared in this scope
   19 |     vector<pair<int, int>> tab;
      |     ^~~~~~
fountain.cpp:2:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    1 | #include <iostream>
  +++ |+#include <vector>
    2 | 
fountain.cpp:19:25: error: expected primary-expression before '>' token
   19 |     vector<pair<int, int>> tab;
      |                         ^~
fountain.cpp:19:28: error: 'tab' was not declared in this scope
   19 |     vector<pair<int, int>> tab;
      |                            ^~~
fountain.cpp:27:12: error: expected primary-expression before 'int'
   27 |     vector<int> stos;
      |            ^~~
fountain.cpp:28:5: error: 'stos' was not declared in this scope
   28 |     stos.push_back(n);
      |     ^~~~