Submission #1017690

# Submission time Handle Problem Language Result Execution time Memory
1017690 2024-07-09T09:30:07 Z codefox Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
13 / 100
2198 ms 121696 KB
#include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pipi pair<pii, pii>

int N = 1<<20;
//20? maybe 18
vector<int> bin(2*N, 1e9);

int query(int curr, int l, int r, int a, int b)
{
    if (l >= b || r <= a) return 1e9;
    if (a <= l && r <= b) return bin[curr];
    int m = (l+r)/2;
    int mx = query(curr*2, l, m, a, b);
    mx = min(mx, query(curr*2+1, m, r, a, b));
    return mx;
}

void update(int i, int x)
{
    i+=N;
    while (i)
    {
        bin[i] = min(bin[i], x);
        i/=2;
    }
}

int main()
{
    int n, q;
    cin >> n >> q;

    vector<pii> books(n);
    set<int> pos;

    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        books[i] = {a, i};
    }
    sort(books.begin(), books.end());

    vector<int> nleft(n, n);
    for (int i = 0; i < n; i++)
    {
        vector<pii> curr(1, books[i]);
        while (i+1 < n && books[i+1].second == books[i].second)
        {
            i++;
            curr.push_back(books[i]);
        }
        for (pii ele:curr)
        {
            if (pos.lower_bound(ele.second)==pos.end()) continue;
            nleft[ele.second] = *pos.lower_bound(ele.second);
        }
        for (pii ele:curr)
        {
            pos.insert(ele.second);
        }
    }

    vector<pipi> queries(q);

    for (int i = 0; i < q; i++)
    {
        int l, r, mood;
        cin >> l >> r >> mood;
        l--;
        //not sure
        queries[i] = {{mood, i}, {l, r}};
    }
    sort(queries.begin(), queries.end(), greater<pipi>());

    int last = n-1;
    vector<int> sol(q, 0);
    for (pipi ele:queries)
    {
        while (books[last].first>ele.first.first)
        {
            update(books[last].second, nleft[books[last].second]);
            last--;
        }
        int rr = query(1, 0, N, ele.second.first, ele.second.second);
        if (rr >= ele.second.second) sol[ele.first.second] = 1;
    }
    for (int ele:sol)
    {
        cout << ele << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Incorrect 3 ms 8540 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Incorrect 3 ms 8540 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2198 ms 120636 KB Output is correct
2 Correct 2196 ms 121696 KB Output is correct
3 Correct 2132 ms 121696 KB Output is correct
4 Correct 2098 ms 121692 KB Output is correct
5 Correct 1582 ms 121684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 146 ms 18516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Incorrect 3 ms 8540 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8540 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Incorrect 3 ms 8540 KB Output isn't correct
4 Halted 0 ms 0 KB -