답안 #523053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523053 2022-02-06T19:27:19 Z infertechno2 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
296 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll Size=1e6+1;

class node{
public:
    set<ll> nums;
    ll ans;
};

ll w[Size];
node seg_tree[4*Size];

void build(ll l,ll r,ll i){
    if(l==r){
        seg_tree[i].ans=0;
        seg_tree[i].nums.insert(w[l]);
    }else{
        ll mid=(l+r)/2;
        build(l,mid,i*2);
        build(mid+1,r,i*2+1);
        ll max_v=*seg_tree[i*2].nums.rbegin(),largest_so_far=0;
        for(auto itr:seg_tree[i*2+1].nums){
            seg_tree[i].nums.insert(itr);
            if(itr>max_v)break;
            largest_so_far=itr;
        }
        for(auto itr:seg_tree[i*2].nums){
            seg_tree[i].nums.insert(itr);
        }
        seg_tree[i].ans=max(max(seg_tree[i*2].ans,seg_tree[i*2+1].ans),max_v+largest_so_far);
    }
}
node query(ll l,ll r,ll i,ll tl,ll tr){
    if(l>tr or r<tl){
        node a;
        a.ans=-1;
        return a;
    }
    if(l==r){
        return seg_tree[i];
    }else{
        ll mid=(l+r)/2;
        node n1=query(l,mid,i*2,tl,min(tr,mid));
        node n2=query(mid+1,r,i*2+1,max(tl,mid+1),tr);
        node res;
        if(n1.ans==-1)return n2;
        if(n2.ans==-1)return n1;
        ll max_v=*n1.nums.rbegin(),largest_so_far=0;
        for(auto itr:n2.nums){
            res.nums.insert(itr);
            if(itr>max_v)break;
            largest_so_far=itr;
        }
        for(auto itr:n1.nums){
            res.nums.insert(itr);
        }
        res.ans=max(max(n1.ans,n2.ans),max_v+largest_so_far);
        return res;
    }
}



void solve(){
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<n;i++){
        cin>>w[i];
    }
    build(0,n-1,1);
    while(m--){
        ll l,r,k;
        cin>>l>>r>>k;
        l--; r--;
        node res=query(0,n-1,1,l,r);
        cout<<(res.ans<=k)<<"\n";
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    while(t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 219476 KB Output is correct
2 Correct 99 ms 219416 KB Output is correct
3 Incorrect 99 ms 219444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 219476 KB Output is correct
2 Correct 99 ms 219416 KB Output is correct
3 Incorrect 99 ms 219444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 296 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 162 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 219476 KB Output is correct
2 Correct 99 ms 219416 KB Output is correct
3 Incorrect 99 ms 219444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 219476 KB Output is correct
2 Correct 99 ms 219416 KB Output is correct
3 Incorrect 99 ms 219444 KB Output isn't correct
4 Halted 0 ms 0 KB -