Submission #686676

# Submission time Handle Problem Language Result Execution time Memory
686676 2023-01-25T18:29:14 Z speedyArda Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
30 / 100
1336 ms 96452 KB
#include "bits/stdc++.h"

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

int seg[MAXN * 4];

void update(int v, int tl, int tr, int pos, int val)
{

    if(tl == tr)
    {
        seg[v] = max(seg[v], val);
        return;
    }
    int tm = (tl + tr) / 2;
        
    if(pos <= tm)
        update(2 * v, tl, tm, pos, val);
    else
        update(2 * v + 1, tm + 1, tr, pos, 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 0;
    if(l == tl && r == tr)
    {
        return seg[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(), 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 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Runtime error 1 ms 468 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Runtime error 1 ms 468 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1273 ms 63556 KB Output is correct
2 Correct 1336 ms 96452 KB Output is correct
3 Correct 1293 ms 78936 KB Output is correct
4 Correct 1271 ms 78912 KB Output is correct
5 Correct 1070 ms 74808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 6800 KB Output is correct
2 Correct 82 ms 8644 KB Output is correct
3 Correct 77 ms 7720 KB Output is correct
4 Correct 72 ms 7784 KB Output is correct
5 Correct 73 ms 7812 KB Output is correct
6 Correct 61 ms 7332 KB Output is correct
7 Correct 61 ms 7260 KB Output is correct
8 Correct 62 ms 7168 KB Output is correct
9 Correct 37 ms 6148 KB Output is correct
10 Correct 61 ms 7188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Runtime error 1 ms 468 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Runtime error 1 ms 468 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -