답안 #502780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502780 2022-01-06T15:10:11 Z blue Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1266 ms 104916 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

const ll INF = 1'000'000'000'000LL;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, M;
    cin >> N >> M;

    vll w(1+N, 0);
    for(int i = 1; i <= N; i++) cin >> w[i];

    vi p(1+N);

    w[0] = INF;
    vector<int> st{0};

    for(int i = 1; i <= N; i++)
    {
        while(w[st.back()] <= w[i]) st.pop_back(); //wrong?
        p[i] = st.back();
        st.push_back(i);
    }

    vi l(1+M), r(1+M), k(1+M);
    vi rq[1+N];
    for(int q = 1; q <= M; q++)
    {
        cin >> l[q] >> r[q] >> k[q];
        rq[r[q]].push_back(q);
    }

    const int sn = (1<<20);

    vll mx(int(sn<<1), 0);

    int ans[1+M];

    for(int i = 1; i <= N; i++)
    {
        ll val = w[i] + w[p[i]];
        mx[ sn + p[i] ] = max(mx[ sn + p[i] ], val);

        for(int j = (sn + p[i]) >> 1; j >= 1; j >>= 1)
            mx[j] = max(mx[2*j], mx[2*j+1]);


        for(int q: rq[i])
        {
            int x = sn + l[q];
            int y = sn + i + 1;

            ll res = 0;

            while(x < y)
            {
                if(x % 2 == 1)
                {
                    res = max(res, mx[x]);
                    x++;
                }
                if(y % 2 == 1)
                {
                    y--;
                    res = max(res, mx[y]);
                }
                x >>= 1;
                y >>= 1;
            }

            ans[q] = (res <= k[q]);
        }
    }

    for(int q = 1; q <= M; q++) cout << ans[q] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16712 KB Output is correct
