#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ld long double
#define ull unsigned long long
#define ui unsigned int
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define plli pair<long long, int>
#define pdi pair<double, int>
#define pldldi pair<ld, pair<ld, int>>
#define pdd pair<double, double>
#define pid pair<int, double>
#define piii pair<int, pair<int, int>>
#define pllll pair<long long, long long>
#define pllllll pair<ll, pllll>
#define INF 2e9 + 5
#define size(v) v.size()
#define f first
#define s second
#define Pi 3.14159265359
using namespace std;
const int up = 1e5 + 5;
int Max[up << 2];
void build(int node, int l, int r, vector<int>&a){
if(l == r){
Max[node] = a[l];
}else{
int mid = (l + r) >> 1;
build(node << 1, l, mid, a);
build((node << 1) | 1, mid + 1, r, a);
Max[node] = max(Max[node << 1], Max[(node << 1) | 1]);
}
}
int queryMax(int node, int l, int r, int ql, int qr){
if(qr < l || r < ql){
return -INF;
}else if(ql <= l && r <= qr){
return Max[node];
}else{
int mid = (l + r) >> 1;
return max(queryMax(node << 1, l, mid, ql, qr), queryMax((node << 1) | 1, mid + 1, r, ql, qr));
}
}
void Subtask1and2(int n, int m, vector<int>&a){
while(m--){
int l, r, k, flag = 0;
cin >> l >> r >> k;
vector<int>v;
for(int i = l; i <= r; i++){
v.pb(a[i]);
}
int Max = -INF;
for(int i = 0; i < size(v); i++){
Max = max(Max, v[i]);
if(i > 0){
if(Max > v[i] && Max + v[i] > k){
flag = 1;
break;
}
}
}
cout << (flag ^ 1) << "\n";
}
}
void Subtask4(int n, int m, vector<int>&a){
build(1, 1, n, a);
set<pii>g;
for(int i = 1; i <= n; i++){
g.insert({a[i], i});
}
while(m--){
int l, r, k;
cin >> l >> r >> k;
set<pii>p;
p.clear();
p = g;
int Res = 0;
for(int w = 1; w <= 1000; w++){
auto itr = p.lower_bound({w, l});
if(itr != p.end()){
if((*itr).f != w){
continue;
}else{
while(itr != p.end() && (*itr).s <= r && (*itr).f == w){
int M = queryMax(1, 1, n, l, (*itr).s);
if(M > w){
Res = max(Res, M + w);
}
++itr;
}
}
}
}
if(Res > k){
cout << "0\n";
}else{
cout << "1\n";
}
}
}
void solve(){
int n, m;
cin >> n >> m;
vector<int>a(n + 1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
if(n <= 5000 && m <= 5000){
Subtask1and2(n, m, a);
}else{
Subtask4(n, m, a);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'void Subtask1and2(int, int, std::vector<int>&)':
sortbooks.cpp:67:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i = 0; i < size(v); i++){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
10 ms |
340 KB |
Output is correct |
13 |
Correct |
9 ms |
412 KB |
Output is correct |
14 |
Correct |
15 ms |
340 KB |
Output is correct |
15 |
Correct |
14 ms |
340 KB |
Output is correct |
16 |
Correct |
31 ms |
400 KB |
Output is correct |
17 |
Correct |
26 ms |
340 KB |
Output is correct |
18 |
Correct |
30 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
93 ms |
8344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3059 ms |
11020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
10 ms |
340 KB |
Output is correct |
13 |
Correct |
9 ms |
412 KB |
Output is correct |
14 |
Correct |
15 ms |
340 KB |
Output is correct |
15 |
Correct |
14 ms |
340 KB |
Output is correct |
16 |
Correct |
31 ms |
400 KB |
Output is correct |
17 |
Correct |
26 ms |
340 KB |
Output is correct |
18 |
Correct |
30 ms |
416 KB |
Output is correct |
19 |
Runtime error |
21 ms |
4308 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
340 KB |
Output is correct |
12 |
Correct |
10 ms |
340 KB |
Output is correct |
13 |
Correct |
9 ms |
412 KB |
Output is correct |
14 |
Correct |
15 ms |
340 KB |
Output is correct |
15 |
Correct |
14 ms |
340 KB |
Output is correct |
16 |
Correct |
31 ms |
400 KB |
Output is correct |
17 |
Correct |
26 ms |
340 KB |
Output is correct |
18 |
Correct |
30 ms |
416 KB |
Output is correct |
19 |
Runtime error |
93 ms |
8344 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |