이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vv vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18; int mod = 119<<23|1;
struct seg{
vector<int> t;
int base = 1;
void init(int n, vector<int> &a){
while(base < n) base <<= 1;
t.resize(base<<1);
for(int i = 1; i <= n; ++i) t[i+base-1] = a[i];
for(int i = base-1; i; --i) t[i] = max(t[i<<1], t[i<<1|1]);
}
int query_max(int i, int s, int e, int x, int y){
if(x <= s && e <= y) return t[i];
int mid = (s+e)>>1, ret = 0;
if(x <= mid) ret = max(ret, query_max(i<<1, s, mid, x, y));
if(mid < y) ret = max(ret, query_max(i<<1|1, mid+1, e, x, y));
return ret;
}
int query(int x, int y){
if(x <= y) return query_max(1, 1, base, max(1, x), min(base, y));
return 0;
}
};
void answer(){
int n; scanf("%d", &n);
vector<int> t(n+1);
for(int i = 1; i <= n; ++i) scanf("%d", &t[i]);
seg seg; seg.init(n, t);
int q; scanf("%d", &q);
for(++q; --q; ){
int l, r; scanf("%d%d", &l, &r);
vector<int> st;
for(int i = r; i > l; --i)
if(st.empty() || t[st.back()] < t[i]) st.emplace_back(i);
int mx_pos = l, result = 0;
for(int i = l+1; i <= r-1; ++i){
if(st.back() == i) st.pop_back();
result = max(result, seg.query(max(l, i-(st.back()-i)), i-1)+t[i]+t[st.back()]);
result = max(result, t[mx_pos]+t[i]+seg.query(i+(i-mx_pos), r));
if(t[mx_pos] <= t[i]) mx_pos = i;
}
printf("%d\n", result);
}
}
int main(){
int T = 1;
for(++T; --T; ) answer();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
jumps.cpp: In function 'void answer()':
jumps.cpp:35:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
jumps.cpp:37:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | for(int i = 1; i <= n; ++i) scanf("%d", &t[i]);
| ~~~~~^~~~~~~~~~~~~
jumps.cpp:39:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | int q; scanf("%d", &q);
| ~~~~~^~~~~~~~~~
jumps.cpp:41:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | int l, r; scanf("%d%d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~
# | 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... |