This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define forik(x) ll i = 1; i <= x; i++
const int mod = 1e9 + 7;
using namespace std;
ll t[8000001], n, m, a, b, c, d, e, k, p[1000001], ans[1000001];
map <ll, ll> mp, tp;
vector <ll> v;
vector <pair <ll, pair <ll, ll>>> g[1000001];
void upd (ll idx, ll val, ll tl = 1, ll tr = n, ll v = 1){
if (tl > idx || tr < idx){
return;
}
if (tl == tr && tl == idx){
t[v] = max (t[v], val);
return;
}
ll tm = (tl + tr) / 2;
upd (idx, val, tl, tm, v * 2);
upd (idx, val, tm + 1, tr, v * 2 + 1);
t[v] = max (t[v * 2], t[v * 2 + 1]);
}
ll get (ll l, ll r, ll tl = 1, ll tr = n, ll v = 1){
if (tl > r || l > tr){
return 0;
}
if (l <= tl && tr <= r){
return t[v];
}
ll tm = (tl + tr) / 2;
return max (get (l, r, tl, tm, v * 2), get (l, r, tm + 1, tr, v * 2 + 1));
}
ll gcd (ll a, ll b){
while (a > 0 && b > 0){
if (a >= b){
a %= b;
}
else{
b %= a;
}
}
return a + b;
}
ll binpow (ll a, ll b){
a %= mod;
if (b == 0){
return 1;
}
if (b % 2 == 1){
return binpow (a, b - 1) % mod * a % mod;
}
else{
ll t = binpow (a, b / 2) % mod;
return t * t % mod;
}
}
signed main (){
//freopen (".in", "r", stdin);
//freopen (".out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++){
cin >> p[i];
}
for (int i = 1; i <= m; i++){
ll l, r, x;
cin >> l >> r >> x;
g[r].pb ({l, {x, i}});
}
for (int i = 1; i <= n; i++){
a = -1;
while (v.size()){
if (p[v[v.size() - 1]] > p[i]){
a = v[v.size() - 1];
break;
}
v.ppb();
}
if (a != -1){
upd (a, p[a] + p[i]);
}
for (int y = 0; y < g[i].size(); y++){
if (get (g[i][y].F, i) > g[i][y].S.F){
ans[g[i][y].S.S] = 0;
}
else{
ans[g[i][y].S.S] = 1;
}
}
v.pb (i);
}
for (int i = 1; i <= m; i++){
cout << ans[i] << '\n';
}
}
Compilation message (stderr)
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:101:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for (int y = 0; y < g[i].size(); y++){
| ~~^~~~~~~~~~~~~| # | 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... |