답안 #1095113

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095113 2024-10-01T09:59:55 Z KasymK Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1191 ms 124752 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e6+6;
const int INF = 2e9;
int v[N], id[N], l[N], r[N], k[N], ans[N];
vector<int> Q[N];

struct node{
    int l, r, val;
} seg[N<<2];

void build(int x, int l, int r){
    seg[x].l = l, seg[x].r = r;
    if(l == r){
        seg[x].val = -INF;
        return;
    }
    int mid = (l+r)>>1;
    build(x<<1, l, mid);
    build(x<<1|1, mid+1, r);
    seg[x].val = max(seg[x<<1].val, seg[x<<1|1].val);
}

void update(int x, int k, int u){
    if(seg[x].l == seg[x].r){
        seg[x].val = u;
        return;
    }
    int mid = (seg[x].l+seg[x].r)>>1;
    if(k <= mid)
        update(x<<1, k, u);
    else
        update(x<<1|1, k, u);
    seg[x].val = max(seg[x<<1].val, seg[x<<1|1].val);
}

int query(int x, int l, int r){
    if(seg[x].l == l and seg[x].r == r)
        return seg[x].val;
    int mid = (seg[x].l+seg[x].r)>>1;
    if(r <= mid)
        return query(x<<1, l, r);
    else if(l > mid)
        return query(x<<1|1, l, r);
    else
        return max(query(x<<1, l, mid), query(x<<1|1, mid+1, r));
}

int main(){
    // freopen("file.txt", "r", stdin);
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i){
        int x;
        scanf("%d", &x);
        v[i] = x;
    }
    stack<int> st;
    for(int i = 1; i <= n; ++i){
        while(!st.empty() and v[st.top()] <= v[i])
            st.pop();
        if(st.empty())
            id[i] = -1;
        else
            id[i] = st.top();
        st.push(i);
    }
    // for(int i = 1; i <= n; ++i)
    //     printf("%d ", id[i]);
    // puts("");
    // wr;
    for(int i = 1; i <= q; ++i){
        scanf("%d%d%d", &l[i], &r[i], &k[i]);
        Q[r[i]].pb(i);
    }
    build(1, 1, n);
    for(int j = 1; j <= n; ++j){
        int i = id[j];
        if(~i)
            update(1, i, v[i]+v[j]);
        for(auto &ww : Q[j])
            ans[ww] = (query(1, l[ww], r[ww]) <= k[ww]);
    }
    for(int i = 1; i <= q; ++i)
        printf("%d\n", ans[i]);
    return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
