#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 5;
int a[N],l[N],r[N],k[N],n,m;
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];
bool check = true;
for (int j = l[i]; j < r[i]; j++)
if (b[j] > b[j + 1]) {
check = false;
break;
}
while (!check) {
bool found = false;
for (int j = l[i]; j < r[i]; j++)
if (b[j] > b[j + 1]) {
if (b[j] + b[j + 1] <= k[i]) swap(b[j],b[j + 1]);
else found = true;
break;
}
if (found) break;
check = true;
for (int j = l[i]; j < r[i]; j++)
if (b[j] > b[j + 1]) {
check = false;
break;
}
}
cout << check << "\n";
}
}
}
namespace sub2 {
void solve() {
for (int i = 1; i <= m; i++) {
set<int>s;
bool check = true;
for (int j = r[i]; j >= l[i]; j--) {
auto it = s.lower_bound(a[j]);
if (it != s.begin()) {
it--;
if ((*it) + a[j] > k[i]) {
check = false;
break;
}
}
s.insert(a[j]);
}
cout << check << "\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 >> l[i] >> r[i] >> k[i];
if (n <= 500 && m <= 500)
sub1::solve();
else if (n <= 5000 && m <= 5000)
sub2::solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
7 ms |
8540 KB |
Output is correct |
7 |
Correct |
15 ms |
8536 KB |
Output is correct |
8 |
Correct |
194 ms |
8540 KB |
Output is correct |
9 |
Correct |
201 ms |
8648 KB |
Output is correct |
10 |
Correct |
144 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
7 ms |
8540 KB |
Output is correct |
7 |
Correct |
15 ms |
8536 KB |
Output is correct |
8 |
Correct |
194 ms |
8540 KB |
Output is correct |
9 |
Correct |
201 ms |
8648 KB |
Output is correct |
10 |
Correct |
144 ms |
8540 KB |
Output is correct |
11 |
Correct |
5 ms |
8536 KB |
Output is correct |
12 |
Correct |
6 ms |
8896 KB |
Output is correct |
13 |
Correct |
7 ms |
8880 KB |
Output is correct |
14 |
Correct |
10 ms |
8796 KB |
Output is correct |
15 |
Correct |
9 ms |
8792 KB |
Output is correct |
16 |
Correct |
922 ms |
9000 KB |
Output is correct |
17 |
Correct |
576 ms |
9040 KB |
Output is correct |
18 |
Correct |
56 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
255 ms |
33108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
7 ms |
8540 KB |
Output is correct |
7 |
Correct |
15 ms |
8536 KB |
Output is correct |
8 |
Correct |
194 ms |
8540 KB |
Output is correct |
9 |
Correct |
201 ms |
8648 KB |
Output is correct |
10 |
Correct |
144 ms |
8540 KB |
Output is correct |
11 |
Correct |
5 ms |
8536 KB |
Output is correct |
12 |
Correct |
6 ms |
8896 KB |
Output is correct |
13 |
Correct |
7 ms |
8880 KB |
Output is correct |
14 |
Correct |
10 ms |
8796 KB |
Output is correct |
15 |
Correct |
9 ms |
8792 KB |
Output is correct |
16 |
Correct |
922 ms |
9000 KB |
Output is correct |
17 |
Correct |
576 ms |
9040 KB |
Output is correct |
18 |
Correct |
56 ms |
8540 KB |
Output is correct |
19 |
Incorrect |
62 ms |
20280 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
7 ms |
8540 KB |
Output is correct |
7 |
Correct |
15 ms |
8536 KB |
Output is correct |
8 |
Correct |
194 ms |
8540 KB |
Output is correct |
9 |
Correct |
201 ms |
8648 KB |
Output is correct |
10 |
Correct |
144 ms |
8540 KB |
Output is correct |
11 |
Correct |
5 ms |
8536 KB |
Output is correct |
12 |
Correct |
6 ms |
8896 KB |
Output is correct |
13 |
Correct |
7 ms |
8880 KB |
Output is correct |
14 |
Correct |
10 ms |
8796 KB |
Output is correct |
15 |
Correct |
9 ms |
8792 KB |
Output is correct |
16 |
Correct |
922 ms |
9000 KB |
Output is correct |
17 |
Correct |
576 ms |
9040 KB |
Output is correct |
18 |
Correct |
56 ms |
8540 KB |
Output is correct |
19 |
Incorrect |
255 ms |
33108 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |