답안 #539360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
539360 2022-03-18T18:36:45 Z PiejanVDC Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
1183 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

vector<int>w;
vector<int>st;
vector<vector<int>>v;

void build(int i, int j, int p) {
    if(i == j) {
        st[p] = 0;
        v[p] = {w[i]};
        return;
    }
    int mid = (i+j)/2;
    build(i, mid, 2*p),
    build(mid+1, j, 2*p+1);
    const int n = (int)v[2*p].size(),
              m = (int)v[2*p+1].size();
    int pp = 0;
    st[p] = max(st[2*p], st[2*p+1]);
    for(int ii = 0 ; ii < n ; ii++) {
        while(pp < m && v[2*p+1][pp] < v[2*p][ii]) {
            st[p] = max(st[p], v[2*p].back() + v[2*p+1][pp]);
            v[p].push_back(v[2*p+1][pp]);
            pp++;
        }
        v[p].push_back(v[2*p][ii]);
    }
    while(pp < m)
        v[p].push_back(v[2*p+1][pp++]);
    //cout << i <<" " << j << " " << st[p] << "\n";
}

int ans;
int l,r;

int query(int i, int j, int p, int mx) {
    if(i > r || j < l)
        return -1;
    if(i >= l && j <= r) {
        ans = max(ans, st[p]);
        if(1) {
            const int n = (int)v[p].size();
            int le = 0, re = n-1, ret = -1;
            while(le <= re) {
                int mi = (le+re)/2;
                if(v[p][mi] < mx) {
                    ret = mi;
                    le = mi+1;
                } else re = mi-1;
            }
            ans = max(ans, (ret == -1 ? 0 : mx + v[p][ret]));
        }
        return v[p].back();
    }
    int mid = (i+j)/2;
    mx = max(mx, query(i, mid, 2*p, mx));
    mx = max(mx, query(mid+1, j, 2*p+1, mx));
    return mx;
}

signed main() {
    int n,q; cin>>n>>q;
    w.resize(n);
    st.resize(8 * n);
    v.resize(8 * n);
    for(auto &z : w)
        cin>>z;
    build(0, n-1, 1);
    while(q--) {
        int k; cin>>l>>r>>k;
        l--,r--;
        ans = 0;
        query(0,n-1,1,-1);
        cout << (ans <= k) << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 12 ms 724 KB Output is correct
12 Correct 14 ms 2036 KB Output is correct
13 Correct 14 ms 2004 KB Output is correct
14 Correct 20 ms 2064 KB Output is correct
15 Correct 23 ms 2084 KB Output is correct
16 Correct 17 ms 2004 KB Output is correct
17 Correct 17 ms 1652 KB Output is correct
18 Correct 19 ms 2004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 608 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 506 ms 35968 KB Output is correct
2 Correct 500 ms 35944 KB Output is correct
3 Correct 428 ms 35956 KB Output is correct
4 Correct 437 ms 35984 KB Output is correct
5 Correct 487 ms 36072 KB Output is correct
6 Correct 382 ms 35960 KB Output is correct
7 Correct 425 ms 35888 KB Output is correct
8 Correct 422 ms 35904 KB Output is correct
9 Correct 243 ms 748 KB Output is correct
10 Correct 414 ms 35956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 12 ms 724 KB Output is correct
12 Correct 14 ms 2036 KB Output is correct
13 Correct 14 ms 2004 KB Output is correct
14 Correct 20 ms 2064 KB Output is correct
15 Correct 23 ms 2084 KB Output is correct
16 Correct 17 ms 2004 KB Output is correct
17 Correct 17 ms 1652 KB Output is correct
18 Correct 19 ms 2004 KB Output is correct
19 Correct 1183 ms 72416 KB Output is correct
20 Correct 1135 ms 72476 KB Output is correct
21 Correct 1042 ms 72520 KB Output is correct
22 Correct 997 ms 72644 KB Output is correct
23 Correct 1051 ms 72536 KB Output is correct
24 Correct 983 ms 72484 KB Output is correct
25 Correct 911 ms 72424 KB Output is correct
26 Correct 1065 ms 72496 KB Output is correct
27 Correct 998 ms 72440 KB Output is correct
28 Correct 1056 ms 72440 KB Output is correct
29 Correct 1076 ms 72492 KB Output is correct
30 Correct 1118 ms 72464 KB Output is correct
31 Correct 1145 ms 72428 KB Output is correct
32 Correct 1136 ms 72400 KB Output is correct
33 Correct 1071 ms 72500 KB Output is correct
34 Correct 959 ms 72472 KB Output is correct
35 Correct 953 ms 72444 KB Output is correct
36 Correct 925 ms 72488 KB Output is correct
37 Correct 901 ms 72520 KB Output is correct
38 Correct 884 ms 72520 KB Output is correct
39 Correct 969 ms 72560 KB Output is correct
40 Correct 774 ms 45572 KB Output is correct
41 Correct 933 ms 72456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 12 ms 724 KB Output is correct
12 Correct 14 ms 2036 KB Output is correct
13 Correct 14 ms 2004 KB Output is correct
14 Correct 20 ms 2064 KB Output is correct
15 Correct 23 ms 2084 KB Output is correct
16 Correct 17 ms 2004 KB Output is correct
17 Correct 17 ms 1652 KB Output is correct
18 Correct 19 ms 2004 KB Output is correct
19 Runtime error 608 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -