답안 #498177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498177 2021-12-24T14:02:08 Z kingline Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1272 ms 99548 KB
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
//#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
//#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
#define int long long
#define pii pair < int, int >
#define pll pair < long long, long long >

using namespace std;

typedef long long ll;
const int N = 1e6 + 5;
const int M = 305;
const int mod = 1e9 + 7;

int n, m, a[N], L[N], t[4 * N], ans[N];
vector < pair < int, pii > > pos[N];

void update(int v, int l, int r, int pos, int val) {
    if(l == r) {
        t[v] = max(t[v], val);
        return;
    }
    int md = (l + r) / 2;
    if(pos <= md) update(v * 2, l, md, pos, val);
    else update(v * 2 + 1, md + 1, r, pos, val);
    t[v] = max(t[v * 2], t[v * 2 + 1]);
}

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

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //file("pieaters");
    cin >> n >> m;
    stack < pii > st;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        while(st.size() && (st.top()).first <= a[i]) {
            st.pop();
        }
        if(st.size()) L[i] = (st.top()).second;
        st.push({a[i], i});
    }
    for(int i = 1; i <= m; i++) {
        int l, r, k;
        cin >> l >> r >> k;
        pos[r].pb({l, {k, i}});
    }
    for(int i = 1; i <= n; i++) {
        if(L[i] > 0) update(1, 1, n, L[i], a[i] + a[L[i]]);
        for(int j = 0; j < pos[i].size(); j++) {
            int lef = pos[i][j].first, kk = pos[i][j].second.first, query = pos[i][j].second.second;
            if(get(1, 1, n, lef, i) > kk) {
                ans[query] = 0;
            } else {
                ans[query] = 1;
            }
        }
    }
    for(int i = 1; i <= m; i++) {
        cout << ans[i] << endl;
    }
}













Compilation message

