이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
int n, q;
vi arr;
class pt{
public:
int sm;
int mx;
ll mood;
};
vector<pt> tree(4 * 1000000);
void build(int node, int l, int r){
if(l == r){
pt cur;
cur.mood = 0;
cur.mx = arr[l];
cur.sm = arr[l];
tree[node] = cur;
}
else{
int mid = (l + r) / 2;
build(node * 2, l, mid);
build(node * 2 + 1, mid + 1, r);
pt next;
next.sm = min(tree[node * 2].sm, tree[node * 2 + 1].sm);
next.mx = max(tree[node * 2].mx, tree[node * 2 + 1].mx);
next.mood = 0;
if(tree[node * 2 + 1].sm < tree[node * 2].mx)
next.mood = tree[node * 2 + 1].sm + tree[node * 2].mx;
next.mood = max(next.mood, tree[node * 2].mood);
next.mood = max(next.mood, tree[node * 2 + 1].mood);
//cout<<l<<" "<<r<<" with mood"<<next.mood<<endl;
tree[node] = next;
}
}
pt query(int node, int l, int r, int L, int R){
if(r < L || l > R) return {-1,-1,-1};
if(L <= l && r <= R) return tree[node];
int mid = (l + r) / 2;
pt left = query(node * 2, l, mid, L, R);
pt right = query(node * 2 + 1, mid + 1, r, L, R);
pt next;
next.sm = min(left.sm, right.sm);
next.mx = max(left.mx, right.mx);
next.mood = 0;
if(left.mx > right.sm)
next.mood = right.sm + left.mx;
next.mood = max(next.mood, left.mood);
next.mood = max(next.mood, right.mood);
return next;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i = 0; i < n; i++){
int a;
cin>>a;
arr.pb(a);
}
build(1, 0, n -1);
while(q--){
int a, b, k;
cin>>a>>b>>k;
a--; b--;
pt rn = query(1, 0, n - 1, a, b);
if(k >= rn.mood)
cout<<1<<endl;
else
cout<<0<<endl;
}
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... |