답안 #874434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874434 2023-11-17T03:38:28 Z sleepntsheep Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1876 ms 41364 KB
#include <iostream>
#include <stack>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;
#define N 1000005

int n, m, a[N], t[N<<1], d[N<<1], e[N];
array<int, 4> b[N];

void push(int v, int l, int r)
{
    t[v] += d[v];
    if (l ^ r)
    {
        int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
        d[vl] += d[v], d[vr] += d[v];
    }
    d[v] = 0;
}

void add(int x, int y, int k, int v, int l, int r)
{
    push(v, l, r);
    if (y < l || r < x) return;
    if (x <= l && r <= y) { d[v] = k; push(v, l, r); return; }
    int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
    add(x, y, k, vl, l, m);
    add(x, y, k, vr, m+1, r);
    t[v] = max(t[vl], t[vr]);
}

int query(int x, int y, int v, int l, int r)
{
    push(v, l, r);
    if (y < l || r < x) return 0;
    if (x <= l && r <= y) return t[v];
    int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
    return max(query(x, y, vl, l, m), query(x, y, vr, m+1, r));
}

std::stack<int> s;

int main()
{
    ShinLena;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 0; i < m; ++i) cin >> b[i][0] >> b[i][1] >> b[i][2], b[i][3] = i;
    sort(b, b+m);

    s.push(n+1); a[n+1] = 2e9;
    int j = m-1;
    for (int i = n; i >= 1; --i)
    {
        while (s.size() && a[s.top()] <= a[i])
        {
            int x = s.top();
            s.pop();
            add(x+1, s.top() - 1, -a[x], 0, 1, n);
        }
        add(i+1, s.top() - 1, a[i], 0, 1, n);
        s.push(i);
        for (; j >= 0 && b[j][0] == i; --j) e[b[j][3]] = b[j][2] >= query(i+1, b[j][1], 0, 1, n);
        add(i, i, a[i], 0, 1, n);
    }
    for (int i = 0; i < m; ++i) cout << e[i] << '\n';

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Incorrect 1 ms 6492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Incorrect 1 ms 6492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1876 ms 41364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 141 ms 9808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Incorrect 1 ms 6492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Incorrect 1 ms 6492 KB Output isn't correct
4 Halted 0 ms 0 KB -