답안 #683576

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683576 2023-01-18T18:30:20 Z FatihSolak Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 123632 KB
#include <bits/stdc++.h>
#define N 1000005
#define K 20
using namespace std;
int len[N];
int maxi[N][K];
int nxt[N];
int a[N];
struct node{
    int val,maxi;
};
int gett(int l,int r){
    if(r < l)
        return -1e9;
    int ln = r-l+1;
    return max(maxi[l][len[ln]],maxi[r - (1<<len[ln]) + 1][len[ln]]);
}
struct SegTree{
    vector<node> t;
    int n;
    SegTree(int sz){
        n = sz;
        t.assign(4*n + 5,{0,0});
        build(1,1,n);
    }
    node merge(node x,node y){
        node ret = x;
        ret.val = max(ret.val,y.val);
        if(a[y.maxi] >= a[x.maxi])
            ret.maxi = y.maxi;
        return ret;
    }
    void build(int v,int tl,int tr){
        if(tl == tr){
            t[v].maxi = tl;
            return;
        }
        int tm = (tl + tr)/2;
        build(v*2,tl,tm);
        build(v*2+1,tm+1,tr);
        t[v] = merge(t[v*2],t[v*2+1]);
        for(int i = tm+1;i<=tr;i++){
            if(a[i] < a[t[v*2].maxi]){
                t[v].val = max(t[v].val,a[t[v*2].maxi] + a[i]);
            }
            else break;
        }
    }
    node get(int v,int tl,int tr,int l,int r){
        if(tr < l || r < tl){
            return {0,0};
        }
        if(l <= tl && tr <= r){
            return t[v];
        }
        int tm = (tl + tr)/2;
        node x = get(v*2,tl,tm,l,r);
        node y = get(v*2+1,tm+1,tr,l,r);
        if(x.maxi > 0)
            x.val = max(x.val,a[x.maxi] + gett(max(l,tm+1),min({nxt[x.maxi]-1,r,tr})));
        return merge(x,y);
    }
    node get(int l,int r){
        return get(1,1,n,l,r);
    }
};
void solve(){
    int n,m;
    cin >> n >> m;
    for(int i = 1;i<=n;i++){
        len[i] = len[i-1];
        if((1<<(len[i]+1)) < i)
            len[i]++;
        cin >> a[i];
        maxi[i][0] = a[i];
    }
    for(int j = 1;j<K;j++){
        for(int i = 1;i<=n;i++){
            if(i + (1<<j) - 1 <= n)
                maxi[i][j] = max(maxi[i][j-1],maxi[i + (1<<(j-1))][j-1]);
        }
    }
    stack<int> st;
    st.push(n+1);
    a[n+1] = 1e9 + 5;
    for(int i =n;i>=1;i--){
        while(a[st.top()] < a[i])
            st.pop();
        assert(st.size());
        nxt[i] = st.top();
        st.push(i);
    }
    SegTree t(n);
    for(int i = 1;i<=m;i++){
        int l,r,k;
        cin >> l >> r >> k;
        cout << (t.get(l,r).val <= k) << '\n';
    }
}
    
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 852 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 5 ms 980 KB Output is correct
15 Correct 6 ms 980 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 5 ms 892 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2964 ms 123632 KB Output is correct
2 Execution timed out 3065 ms 123532 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 152 ms 12620 KB Output is correct
2 Correct 140 ms 14592 KB Output is correct
3 Correct 99 ms 15004 KB Output is correct
4 Correct 97 ms 15032 KB Output is correct
5 Correct 108 ms 15064 KB Output is correct
6 Correct 106 ms 14796 KB Output is correct
7 Correct 90 ms 14816 KB Output is correct
8 Correct 84 ms 14500 KB Output is correct
9 Correct 41 ms 1900 KB Output is correct
10 Correct 98 ms 14492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 852 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 5 ms 980 KB Output is correct
15 Correct 6 ms 980 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 5 ms 892 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 443 ms 26176 KB Output is correct
20 Correct 461 ms 28320 KB Output is correct
21 Correct 320 ms 28316 KB Output is correct
22 Correct 333 ms 28296 KB Output is correct
23 Correct 305 ms 28348 KB Output is correct
24 Correct 269 ms 29144 KB Output is correct
25 Correct 213 ms 29212 KB Output is correct
26 Correct 242 ms 29156 KB Output is correct
27 Correct 296 ms 29172 KB Output is correct
28 Correct 238 ms 29056 KB Output is correct
29 Correct 243 ms 29236 KB Output is correct
30 Correct 256 ms 29060 KB Output is correct
31 Correct 250 ms 29160 KB Output is correct
32 Correct 252 ms 29172 KB Output is correct
33 Correct 244 ms 29112 KB Output is correct
34 Correct 227 ms 29096 KB Output is correct
35 Correct 218 ms 29136 KB Output is correct
36 Correct 210 ms 29152 KB Output is correct
37 Correct 221 ms 29172 KB Output is correct
38 Correct 224 ms 29068 KB Output is correct
39 Correct 227 ms 28908 KB Output is correct
40 Correct 191 ms 20376 KB Output is correct
41 Correct 210 ms 28680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 852 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 5 ms 980 KB Output is correct
15 Correct 6 ms 980 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 5 ms 892 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 2964 ms 123632 KB Output is correct
20 Execution timed out 3065 ms 123532 KB Time limit exceeded
21 Halted 0 ms 0 KB -