#include <bits/stdc++.h>
#define ll long long
#define fort(x , y) for(int y = 1 ; y <= x ; y++)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define int long long
#define F first
#define S second
using namespace std;
const int N = 2e5 + 5;
const int NN = 1e9 + 7;
int n,m,w[N],l,r,k,p[N],b[N],swpd[N];
void check(){
}
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 >> w[i];
p[i] = p[i - 1] + w[i];
b[i] = w[i];
}
sort(b + 1 , b + n + 1);
for(int j = 1 ; j <= m ; j++){
cin >> l >> r >> k;
if(l == r){
if(w[l] <= k){
cout << 1 << '\n';
}
else{
cout << 0 << '\n';
}
continue;
}
bool ok = 0;
int can_swap = 0;
int v = 0 , bro = 0;
for(int i = l ; i <= r ; i++){
if(w[i] != b[i]){
v++;
}
}
while(true){
bro = can_swap;
for(int i = l ; i < r ; i++){
if(swpd[i] == 1) continue;
if(w[i] + w[i + 1] <= k){
swpd[i] = 1;
can_swap++;
swap(w[i] , w[i + 1]);
}
}
if(can_swap == bro){
break;
}
}
if(can_swap + 1 >= v){
ok = 1;
}
if(ok){
cout << 1 << '\n';
}
else{
cout << 0 << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
21 ms |
12892 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2980 ms |
4944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |