#include <bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
using namespace std;
//using namespace __gnu_pbds;
//template <typename T> using ordered_set = tree <T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 gen(time(0));
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define sz(a) int32_t(a.size())
#define endl '\n'
//#define int long long
const int N = 1e6 + 100;
const int M = 31;
const int mod = 998244353;
const int inf = 2e9 + 100;
int a[N];
struct DO
{
vector < int > t, add;
int pr = 2;
void build(int n)
{
while (pr < n) pr *= 2;
t.resize(2 * pr);
add.resize(2 * pr, 0);
for(int i = pr; i < pr + n; i++)
t[i] = a[i - pr];
for(int v = pr - 1; v > 0; v--)
t[v] = t[v * 2] + t[v * 2 + 1];
}
void push(int v)
{
t[v * 2] += add[v]; t[v * 2 + 1] += add[v];
add[v * 2] += add[v]; add[v * 2 + 1] += add[v];
add[v] = 0;
}
void upd(int l, int r, int v, int cl, int cr, int zn)
{
if (cr < l || r < cl) return;
if (cl != cr) push(zn);
if (l <= cl && cr <= r)
{
t[v] += zn;
add[v] += zn;
return;
}
int mid = (cl + cr) / 2;
upd(l, r, v * 2, cl, mid, zn);
upd(l, r, v * 2 + 1, mid + 1, cr, zn);
t[v] = t[v * 2] + t[v * 2 + 1];
}
int get(int l, int r, int v, int cl, int cr)
{
if (cr < l || r < cl) return 0;
if (l <= cl && cr <= r) return t[v];
int mid = (cl + cr) / 2;
return max(get(l, r, v * 2, cl, mid), get(l, r, v * 2 + 1, mid + 1, cr));
}
};
DO t;
vector < pair < pair < int, int >, int > > ask[N];
int ans[N];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // LOCAL
int n, q;
cin >> n >> q;
for(int i = 0; i < n; i++)
cin >> a[i];
t.build(n);
for(int i = 0; i < q; i++)
{
int l, r, k;
cin >> l >> r >> k;
l--; r--;
ask[l].pb({{r, k}, i});
}
vector < pair < pair < int, int >, int > > b;
for(int i = n - 1; i >= 0; i--)
{
while (sz(b) && b.back().S <= a[i])
{
t.upd(b.back().F.F, b.back().F.S, 1, 0, t.pr - 1, -b.back().S);
b.pop_back();
}
if (!sz(b))
{
b.pb({{i, n - 1}, a[i]});
t.upd(i + 1, n - 1, 1, 0, t.pr - 1, a[i]);
}
else
{
t.upd(i + 1, b.back().F.F - 1, 1, 0, t.pr - 1, a[i]);
b.pb({{i, b.back().F.F - 1}, a[i]});
}
for(auto to: ask[i])
ans[to.S] = (t.get(i + 1, to.F.F, 1, 0, t.pr - 1) <= to.F.S);
}
for(int i = 0; i < q; i++)
cout << ans[i] << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
31 ms |
48068 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
31 ms |
48068 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
602 ms |
137640 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
73 ms |
59516 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
31 ms |
48068 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
31 ms |
48068 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |