# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
404321 | Ruxandra985 | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 1014 ms | 63248 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>
#define DIMN 1000010
using namespace std;
int v[DIMN] , bigger[DIMN] , st[DIMN] , sol[DIMN];
vector <pair <int , pair <int , int> > > q[DIMN];
int aib[DIMN] , n;
void update (int poz , int val){
for (;poz <= n ; poz = (poz + (poz & (-poz))))
aib[poz] = max(aib[poz] , val);
}
int query (int poz){
int maxi = -1;
for (;poz <= n ; poz = (poz + (poz & (-poz))))
maxi = max(maxi , aib[poz]);
return maxi;
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int qr , i , l , r , k , elem , j , idx;
fscanf (fin,"%d%d",&n,&qr);
elem = 0;
for (i = 1 ; i <= n ; i++){
fscanf (fin,"%d",&v[i]);
while (elem && v[st[elem]] <= v[i])
elem--;
bigger[i] = st[elem];
st[++elem] = i;
}
/// bigger[i] = primul > v[i] de la stanga lui i
for (i = 1 ; i <= qr ; i++){
fscanf (fin,"%d%d%d", &l , &r , &k);
q[r].push_back(make_pair(l , make_pair(k , i)));
}
for (i = 1 ; i <= n ; i++){
/// adaugi i ul pt evaluat
if (bigger[i])
update(bigger[i] , v[i] + v[bigger[i]]);
for (j = 0 ; j < q[i].size() ; j++){
r = i;
l = q[i][j].first;
k = q[i][j].second.first;
idx = q[i][j].second.second;
/// query de la l in colo, suma maxima
sol[idx] = (query(l) <= k);
}
}
for (i = 1 ; i <= qr ; i++){
fprintf (fout,"%d\n",sol[i]);
}
return 0;
}
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... |