답안 #161905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161905 2019-11-05T09:23:26 Z Alexa2001 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1157 ms 103196 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1e6 + 5;

int w[Nmax];
vector<int> start[Nmax];
int n, m;
int l[Nmax], r[Nmax], val[Nmax], ans[Nmax];

class SegTree
{
    int a[Nmax];
    int ub(int x) { return (x&(-x)); }

public:
    int query(int x)
    {
        int ans = 0;
        for(; x; x-=ub(x)) ans = max(ans, a[x]);
        return ans;
    }

    void update(int pos, int val)
    {
        for(; pos <= n; pos += ub(pos)) a[pos] = max(a[pos], val);
    }
} aib;

void prepare()
{
    int i, nr = 0;
    int st[Nmax];

    for(i=1; i<=n; ++i)
    {
        while(nr && w[st[nr]] <= w[i]) 
            --nr;

        if(nr) start[st[nr]].push_back(i);
        st[++nr] = i;
    }
}

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> n >> m;
   
    int i;
    for(i=1; i<=n; ++i) cin >> w[i];

    prepare();

    for(i=1; i<=m; ++i) cin >> l[i] >> r[i] >> val[i];

    vector<int> ord;
    for(i=1; i<=m; ++i) ord.push_back(i);

    sort( ord.begin(), ord.end(), [] (int x, int y) { return (l[x] > l[y]); } );
    
    int id = n;
    for(auto it : ord)
    {
        while(id >= l[it])
        {
            for(auto el : start[id])
                aib.update(el, w[id] + w[el]);
            --id;
        }

        ans[it] = (aib.query(r[it]) <= val[it]);
    }

    for(i=1; i<=m; ++i) cout << ans[i] << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 25 ms 23900 KB Output is correct
