답안 #442357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442357 2021-07-07T13:59:44 Z MladenP Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1567 ms 75696 KB
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 1000010
int N, M, a[MAXN], rez[MAXN], seg[4*MAXN];
stack<int> st;
vector<pii> p;
struct Query{
    int l, r, k, idx;
}q[MAXN];
void update(int node, int l, int r, int idx, int val) {
    if(l == r) {
        seg[node] = max(seg[node], val);
        return;
    }
    if(idx <= mid) update(2*node, l, mid, idx, val);
    else update(2*node+1, mid+1, r, idx, val);
    seg[node] = max(seg[2*node], seg[2*node+1]);
}
int query(int node, int l, int r, int L, int R) {
    if(L <= l && r <= R) return seg[node];
    int rez = 0;
    if(L <= mid) rez = max(rez, query(2*node, l, mid, L, R));
    if(R > mid) rez = max(rez, query(2*node+1, mid+1, r, L, R));
    return rez;
}
bool cmp1(Query a, Query b) {
    return a.l > b.l;
}
int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> N >> M;
    a[0] = INF+1;
    st.push(0);
    for(int i = 1; i <= N; i++) {
        cin >> a[i];
        while(a[i] >= a[st.top()]) st.pop();
        p.pb({st.top(), i});
        st.push(i);
    }
    for(int i = 1; i <= M; i++) {
        cin >> q[i].l >> q[i].r >> q[i].k;
        q[i].idx = i;
    }
    sort(q+1, q+1+M, cmp1);
    sort(all(p));
    int id = N-1;
    for(int i = 1; i <= M; i++) {
        int l = q[i].l, r = q[i].r, k = q[i].k, idx = q[i].idx;
        while(id >= 0 && l <= p[id].fi) {
            update(1, 1, N, p[id].se, a[p[id].fi]+a[p[id].se]);
            id--;
        }
        rez[idx] = (query(1, 1, N, l, r) <= k);
    }
    for(int i = 1; i <= M; i++) cout << rez[i] << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 584 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
