#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int n , q , a[N];
struct Node{
int mx ,ans;
set<int> s;
};
Node T[4*N];
void B(int l , int r, int pos , vector<int> y){
for(int x : y)T[pos].s.insert(x), T[pos].mx = max(T[pos].mx , x);
T[pos].s.insert(2e9);
if(l==r)return;
int mid = (l + r) >> 1;
vector<int> ax , bx;
for(int i = 0; i <= mid; ++i)ax.emplace_back(y[i]);
for(int i =mid + 1; i < y.size(); ++i) bx.emplace_back(y[i]);
B(l ,mid , pos * 2 , ax); B( mid + 1 , r , pos * 2 + 1 , bx);
int MX = T[pos * 2].mx;
auto it = T[pos*2 + 1].s.lower_bound(MX);
if(it != T[pos*2 + 1].s.begin()){
--it;
T[pos].ans = MX + *it;
}
T[pos].ans = max({T[pos].ans , T[pos * 2].ans , T[pos * 2 + 1].ans});
return;
}
vector<pair<int , int> > H;
void y(int L , int R , int l=1 , int r=n , int pos=1){
if(r < L || R < l)return;
if(L <= l && r <= R) {H.push_back({l , pos}); return;}
int mid = (l + r) >> 1;
y(L , R , l , mid , pos * 2); y(L , R , mid +1 ,r ,pos * 2 + 1);
}
int main (){
ios_base::sync_with_stdio(0);
cin >> n>>q;
vector<int> K;
for(int i = 1; i<= n; ++i)cin >> a[i] , K.emplace_back(a[i]);
B(1 , n , 1 , K);
while(q--){
int l , r ,d;
cin >> l >> r >> d;
H.clear();
y(l , r);
int z = 0;
sort(H.begin() , H.end());
for(int i = 0; i< H.size(); ++i){
//cout << H[i].second << " pos" << endl;
z = max(z , T[H[i].second].ans);
for(int j = i + 1; j < H.size(); ++j){
int MX = T[H[i].second].mx;
auto it = T[H[j].second].s.lower_bound(MX);
if(it != T[H[j].second].s.begin()){
--it;
z = max(z , MX + *it);
}
}
}
//cout << z << " z"<<endl;
if(z > d)cout << 0 << endl;
else cout << 1 << endl;
}
//for(int x : T[9].s)cout << x << "x ";
}
Compilation message
sortbooks.cpp: In function 'void B(int, int, int, std::vector<int>)':
sortbooks.cpp:19:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int i =mid + 1; i < y.size(); ++i) bx.emplace_back(y[i]);
| ~~^~~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:51:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i = 0; i< H.size(); ++i){
| ~^~~~~~~~~~
sortbooks.cpp:54:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int j = i + 1; j < H.size(); ++j){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
219388 KB |
Output is correct |
2 |
Correct |
95 ms |
219408 KB |
Output is correct |
3 |
Runtime error |
266 ms |
262144 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
219388 KB |
Output is correct |
2 |
Correct |
95 ms |
219408 KB |
Output is correct |
3 |
Runtime error |
266 ms |
262144 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
586 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
313 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
219388 KB |
Output is correct |
2 |
Correct |
95 ms |
219408 KB |
Output is correct |
3 |
Runtime error |
266 ms |
262144 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
219388 KB |
Output is correct |
2 |
Correct |
95 ms |
219408 KB |
Output is correct |
3 |
Runtime error |
266 ms |
262144 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |