#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define MAXN 1000013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef pair<pii, pii> ppp;
int N, Q;
int arr[MAXN];
int pos[MAXN];
vpi guys;
vector<ppp> quer;
vi upds[MAXN];
bitset<MAXN> ans;
int fen[MAXN];
void update(int idx, int v)
{
for (int e = idx + 1; e <= N; e += e & (-e)) ckmax(fen[e], v);
}
int query(int idx)
{
int res = 0;
for (int e = idx + 1; e; e -= e & (-e)) ckmax(res, fen[e]);
return res;
}
//max (a[i] + a[j]) such that a[i] > a[j]
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> Q;
FOR(i, 0, N)
{
cin >> arr[i];
}
FOR(i, 0, Q)
{
int l, r, v; cin >> l >> r >> v; l--; r--;
quer.PB({{l, r}, {v, i}});
}
guys.PB({1000000013, -1});
FOR(i, 0, N)
{
while(guys.back().fi <= arr[i])
{
guys.pop_back();
}
pos[i] = guys.back().se;
guys.PB({arr[i], i});
upds[pos[i]].PB(i);
}
sort(ALL(quer));
int iter = SZ(quer) - 1;
FORD(i, N, 0)
{
for (int x : upds[i])
{
update(x, arr[i] + arr[x]);
}
while(iter > 0 && quer[iter].fi.fi == i)
{
int l = quer[iter].fi.fi, r = quer[iter].fi.se, v = quer[i].se.fi, qid = quer[i].se.se;
ans[qid] = (query(r) > v);
iter--;
}
}
//find the first guy > x on left.
//left, right, value, qid;
FOR(i, 0, Q)
{
cout << (ans[i] ? 0 : 1) << '\n';
}
}
Compilation message
sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:94:8: warning: unused variable 'l' [-Wunused-variable]
int l = quer[iter].fi.fi, r = quer[iter].fi.se, v = quer[i].se.fi, qid = quer[i].se.se;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
23800 KB |
Output is correct |
3 |
Incorrect |
24 ms |
23800 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
23800 KB |
Output is correct |
3 |
Incorrect |
24 ms |
23800 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
928 ms |
69560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
100 ms |
28520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
23800 KB |
Output is correct |
3 |
Incorrect |
24 ms |
23800 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23800 KB |
Output is correct |
2 |
Correct |
23 ms |
23800 KB |
Output is correct |
3 |
Incorrect |
24 ms |
23800 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |