답안 #1058785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058785 2024-08-14T13:47:43 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
684 ms 97764 KB
#include <bits/stdc++.h>
#ifdef LOCAL
    #include "/home/trcmai/code/tools.h"
    #define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
    #define debug(x...)
#endif
using namespace std;
#define all(a) a.begin(), a.end()
#define ll long long
#define endl '\n'
const int N = 1e6 + 6, LOG = 27, MOD = 1e9 + 7;
const ll INF = 1e18;
int n,q,jmp[N]; 
ll w[N];
vector<tuple<int,int,ll>>Q[N];

ll tr[4*N];
void update(int i,int l,int r,int pos,ll val){
    if(l == r){
        tr[i] = w[l]; 
        return;
    }
    int m = (r+l) >> 1; 
    if(pos <= m) update(2*i,l,m,pos,val);
    else update(2*i+1,m+1,r,pos,val);
    tr[i] = max(tr[2*i],tr[2*i+1]);
}
ll get(int i,int l,int r,int ql,int qr){
    if(l > qr || r < ql) return 0;
    if(ql <= l && r <= qr) return tr[i];
    int m = (r+l) >> 1; 
    return max(get(2*i,l,m,ql,qr),get(2*i+1,m+1,r,ql,qr));
}


signed main() {
    cin.tie(0)->sync_with_stdio(0);
    auto solver=[&](){
        cin>>n>>q;
        for(int i = 1;i <= n;++i){ 
            cin>>w[i];
            jmp[i] = i - 1; 
            while(jmp[i] && w[i] >= w[jmp[i]]) jmp[i] = jmp[jmp[i]]; 
        }
        for(int i = 1;i <= q;++i){
            int l,r; ll c; 
            cin>>l>>r>>c;
            Q[r].emplace_back(i,l,c);
        }
        vector<bool>res(q + 1);
        for(int i = 1;i <= n;++i){ 
            update(1,1,n,jmp[i],w[i] + w[jmp[i]]);
            for(auto [idx,l,c] : Q[i])
                res[idx] = (get(1,1,n,l,n) <= c);
        }
        for(int i = 1;i <= q;++i)
            cout<<res[i]<<endl;
    };
    int t = 1; // cin>>t;
    while (t--) solver();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 3 ms 27132 KB Output is correct
3 Incorrect 3 ms 27148 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 3 ms 27132 KB Output is correct
3 Incorrect 3 ms 27148 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 680 ms 97376 KB Output is correct
2 Correct 650 ms 97744 KB Output is correct
3 Correct 656 ms 97644 KB Output is correct
4 Correct 639 ms 97764 KB Output is correct
5 Incorrect 684 ms 87592 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 33364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 3 ms 27132 KB Output is correct
3 Incorrect 3 ms 27148 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 26972 KB Output is correct
2 Correct 3 ms 27132 KB Output is correct
3 Incorrect 3 ms 27148 KB Output isn't correct
4 Halted 0 ms 0 KB -