sortbooks.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         scanf("%d%d%d", &l[i], &r[i], &k[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23896 KB Output is correct
2 Correct 9 ms 23900 KB Output is correct
3 Correct 9 ms 23948 KB Output is correct
4 Correct 9 ms 23896 KB Output is correct
5 Correct 9 ms 23752 KB Output is correct
6 Correct 11 ms 23900 KB Output is correct
7 Correct 11 ms 23896 KB Output is correct
8 Correct 13 ms 23900 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 11 ms 23940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23896 KB Output is correct
2 Correct 9 ms 23900 KB Output is correct
3 Correct 9 ms 23948 KB Output is correct
4 Correct 9 ms 23896 KB Output is correct
5 Correct 9 ms 23752 KB Output is correct
6 Correct 11 ms 23900 KB Output is correct
7 Correct 11 ms 23896 KB Output is correct
8 Correct 13 ms 23900 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 11 ms 23940 KB Output is correct
11 Correct 12 ms 24156 KB Output is correct
12 Correct 13 ms 24360 KB Output is correct
13 Correct 13 ms 24200 KB Output is correct
14 Correct 13 ms 24412 KB Output is correct
15 Correct 13 ms 24360 KB Output is correct
16 Correct 13 ms 24408 KB Output is correct
17 Correct 12 ms 24156 KB Output is correct
18 Correct 14 ms 24412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1191 ms 123728 KB Output is correct
2 Correct 1164 ms 124752 KB Output is correct
3 Correct 1129 ms 124496 KB Output is correct
4 Correct 1070 ms 124752 KB Output is correct
5 Correct 910 ms 124496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 33000 KB Output is correct
2 Correct 91 ms 32232 KB Output is correct
3 Correct 73 ms 32880 KB Output is correct
4 Correct 72 ms 33104 KB Output is correct
5 Correct 75 ms 32988 KB Output is correct
6 Correct 63 ms 31872 KB Output is correct
7 Correct 61 ms 31992 KB Output is correct
8 Correct 90 ms 32720 KB Output is correct
9 Correct 43 ms 27372 KB Output is correct
10 Correct 70 ms 32720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23896 KB Output is correct
2 Correct 9 ms 23900 KB Output is correct
3 Correct 9 ms 23948 KB Output is correct
4 Correct 9 ms 23896 KB Output is correct
5 Correct 9 ms 23752 KB Output is correct
6 Correct 11 ms 23900 KB Output is correct
7 Correct 11 ms 23896 KB Output is correct
8 Correct 13 ms 23900 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 11 ms 23940 KB Output is correct
11 Correct 12 ms 24156 KB Output is correct
12 Correct 13 ms 24360 KB Output is correct
13 Correct 13 ms 24200 KB Output is correct
14 Correct 13 ms 24412 KB Output is correct
15 Correct 13 ms 24360 KB Output is correct
16 Correct 13 ms 24408 KB Output is correct
17 Correct 12 ms 24156 KB Output is correct
18 Correct 14 ms 24412 KB Output is correct
19 Correct 211 ms 44968 KB Output is correct
20 Correct 190 ms 44884 KB Output is correct
21 Correct 170 ms 43092 KB Output is correct
22 Correct 166 ms 43092 KB Output is correct
23 Correct 160 ms 43140 KB Output is correct
24 Correct 127 ms 42836 KB Output is correct
25 Correct 133 ms 42836 KB Output is correct
26 Correct 141 ms 43752 KB Output is correct
27 Correct 152 ms 43712 KB Output is correct
28 Correct 145 ms 43856 KB Output is correct
29 Correct 154 ms 44884 KB Output is correct
30 Correct 164 ms 44880 KB Output is correct
31 Correct 155 ms 44880 KB Output is correct
32 Correct 154 ms 44884 KB Output is correct
33 Correct 159 ms 44880 KB Output is correct
34 Correct 141 ms 42344 KB Output is correct
35 Correct 115 ms 42320 KB Output is correct
36 Correct 136 ms 42356 KB Output is correct
37 Correct 111 ms 42324 KB Output is correct
38 Correct 110 ms 42320 KB Output is correct
39 Correct 129 ms 43216 KB Output is correct
40 Correct 106 ms 38604 KB Output is correct
41 Correct 124 ms 42920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23896 KB Output is correct
2 Correct 9 ms 23900 KB Output is correct
3 Correct 9 ms 23948 KB Output is correct
4 Correct 9 ms 23896 KB Output is correct
5 Correct 9 ms 23752 KB Output is correct
6 Correct 11 ms 23900 KB Output is correct
7 Correct 11 ms 23896 KB Output is correct
8 Correct 13 ms 23900 KB Output is correct
9 Correct 11 ms 23896 KB Output is correct
10 Correct 11 ms 23940 KB Output is correct
11 Correct 12 ms 24156 KB Output is correct
12 Correct 13 ms 24360 KB Output is correct
13 Correct 13 ms 24200 KB Output is correct
14 Correct 13 ms 24412 KB Output is correct
15 Correct 13 ms 24360 KB Output is correct
16 Correct 13 ms 24408 KB Output is correct
17 Correct 12 ms 24156 KB Output is correct
18 Correct 14 ms 24412 KB Output is correct
19 Correct 1191 ms 123728 KB Output is correct
20 Correct 1164 ms 124752 KB Output is correct
21 Correct 1129 ms 124496 KB Output is correct
22 Correct 1070 ms 124752 KB Output is correct
23 Correct 910 ms 124496 KB Output is correct
24 Correct 86 ms 33000 KB Output is correct
25 Correct 91 ms 32232 KB Output is correct
26 Correct 73 ms 32880 KB Output is correct
27 Correct 72 ms 33104 KB Output is correct
28 Correct 75 ms 32988 KB Output is correct
29 Correct 63 ms 31872 KB Output is correct
30 Correct 61 ms 31992 KB Output is correct
31 Correct 90 ms 32720 KB Output is correct
32 Correct 43 ms 27372 KB Output is correct
33 Correct 70 ms 32720 KB Output is correct
34 Correct 211 ms 44968 KB Output is correct
35 Correct 190 ms 44884 KB Output is correct
36 Correct 170 ms 43092 KB Output is correct
37 Correct 166 ms 43092 KB Output is correct
38 Correct 160 ms 43140 KB Output is correct
39 Correct 127 ms 42836 KB Output is correct
40 Correct 133 ms 42836 KB Output is correct
41 Correct 141 ms 43752 KB Output is correct
42 Correct 152 ms 43712 KB Output is correct
43 Correct 145 ms 43856 KB Output is correct
44 Correct 154 ms 44884 KB Output is correct
45 Correct 164 ms 44880 KB Output is correct
46 Correct 155 ms 44880 KB Output is correct
47 Correct 154 ms 44884 KB Output is correct
48 Correct 159 ms 44880 KB Output is correct
49 Correct 141 ms 42344 KB Output is correct
50 Correct 115 ms 42320 KB Output is correct
51 Correct 136 ms 42356 KB Output is correct
52 Correct 111 ms 42324 KB Output is correct
53 Correct 110 ms 42320 KB Output is correct
54 Correct 129 ms 43216 KB Output is correct
55 Correct 106 ms 38604 KB Output is correct
56 Correct 124 ms 42920 KB Output is correct
57 Correct 1057 ms 123628 KB Output is correct
58 Correct 1131 ms 123964 KB Output is correct
59 Correct 1082 ms 119644 KB Output is correct
60 Correct 1027 ms 119540 KB Output is correct
61 Correct 1050 ms 119572 KB Output is correct
62 Correct 1062 ms 119656 KB Output is correct
63 Correct 642 ms 111952 KB Output is correct
64 Correct 631 ms 111864 KB Output is correct
65 Correct 812 ms 119040 KB Output is correct
66 Correct 811 ms 118876 KB Output is correct
67 Correct 814 ms 119388 KB Output is correct
68 Correct 916 ms 123600 KB Output is correct
69 Correct 951 ms 123732 KB Output is correct
70 Correct 941 ms 122964 KB Output is correct
71 Correct 971 ms 123096 KB Output is correct
72 Correct 973 ms 123044 KB Output is correct
73 Correct 597 ms 109904 KB Output is correct
74 Correct 592 ms 110712 KB Output is correct
75 Correct 580 ms 109892 KB Output is correct
76 Correct 552 ms 109908 KB Output is correct
77 Correct 560 ms 109860 KB Output is correct
78 Correct 849 ms 115652 KB Output is correct
79 Correct 589 ms 92636 KB Output is correct
80 Correct 871 ms 113508 KB Output is correct