#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()
{
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
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:69:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int h = 0; h < interval[i].size(); h++)
~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:71: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 |
1 |
Correct |
57 ms |
47352 KB |
Output is correct |
2 |
Correct |
47 ms |
47480 KB |
Output is correct |
3 |
Correct |
47 ms |
47336 KB |
Output is correct |
4 |
Correct |
46 ms |
47352 KB |
Output is correct |
5 |
Correct |
55 ms |
47352 KB |
Output is correct |
6 |
Correct |
57 ms |
47352 KB |
Output is correct |
7 |
Correct |
56 ms |
47352 KB |
Output is correct |
8 |
Correct |
48 ms |
47316 KB |
Output is correct |
9 |
Correct |
47 ms |
47352 KB |
Output is correct |
10 |
Incorrect |
47 ms |
47480 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
47352 KB |
Output is correct |
2 |
Correct |
47 ms |
47480 KB |
Output is correct |
3 |
Correct |
47 ms |
47336 KB |
Output is correct |
4 |
Correct |
46 ms |
47352 KB |
Output is correct |
5 |
Correct |
55 ms |
47352 KB |
Output is correct |
6 |
Correct |
57 ms |
47352 KB |
Output is correct |
7 |
Correct |
56 ms |
47352 KB |
Output is correct |
8 |
Correct |
48 ms |
47316 KB |
Output is correct |
9 |
Correct |
47 ms |
47352 KB |
Output is correct |
10 |
Incorrect |
47 ms |
47480 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3024 ms |
113100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
326 ms |
54716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
47352 KB |
Output is correct |
2 |
Correct |
47 ms |
47480 KB |
Output is correct |
3 |
Correct |
47 ms |
47336 KB |
Output is correct |
4 |
Correct |
46 ms |
47352 KB |
Output is correct |
5 |
Correct |
55 ms |
47352 KB |
Output is correct |
6 |
Correct |
57 ms |
47352 KB |
Output is correct |
7 |
Correct |
56 ms |
47352 KB |
Output is correct |
8 |
Correct |
48 ms |
47316 KB |
Output is correct |
9 |
Correct |
47 ms |
47352 KB |
Output is correct |
10 |
Incorrect |
47 ms |
47480 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
47352 KB |
Output is correct |
2 |
Correct |
47 ms |
47480 KB |
Output is correct |
3 |
Correct |
47 ms |
47336 KB |
Output is correct |
4 |
Correct |
46 ms |
47352 KB |
Output is correct |
5 |
Correct |
55 ms |
47352 KB |
Output is correct |
6 |
Correct |
57 ms |
47352 KB |
Output is correct |
7 |
Correct |
56 ms |
47352 KB |
Output is correct |
8 |
Correct |
48 ms |
47316 KB |
Output is correct |
9 |
Correct |
47 ms |
47352 KB |
Output is correct |
10 |
Incorrect |
47 ms |
47480 KB |
Output isn't correct |