#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <unordered_set>
#include <sstream>
#include <cstring>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <random>
#include <cfloat>
#include <chrono>
#include <bitset>
#include <complex>
#include <immintrin.h>
#include <cassert>
struct Query {
int32_t left, x;
int32_t ind;
Query(int32_t left_, int32_t x_, int32_t ind_) {
left = left_;
x = x_;
ind = ind_;
}
};
struct Segtree {
int32_t* arr, *arr2;
Segtree(int32_t n, int32_t* arr_) {
arr = arr_;
arr2 = new int32_t[n];
for(int32_t i = 0; i < n; i++)
arr2[i] = -1'000'000'005;
}
int32_t max_eq(int32_t left, int32_t right, int32_t x) {
for(int32_t i = left; i < right; i++)
arr2[i] = std::max(arr2[i], x);
}
int32_t get(int32_t left, int32_t right) {
int32_t res = -1'000'000'005;
for(int32_t i = left; i < right; i++)
res = std::max(res, arr[i] + arr2[i]);
return res;
}
};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int32_t n, num_q;
std::cin >> n >> num_q;
int32_t* arr = new int32_t[n];
for(int32_t i = 0; i < n; i++)
std::cin >> arr[i];
std::vector<Query>* queries = new std::vector<Query>[n];
int32_t* bounds = new int32_t[num_q];
for(int32_t q = 0; q < num_q; q++) {
int32_t left, right, x;
std::cin >> left >> right >> x;
left--;
right--;
bounds[q] = x;
queries[right].emplace_back(left, x, q);
}
Segtree tree(n, arr);
std::stack<int32_t> maximums;
int32_t* ans = new int32_t[n];
for(int32_t i = 0; i < n; i++) {
while(!maximums.empty() && arr[maximums.top()] <= arr[i])
maximums.pop();
if(!maximums.empty())
tree.max_eq(0, maximums.top() + 1, arr[i]);
maximums.push(i);
for(int32_t q = 0; q < queries[i].size(); q++)
ans[queries[i][q].ind] = tree.get(queries[i][q].left, i + 1);
}
for(int32_t q = 0; q < num_q; q++)
std::cout << (ans[q] > bounds[q] ? 0 : 1) << "\n";
return 0;
}
Compilation message
sortbooks.cpp: In member function 'int32_t Segtree::max_eq(int32_t, int32_t, int32_t)':
sortbooks.cpp:48:5: warning: no return statement in function returning non-void [-Wreturn-type]
48 | }
| ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:91:30: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'int'} and 'std::vector<Query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for(int32_t q = 0; q < queries[i].size(); q++)
| ~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
613 ms |
147908 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
48 ms |
13924 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |