Submission #890683

# Submission time Handle Problem Language Result Execution time Memory
890683 2023-12-21T18:26:52 Z NotLinux Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
974 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int M = 4e6 + 7;
const int inf = 2e9 + 7;
// bool debug_mode = 0;
struct MergeSortTree{
    vector < int > tree[M];
    void build(vector < int > &v , int ind=1 , int l=1 , int r=N){
        for(int i = l-1;i<r;i++){
            tree[ind].push_back(v[i]);
        }
        sort(tree[ind].begin() , tree[ind].end());
        if(l != r){
            int mid = (l+r) >> 1;
            build(v , ind*2 , l , mid);
            build(v , ind*2+1 , mid+1 , r);
        }
    }
    inline int query(int ind , int val){
        auto it = lower_bound(tree[ind].begin() , tree[ind].end() , val);
        int res = -1;
        if(it != tree[ind].begin()){
            res = *(--it);
        }
        // if(debug_mode){
        //     cout << "v : ";for(auto itr : tree[ind])cout << itr << " ";cout << endl;
        //     cout << "val : " << val << endl;
        //     cout << "res : " << res << endl;
        // }
        return res;
    }
} mst;
struct SegmentTree{
    struct Node{
        int mx=0 , indx=0 , ans=-inf;
    } tree[M];
    Node merge(Node &a , Node &b){
        Node c;
        c.mx = max(a.mx , b.mx);
        int tmp = mst.query(b.indx , a.mx);
        if(tmp != -1){
            c.ans = max({a.ans , b.ans , (int)a.mx + (int)tmp});
        }
        else {
            c.ans = max(a.ans , b.ans);
        }
        return c;
    }
    void build(vector < int > &v , int ind=1 , int l=1 , int r=N){
        for(int i = l-1;i<r;i++){
            tree[ind].mx = max(tree[ind].mx , v[i]);
        }
        if(l != r){
            int mid = (l+r) >> 1;
            build(v , ind*2 , l , mid);
            build(v , ind*2+1 , mid+1 , r);
            tree[ind] = merge(tree[ind*2] , tree[ind*2+1]);
        }
        tree[ind].indx = ind;
        // cout << l << " " << r << " => " << tree[ind].mx << " " << tree[ind].ans << endl;
    }
    vector < Node > vec;
    void dfs(int ql , int qr , int ind=1 , int l=1 , int r=N){
        if(l >= ql and r <= qr){
            // cout << l << " " << r << " : " << tree[ind].mx << " " << tree[ind].ans << endl;
            vec.push_back(tree[ind]);
        }
        else if(l > qr or r < ql){
            return;
        }
        else{
            int mid = (l+r) >> 1;
            dfs(ql , qr , ind*2 , l , mid);
            dfs(ql , qr , ind*2+1 , mid+1 , r);
        }
    }
    int query(int l , int r){
        Node ret;
        // debug_mode = 1;
        for(auto itr : vec){
            ret = merge(ret , itr);
            // cout << ret.mx << " " << ret.ans << endl;
        }
        // debug_mode = 0;
        vec.clear();
        // cout << "query : " << ret.ans << endl;
        return ret.ans;
    }
} segt;
void solve(){
    int n,m;
    cin >> n >> m;
    vector < int > arr(n);
    for(int i = 0;i<n;i++){
        cin >> arr[i];
    }
    mst.build(arr,1,1,arr.size());
    segt.build(arr,1,1,arr.size());
    // cout << "---" << endl;
    for(int qt = 0;qt<m;qt++){
        int l,r,k;
        cin >> l >> r >> k;
        segt.dfs(l,r,1,1,arr.size());
        cout << (segt.query(l,r) <= k) << '\n';
        // cout << "---" << endl;
    }
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int testcase = 1;//cin >> testcase;
    while(testcase--)solve();
}
# Verdict Execution time Memory Grader output
1 Correct 37 ms 141136 KB Output is correct
2 Correct 29 ms 141144 KB Output is correct
3 Correct 29 ms 141148 KB Output is correct
4 Correct 29 ms 141140 KB Output is correct
5 Correct 29 ms 141148 KB Output is correct
6 Correct 30 ms 141404 KB Output is correct
7 Correct 29 ms 141260 KB Output is correct
8 Correct 32 ms 141252 KB Output is correct
9 Correct 36 ms 141576 KB Output is correct
10 Correct 29 ms 141136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 141136 KB Output is correct
2 Correct 29 ms 141144 KB Output is correct
3 Correct 29 ms 141148 KB Output is correct
4 Correct 29 ms 141140 KB Output is correct
5 Correct 29 ms 141148 KB Output is correct
6 Correct 30 ms 141404 KB Output is correct
7 Correct 29 ms 141260 KB Output is correct
8 Correct 32 ms 141252 KB Output is correct
9 Correct 36 ms 141576 KB Output is correct
10 Correct 29 ms 141136 KB Output is correct
11 Correct 33 ms 141508 KB Output is correct
12 Correct 34 ms 141908 KB Output is correct
13 Correct 34 ms 142052 KB Output is correct
14 Correct 37 ms 141980 KB Output is correct
15 Correct 38 ms 142136 KB Output is correct
16 Correct 34 ms 141912 KB Output is correct
17 Correct 33 ms 141660 KB Output is correct
18 Correct 34 ms 141904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 974 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 227 ms 155932 KB Output is correct
2 Correct 208 ms 156412 KB Output is correct
3 Correct 171 ms 156368 KB Output is correct
4 Correct 180 ms 156456 KB Output is correct
5 Correct 162 ms 156280 KB Output is correct
6 Correct 144 ms 156116 KB Output is correct
7 Correct 150 ms 156920 KB Output is correct
8 Correct 142 ms 156116 KB Output is correct
9 Correct 62 ms 142416 KB Output is correct
10 Correct 141 ms 156112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 141136 KB Output is correct
2 Correct 29 ms 141144 KB Output is correct
3 Correct 29 ms 141148 KB Output is correct
4 Correct 29 ms 141140 KB Output is correct
5 Correct 29 ms 141148 KB Output is correct
6 Correct 30 ms 141404 KB Output is correct
7 Correct 29 ms 141260 KB Output is correct
8 Correct 32 ms 141252 KB Output is correct
9 Correct 36 ms 141576 KB Output is correct
10 Correct 29 ms 141136 KB Output is correct
11 Correct 33 ms 141508 KB Output is correct
12 Correct 34 ms 141908 KB Output is correct
13 Correct 34 ms 142052 KB Output is correct
14 Correct 37 ms 141980 KB Output is correct
15 Correct 38 ms 142136 KB Output is correct
16 Correct 34 ms 141912 KB Output is correct
17 Correct 33 ms 141660 KB Output is correct
18 Correct 34 ms 141904 KB Output is correct
19 Correct 536 ms 173260 KB Output is correct
20 Correct 536 ms 173608 KB Output is correct
21 Correct 426 ms 173300 KB Output is correct
22 Correct 434 ms 173348 KB Output is correct
23 Correct 443 ms 173512 KB Output is correct
24 Correct 305 ms 173260 KB Output is correct
25 Correct 302 ms 173420 KB Output is correct
26 Correct 377 ms 173428 KB Output is correct
27 Correct 372 ms 173220 KB Output is correct
28 Correct 398 ms 173520 KB Output is correct
29 Correct 398 ms 173392 KB Output is correct
30 Correct 391 ms 173344 KB Output is correct
31 Correct 400 ms 173264 KB Output is correct
32 Correct 393 ms 173460 KB Output is correct
33 Correct 420 ms 173372 KB Output is correct
34 Correct 292 ms 173336 KB Output is correct
35 Correct 295 ms 173536 KB Output is correct
36 Correct 287 ms 173140 KB Output is correct
37 Correct 292 ms 173180 KB Output is correct
38 Correct 291 ms 173260 KB Output is correct
39 Correct 409 ms 173004 KB Output is correct
40 Correct 219 ms 160476 KB Output is correct
41 Correct 362 ms 172480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 141136 KB Output is correct
2 Correct 29 ms 141144 KB Output is correct
3 Correct 29 ms 141148 KB Output is correct
4 Correct 29 ms 141140 KB Output is correct
5 Correct 29 ms 141148 KB Output is correct
6 Correct 30 ms 141404 KB Output is correct
7 Correct 29 ms 141260 KB Output is correct
8 Correct 32 ms 141252 KB Output is correct
9 Correct 36 ms 141576 KB Output is correct
10 Correct 29 ms 141136 KB Output is correct
11 Correct 33 ms 141508 KB Output is correct
12 Correct 34 ms 141908 KB Output is correct
13 Correct 34 ms 142052 KB Output is correct
14 Correct 37 ms 141980 KB Output is correct
15 Correct 38 ms 142136 KB Output is correct
16 Correct 34 ms 141912 KB Output is correct
17 Correct 33 ms 141660 KB Output is correct
18 Correct 34 ms 141904 KB Output is correct
19 Runtime error 974 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -