이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
}
컴파일 시 표준 에러 (stderr) 메시지
railway_trip.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
25 | main() {
| ^~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |