답안 #228294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228294 2020-04-30T12:15:56 Z emil_physmath Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1289 ms 76100 KB
#include <algorithm>
#include <iostream>
#include <bitset>
#include <vector>
using namespace std;

int a[1000'000], ans[1000'000], t[4000'000], t1[4000'000];

void Build(int v, int vl, int vr)
{
    if (vl == vr)
    {
        t[v] = a[vr];
        return;
    }
    int vm = (vl + vr) / 2;
    Build(v * 2, vl, vm);
    Build(v * 2 + 1, vm + 1, vr);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
}
int Grt(int v, int vl, int vr, int i)
{
    if (i <= vl || t[v] <= a[i])
        return -1;
    if (vl == vr)
        return t[v] > a[i] ? vr : -1;
    int vm = (vl + vr) / 2;
    int res = Grt(v * 2 + 1, vm + 1, vr, i);
    if (res != -1)
        return res;
    return Grt(v * 2, vl, vm, i);
}
void Maxi(int v, int vl, int vr, int l, int r, int val)
{
    if (l > vr || vl > r)
        return;
    if (l <= vl && vr <= r)
    {
        t1[v] = max(t1[v], val);
        return;
    }
    int vm = (vl + vr) / 2;
    Maxi(v * 2, vl, vm, l, r, val);
    Maxi(v * 2 + 1, vm + 1, vr, l, r, val);
}
int GetMax(int v, int vl, int vr, int i)
{
    if (vl == vr)
        return t1[v];
    int vm = (vl + vr) / 2;
    if (i <= vm)
        return max(GetMax(v * 2, vl, vm, i), t1[v]);
    return max(GetMax(v * 2 + 1, vm + 1, vr, i), t1[v]);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    Build(1, 0, n - 1);
    struct Query
    {
        int l, r, w, ind;
        bool ans;
    };
    vector<Query> q(m);
    for (int i = 0; i < m; ++i)
    {
        q[i].ind = i;
        cin >> q[i].l >> q[i].r >> q[i].w;
        --q[i].l; --q[i].r;
    }
    sort(q.begin(), q.end(), [](const Query& l, const Query& r) {
         return l.r < r.r;
    });
    int maxr = -1;
    for (int i = 0; i < m; ++i)
    {
        int l = q[i].l, r = q[i].r, w = q[i].w;
        while (maxr < r)
        {
            int j = Grt(1, 0, n - 1, ++maxr);
            if (j != -1)
                Maxi(1, 0, n - 1, 0, j, a[j] + a[maxr]);
        }
        q[i].ans = GetMax(1, 0, n - 1, l) <= w;
    }
    sort(q.begin(), q.end(), [](const Query& l, const Query& r) {
         return l.ind < r.ind;
    });
    for (int i = 0; i < m; ++i)
        cout << q[i].ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 9 ms 768 KB Output is correct
16 Correct 9 ms 640 KB Output is correct
17 Correct 8 ms 640 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1231 ms 53240 KB Output is correct
2 Correct 1227 ms 57612 KB Output is correct
3 Correct 1289 ms 57624 KB Output is correct
4 Correct 1269 ms 57960 KB Output is correct
5 Correct 1082 ms 49656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 5624 KB Output is correct
2 Correct 102 ms 5624 KB Output is correct
3 Correct 84 ms 4600 KB Output is correct
4 Correct 86 ms 4604 KB Output is correct
5 Correct 83 ms 4600 KB Output is correct
6 Correct 75 ms 4600 KB Output is correct
7 Correct 83 ms 4600 KB Output is correct
8 Correct 88 ms 4600 KB Output is correct
9 Correct 57 ms 3192 KB Output is correct
10 Correct 86 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 9 ms 768 KB Output is correct
16 Correct 9 ms 640 KB Output is correct
17 Correct 8 ms 640 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
19 Correct 231 ms 10872 KB Output is correct
20 Correct 234 ms 10732 KB Output is correct
21 Correct 216 ms 10744 KB Output is correct
22 Correct 225 ms 10744 KB Output is correct
23 Correct 235 ms 10744 KB Output is correct
24 Correct 190 ms 8696 KB Output is correct
25 Correct 193 ms 8828 KB Output is correct
26 Correct 205 ms 8696 KB Output is correct
27 Correct 203 ms 8700 KB Output is correct
28 Correct 210 ms 8756 KB Output is correct
29 Correct 209 ms 8696 KB Output is correct
30 Correct 207 ms 8696 KB Output is correct
31 Correct 212 ms 8696 KB Output is correct
32 Correct 199 ms 8696 KB Output is correct
33 Correct 203 ms 8696 KB Output is correct
34 Correct 187 ms 8696 KB Output is correct
35 Correct 187 ms 8696 KB Output is correct
36 Correct 188 ms 8696 KB Output is correct
37 Correct 188 ms 8696 KB Output is correct
38 Correct 181 ms 8696 KB Output is correct
39 Correct 197 ms 9412 KB Output is correct
40 Correct 163 ms 7232 KB Output is correct
41 Correct 172 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 9 ms 768 KB Output is correct
16 Correct 9 ms 640 KB Output is correct
17 Correct 8 ms 640 KB Output is correct
18 Correct 8 ms 640 KB Output is correct
19 Correct 1231 ms 53240 KB Output is correct
20 Correct 1227 ms 57612 KB Output is correct
21 Correct 1289 ms 57624 KB Output is correct
22 Correct 1269 ms 57960 KB Output is correct
23 Correct 1082 ms 49656 KB Output is correct
24 Correct 100 ms 5624 KB Output is correct
25 Correct 102 ms 5624 KB Output is correct
26 Correct 84 ms 4600 KB Output is correct
27 Correct 86 ms 4604 KB Output is correct
28 Correct 83 ms 4600 KB Output is correct
29 Correct 75 ms 4600 KB Output is correct
30 Correct 83 ms 4600 KB Output is correct
31 Correct 88 ms 4600 KB Output is correct
32 Correct 57 ms 3192 KB Output is correct
33 Correct 86 ms 4600 KB Output is correct
34 Correct 231 ms 10872 KB Output is correct
35 Correct 234 ms 10732 KB Output is correct
36 Correct 216 ms 10744 KB Output is correct
37 Correct 225 ms 10744 KB Output is correct
38 Correct 235 ms 10744 KB Output is correct
39 Correct 190 ms 8696 KB Output is correct
40 Correct 193 ms 8828 KB Output is correct
41 Correct 205 ms 8696 KB Output is correct
42 Correct 203 ms 8700 KB Output is correct
43 Correct 210 ms 8756 KB Output is correct
44 Correct 209 ms 8696 KB Output is correct
45 Correct 207 ms 8696 KB Output is correct
46 Correct 212 ms 8696 KB Output is correct
47 Correct 199 ms 8696 KB Output is correct
48 Correct 203 ms 8696 KB Output is correct
49 Correct 187 ms 8696 KB Output is correct
50 Correct 187 ms 8696 KB Output is correct
51 Correct 188 ms 8696 KB Output is correct
52 Correct 188 ms 8696 KB Output is correct
53 Correct 181 ms 8696 KB Output is correct
54 Correct 197 ms 9412 KB Output is correct
55 Correct 163 ms 7232 KB Output is correct
56 Correct 172 ms 8696 KB Output is correct
57 Correct 1242 ms 76100 KB Output is correct
58 Correct 1275 ms 75948 KB Output is correct
59 Correct 1216 ms 75908 KB Output is correct
60 Correct 1230 ms 75792 KB Output is correct
61 Correct 1213 ms 76016 KB Output is correct
62 Correct 1195 ms 75956 KB Output is correct
63 Correct 962 ms 65800 KB Output is correct
64 Correct 958 ms 65652 KB Output is correct
65 Correct 1078 ms 67644 KB Output is correct
66 Correct 1056 ms 67584 KB Output is correct
67 Correct 1030 ms 67828 KB Output is correct
68 Correct 1053 ms 67784 KB Output is correct
69 Correct 1068 ms 67700 KB Output is correct
70 Correct 1076 ms 67832 KB Output is correct
71 Correct 1074 ms 67824 KB Output is correct
72 Correct 1065 ms 67696 KB Output is correct
73 Correct 973 ms 64420 KB Output is correct
74 Correct 933 ms 65256 KB Output is correct
75 Correct 921 ms 64268 KB Output is correct
76 Correct 913 ms 64236 KB Output is correct
77 Correct 956 ms 64364 KB Output is correct
78 Correct 1028 ms 64348 KB Output is correct
79 Correct 829 ms 50952 KB Output is correct
80 Correct 972 ms 58756 KB Output is correct