답안 #1097344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097344 2024-10-07T01:28:57 Z TrinhKhanhDung Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
542 ms 63488 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(998244353)

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

const int MAX = 1e6 + 10;

struct fen{
    vector<int> tree;
    int n;

    fen(int _n = 0){
        n = _n;
        tree.resize(n + 3, 0);
    }

    void upd(int p, int c){
        for(; p > 0; p -= p & -p) maximize(tree[p], c);
    }

    int get(int p){
        int ans = 0;
        for(; p <= n; p += p & -p) maximize(ans, tree[p]);
        return ans;
    }
};

const int maxN = 1e6 + 10;

int N, Q;
int a[maxN], ans[maxN];
vector<array<int, 4>> que;

void solve(){
    cin >> N >> Q;
    for(int i = 1; i <= N; i++){
        int x; cin >> x;
        a[i] = x;
    }
    for(int i = 1; i <= Q; i++){
        int l, r, k; cin >> l >> r >> k;
        que.push_back({r, l, k, i});
    }
    sort(ALL(que));

    fen bit(N);
    stack<int> st;
    int j = 0;
    for(int i = 1; i <= N; i++){
        while(sz(st) && a[st.top()] <= a[i]) st.pop();
        if(sz(st)) bit.upd(st.top(), a[st.top()] + a[i]);
        st.push(i);
        while(j < Q && que[j][0] <= i){
            ans[que[j][3]] = (bit.get(que[j][1]) <= que[j][2]);
            j++;
        }
    }

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

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//     freopen("boxes.inp","r",stdin);
//     freopen("boxes.out","w",stdout);

    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 584 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 499 ms 61488 KB Output is correct
2 Correct 519 ms 62604 KB Output is correct
3 Correct 542 ms 62368 KB Output is correct
4 Correct 477 ms 62620 KB Output is correct
5 Correct 462 ms 62620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 5328 KB Output is correct
2 Correct 42 ms 5328 KB Output is correct
3 Correct 38 ms 5304 KB Output is correct
4 Correct 45 ms 5324 KB Output is correct
5 Correct 37 ms 5252 KB Output is correct
6 Correct 38 ms 5176 KB Output is correct
7 Correct 37 ms 5060 KB Output is correct
8 Correct 37 ms 5064 KB Output is correct
9 Correct 31 ms 3940 KB Output is correct
10 Correct 39 ms 5064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 584 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 106 ms 12732 KB Output is correct
20 Correct 95 ms 12712 KB Output is correct
21 Correct 94 ms 12620 KB Output is correct
22 Correct 94 ms 12736 KB Output is correct
23 Correct 93 ms 12524 KB Output is correct
24 Correct 94 ms 12624 KB Output is correct
25 Correct 100 ms 12624 KB Output is correct
26 Correct 91 ms 12612 KB Output is correct
27 Correct 95 ms 12736 KB Output is correct
28 Correct 89 ms 12692 KB Output is correct
29 Correct 90 ms 12740 KB Output is correct
30 Correct 90 ms 12732 KB Output is correct
31 Correct 90 ms 12708 KB Output is correct
32 Correct 90 ms 12844 KB Output is correct
33 Correct 88 ms 12896 KB Output is correct
34 Correct 89 ms 12480 KB Output is correct
35 Correct 90 ms 12480 KB Output is correct
36 Correct 92 ms 12160 KB Output is correct
37 Correct 86 ms 12128 KB Output is correct
38 Correct 90 ms 12520 KB Output is correct
39 Correct 90 ms 11452 KB Output is correct
40 Correct 78 ms 10244 KB Output is correct
41 Correct 83 ms 10944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 584 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 499 ms 61488 KB Output is correct
20 Correct 519 ms 62604 KB Output is correct
21 Correct 542 ms 62368 KB Output is correct
22 Correct 477 ms 62620 KB Output is correct
23 Correct 462 ms 62620 KB Output is correct
24 Correct 45 ms 5328 KB Output is correct
25 Correct 42 ms 5328 KB Output is correct
26 Correct 38 ms 5304 KB Output is correct
27 Correct 45 ms 5324 KB Output is correct
28 Correct 37 ms 5252 KB Output is correct
29 Correct 38 ms 5176 KB Output is correct
30 Correct 37 ms 5060 KB Output is correct
31 Correct 37 ms 5064 KB Output is correct
32 Correct 31 ms 3940 KB Output is correct
33 Correct 39 ms 5064 KB Output is correct
34 Correct 106 ms 12732 KB Output is correct
35 Correct 95 ms 12712 KB Output is correct
36 Correct 94 ms 12620 KB Output is correct
37 Correct 94 ms 12736 KB Output is correct
38 Correct 93 ms 12524 KB Output is correct
39 Correct 94 ms 12624 KB Output is correct
40 Correct 100 ms 12624 KB Output is correct
41 Correct 91 ms 12612 KB Output is correct
42 Correct 95 ms 12736 KB Output is correct
43 Correct 89 ms 12692 KB Output is correct
44 Correct 90 ms 12740 KB Output is correct
45 Correct 90 ms 12732 KB Output is correct
46 Correct 90 ms 12708 KB Output is correct
47 Correct 90 ms 12844 KB Output is correct
48 Correct 88 ms 12896 KB Output is correct
49 Correct 89 ms 12480 KB Output is correct
50 Correct 90 ms 12480 KB Output is correct
51 Correct 92 ms 12160 KB Output is correct
52 Correct 86 ms 12128 KB Output is correct
53 Correct 90 ms 12520 KB Output is correct
54 Correct 90 ms 11452 KB Output is correct
55 Correct 78 ms 10244 KB Output is correct
56 Correct 83 ms 10944 KB Output is correct
57 Correct 528 ms 63312 KB Output is correct
58 Correct 494 ms 63216 KB Output is correct
59 Correct 478 ms 63212 KB Output is correct
60 Correct 490 ms 63488 KB Output is correct
61 Correct 466 ms 63172 KB Output is correct
62 Correct 474 ms 63132 KB Output is correct
63 Correct 441 ms 61268 KB Output is correct
64 Correct 473 ms 61440 KB Output is correct
65 Correct 466 ms 63128 KB Output is correct
66 Correct 454 ms 63320 KB Output is correct
67 Correct 463 ms 63084 KB Output is correct
68 Correct 448 ms 63136 KB Output is correct
69 Correct 449 ms 63368 KB Output is correct
70 Correct 463 ms 63132 KB Output is correct
71 Correct 508 ms 63136 KB Output is correct
72 Correct 478 ms 63132 KB Output is correct
73 Correct 457 ms 60048 KB Output is correct
74 Correct 436 ms 60828 KB Output is correct
75 Correct 440 ms 59808 KB Output is correct
76 Correct 428 ms 59732 KB Output is correct
77 Correct 441 ms 59804 KB Output is correct
78 Correct 436 ms 57180 KB Output is correct
79 Correct 373 ms 48520 KB Output is correct
80 Correct 416 ms 54432 KB Output is correct