답안 #867822

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867822 2023-10-29T14:16:46 Z 12345678 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1487 ms 119016 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+1, a)<=b;
    }
    for (int i=0; i<m; i++) cout<<ans[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 26972 KB Output is correct
2 Correct 5 ms 27144 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 5 ms 26972 KB Output is correct
5 Correct 5 ms 26972 KB Output is correct
6 Correct 7 ms 27168 KB Output is correct
7 Correct 6 ms 26968 KB Output is correct
8 Correct 5 ms 27176 KB Output is correct
9 Correct 5 ms 26972 KB Output is correct
10 Correct 5 ms 27176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 26972 KB Output is correct
2 Correct 5 ms 27144 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 5 ms 26972 KB Output is correct
5 Correct 5 ms 26972 KB Output is correct
6 Correct 7 ms 27168 KB Output is correct
7 Correct 6 ms 26968 KB Output is correct
8 Correct 5 ms 27176 KB Output is correct
9 Correct 5 ms 26972 KB Output is correct
10 Correct 5 ms 27176 KB Output is correct
11 Correct 7 ms 27224 KB Output is correct
12 Correct 9 ms 27460 KB Output is correct
13 Correct 9 ms 27228 KB Output is correct
14 Correct 10 ms 27484 KB Output is correct
15 Correct 10 ms 27556 KB Output is correct
16 Correct 8 ms 27336 KB Output is correct
17 Correct 8 ms 27228 KB Output is correct
18 Correct 8 ms 27228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1440 ms 80636 KB Output is correct
2 Correct 1387 ms 80620 KB Output is correct
3 Correct 1399 ms 80696 KB Output is correct
4 Correct 1439 ms 80408 KB Output is correct
5 Correct 1038 ms 84748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 34636 KB Output is correct
2 Correct 111 ms 36352 KB Output is correct
3 Correct 70 ms 36952 KB Output is correct
4 Correct 68 ms 36912 KB Output is correct
5 Correct 72 ms 36956 KB Output is correct
6 Correct 56 ms 35412 KB Output is correct
7 Correct 63 ms 35396 KB Output is correct
8 Correct 68 ms 36108 KB Output is correct
9 Correct 34 ms 29960 KB Output is correct
10 Correct 73 ms 36620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 26972 KB Output is correct
2 Correct 5 ms 27144 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 5 ms 26972 KB Output is correct
5 Correct 5 ms 26972 KB Output is correct
6 Correct 7 ms 27168 KB Output is correct
7 Correct 6 ms 26968 KB Output is correct
8 Correct 5 ms 27176 KB Output is correct
9 Correct 5 ms 26972 KB Output is correct
10 Correct 5 ms 27176 KB Output is correct
11 Correct 7 ms 27224 KB Output is correct
12 Correct 9 ms 27460 KB Output is correct
13 Correct 9 ms 27228 KB Output is correct
14 Correct 10 ms 27484 KB Output is correct
15 Correct 10 ms 27556 KB Output is correct
16 Correct 8 ms 27336 KB Output is correct
17 Correct 8 ms 27228 KB Output is correct
18 Correct 8 ms 27228 KB Output is correct
19 Correct 236 ms 47720 KB Output is correct
20 Correct 240 ms 47696 KB Output is correct
21 Correct 204 ms 47184 KB Output is correct
22 Correct 208 ms 47384 KB Output is correct
23 Correct 214 ms 47140 KB Output is correct
24 Correct 130 ms 46928 KB Output is correct
25 Correct 147 ms 46932 KB Output is correct
26 Correct 181 ms 47700 KB Output is correct
27 Correct 146 ms 47796 KB Output is correct
28 Correct 147 ms 48208 KB Output is correct
29 Correct 175 ms 48576 KB Output is correct
30 Correct 175 ms 48668 KB Output is correct
31 Correct 201 ms 48468 KB Output is correct
32 Correct 161 ms 48600 KB Output is correct
33 Correct 159 ms 48464 KB Output is correct
34 Correct 122 ms 45964 KB Output is correct
35 Correct 146 ms 46108 KB Output is correct
36 Correct 120 ms 45776 KB Output is correct
37 Correct 118 ms 45912 KB Output is correct
38 Correct 120 ms 45904 KB Output is correct
39 Correct 156 ms 46132 KB Output is correct
40 Correct 132 ms 42860 KB Output is correct
41 Correct 140 ms 45568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 26972 KB Output is correct
2 Correct 5 ms 27144 KB Output is correct
3 Correct 5 ms 26972 KB Output is correct
4 Correct 5 ms 26972 KB Output is correct
5 Correct 5 ms 26972 KB Output is correct
6 Correct 7 ms 27168 KB Output is correct
7 Correct 6 ms 26968 KB Output is correct
8 Correct 5 ms 27176 KB Output is correct
9 Correct 5 ms 26972 KB Output is correct
10 Correct 5 ms 27176 KB Output is correct
11 Correct 7 ms 27224 KB Output is correct
12 Correct 9 ms 27460 KB Output is correct
13 Correct 9 ms 27228 KB Output is correct
14 Correct 10 ms 27484 KB Output is correct
15 Correct 10 ms 27556 KB Output is correct
16 Correct 8 ms 27336 KB Output is correct
17 Correct 8 ms 27228 KB Output is correct
18 Correct 8 ms 27228 KB Output is correct
19 Correct 1440 ms 80636 KB Output is correct
20 Correct 1387 ms 80620 KB Output is correct
21 Correct 1399 ms 80696 KB Output is correct
22 Correct 1439 ms 80408 KB Output is correct
23 Correct 1038 ms 84748 KB Output is correct
24 Correct 102 ms 34636 KB Output is correct
25 Correct 111 ms 36352 KB Output is correct
26 Correct 70 ms 36952 KB Output is correct
27 Correct 68 ms 36912 KB Output is correct
28 Correct 72 ms 36956 KB Output is correct
29 Correct 56 ms 35412 KB Output is correct
30 Correct 63 ms 35396 KB Output is correct
31 Correct 68 ms 36108 KB Output is correct
32 Correct 34 ms 29960 KB Output is correct
33 Correct 73 ms 36620 KB Output is correct
34 Correct 236 ms 47720 KB Output is correct
35 Correct 240 ms 47696 KB Output is correct
36 Correct 204 ms 47184 KB Output is correct
37 Correct 208 ms 47384 KB Output is correct
38 Correct 214 ms 47140 KB Output is correct
39 Correct 130 ms 46928 KB Output is correct
40 Correct 147 ms 46932 KB Output is correct
41 Correct 181 ms 47700 KB Output is correct
42 Correct 146 ms 47796 KB Output is correct
43 Correct 147 ms 48208 KB Output is correct
44 Correct 175 ms 48576 KB Output is correct
45 Correct 175 ms 48668 KB Output is correct
46 Correct 201 ms 48468 KB Output is correct
47 Correct 161 ms 48600 KB Output is correct
48 Correct 159 ms 48464 KB Output is correct
49 Correct 122 ms 45964 KB Output is correct
50 Correct 146 ms 46108 KB Output is correct
51 Correct 120 ms 45776 KB Output is correct
52 Correct 118 ms 45912 KB Output is correct
53 Correct 120 ms 45904 KB Output is correct
54 Correct 156 ms 46132 KB Output is correct
55 Correct 132 ms 42860 KB Output is correct
56 Correct 140 ms 45568 KB Output is correct
57 Correct 1481 ms 114712 KB Output is correct
58 Correct 1487 ms 114876 KB Output is correct
59 Correct 1348 ms 112588 KB Output is correct
60 Correct 1422 ms 112736 KB Output is correct
61 Correct 1392 ms 112596 KB Output is correct
62 Correct 1295 ms 112720 KB Output is correct
63 Correct 714 ms 108292 KB Output is correct
64 Correct 650 ms 108136 KB Output is correct
65 Correct 918 ms 116820 KB Output is correct
66 Correct 916 ms 116952 KB Output is correct
67 Correct 933 ms 117080 KB Output is correct
68 Correct 1008 ms 119016 KB Output is correct
69 Correct 1041 ms 118868 KB Output is correct
70 Correct 1041 ms 118460 KB Output is correct
71 Correct 1052 ms 118384 KB Output is correct
72 Correct 1010 ms 118428 KB Output is correct
73 Correct 592 ms 106540 KB Output is correct
74 Correct 609 ms 107676 KB Output is correct
75 Correct 604 ms 106644 KB Output is correct
76 Correct 607 ms 106580 KB Output is correct
77 Correct 612 ms 106776 KB Output is correct
78 Correct 952 ms 107604 KB Output is correct
79 Correct 683 ms 87380 KB Output is correct
80 Correct 889 ms 104096 KB Output is correct