| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 971029 | RandomUser | Pismo (COCI18_pismo) | C++17 | 39 ms | 18772 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int log_dp[maxn+1], table[maxn+1][20], v[maxn+1], L[maxn+1], R[maxn+1];
int query(int l, int r) {
int k = log_dp[r-l+1];
return max(table[l][k], table[r-(1<<k)+1][k]);
}
int main() {
int n, ans = 0;
cin >> n;
for(int i=2; i<=n; i++) log_dp[i] = log_dp[i/2] + 1;
for(int i=0; i<n; i++) cin >> v[i], table[i][0] = v[i];
for(int j=1; j<20; j++)
for(int i=0; i+(1<<j)-1<n; i++) table[i][j] = max(table[i][j-1], table[i+(1<<(j-1))][j-1]);
stack<pair<int, int> > st;
st.push({ -1, -1 });
for(int i=0; i<n; i++) {
while(!st.empty() && st.top().second >= v[i]) st.pop();
L[i] = st.top().first + 1;
st.push({ i, v[i] });
}
while(!st.empty()) st.pop();
st.push({ n, -1 });
for(int i=n-1; i>=0; i--) {
while(!st.empty() && st.top().second >= v[i]) st.pop();
R[i] = st.top().first - 1;
st.push({ i, v[i] });
}
for(int i=0; i<n; i++) ans = max(ans, query(L[i], R[i]) - v[i]);
cout << ans << '\n';
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