14 Correct 6 ms 716 KB Output is correct
15 Correct 6 ms 716 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1506 ms 42120 KB Output is correct
2 Correct 1489 ms 41864 KB Output is correct
3 Correct 1526 ms 42052 KB Output is correct
4 Correct 1515 ms 42044 KB Output is correct
5 Correct 1189 ms 33700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 4800 KB Output is correct
2 Correct 115 ms 6660 KB Output is correct
3 Correct 98 ms 5688 KB Output is correct
4 Correct 103 ms 5860 KB Output is correct
5 Correct 95 ms 5796 KB Output is correct
6 Correct 93 ms 5756 KB Output is correct
7 Correct 96 ms 5696 KB Output is correct
8 Correct 99 ms 6176 KB Output is correct
9 Correct 53 ms 3768 KB Output is correct
10 Correct 98 ms 6080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 584 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
14 Correct 6 ms 716 KB Output is correct
15 Correct 6 ms 716 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 273 ms 15732 KB Output is correct
20 Correct 285 ms 15680 KB Output is correct
21 Correct 284 ms 15516 KB Output is correct
22 Correct 271 ms 15540 KB Output is correct
23 Correct 259 ms 15544 KB Output is correct
24 Correct 224 ms 13556 KB Output is correct
25 Correct 224 ms 13380 KB Output is correct
26 Correct 229 ms 13612 KB Output is correct
27 Correct 237 ms 13668 KB Output is correct
28 Correct 225 ms 13544 KB Output is correct
29 Correct 217 ms 13660 KB Output is correct
30 Correct 214 ms 13624 KB Output is correct
31 Correct 217 ms 13632 KB Output is correct
32 Correct 226 ms 13656 KB Output is correct
33 Correct 221 ms 13712 KB Output is correct
34 Correct 203 ms 13372 KB Output is correct
35 Correct 208 ms 13480 KB Output is correct
36 Correct 198 ms 13196 KB Output is correct
37 Correct 197 ms 13232 KB Output is correct
38 Correct 205 ms 13376 KB Output is correct
39 Correct 212 ms 12932 KB Output is correct
40 Correct 161 ms 11056 KB Output is correct
41 Correct 199 ms 12988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 4 ms 584 KB Output is correct
13 Correct 4 ms 716 KB Output is correct
14 Correct 6 ms 716 KB Output is correct
15 Correct 6 ms 716 KB Output is correct
16 Correct 5 ms 716 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 1506 ms 42120 KB Output is correct
20 Correct 1489 ms 41864 KB Output is correct
21 Correct 1526 ms 42052 KB Output is correct
22 Correct 1515 ms 42044 KB Output is correct
23 Correct 1189 ms 33700 KB Output is correct
24 Correct 117 ms 4800 KB Output is correct
25 Correct 115 ms 6660 KB Output is correct
26 Correct 98 ms 5688 KB Output is correct
27 Correct 103 ms 5860 KB Output is correct
28 Correct 95 ms 5796 KB Output is correct
29 Correct 93 ms 5756 KB Output is correct
30 Correct 96 ms 5696 KB Output is correct
31 Correct 99 ms 6176 KB Output is correct
32 Correct 53 ms 3768 KB Output is correct
33 Correct 98 ms 6080 KB Output is correct
34 Correct 273 ms 15732 KB Output is correct
35 Correct 285 ms 15680 KB Output is correct
36 Correct 284 ms 15516 KB Output is correct
37 Correct 271 ms 15540 KB Output is correct
38 Correct 259 ms 15544 KB Output is correct
39 Correct 224 ms 13556 KB Output is correct
40 Correct 224 ms 13380 KB Output is correct
41 Correct 229 ms 13612 KB Output is correct
42 Correct 237 ms 13668 KB Output is correct
43 Correct 225 ms 13544 KB Output is correct
44 Correct 217 ms 13660 KB Output is correct
45 Correct 214 ms 13624 KB Output is correct
46 Correct 217 ms 13632 KB Output is correct
47 Correct 226 ms 13656 KB Output is correct
48 Correct 221 ms 13712 KB Output is correct
49 Correct 203 ms 13372 KB Output is correct
50 Correct 208 ms 13480 KB Output is correct
51 Correct 198 ms 13196 KB Output is correct
52 Correct 197 ms 13232 KB Output is correct
53 Correct 205 ms 13376 KB Output is correct
54 Correct 212 ms 12932 KB Output is correct
55 Correct 161 ms 11056 KB Output is correct
56 Correct 199 ms 12988 KB Output is correct
57 Correct 1567 ms 75572 KB Output is correct
58 Correct 1554 ms 75616 KB Output is correct
59 Correct 1504 ms 75436 KB Output is correct
60 Correct 1471 ms 75428 KB Output is correct
61 Correct 1482 ms 75568 KB Output is correct
62 Correct 1480 ms 75696 KB Output is correct
63 Correct 1129 ms 65372 KB Output is correct
64 Correct 1145 ms 65380 KB Output is correct
65 Correct 1210 ms 67184 KB Output is correct
66 Correct 1180 ms 67176 KB Output is correct
67 Correct 1196 ms 67248 KB Output is correct
68 Correct 1198 ms 67420 KB Output is correct
69 Correct 1184 ms 67356 KB Output is correct
70 Correct 1209 ms 67336 KB Output is correct
71 Correct 1189 ms 67348 KB Output is correct
72 Correct 1206 ms 67464 KB Output is correct
73 Correct 1126 ms 63932 KB Output is correct
74 Correct 1156 ms 64860 KB Output is correct
75 Correct 1113 ms 63836 KB Output is correct
76 Correct 1050 ms 64000 KB Output is correct
77 Correct 1059 ms 63864 KB Output is correct
78 Correct 1172 ms 64012 KB Output is correct
79 Correct 839 ms 51860 KB Output is correct
80 Correct 1170 ms 64228 KB Output is correct