sortbooks.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   51 | main() {
      | ^~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:73:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int j = 0; j < pos[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23816 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 13 ms 23864 KB Output is correct
7 Correct 13 ms 23740 KB Output is correct
8 Correct 13 ms 23876 KB Output is correct
9 Correct 13 ms 23856 KB Output is correct
10 Correct 13 ms 23756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23816 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 13 ms 23864 KB Output is correct
7 Correct 13 ms 23740 KB Output is correct
8 Correct 13 ms 23876 KB Output is correct
9 Correct 13 ms 23856 KB Output is correct
10 Correct 13 ms 23756 KB Output is correct
11 Correct 15 ms 23944 KB Output is correct
12 Correct 15 ms 24144 KB Output is correct
13 Correct 15 ms 24120 KB Output is correct
14 Correct 17 ms 24176 KB Output is correct
15 Correct 18 ms 24188 KB Output is correct
16 Correct 17 ms 24132 KB Output is correct
17 Correct 15 ms 24012 KB Output is correct
18 Correct 16 ms 24140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1258 ms 98224 KB Output is correct
2 Correct 1272 ms 98256 KB Output is correct
3 Correct 1268 ms 98172 KB Output is correct
4 Correct 1264 ms 98172 KB Output is correct
5 Correct 1066 ms 73896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 31556 KB Output is correct
2 Correct 83 ms 31788 KB Output is correct
3 Correct 80 ms 28808 KB Output is correct
4 Correct 84 ms 29260 KB Output is correct
5 Correct 82 ms 29196 KB Output is correct
6 Correct 66 ms 29444 KB Output is correct
7 Correct 65 ms 29532 KB Output is correct
8 Correct 77 ms 29492 KB Output is correct
9 Correct 44 ms 28240 KB Output is correct
10 Correct 76 ms 29460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23816 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 13 ms 23864 KB Output is correct
7 Correct 13 ms 23740 KB Output is correct
8 Correct 13 ms 23876 KB Output is correct
9 Correct 13 ms 23856 KB Output is correct
10 Correct 13 ms 23756 KB Output is correct
11 Correct 15 ms 23944 KB Output is correct
12 Correct 15 ms 24144 KB Output is correct
13 Correct 15 ms 24120 KB Output is correct
14 Correct 17 ms 24176 KB Output is correct
15 Correct 18 ms 24188 KB Output is correct
16 Correct 17 ms 24132 KB Output is correct
17 Correct 15 ms 24012 KB Output is correct
18 Correct 16 ms 24140 KB Output is correct
19 Correct 224 ms 39468 KB Output is correct
20 Correct 225 ms 39544 KB Output is correct
21 Correct 167 ms 40104 KB Output is correct
22 Correct 168 ms 40020 KB Output is correct
23 Correct 178 ms 40068 KB Output is correct
24 Correct 143 ms 34564 KB Output is correct
25 Correct 143 ms 35000 KB Output is correct
26 Correct 164 ms 34536 KB Output is correct
27 Correct 164 ms 34496 KB Output is correct
28 Correct 171 ms 34428 KB Output is correct
29 Correct 184 ms 34288 KB Output is correct
30 Correct 181 ms 34268 KB Output is correct
31 Correct 188 ms 34388 KB Output is correct
32 Correct 182 ms 34304 KB Output is correct
33 Correct 192 ms 34304 KB Output is correct
34 Correct 134 ms 34568 KB Output is correct
35 Correct 135 ms 34500 KB Output is correct
36 Correct 130 ms 34416 KB Output is correct
37 Correct 133 ms 34508 KB Output is correct
38 Correct 135 ms 34452 KB Output is correct
39 Correct 162 ms 35704 KB Output is correct
40 Correct 134 ms 32988 KB Output is correct
41 Correct 160 ms 34616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 12 ms 23816 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 13 ms 23864 KB Output is correct
7 Correct 13 ms 23740 KB Output is correct
8 Correct 13 ms 23876 KB Output is correct
9 Correct 13 ms 23856 KB Output is correct
10 Correct 13 ms 23756 KB Output is correct
11 Correct 15 ms 23944 KB Output is correct
12 Correct 15 ms 24144 KB Output is correct
13 Correct 15 ms 24120 KB Output is correct
14 Correct 17 ms 24176 KB Output is correct
15 Correct 18 ms 24188 KB Output is correct
16 Correct 17 ms 24132 KB Output is correct
17 Correct 15 ms 24012 KB Output is correct
18 Correct 16 ms 24140 KB Output is correct
19 Correct 1258 ms 98224 KB Output is correct
20 Correct 1272 ms 98256 KB Output is correct
21 Correct 1268 ms 98172 KB Output is correct
22 Correct 1264 ms 98172 KB Output is correct
23 Correct 1066 ms 73896 KB Output is correct
24 Correct 94 ms 31556 KB Output is correct
25 Correct 83 ms 31788 KB Output is correct
26 Correct 80 ms 28808 KB Output is correct
27 Correct 84 ms 29260 KB Output is correct
28 Correct 82 ms 29196 KB Output is correct
29 Correct 66 ms 29444 KB Output is correct
30 Correct 65 ms 29532 KB Output is correct
31 Correct 77 ms 29492 KB Output is correct
32 Correct 44 ms 28240 KB Output is correct
33 Correct 76 ms 29460 KB Output is correct
34 Correct 224 ms 39468 KB Output is correct
35 Correct 225 ms 39544 KB Output is correct
36 Correct 167 ms 40104 KB Output is correct
37 Correct 168 ms 40020 KB Output is correct
38 Correct 178 ms 40068 KB Output is correct
39 Correct 143 ms 34564 KB Output is correct
40 Correct 143 ms 35000 KB Output is correct
41 Correct 164 ms 34536 KB Output is correct
42 Correct 164 ms 34496 KB Output is correct
43 Correct 171 ms 34428 KB Output is correct
44 Correct 184 ms 34288 KB Output is correct
45 Correct 181 ms 34268 KB Output is correct
46 Correct 188 ms 34388 KB Output is correct
47 Correct 182 ms 34304 KB Output is correct
48 Correct 192 ms 34304 KB Output is correct
49 Correct 134 ms 34568 KB Output is correct
50 Correct 135 ms 34500 KB Output is correct
51 Correct 130 ms 34416 KB Output is correct
52 Correct 133 ms 34508 KB Output is correct
53 Correct 135 ms 34452 KB Output is correct
54 Correct 162 ms 35704 KB Output is correct
55 Correct 134 ms 32988 KB Output is correct
56 Correct 160 ms 34616 KB Output is correct
57 Correct 1250 ms 98512 KB Output is correct
58 Correct 1252 ms 98580 KB Output is correct
59 Correct 1164 ms 99268 KB Output is correct
60 Correct 1207 ms 99292 KB Output is correct
61 Correct 1186 ms 99144 KB Output is correct
62 Correct 1175 ms 99548 KB Output is correct
63 Correct 711 ms 76796 KB Output is correct
64 Correct 715 ms 77004 KB Output is correct
65 Correct 1000 ms 75516 KB Output is correct
66 Correct 980 ms 75144 KB Output is correct
67 Correct 1006 ms 75152 KB Output is correct
68 Correct 1053 ms 74256 KB Output is correct
69 Correct 1074 ms 74228 KB Output is correct
70 Correct 1071 ms 74340 KB Output is correct
71 Correct 1077 ms 74288 KB Output is correct
72 Correct 1057 ms 74576 KB Output is correct
73 Correct 677 ms 72280 KB Output is correct
74 Correct 679 ms 72360 KB Output is correct
75 Correct 672 ms 72644 KB Output is correct
76 Correct 723 ms 72696 KB Output is correct
77 Correct 655 ms 72184 KB Output is correct
78 Correct 943 ms 80024 KB Output is correct
79 Correct 689 ms 66772 KB Output is correct
80 Correct 886 ms 76376 KB Output is correct