답안 #801824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
801824 2023-08-02T07:55:11 Z vjudge1 Railway Trip (JOI17_railway_trip) C++17
20 / 100
2000 ms 3252 KB
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1<<17;

int n, k, Q, arr[N], cnt[N][21], LEFT[N], RIGHT[N];
ll use[N], T, nT;

void solve_subtask3() {
    for(int i = 1; i <= n; ++ i) {
        for(int j = k; j; -- j) {
            cnt[i][j] = cnt[i - 1][j] + (arr[i] <= j);
        }
    }
}

main() {
#ifdef Home
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // Home
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k >> Q;

    stack < int > st;

    for(int i = 1; i <= n; ++ i) {
        cin >> arr[i];
        
        for(; !st.empty() && arr[i] >= arr[st.top()]; st.pop());
        LEFT[i] = st.empty() ? 0 : st.top();
        st.push(i);
    }

    for(; !st.empty(); st.pop());

    for(int i = n; i; -- i) {
        for(; !st.empty() && arr[i] >= arr[st.top()]; st.pop());
        RIGHT[i] = st.empty() ? n + 1 : st.top();
        st.push(i);
    }

    queue < int > q;
    for(int a, b; Q --> 0;) {
        cin >> a >> b;
        ++ T;
        use[a] = T;
        q.push(a);
        for(; !q.empty();) {
            int v = q.front();
            q.pop();
            int l = v - 1, r = v + 1, m = 1;
            for(; l && m;) {
                m &= arr[l] < arr[v];
                if(use[l] < T) {
                    use[l] = use[v] + 1;
                    q.push(l);
                }
                l = LEFT[l];
            }
            for(m = 1; r <= n && m;) {
                m &= arr[r] < arr[v];
                if(use[r] < T) {
                    use[r] = use[v] + 1;
                    q.push(r);
                } 
                r = RIGHT[r];
            }
        }
        cout << use[b] - T - 1 << '\n';
        T += n;
    }
}

Compilation message

railway_trip.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 130 ms 2488 KB Output is correct
3 Correct 130 ms 2528 KB Output is correct
4 Correct 131 ms 2564 KB Output is correct
5 Correct 134 ms 2572 KB Output is correct
6 Correct 127 ms 2692 KB Output is correct
7 Correct 133 ms 2952 KB Output is correct
8 Correct 33 ms 2388 KB Output is correct
9 Correct 51 ms 2948 KB Output is correct
10 Correct 37 ms 2720 KB Output is correct
11 Correct 109 ms 2904 KB Output is correct
12 Correct 106 ms 2908 KB Output is correct
13 Correct 104 ms 2772 KB Output is correct
14 Correct 105 ms 2900 KB Output is correct
15 Correct 106 ms 2900 KB Output is correct
16 Correct 106 ms 2864 KB Output is correct
17 Correct 131 ms 2968 KB Output is correct
18 Correct 128 ms 2968 KB Output is correct
19 Correct 79 ms 2980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2060 ms 2780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2054 ms 3252 KB Time limit exceeded
2 Halted 0 ms 0 KB -