3 Correct 35 ms 23928 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 28 ms 23928 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 24 ms 23932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 25 ms 23900 KB Output is correct
3 Correct 35 ms 23928 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 28 ms 23928 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 24 ms 23932 KB Output is correct
11 Correct 27 ms 24096 KB Output is correct
12 Correct 28 ms 24184 KB Output is correct
13 Correct 27 ms 24232 KB Output is correct
14 Correct 27 ms 24312 KB Output is correct
15 Correct 28 ms 24256 KB Output is correct
16 Correct 27 ms 24172 KB Output is correct
17 Correct 28 ms 24188 KB Output is correct
18 Correct 27 ms 24196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1104 ms 101368 KB Output is correct
2 Correct 1157 ms 78920 KB Output is correct
3 Correct 1097 ms 78856 KB Output is correct
4 Correct 1104 ms 78948 KB Output is correct
5 Correct 908 ms 58848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 30512 KB Output is correct
2 Correct 103 ms 30572 KB Output is correct
3 Correct 92 ms 28660 KB Output is correct
4 Correct 90 ms 28532 KB Output is correct
5 Correct 94 ms 28532 KB Output is correct
6 Correct 85 ms 28452 KB Output is correct
7 Correct 84 ms 28528 KB Output is correct
8 Correct 92 ms 28784 KB Output is correct
9 Correct 68 ms 27508 KB Output is correct
10 Correct 87 ms 28820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 25 ms 23900 KB Output is correct
3 Correct 35 ms 23928 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 28 ms 23928 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 24 ms 23932 KB Output is correct
11 Correct 27 ms 24096 KB Output is correct
12 Correct 28 ms 24184 KB Output is correct
13 Correct 27 ms 24232 KB Output is correct
14 Correct 27 ms 24312 KB Output is correct
15 Correct 28 ms 24256 KB Output is correct
16 Correct 27 ms 24172 KB Output is correct
17 Correct 28 ms 24188 KB Output is correct
18 Correct 27 ms 24196 KB Output is correct
19 Correct 223 ms 39764 KB Output is correct
20 Correct 220 ms 39896 KB Output is correct
21 Correct 208 ms 39528 KB Output is correct
22 Correct 207 ms 39656 KB Output is correct
23 Correct 207 ms 39616 KB Output is correct
24 Correct 178 ms 35440 KB Output is correct
25 Correct 179 ms 35408 KB Output is correct
26 Correct 188 ms 35696 KB Output is correct
27 Correct 189 ms 35700 KB Output is correct
28 Correct 183 ms 35804 KB Output is correct
29 Correct 187 ms 35696 KB Output is correct
30 Correct 190 ms 35824 KB Output is correct
31 Correct 190 ms 35824 KB Output is correct
32 Correct 188 ms 35772 KB Output is correct
33 Correct 208 ms 35696 KB Output is correct
34 Correct 175 ms 35440 KB Output is correct
35 Correct 172 ms 35440 KB Output is correct
36 Correct 168 ms 35164 KB Output is correct
37 Correct 164 ms 35324 KB Output is correct
38 Correct 167 ms 35336 KB Output is correct
39 Correct 172 ms 35604 KB Output is correct
40 Correct 152 ms 33644 KB Output is correct
41 Correct 164 ms 35252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 25 ms 23900 KB Output is correct
3 Correct 35 ms 23928 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 28 ms 23928 KB Output is correct
7 Correct 25 ms 23928 KB Output is correct
8 Correct 23 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 24 ms 23932 KB Output is correct
11 Correct 27 ms 24096 KB Output is correct
12 Correct 28 ms 24184 KB Output is correct
13 Correct 27 ms 24232 KB Output is correct
14 Correct 27 ms 24312 KB Output is correct
15 Correct 28 ms 24256 KB Output is correct
16 Correct 27 ms 24172 KB Output is correct
17 Correct 28 ms 24188 KB Output is correct
18 Correct 27 ms 24196 KB Output is correct
19 Correct 1104 ms 101368 KB Output is correct
20 Correct 1157 ms 78920 KB Output is correct
21 Correct 1097 ms 78856 KB Output is correct
22 Correct 1104 ms 78948 KB Output is correct
23 Correct 908 ms 58848 KB Output is correct
24 Correct 106 ms 30512 KB Output is correct
25 Correct 103 ms 30572 KB Output is correct
26 Correct 92 ms 28660 KB Output is correct
27 Correct 90 ms 28532 KB Output is correct
28 Correct 94 ms 28532 KB Output is correct
29 Correct 85 ms 28452 KB Output is correct
30 Correct 84 ms 28528 KB Output is correct
31 Correct 92 ms 28784 KB Output is correct
32 Correct 68 ms 27508 KB Output is correct
33 Correct 87 ms 28820 KB Output is correct
34 Correct 223 ms 39764 KB Output is correct
35 Correct 220 ms 39896 KB Output is correct
36 Correct 208 ms 39528 KB Output is correct
37 Correct 207 ms 39656 KB Output is correct
38 Correct 207 ms 39616 KB Output is correct
39 Correct 178 ms 35440 KB Output is correct
40 Correct 179 ms 35408 KB Output is correct
41 Correct 188 ms 35696 KB Output is correct
42 Correct 189 ms 35700 KB Output is correct
43 Correct 183 ms 35804 KB Output is correct
44 Correct 187 ms 35696 KB Output is correct
45 Correct 190 ms 35824 KB Output is correct
46 Correct 190 ms 35824 KB Output is correct
47 Correct 188 ms 35772 KB Output is correct
48 Correct 208 ms 35696 KB Output is correct
49 Correct 175 ms 35440 KB Output is correct
50 Correct 172 ms 35440 KB Output is correct
51 Correct 168 ms 35164 KB Output is correct
52 Correct 164 ms 35324 KB Output is correct
53 Correct 167 ms 35336 KB Output is correct
54 Correct 172 ms 35604 KB Output is correct
55 Correct 152 ms 33644 KB Output is correct
56 Correct 164 ms 35252 KB Output is correct
57 Correct 1138 ms 101972 KB Output is correct
58 Correct 1147 ms 103196 KB Output is correct
59 Correct 1107 ms 103060 KB Output is correct
60 Correct 1100 ms 103144 KB Output is correct
61 Correct 1095 ms 103156 KB Output is correct
62 Correct 1088 ms 103144 KB Output is correct
63 Correct 838 ms 81276 KB Output is correct
64 Correct 865 ms 81348 KB Output is correct
65 Correct 913 ms 83072 KB Output is correct
66 Correct 952 ms 83084 KB Output is correct
67 Correct 940 ms 83164 KB Output is correct
68 Correct 953 ms 83104 KB Output is correct
69 Correct 995 ms 83212 KB Output is correct
70 Correct 883 ms 83308 KB Output is correct
71 Correct 916 ms 83236 KB Output is correct
72 Correct 917 ms 83016 KB Output is correct
73 Correct 827 ms 79888 KB Output is correct
74 Correct 816 ms 80760 KB Output is correct
75 Correct 867 ms 79708 KB Output is correct
76 Correct 845 ms 79708 KB Output is correct
77 Correct 846 ms 79580 KB Output is correct
78 Correct 884 ms 83856 KB Output is correct
79 Correct 794 ms 71396 KB Output is correct
80 Correct 837 ms 81804 KB Output is correct