이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 1000000;
struct kveri{
int l, val, ind;
};
vector <kveri> queries[MAXN+5];
int seg[4*MAXN+5];
int a[MAXN+5];
void upd(int node, int l, int r, int x, int val){
if(l == r){
seg[node] = max(seg[node], val);
return;
}
int mid = (l+r)/2;
if(x <= mid) upd(node*2, l, mid, x, val);
else upd(node*2+1, mid+1, r, x, val);
}
int query(int node, int l, int r, int tl, int tr){
if(l > tr || tl > r) return 0;
if(tl <= l && r <= tr) return seg[node];
int mid = (l+r)/2;
return max(query(node*2, l, mid, tl, tr), query(node*2+1, mid+1, r, tl, tr));
}
bool res[MAXN+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=m; i++){
int l, r, v;
cin >> l >> r >> v;
queries[r].push_back({l, v, i});
}
stack <int> st;
for(int i=1; i<=n; i++){
while(!st.empty() && a[st.top()] <= a[i]) st.pop();
if(!st.empty()){
upd(1, 1, n, st.top(), a[st.top()] + a[i]);
}
for(auto kveri : queries[i]){
res[kveri.ind] = (query(1, 1, n, kveri.l, i) <= kveri.val);
}
st.push(i);
}
for(int i=1; i<=m; i++) cout << res[i] << "\n";
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |