#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define piii pair<pii,int>
#define fi first
#define se second
#define mp make_pair
const int N = 1e6 + 5;
int a[N],n,m;
piii queries[N];
namespace sub1 {
int b[N];
void solve() {
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) b[j] = a[j];
int l = queries[i].fi.fi,r = queries[i].fi.se,k = queries[i].se;
bool check = true;
for (int j = l; j < r; j++)
if (b[j] > b[j + 1]) {
check = false;
break;
}
while (!check) {
bool found = false;
for (int j = l; j < r; j++)
if (b[j] > b[j + 1]) {
if (b[j] + b[j + 1] <= k) swap(b[j],b[j + 1]);
else found = true;
break;
}
if (found) break;
check = true;
for (int j = l; j < r; j++)
if (b[j] > b[j + 1]) {
check = false;
break;
}
}
cout << check << "\n";
}
}
}
namespace sub2 {
void solve() {
for (int i = 1; i <= m; i++) {
int l = queries[i].fi.fi,r = queries[i].fi.se,k = queries[i].se;
set<int>s;
bool check = true;
for (int j = r; j >= l; j--) {
auto it = s.lower_bound(a[j]);
if (it != s.begin()) {
it--;
if ((*it) + a[j] > k) {
check = false;
break;
}
}
s.insert(a[j]);
}
cout << check << "\n";
}
}
}
namespace sub3 {
bool check_condition() {
int Min = 1e9 + 7;
for (int i = 1; i <= n; i++) Min = min(Min,a[i]);
for (int i = 1; i <= m; i++)
if (queries[i].se > Min) return false;
return true;
}
void solve() {
for (int i = 1; i <= m; i++) cout << 0 << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++)
cin >> queries[i].fi.fi >> queries[i].fi.se >> queries[i].se;
if (n <= 500 && m <= 500)
sub1::solve();
else if (n <= 5000 && m <= 5000)
sub2::solve();
else if (sub3::check_condition())
sub3::solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
7 ms |
4440 KB |
Output is correct |
7 |
Correct |
20 ms |
4444 KB |
Output is correct |
8 |
Correct |
252 ms |
4564 KB |
Output is correct |
9 |
Correct |
246 ms |
4548 KB |
Output is correct |
10 |
Correct |
194 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
7 ms |
4440 KB |
Output is correct |
7 |
Correct |
20 ms |
4444 KB |
Output is correct |
8 |
Correct |
252 ms |
4564 KB |
Output is correct |
9 |
Correct |
246 ms |
4548 KB |
Output is correct |
10 |
Correct |
194 ms |
4444 KB |
Output is correct |
11 |
Correct |
4 ms |
4444 KB |
Output is correct |
12 |
Correct |
6 ms |
4700 KB |
Output is correct |
13 |
Correct |
6 ms |
4700 KB |
Output is correct |
14 |
Correct |
10 ms |
4900 KB |
Output is correct |
15 |
Correct |
9 ms |
4716 KB |
Output is correct |
16 |
Correct |
925 ms |
4956 KB |
Output is correct |
17 |
Correct |
572 ms |
4836 KB |
Output is correct |
18 |
Correct |
52 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
326 ms |
60228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
8276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
7 ms |
4440 KB |
Output is correct |
7 |
Correct |
20 ms |
4444 KB |
Output is correct |
8 |
Correct |
252 ms |
4564 KB |
Output is correct |
9 |
Correct |
246 ms |
4548 KB |
Output is correct |
10 |
Correct |
194 ms |
4444 KB |
Output is correct |
11 |
Correct |
4 ms |
4444 KB |
Output is correct |
12 |
Correct |
6 ms |
4700 KB |
Output is correct |
13 |
Correct |
6 ms |
4700 KB |
Output is correct |
14 |
Correct |
10 ms |
4900 KB |
Output is correct |
15 |
Correct |
9 ms |
4716 KB |
Output is correct |
16 |
Correct |
925 ms |
4956 KB |
Output is correct |
17 |
Correct |
572 ms |
4836 KB |
Output is correct |
18 |
Correct |
52 ms |
4440 KB |
Output is correct |
19 |
Incorrect |
57 ms |
16088 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
7 ms |
4440 KB |
Output is correct |
7 |
Correct |
20 ms |
4444 KB |
Output is correct |
8 |
Correct |
252 ms |
4564 KB |
Output is correct |
9 |
Correct |
246 ms |
4548 KB |
Output is correct |
10 |
Correct |
194 ms |
4444 KB |
Output is correct |
11 |
Correct |
4 ms |
4444 KB |
Output is correct |
12 |
Correct |
6 ms |
4700 KB |
Output is correct |
13 |
Correct |
6 ms |
4700 KB |
Output is correct |
14 |
Correct |
10 ms |
4900 KB |
Output is correct |
15 |
Correct |
9 ms |
4716 KB |
Output is correct |
16 |
Correct |
925 ms |
4956 KB |
Output is correct |
17 |
Correct |
572 ms |
4836 KB |
Output is correct |
18 |
Correct |
52 ms |
4440 KB |
Output is correct |
19 |
Incorrect |
326 ms |
60228 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |