답안 #497911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497911 2021-12-24T04:38:52 Z Nalrimet Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1465 ms 93456 KB
#include<bits/stdc++.h>

//#pragma GCC optimization("g", on)
//#pragma GCC optimize ("inline")
//#pragma GCC optimization("03")
//#pragma GCC optimization("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popused,abm,mmx,avx,tune=native")
using namespace std;

const int N = 1e6 + 5;
const long long inf = 2000000000;
#define ll long long
#define int long long

#define F first
#define S second
#define pb push_back

int n, m, a[N], l[N], r[N], k[N];
int t[4 * N], mx;
bool ans[N];
vector<int> v[N];

void update(int pos, int val, int tl = 1, int tr = n, int v = 1){
    if(tl == tr) {
        t[v] = max(t[v], val);
    }
    else{
        int tm = (tl + tr) / 2;
        if(pos <= tm) update(pos, val, tl, tm, v * 2);
        else update(pos, val, tm + 1, tr, v * 2 + 1);
        t[v] = max(t[v * 2], t[v * 2 + 1]);
    }
}

int get(int v, int tl, int tr, int l, int r){
    if(l <= tl && tr <= r) return t[v];
    if(l > tr || r < tl) return 0;
    int tm = (tl + tr) / 2;
    return max(get(v * 2, tl, tm, l, r), get(v * 2 + 1, tm + 1, tr, l, r));
}


 main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;

    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }

    for(int i = 1; i <= m; ++i){
        cin >> l[i] >> r[i] >> k[i];
        v[r[i]].pb(i);
    }

    stack<int> st;
    st.push(0);
    a[0] = inf;

    for(int i = 1; i <= n; ++i){
        while(a[st.top()] <= a[i]) st.pop();
        if(st.top() != 0) update(st.top(), a[st.top()] + a[i]);
        st.push(i);
        for(auto to : v[i]){
            mx = get(1, 1, n, l[to], i);
            if(mx <= k[to]) ans[to] = 1;
        }
    }

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

Compilation message