2 Correct 7 ms 16728 KB Output is correct
3 Correct 8 ms 16716 KB Output is correct
4 Correct 7 ms 16716 KB Output is correct
5 Correct 7 ms 16672 KB Output is correct
6 Correct 7 ms 16716 KB Output is correct
7 Correct 8 ms 16716 KB Output is correct
8 Correct 8 ms 16716 KB Output is correct
9 Correct 8 ms 16716 KB Output is correct
10 Correct 8 ms 16716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16712 KB Output is correct
2 Correct 7 ms 16728 KB Output is correct
3 Correct 8 ms 16716 KB Output is correct
4 Correct 7 ms 16716 KB Output is correct
5 Correct 7 ms 16672 KB Output is correct
6 Correct 7 ms 16716 KB Output is correct
7 Correct 8 ms 16716 KB Output is correct
8 Correct 8 ms 16716 KB Output is correct
9 Correct 8 ms 16716 KB Output is correct
10 Correct 8 ms 16716 KB Output is correct
11 Correct 12 ms 16856 KB Output is correct
12 Correct 9 ms 16972 KB Output is correct
13 Correct 10 ms 16920 KB Output is correct
14 Correct 16 ms 17036 KB Output is correct
15 Correct 11 ms 17084 KB Output is correct
16 Correct 10 ms 16972 KB Output is correct
17 Correct 11 ms 16972 KB Output is correct
18 Correct 9 ms 16972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1166 ms 87572 KB Output is correct
2 Correct 1125 ms 87472 KB Output is correct
3 Correct 1165 ms 87480 KB Output is correct
4 Correct 1146 ms 87484 KB Output is correct
5 Correct 1266 ms 87556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 23560 KB Output is correct
2 Correct 68 ms 22852 KB Output is correct
3 Correct 79 ms 23308 KB Output is correct
4 Correct 87 ms 23532 KB Output is correct
5 Correct 87 ms 23620 KB Output is correct
6 Correct 74 ms 22524 KB Output is correct
7 Correct 77 ms 22520 KB Output is correct
8 Correct 75 ms 23500 KB Output is correct
9 Correct 40 ms 19008 KB Output is correct
10 Correct 90 ms 23488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16712 KB Output is correct
2 Correct 7 ms 16728 KB Output is correct
3 Correct 8 ms 16716 KB Output is correct
4 Correct 7 ms 16716 KB Output is correct
5 Correct 7 ms 16672 KB Output is correct
6 Correct 7 ms 16716 KB Output is correct
7 Correct 8 ms 16716 KB Output is correct
8 Correct 8 ms 16716 KB Output is correct
9 Correct 8 ms 16716 KB Output is correct
10 Correct 8 ms 16716 KB Output is correct
11 Correct 12 ms 16856 KB Output is correct
12 Correct 9 ms 16972 KB Output is correct
13 Correct 10 ms 16920 KB Output is correct
14 Correct 16 ms 17036 KB Output is correct
15 Correct 11 ms 17084 KB Output is correct
16 Correct 10 ms 16972 KB Output is correct
17 Correct 11 ms 16972 KB Output is correct
18 Correct 9 ms 16972 KB Output is correct
19 Correct 183 ms 30548 KB Output is correct
20 Correct 176 ms 30412 KB Output is correct
21 Correct 152 ms 28832 KB Output is correct
22 Correct 145 ms 28744 KB Output is correct
23 Correct 150 ms 28788 KB Output is correct
24 Correct 157 ms 28596 KB Output is correct
25 Correct 164 ms 28572 KB Output is correct
26 Correct 179 ms 29292 KB Output is correct
27 Correct 180 ms 29344 KB Output is correct
28 Correct 168 ms 29580 KB Output is correct
29 Correct 180 ms 30484 KB Output is correct
30 Correct 192 ms 30548 KB Output is correct
31 Correct 188 ms 30440 KB Output is correct
32 Correct 193 ms 30392 KB Output is correct
33 Correct 183 ms 30352 KB Output is correct
34 Correct 148 ms 28376 KB Output is correct
35 Correct 146 ms 28340 KB Output is correct
36 Correct 166 ms 28500 KB Output is correct
37 Correct 149 ms 28484 KB Output is correct
38 Correct 146 ms 28328 KB Output is correct
39 Correct 190 ms 30168 KB Output is correct
40 Correct 131 ms 27400 KB Output is correct
41 Correct 146 ms 30308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16712 KB Output is correct
2 Correct 7 ms 16728 KB Output is correct
3 Correct 8 ms 16716 KB Output is correct
4 Correct 7 ms 16716 KB Output is correct
5 Correct 7 ms 16672 KB Output is correct
6 Correct 7 ms 16716 KB Output is correct
7 Correct 8 ms 16716 KB Output is correct
8 Correct 8 ms 16716 KB Output is correct
9 Correct 8 ms 16716 KB Output is correct
10 Correct 8 ms 16716 KB Output is correct
11 Correct 12 ms 16856 KB Output is correct
12 Correct 9 ms 16972 KB Output is correct
13 Correct 10 ms 16920 KB Output is correct
14 Correct 16 ms 17036 KB Output is correct
15 Correct 11 ms 17084 KB Output is correct
16 Correct 10 ms 16972 KB Output is correct
17 Correct 11 ms 16972 KB Output is correct
18 Correct 9 ms 16972 KB Output is correct
19 Correct 1166 ms 87572 KB Output is correct
20 Correct 1125 ms 87472 KB Output is correct
21 Correct 1165 ms 87480 KB Output is correct
22 Correct 1146 ms 87484 KB Output is correct
23 Correct 1266 ms 87556 KB Output is correct
24 Correct 72 ms 23560 KB Output is correct
25 Correct 68 ms 22852 KB Output is correct
26 Correct 79 ms 23308 KB Output is correct
27 Correct 87 ms 23532 KB Output is correct
28 Correct 87 ms 23620 KB Output is correct
29 Correct 74 ms 22524 KB Output is correct
30 Correct 77 ms 22520 KB Output is correct
31 Correct 75 ms 23500 KB Output is correct
32 Correct 40 ms 19008 KB Output is correct
33 Correct 90 ms 23488 KB Output is correct
34 Correct 183 ms 30548 KB Output is correct
35 Correct 176 ms 30412 KB Output is correct
36 Correct 152 ms 28832 KB Output is correct
37 Correct 145 ms 28744 KB Output is correct
38 Correct 150 ms 28788 KB Output is correct
39 Correct 157 ms 28596 KB Output is correct
40 Correct 164 ms 28572 KB Output is correct
41 Correct 179 ms 29292 KB Output is correct
42 Correct 180 ms 29344 KB Output is correct
43 Correct 168 ms 29580 KB Output is correct
44 Correct 180 ms 30484 KB Output is correct
45 Correct 192 ms 30548 KB Output is correct
46 Correct 188 ms 30440 KB Output is correct
47 Correct 193 ms 30392 KB Output is correct
48 Correct 183 ms 30352 KB Output is correct
49 Correct 148 ms 28376 KB Output is correct
50 Correct 146 ms 28340 KB Output is correct
51 Correct 166 ms 28500 KB Output is correct
52 Correct 149 ms 28484 KB Output is correct
53 Correct 146 ms 28328 KB Output is correct
54 Correct 190 ms 30168 KB Output is correct
55 Correct 131 ms 27400 KB Output is correct
56 Correct 146 ms 30308 KB Output is correct
57 Correct 1212 ms 85752 KB Output is correct
58 Correct 1096 ms 85740 KB Output is correct
59 Correct 1065 ms 81652 KB Output is correct
60 Correct 1039 ms 82220 KB Output is correct
61 Correct 1092 ms 87408 KB Output is correct
62 Correct 1100 ms 90592 KB Output is correct
63 Correct 876 ms 80972 KB Output is correct
64 Correct 845 ms 81844 KB Output is correct
65 Correct 1173 ms 89832 KB Output is correct
66 Correct 1182 ms 98892 KB Output is correct
67 Correct 1211 ms 83572 KB Output is correct
68 Correct 1265 ms 104916 KB Output is correct
69 Correct 1171 ms 103520 KB Output is correct
70 Correct 1241 ms 96996 KB Output is correct
71 Correct 1235 ms 99628 KB Output is correct
72 Correct 1192 ms 104512 KB Output is correct
73 Correct 858 ms 86724 KB Output is correct
74 Correct 1002 ms 93924 KB Output is correct
75 Correct 914 ms 92544 KB Output is correct
76 Correct 855 ms 86092 KB Output is correct
77 Correct 915 ms 89228 KB Output is correct
78 Correct 1149 ms 94676 KB Output is correct
79 Correct 833 ms 68676 KB Output is correct
80 Correct 1118 ms 94312 KB Output is correct