This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <chrono>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <random>
#include <cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
#define ff first
#define ss second
ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll N = 1000007;
ll n, m, k;
ll a[N];
ll lgs[N];
ll c[N];
vector<pair<pair<int, int>, pair<int, ll>>>q;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
lgs[1] = 0;
lgs[2] = 1;
for (int i = 3; i < N; i++) {
lgs[i] = lgs[i / 2] + 1;
}
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (n <= 5000 && m <= 5000) {
vector<int>ans(m);
for (int i = 0; i < m; i++) {
int l, r;
cin >> l >> r >> k;
l--, r--;
q.push_back({ { l,r },{i,k} });
}
sort(q.begin(), q.end());
int qi = 0;
for (int i = 0; i < n; i++) {
ll max_val = 0;
ll mx = 0;
for (int j = i; j < n; j++) {
if (mx > a[j]) {
max_val = max(max_val, a[j] + mx);
}
else {
mx = a[j];
}
while (qi < m && q[qi].ff.ff == i && q[qi].ff.ss == j) {
ans[q[qi].ss.ff] = (max_val <= q[qi].ss.ss);
//cout << "DNUM EM: " << q[qi].ss.ff << ": "
// << max_val << ", " << q[qi].ss.ss << endl;
qi++;
}
}
}
for (auto x : ans) {
cout << x << endl;
}
}
else {
int cur = 0;
c[0] = 0;
for (int i = 1; i < n; i++) {
if (a[i] < a[i - 1])cur++;
c[i] = cur;
}
for (int i = 0; i < m; i++) {
int l, r;
cin >> l >> r >> k;
l--, r--;
cout << (c[l] == c[r]) << endl;
}
}
return 0;
}
/// ---- - -------- ------ -------- -- - - -
/// Just a reminder. Ubuntu password is I O I
/// ---- - -------- ------ -------- -- - - -
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |