답안 #539321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
539321 2022-03-18T17:32:05 Z PiejanVDC Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
614 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++]);
}

int ans;
int l,r;

int query(int i, int j, int p, int mx, bool r_) {
    if(i > r || j < l)
        return 0;
    if(i >= l && j <= r) {
        ans = max(ans, st[p]);
        if(r_) {
            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, 0));
    mx = max(mx, query(mid+1, j, 2*p+1, mx, 1));
    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,0,0);
        cout << (ans <= k) << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 2 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 2 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 614 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 434 ms 36160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 2 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 2 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -