# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
524546 | asliddinaif | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 134 ms | 13756 KiB |
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<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
const int maxx = 2e5+5;
int tr[maxx], n, m, a[maxx], ans[maxx], k[maxx], x[maxx], y[maxx];
vector <int> g[maxx];
void ad(int x, int val){
while(x > 0)
tr[x] = max(tr[x], val), x -= x & -x;
}
int get(int x){
int s = 0;
while(x <= n)
s = max(tr[x], s), x += x & -x;
return s;
}
void S()
{
cin >> n >> m;
fpp(i,1,n)
cin >> a[i];
fpp(i,1,m){
cin >> x[i] >> y[i] >> k[i];
g[y[i]].push_back(i);
}
vector <int> v;
fpp(i,1,n){
while(!v.empty() && a[v.back()] <= a[i])
v.pop_back();
int xx = (v.size() == 0 ? 0 : v.back());
ad(xx, a[xx]+a[i]);
for(auto it : g[i])
ans[it] = (get(x[it]) <= k[it]);//, cout << get(x[it]) << " " << i << " " << it << " ";
v.push_back(i);
// cout << a[xx] << "\n";
}
fpp(i,1,m)
cout << ans[i] << "\n";
}
int main()
{
IOS;
S();
}
Compilation message (stderr)
# | 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... |