제출 #1336268

#제출 시각아이디문제언어결과실행 시간메모리
1336268yhkhooHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
432 ms26052 KiB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1000005;

struct Query{
    int l, r, k, i;
} q[MAXN];
bool operator< (Query &a, Query &b){
    return a.r < b.r;
}
int n, m, w[MAXN], st[MAXN];
bitset<MAXN> ans;

#define lsb(x) ((x) & (-(x)))
struct Fenwick{ // 0-index suffix max
    int t[MAXN];

    Fenwick(){
        memset(t, -1, sizeof(t));
    }
    
    void update(int X, int V){
        X = n-X;
        for(; X <= n; X += lsb(X)){
            t[X] = max(t[X], V);
        }
    }

    int query(int X){
        X = n-X;
        int ret = 0;
        for(; X; X -= lsb(X)){
            ret = max(ret, t[X]);
        }
        return ret;
    }
} fw;

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i=0; i<n; i++){
        cin >> w[i];
    }
    for(int i=0; i<m; i++){
        int l, r, k;
        cin >> l >> r >> k;
        l--; r--;
        q[i] = {l, r, k, i};
    }
    sort(q, q+m);
    auto qp = q;
    auto stb = st;
    for(int i=0; i<n; i++){
        while(stb != st && w[*(stb-1)] <= w[i]){
            stb--;
        }
        if(stb != st){
            int tw = w[i] + w[*(stb-1)];
            fw.update(*(stb-1), tw);
        }
        *(stb++) = i;
        while(qp != q+m && qp->r == i){
            ans[qp->i] = fw.query(qp->l) <= qp->k;
            qp++;
        }
    }
    for(int i=0; i<m; i++){
        cout << ans[i] << '\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...