Submission #686671

# Submission time Handle Problem Language Result Execution time Memory
686671 2023-01-25T18:21:59 Z speedyArda Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
1465 ms 63472 KB
#include "bits/stdc++.h"

using namespace std;
const int MAXN = 1e6 + 5;

int seg[MAXN * 4];
void push(int v)
{
    seg[v * 2] = max(seg[v * 2], seg[v]);
    seg[v * 2 + 1] = max(seg[v * 2 + 1], seg[v]);
}
void update(int v, int tl, int tr, int l, int r, int val)
{
    if(l > r)
        return;
    if(l == tl && r == tr)
    {
        seg[v] = max(seg[v], val);
        return;
    }
    push(v);
    int tm = (tl + tr) / 2;


    update(2 * v, tl, tm, l, min(r, tm), val);
    update(2 * v + 1, tm + 1, tr, max(tm + 1, l), r, val);
    seg[v] = max(seg[v * 2], seg[v * 2 + 1]);

}

int get(int v, int tl, int tr, int l, int r)
{
    if(l > r)
        return - 1;
    if(l == tl && r == tr)
    {
        return seg[v];
    }
    push(v);
    int tm = (tl + tr) / 2;


    return max(get(2 * v, tl, tm, l, min(r, tm)), get(2 * v + 1, tm + 1, tr, max(tm + 1, l), r));
}

int main() 
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    int w[n+5];
    for(int i = 1; i <= n; i++)
        cin >> w[i];
    vector< vector < pair<pair<int, int>, int> > > q(m+5);

    for(int i = 1; i <= m; i++)
    {
        int l, r, k;
        cin >> l >> r >> k;
        q[l].push_back({{r, k}, i});
    }
    int ans[m+5];
    vector<int> curr;
    for(int i = n; i >= 1; i--)
    {
        while(!curr.empty() && w[curr.back()] <= w[i])
        {
            if(w[curr.back()] != w[i])
                update(1, 1, n, curr.back(), n, w[curr.back()] + w[i]);
            curr.pop_back();
        }
        curr.push_back(i);
        for(pair< pair<int, int>, int> elem : q[i])
        {
            int temp = get(1, 1, n, i, elem.first.first);
            if(temp <= elem.first.second)
                ans[elem.second] = 1;
            else
                ans[elem.second] = 0;
        }
    }


    for(int i = 1; i <= m; i++)
        cout << ans[i] << "\n";

}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1465 ms 63472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 6856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -