Submission #993069

#TimeUsernameProblemLanguageResultExecution timeMemory
993069serkanrashidHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
742 ms96084 KiB
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

const int maxn = 1e6+5;

int n,m;
int w[maxn],bigidx[maxn];
int what[maxn],jump[maxn][20];

void pre()
{
    int last = 0;
    for(int j = 0; j <= 20; j++)
    {
        int gr = min(n,(1<<(j+1)));
        for(int i = last + 1; i <= gr; i++) what[i] = j;
        last = gr;
    }
    for(int i = 1; i <= n; i++) jump[i][0] = w[i];
    for(int j = 1; j <= 20; j++)
    {
        for(int i = 1; i <= n; i++)
        {
            jump[i][j] = max(jump[i][j-1],jump[jump[i][j-1]+1][j-1]);
        }
    }
}

int query(int l, int r)
{
    int step = what[r-l+1];
    return max(jump[l][step],jump[r-(1<<step)+1][step]);
}

bool check(int l, int r, int k)
{
    int maxch,razmqna;
    maxch = razmqna = 0;
    for(int i = l; i < r; i = bigidx[i])
    {
        razmqna = max(razmqna,maxch+query(i+1,r));
        maxch = w[i];
    }
    return k >= razmqna;
}

void read()
{
    cin >> n >> m;

    pre();
    for(int i = 1; i <= n; i++) cin >> w[i];

    w[n+1] = 1e9+1;
    stack<int>s1;
    s1.push(n+1);
    for(int i = n; i >= 1; i--)
    {
        while(!s1.empty()&&w[s1.top()]<=w[i]) s1.pop();
        bigidx[i] = s1.top();
        s1.push(i);
    }
    int l,r,k;
    for(int i = 1; i <= m; i++)
    {
        cin >> l >> r >> k;
        if(check(l,r,k)) cout << 1 << endl;
        else cout << 0 << endl;
    }
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	read();
return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...