# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
218334 | Lawliet | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 1117 ms | 52712 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;
const int MAXN = 1000010;
const int INF = 1000000010;
struct query
{
int L, k;
int ind;
query(int l, int k, int i)
: L(l), k(k), ind(i) {}
};
int n, q;
int v[MAXN];
bool ans[MAXN];
vector< int > s;
vector< query > sweep[MAXN];
int main()
{
scanf("%d %d",&n,&q);
v[0] = INF;
s.push_back( 0 );
for(int i = 1 ; i <= n ; i++)
scanf("%d",&v[i]);
for(int i = 1 ; i <= q ; i++)
{
int L, R, k;
scanf("%d %d %d",&L,&R,&k);
sweep[R].push_back( query( L , k , i ) );
}
for(int i = 1 ; i <= n ; i++)
{
while( v[ s.back() ] <= v[i] )
s.pop_back();
s.push_back( i );
while( !sweep[i].empty() )
{
int curL = sweep[i].back().L;
int curK = sweep[i].back().k;
int curInd = sweep[i].back().ind;
sweep[i].pop_back();
int aux = lower_bound( s.begin() , s.end() , curL ) - s.begin();
if( aux == s.size() - 1 ) ans[curInd] = true;
else
{
int A = s[aux];
int B = s[aux + 1];
ans[curInd] = ( A + B <= curK );
}
}
}
for(int i = 1 ; i <= q ; i++)
printf("%d\n",ans[i]);
}
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... |