This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
using namespace std;
#define ll long long
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 1000000;
int v[1 + nmax];
vector<pair<int,int>> querys[1 + nmax];
vector<pair<int,int>> interval[1 + nmax];
int sol[1 + nmax];
int key[1 + nmax];
int aint[1 + nmax * 4];
void update(int node, int from, int to, int x, int val){
if(from < to){
int mid = (from + to) / 2;
if(x <= mid)
update(node * 2 , from, mid, x, val);
else
update(node * 2 + 1, mid + 1 , to, x, val);
aint[node] = MAX(aint[node * 2], aint[node * 2 + 1]);
} else
aint[node] = MAX(aint[node], val);
}
int query(int node,int from, int to, int x, int y){
if(from == x && to == y)
return aint[node];
else{
int mid = (from + to) / 2;
int result1 = 0, result2 = 0;
if(x <= mid)
result1 = query(node * 2, from, mid, x, MIN(y, mid));
if(mid + 1 <= y)
result2 = query(node * 2 + 1, mid + 1, to, MAX(mid + 1, x), y);
return MAX(result1, result2);
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
stack<int> st;
for(int i = 1; i <= n; i++) {
cin >> v[i];
while(0 < st.size() && v[st.top()] <= v[i])
st.pop();
if(0 < st.size())
interval[i].push_back({st.top(), v[st.top()] + v[i]});
st.push(i);
}
for(int i = 1;i <= m; i++){
int x, y;
cin >> x >> y >> key[i];
querys[y].push_back({x, i});
}
for(int i = 1;i <= n; i++){
for(int h = 0; h < interval[i].size(); h++)
update(1, 1, n, interval[i][h].first, interval[i][h].second);
for(int h = 0; h < querys[i].size(); h++)
sol[querys[i][h].second] = query(1, 1, n, querys[i][h].first , i);
}
for(int i = 1;i <= m; i++)
cout << (sol[i] <= key[i]) << '\n';
return 0;
}
Compilation message (stderr)
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:73:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int h = 0; h < interval[i].size(); h++)
~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:75:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int h = 0; h < querys[i].size(); h++)
~~^~~~~~~~~~~~~~~~~~
# | 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... |