sortbooks.cpp:46:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 |  main() {
      |  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23836 KB Output is correct
3 Correct 13 ms 23960 KB Output is correct
4 Correct 12 ms 23756 KB Output is correct
5 Correct 12 ms 23784 KB Output is correct
6 Correct 12 ms 23872 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 13 ms 23860 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23836 KB Output is correct
3 Correct 13 ms 23960 KB Output is correct
4 Correct 12 ms 23756 KB Output is correct
5 Correct 12 ms 23784 KB Output is correct
6 Correct 12 ms 23872 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 13 ms 23860 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 15 ms 23904 KB Output is correct
12 Correct 15 ms 24064 KB Output is correct
13 Correct 14 ms 24156 KB Output is correct
14 Correct 17 ms 24144 KB Output is correct
15 Correct 16 ms 24144 KB Output is correct
16 Correct 17 ms 24084 KB Output is correct
17 Correct 16 ms 24120 KB Output is correct
18 Correct 17 ms 24144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1465 ms 93456 KB Output is correct
2 Correct 1450 ms 93376 KB Output is correct
3 Correct 1456 ms 93344 KB Output is correct
4 Correct 1431 ms 93316 KB Output is correct
5 Correct 1205 ms 77900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 31164 KB Output is correct
2 Correct 97 ms 30588 KB Output is correct
3 Correct 96 ms 28900 KB Output is correct
4 Correct 101 ms 29124 KB Output is correct
5 Correct 85 ms 29020 KB Output is correct
6 Correct 70 ms 28244 KB Output is correct
7 Correct 72 ms 28228 KB Output is correct
8 Correct 79 ms 29064 KB Output is correct
9 Correct 51 ms 27436 KB Output is correct
10 Correct 88 ms 29032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23836 KB Output is correct
3 Correct 13 ms 23960 KB Output is correct
4 Correct 12 ms 23756 KB Output is correct
5 Correct 12 ms 23784 KB Output is correct
6 Correct 12 ms 23872 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 13 ms 23860 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 15 ms 23904 KB Output is correct
12 Correct 15 ms 24064 KB Output is correct
13 Correct 14 ms 24156 KB Output is correct
14 Correct 17 ms 24144 KB Output is correct
15 Correct 16 ms 24144 KB Output is correct
16 Correct 17 ms 24084 KB Output is correct
17 Correct 16 ms 24120 KB Output is correct
18 Correct 17 ms 24144 KB Output is correct
19 Correct 226 ms 38484 KB Output is correct
20 Correct 233 ms 38532 KB Output is correct
21 Correct 186 ms 37444 KB Output is correct
22 Correct 186 ms 37392 KB Output is correct
23 Correct 218 ms 37316 KB Output is correct
24 Correct 156 ms 33132 KB Output is correct
25 Correct 153 ms 33220 KB Output is correct
26 Correct 171 ms 33580 KB Output is correct
27 Correct 180 ms 33732 KB Output is correct
28 Correct 204 ms 33788 KB Output is correct
29 Correct 200 ms 34416 KB Output is correct
30 Correct 202 ms 34396 KB Output is correct
31 Correct 206 ms 34340 KB Output is correct
32 Correct 183 ms 34376 KB Output is correct
33 Correct 186 ms 34372 KB Output is correct
34 Correct 153 ms 33124 KB Output is correct
35 Correct 148 ms 33108 KB Output is correct
36 Correct 162 ms 32888 KB Output is correct
37 Correct 147 ms 32964 KB Output is correct
38 Correct 171 ms 33008 KB Output is correct
39 Correct 176 ms 35420 KB Output is correct
40 Correct 128 ms 33268 KB Output is correct
41 Correct 169 ms 34260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23836 KB Output is correct
3 Correct 13 ms 23960 KB Output is correct
4 Correct 12 ms 23756 KB Output is correct
5 Correct 12 ms 23784 KB Output is correct
6 Correct 12 ms 23872 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 13 ms 23860 KB Output is correct
9 Correct 13 ms 23756 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 15 ms 23904 KB Output is correct
12 Correct 15 ms 24064 KB Output is correct
13 Correct 14 ms 24156 KB Output is correct
14 Correct 17 ms 24144 KB Output is correct
15 Correct 16 ms 24144 KB Output is correct
16 Correct 17 ms 24084 KB Output is correct
17 Correct 16 ms 24120 KB Output is correct
18 Correct 17 ms 24144 KB Output is correct
19 Correct 1465 ms 93456 KB Output is correct
20 Correct 1450 ms 93376 KB Output is correct
21 Correct 1456 ms 93344 KB Output is correct
22 Correct 1431 ms 93316 KB Output is correct
23 Correct 1205 ms 77900 KB Output is correct
24 Correct 113 ms 31164 KB Output is correct
25 Correct 97 ms 30588 KB Output is correct
26 Correct 96 ms 28900 KB Output is correct
27 Correct 101 ms 29124 KB Output is correct
28 Correct 85 ms 29020 KB Output is correct
29 Correct 70 ms 28244 KB Output is correct
30 Correct 72 ms 28228 KB Output is correct
31 Correct 79 ms 29064 KB Output is correct
32 Correct 51 ms 27436 KB Output is correct
33 Correct 88 ms 29032 KB Output is correct
34 Correct 226 ms 38484 KB Output is correct
35 Correct 233 ms 38532 KB Output is correct
36 Correct 186 ms 37444 KB Output is correct
37 Correct 186 ms 37392 KB Output is correct
38 Correct 218 ms 37316 KB Output is correct
39 Correct 156 ms 33132 KB Output is correct
40 Correct 153 ms 33220 KB Output is correct
41 Correct 171 ms 33580 KB Output is correct
42 Correct 180 ms 33732 KB Output is correct
43 Correct 204 ms 33788 KB Output is correct
44 Correct 200 ms 34416 KB Output is correct
45 Correct 202 ms 34396 KB Output is correct
46 Correct 206 ms 34340 KB Output is correct
47 Correct 183 ms 34376 KB Output is correct
48 Correct 186 ms 34372 KB Output is correct
49 Correct 153 ms 33124 KB Output is correct
50 Correct 148 ms 33108 KB Output is correct
51 Correct 162 ms 32888 KB Output is correct
52 Correct 147 ms 32964 KB Output is correct
53 Correct 171 ms 33008 KB Output is correct
54 Correct 176 ms 35420 KB Output is correct
55 Correct 128 ms 33268 KB Output is correct
56 Correct 169 ms 34260 KB Output is correct
57 Correct 1464 ms 93420 KB Output is correct
58 Correct 1450 ms 93280 KB Output is correct
59 Correct 1347 ms 90520 KB Output is correct
60 Correct 1363 ms 90612 KB Output is correct
61 Correct 1324 ms 90484 KB Output is correct
62 Correct 1305 ms 90492 KB Output is correct
63 Correct 840 ms 70488 KB Output is correct
64 Correct 843 ms 70520 KB Output is correct
65 Correct 1075 ms 73848 KB Output is correct
66 Correct 1065 ms 73756 KB Output is correct
67 Correct 1077 ms 74040 KB Output is correct
68 Correct 1158 ms 76764 KB Output is correct
69 Correct 1145 ms 76768 KB Output is correct
70 Correct 1165 ms 76484 KB Output is correct
71 Correct 1145 ms 76360 KB Output is correct
72 Correct 1112 ms 76232 KB Output is correct
73 Correct 833 ms 69004 KB Output is correct
74 Correct 808 ms 68712 KB Output is correct
75 Correct 803 ms 68968 KB Output is correct
76 Correct 787 ms 69056 KB Output is correct
77 Correct 828 ms 68832 KB Output is correct
78 Correct 996 ms 80452 KB Output is correct
79 Correct 717 ms 69004 KB Output is correct
80 Correct 960 ms 75488 KB Output is correct