답안 #867819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867819 2023-10-29T14:13:12 Z 12345678 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1466 ms 84564 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=1e6+5;
int n, m, v[nx], l, r, k, ans[nx];
vector<tuple<int, int, int>> d[nx];
stack<int> st;

struct segtree
{
    int d[4*nx], lz[4*nx];
    void pushlz(int l, int r, int i)
    {
        d[i]+=lz[i];
        if (l==r) return void(lz[i]=0);
        lz[2*i]+=lz[i];
        lz[2*i+1]+=lz[i];
        lz[i]=0;
    }
    void setval(int l, int r, int i, int idx)
    {
        pushlz(l, r, i);
        if (idx<l||r<idx) return;
        if (l==r) return void(d[i]=v[idx]);
        int md=(l+r)/2;
        setval(l, md, 2*i, idx);
        setval(md+1, r, 2*i+1, idx);
        d[i]=max(d[2*i], d[2*i+1]);
    }
    void update(int l, int r, int i, int ul, int ur, int vl)
    {
        if (ur<ul) return;
        pushlz(l, r, i);
        if (r<ul||ur<l) return;
        if (ul<=l&&r<=ur) return lz[i]=vl, pushlz(l, r, i), void();
        int md=(l+r)/2;
        update(l, md, 2*i, ul, ur, vl);
        update(md+1, r, 2*i+1, ul, ur, vl);
        d[i]=max(d[2*i], d[2*i+1]);
    }
    int query(int l, int r, int i, int ql, int qr)
    {
        pushlz(l, r, i);
        if (r<ql||qr<l) return INT_MIN;
        if (ql<=l&&r<=qr) return d[i];
        int md=(l+r)/2;
        return max(query(l, md, 2*i, ql, qr), query(md+1, r, 2*i+1, ql, qr));
    }
} s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1; i<=n; i++) cin>>v[i];
    for (int i=1; i<=4*n; i++) s.d[i]=INT_MIN;
    v[n+1]=INT_MAX;
    for (int i=0; i<m; i++) cin>>l>>r>>k, d[l].push_back({r, k, i});
    st.push(n+1);
    for (int i=n; i>=1; i--)
    {
        while (st.size()>1&&v[i]>=v[st.top()])
        {
            int x=st.top();
            st.pop();
            s.setval(1, n, 1, x);
            s.update(1, n, 1, x+1, st.top()-1, -v[x]);
        }
        s.update(1, n, 1, i+1, st.top()-1, v[i]);
        st.push(i);
        //cout<<i<<": ";
        //for (int j=1; j<=n; j++) cout<<s.query(1, n, 1, j, j)<<' ';
        //cout<<'\n';
        for (auto [a, b, c]:d[i]) ans[c]=s.query(1, n, 1, i, a)<=b;
    }
    for (int i=0; i<m; i++) cout<<ans[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 26972 KB Output is correct
2 Correct 6 ms 27152 KB Output is correct
3 Correct 6 ms 27160 KB Output is correct
4 Correct 6 ms 26968 KB Output is correct
5 Correct 6 ms 26972 KB Output is correct
6 Correct 6 ms 26972 KB Output is correct
7 Correct 5 ms 26972 KB Output is correct
8 Correct 6 ms 26972 KB Output is correct
9 Correct 6 ms 26968 KB Output is correct
10 Incorrect 6 ms 26972 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 26972 KB Output is correct
2 Correct 6 ms 27152 KB Output is correct
3 Correct 6 ms 27160 KB Output is correct
4 Correct 6 ms 26968 KB Output is correct
5 Correct 6 ms 26972 KB Output is correct
6 Correct 6 ms 26972 KB Output is correct
7 Correct 5 ms 26972 KB Output is correct
8 Correct 6 ms 26972 KB Output is correct
9 Correct 6 ms 26968 KB Output is correct
10 Incorrect 6 ms 26972 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1458 ms 80792 KB Output is correct
2 Correct 1420 ms 80412 KB Output is correct
3 Correct 1466 ms 80440 KB Output is correct
4 Correct 1451 ms 80676 KB Output is correct
5 Incorrect 1052 ms 84564 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 102 ms 34644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 26972 KB Output is correct
2 Correct 6 ms 27152 KB Output is correct
3 Correct 6 ms 27160 KB Output is correct
4 Correct 6 ms 26968 KB Output is correct
5 Correct 6 ms 26972 KB Output is correct
6 Correct 6 ms 26972 KB Output is correct
7 Correct 5 ms 26972 KB Output is correct
8 Correct 6 ms 26972 KB Output is correct
9 Correct 6 ms 26968 KB Output is correct
10 Incorrect 6 ms 26972 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 26972 KB Output is correct
2 Correct 6 ms 27152 KB Output is correct
3 Correct 6 ms 27160 KB Output is correct
4 Correct 6 ms 26968 KB Output is correct
5 Correct 6 ms 26972 KB Output is correct
6 Correct 6 ms 26972 KB Output is correct
7 Correct 5 ms 26972 KB Output is correct
8 Correct 6 ms 26972 KB Output is correct
9 Correct 6 ms 26968 KB Output is correct
10 Incorrect 6 ms 26972 KB Output isn't correct
11 Halted 0 ms 0 KB -