// Problem: C - Hedgehog Daniyar and Algorithms
// Contest: Virtual Judge - Yosik IOI contest #1
// URL: https://vjudge.net/contest/601761#problem/C
// Memory Limit: 256 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(v) (v).begin(),(v).end()
#define rall(v) ((v).rbegin()), ((v).rend())
#define out(v) for(auto& i : v) cout << i << ' ';
#define F first
#define S second
#define int long long
const ll N = 5000 + 17;
const ll MOD = 1e9 + 7;
const string alf = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int a[N];
void solve (){
int n , m;
cin >> n >> m;
vector <int > a(n) , b(n);
int ok = 1;
// vector <pair <int ,int > >
for(int i = 0; i < n; i ++){
cin >> a[i];
}
b = a;
for(int j = 1; j <= m; j ++){
int l , r , k;
cin >> l >> r >> k;
a = b;
l --, r--;
for(int i = r - 1; i >= l; i --){
if (a[i] > a[i + 1]){
if (a[i] + a[i + 1] <= k){
int p= a[i];
a[i] = a[i + 1];
a[i + 1] = p;
}
}
}
int ok = 1;
for(int i = l + 1; i <= r; i ++){
if (a[i] < a[i - 1]){
ok = 0;
// cout <<"NO" << endl;
break;
}
}
if (ok)cout <<1 << endl;
else cout <<0 << endl;
}
}
signed main(){
// freopen("ones.in" , "r" , stdin) ;
// freopen("ones.out" , "w" , stdout) ;
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
// int cs = 1;
// cin >>T;
while (T --){
// cout <<"Case " << cs ++<< ":" << endl;
solve ();
// cout <<endl;
}
}
Compilation message
sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:32:6: warning: unused variable 'ok' [-Wunused-variable]
32 | int ok = 1;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3035 ms |
16116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3061 ms |
2064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |