답안 #1100858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100858 2024-10-14T20:09:30 Z raphaelp Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2243 ms 166608 KB
#include <bits/stdc++.h>
using namespace std;
class SegTree
{
private:
    vector<int> st;
    int N;
    int l(int x) { return (x << 1); }
    int r(int x) { return (x << 1) + 1; }
    void update(int L, int R, int a, int val, int x)
    {
        if (L > a || R < a)
            return;
        if (L == a && R == a)
        {
            st[x] = val;
        }
        else
        {
            int m = (L + R) / 2;
            update(L, m, a, val, l(x));
            update(m + 1, R, a, val, r(x));
            st[x] = min(st[l(x)], st[r(x)]);
        }
    }
    int RMQ(int L, int R, int a, int b, int x)
    {
        if (L > b || R < a)
            return 2000000001;
        if (L >= a && R <= b)
            return st[x];
        int m = (L + R) / 2;
        return min(RMQ(L, m, a, b, l(x)), RMQ(m + 1, R, a, b, r(x)));
    }

public:
    SegTree(int x)
    {
        N = pow(2, ceil(log2(x)));
        st.assign(2 * N, 2000000001);
    }
    void update(int x, int val) { update(0, N - 1, x, val, 1); }
    int RMQ(int a, int b) { return RMQ(0, N - 1, a, b, 1); }
};
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> Tab(N);
    for (int i = 0; i < N; i++)
        cin >> Tab[i];
    vector<vector<int>> Qs(M, vector<int>(4));
    for (int i = 0; i < M; i++)
    {
        cin >> Qs[i][1] >> Qs[i][2] >> Qs[i][0];
        Qs[i][1]--, Qs[i][2]--;
        Qs[i][3] = i;
    }
    sort(Qs.begin(), Qs.end());
    set<pair<int, int>> S;
    vector<int> rig(N, N);
    for (int i = N - 1; i >= 0; i--)
    {
        auto pos = S.lower_bound({Tab[i], 0});
        if (pos != S.end())
            rig[i] = pos->second;
        S.insert({Tab[i], i});
        while (S.lower_bound({Tab[i], i}) != S.begin())
        {
            S.erase(S.begin());
        }
    }
    vector<vector<int>> events;
    for (int i = 0; i < N; i++)
    {
        int x = i + 1;
        while (x < N && Tab[x] < Tab[i])
        {
            events.push_back({Tab[x] + Tab[i], i, x});
            x = rig[x];
        }
    }
    sort(events.begin(), events.end());
    SegTree ST(N);
    vector<int> ans(M);
    int buff = events.size() - 1;
    for (int i = M - 1; i >= 0; i--)
    {
        while (buff >= 0 && events[buff][0] > Qs[i][0])
        {
            ST.update(events[buff][1], events[buff][2]);
            buff--;
        }
        if (ST.RMQ(Qs[i][1], Qs[i][2]) > Qs[i][2])
            ans[Qs[i][3]] = 1;
    }
    for (int i = 0; i < M; i++)
    {
        cout << ans[i] << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 4 ms 592 KB Output is correct
12 Correct 6 ms 848 KB Output is correct
13 Correct 6 ms 988 KB Output is correct
14 Correct 8 ms 1080 KB Output is correct
15 Correct 9 ms 1104 KB Output is correct
16 Correct 6 ms 1104 KB Output is correct
17 Correct 6 ms 848 KB Output is correct
18 Correct 6 ms 1104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2142 ms 164828 KB Output is correct
2 Correct 2201 ms 165760 KB Output is correct
3 Correct 2243 ms 165684 KB Output is correct
4 Correct 2218 ms 165852 KB Output is correct
5 Correct 1948 ms 157000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 15548 KB Output is correct
2 Correct 147 ms 15540 KB Output is correct
3 Correct 141 ms 14920 KB Output is correct
4 Correct 142 ms 14920 KB Output is correct
5 Correct 131 ms 14920 KB Output is correct
6 Correct 124 ms 14724 KB Output is correct
7 Correct 123 ms 14724 KB Output is correct
8 Correct 143 ms 15544 KB Output is correct
9 Correct 66 ms 7752 KB Output is correct
10 Correct 130 ms 14908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 4 ms 592 KB Output is correct
12 Correct 6 ms 848 KB Output is correct
13 Correct 6 ms 988 KB Output is correct
14 Correct 8 ms 1080 KB Output is correct
15 Correct 9 ms 1104 KB Output is correct
16 Correct 6 ms 1104 KB Output is correct
17 Correct 6 ms 848 KB Output is correct
18 Correct 6 ms 1104 KB Output is correct
19 Correct 359 ms 35068 KB Output is correct
20 Correct 370 ms 35164 KB Output is correct
21 Correct 371 ms 34796 KB Output is correct
22 Correct 363 ms 34796 KB Output is correct
23 Correct 363 ms 34796 KB Output is correct
24 Correct 328 ms 31816 KB Output is correct
25 Correct 332 ms 31816 KB Output is correct
26 Correct 340 ms 31864 KB Output is correct
27 Correct 339 ms 32040 KB Output is correct
28 Correct 355 ms 31872 KB Output is correct
29 Correct 332 ms 32072 KB Output is correct
30 Correct 336 ms 32172 KB Output is correct
31 Correct 327 ms 32176 KB Output is correct
32 Correct 325 ms 32048 KB Output is correct
33 Correct 338 ms 32072 KB Output is correct
34 Correct 314 ms 31820 KB Output is correct
35 Correct 328 ms 31796 KB Output is correct
36 Correct 310 ms 31492 KB Output is correct
37 Correct 322 ms 31404 KB Output is correct
38 Correct 303 ms 31560 KB Output is correct
39 Correct 319 ms 31732 KB Output is correct
40 Correct 241 ms 25360 KB Output is correct
41 Correct 286 ms 31220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 4 ms 592 KB Output is correct
12 Correct 6 ms 848 KB Output is correct
13 Correct 6 ms 988 KB Output is correct
14 Correct 8 ms 1080 KB Output is correct
15 Correct 9 ms 1104 KB Output is correct
16 Correct 6 ms 1104 KB Output is correct
17 Correct 6 ms 848 KB Output is correct
18 Correct 6 ms 1104 KB Output is correct
19 Correct 2142 ms 164828 KB Output is correct
20 Correct 2201 ms 165760 KB Output is correct
21 Correct 2243 ms 165684 KB Output is correct
22 Correct 2218 ms 165852 KB Output is correct
23 Correct 1948 ms 157000 KB Output is correct
24 Correct 149 ms 15548 KB Output is correct
25 Correct 147 ms 15540 KB Output is correct
26 Correct 141 ms 14920 KB Output is correct
27 Correct 142 ms 14920 KB Output is correct
28 Correct 131 ms 14920 KB Output is correct
29 Correct 124 ms 14724 KB Output is correct
30 Correct 123 ms 14724 KB Output is correct
31 Correct 143 ms 15544 KB Output is correct
32 Correct 66 ms 7752 KB Output is correct
33 Correct 130 ms 14908 KB Output is correct
34 Correct 359 ms 35068 KB Output is correct
35 Correct 370 ms 35164 KB Output is correct
36 Correct 371 ms 34796 KB Output is correct
37 Correct 363 ms 34796 KB Output is correct
38 Correct 363 ms 34796 KB Output is correct
39 Correct 328 ms 31816 KB Output is correct
40 Correct 332 ms 31816 KB Output is correct
41 Correct 340 ms 31864 KB Output is correct
42 Correct 339 ms 32040 KB Output is correct
43 Correct 355 ms 31872 KB Output is correct
44 Correct 332 ms 32072 KB Output is correct
45 Correct 336 ms 32172 KB Output is correct
46 Correct 327 ms 32176 KB Output is correct
47 Correct 325 ms 32048 KB Output is correct
48 Correct 338 ms 32072 KB Output is correct
49 Correct 314 ms 31820 KB Output is correct
50 Correct 328 ms 31796 KB Output is correct
51 Correct 310 ms 31492 KB Output is correct
52 Correct 322 ms 31404 KB Output is correct
53 Correct 303 ms 31560 KB Output is correct
54 Correct 319 ms 31732 KB Output is correct
55 Correct 241 ms 25360 KB Output is correct
56 Correct 286 ms 31220 KB Output is correct
57 Correct 2222 ms 166608 KB Output is correct
58 Correct 2201 ms 166564 KB Output is correct
59 Correct 2204 ms 166392 KB Output is correct
60 Correct 2243 ms 166524 KB Output is correct
61 Correct 2172 ms 166364 KB Output is correct
62 Correct 2127 ms 166604 KB Output is correct
63 Correct 1870 ms 155800 KB Output is correct
64 Correct 1895 ms 155588 KB Output is correct
65 Correct 2011 ms 157480 KB Output is correct
66 Correct 2073 ms 157472 KB Output is correct
67 Correct 1891 ms 157420 KB Output is correct
68 Correct 1977 ms 157592 KB Output is correct
69 Correct 2005 ms 157704 KB Output is correct
70 Correct 1984 ms 157648 KB Output is correct
71 Correct 1966 ms 157512 KB Output is correct
72 Correct 1923 ms 157680 KB Output is correct
73 Correct 1776 ms 154256 KB Output is correct
74 Correct 1830 ms 155208 KB Output is correct
75 Correct 1803 ms 154184 KB Output is correct
76 Correct 1811 ms 154100 KB Output is correct
77 Correct 1817 ms 154140 KB Output is correct
78 Correct 1993 ms 154340 KB Output is correct
79 Correct 1289 ms 117496 KB Output is correct
80 Correct 1789 ms 155960 KB Output is correct