Submission #956461

# Submission time Handle Problem Language Result Execution time Memory
956461 2024-04-02T01:57:21 Z Darren0724 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
485 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=1000005;
const int INF=1e9;
vector<int> t;
struct segtree{
    struct seg{
        vector<int> v;
        int val=0;
    }tr[N<<2];
    seg merge(seg a,seg b){
        seg ans;
        ans.val=max(a.val,b.val);
        auto &c=a.v,&d=b.v;
        int ptr1=0,ptr2=0;
        while(ptr1<c.size()&&ptr2<d.size()){
            if(c[ptr1]<=d[ptr2]){
                if(ptr2>0)ans.val=max(ans.val,c[ptr1]+d[ptr2-1]);
                ans.v.push_back(c[ptr1++]);
            }
            else{
                ans.v.push_back(d[ptr2++]);
            }
        }
        while(ptr1<c.size()){
            if(ptr2>0)ans.val=max(ans.val,c[ptr1]+d[ptr2-1]);
            ans.v.push_back(c[ptr1++]);
        }
        while(ptr2<d.size()){
            ans.v.push_back(d[ptr2++]);
        }
        return ans;
    }
    void build(vector<int> &a,int id,int l,int r){
        if(r-l==1){
            tr[id].v.push_back(a[l]);
            return;        
        }
        int m=(l+r)>>1;
        build(a,id<<1,l,m);
        build(a,id<<1|1,m,r);
        tr[id]=merge(tr[id<<1],tr[id<<1|1]);
    }
    void ask(int id,int a,int b,int l,int r){
        if(a<=l&&b>=r)return t.push_back(id);
        int m=(l+r)>>1;
        if(a<m)ask(id<<1,a,b,l,m);
        if(b>m)ask(id<<1|1,a,b,m,r);
    }
};
int32_t main() {
    LCBorz;
    int n,q;cin>>n>>q;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    segtree st;
    st.build(v,1,0,n);
    for(int i=0;i<q;i++){
        int l,r,c;cin>>l>>r>>c;
        t.clear();
        st.ask(1,l-1,r,0,n);
        int m=t.size();
        int mx=0;
        int ans=0;
        for(int j=0;j<m;j++){
            int f=t[j];
            auto &c=st.tr[f].v;
            ans=max(ans,st.tr[f].val);
            if(mx>c[0]){
                int t=lower_bound(all(c),mx)-c.begin()-1;
                ans=max(ans,mx+c[t]);
            }
            mx=max(mx,c.back());
        }
        cout<<(ans<=c)<<endl;
    }
    
    return 0;
}

Compilation message

sortbooks.cpp: In member function 'segtree::seg segtree::merge(segtree::seg, segtree::seg)':
sortbooks.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         while(ptr1<c.size()&&ptr2<d.size()){
      |               ~~~~^~~~~~~~~
sortbooks.cpp:19:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         while(ptr1<c.size()&&ptr2<d.size()){
      |                              ~~~~^~~~~~~~~
sortbooks.cpp:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         while(ptr1<c.size()){
      |               ~~~~^~~~~~~~~
sortbooks.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         while(ptr2<d.size()){
      |               ~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 76 ms 125524 KB Output is correct
2 Correct 76 ms 125524 KB Output is correct
3 Correct 77 ms 125680 KB Output is correct
4 Correct 79 ms 125776 KB Output is correct
5 Correct 80 ms 125572 KB Output is correct
6 Correct 79 ms 125680 KB Output is correct
7 Correct 78 ms 125528 KB Output is correct
8 Correct 77 ms 125520 KB Output is correct
9 Correct 76 ms 125524 KB Output is correct
10 Correct 78 ms 125716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 125524 KB Output is correct
2 Correct 76 ms 125524 KB Output is correct
3 Correct 77 ms 125680 KB Output is correct
4 Correct 79 ms 125776 KB Output is correct
5 Correct 80 ms 125572 KB Output is correct
6 Correct 79 ms 125680 KB Output is correct
7 Correct 78 ms 125528 KB Output is correct
8 Correct 77 ms 125520 KB Output is correct
9 Correct 76 ms 125524 KB Output is correct
10 Correct 78 ms 125716 KB Output is correct
11 Correct 79 ms 125776 KB Output is correct
12 Correct 80 ms 126288 KB Output is correct
13 Correct 81 ms 126288 KB Output is correct
14 Correct 85 ms 126392 KB Output is correct
15 Correct 83 ms 126288 KB Output is correct
16 Correct 80 ms 126360 KB Output is correct
17 Correct 80 ms 125896 KB Output is correct
18 Correct 80 ms 126208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 480 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 224 ms 139824 KB Output is correct
2 Correct 236 ms 140196 KB Output is correct
3 Correct 180 ms 141772 KB Output is correct
4 Correct 182 ms 141636 KB Output is correct
5 Correct 179 ms 141612 KB Output is correct
6 Correct 159 ms 141668 KB Output is correct
7 Correct 162 ms 141616 KB Output is correct
8 Correct 176 ms 141260 KB Output is correct
9 Correct 105 ms 127052 KB Output is correct
10 Correct 171 ms 141356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 125524 KB Output is correct
2 Correct 76 ms 125524 KB Output is correct
3 Correct 77 ms 125680 KB Output is correct
4 Correct 79 ms 125776 KB Output is correct
5 Correct 80 ms 125572 KB Output is correct
6 Correct 79 ms 125680 KB Output is correct
7 Correct 78 ms 125528 KB Output is correct
8 Correct 77 ms 125520 KB Output is correct
9 Correct 76 ms 125524 KB Output is correct
10 Correct 78 ms 125716 KB Output is correct
11 Correct 79 ms 125776 KB Output is correct
12 Correct 80 ms 126288 KB Output is correct
13 Correct 81 ms 126288 KB Output is correct
14 Correct 85 ms 126392 KB Output is correct
15 Correct 83 ms 126288 KB Output is correct
16 Correct 80 ms 126360 KB Output is correct
17 Correct 80 ms 125896 KB Output is correct
18 Correct 80 ms 126208 KB Output is correct
19 Correct 469 ms 157032 KB Output is correct
20 Correct 485 ms 160976 KB Output is correct
21 Correct 365 ms 160632 KB Output is correct
22 Correct 378 ms 160976 KB Output is correct
23 Correct 375 ms 160720 KB Output is correct
24 Correct 282 ms 160528 KB Output is correct
25 Correct 272 ms 160484 KB Output is correct
26 Correct 325 ms 161072 KB Output is correct
27 Correct 361 ms 160776 KB Output is correct
28 Correct 342 ms 160892 KB Output is correct
29 Correct 339 ms 160980 KB Output is correct
30 Correct 387 ms 161232 KB Output is correct
31 Correct 354 ms 160980 KB Output is correct
32 Correct 352 ms 161064 KB Output is correct
33 Correct 362 ms 160980 KB Output is correct
34 Correct 270 ms 160728 KB Output is correct
35 Correct 283 ms 160472 KB Output is correct
36 Correct 286 ms 160396 KB Output is correct
37 Correct 278 ms 160424 KB Output is correct
38 Correct 298 ms 160624 KB Output is correct
39 Correct 338 ms 159560 KB Output is correct
40 Correct 230 ms 146888 KB Output is correct
41 Correct 331 ms 159108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 125524 KB Output is correct
2 Correct 76 ms 125524 KB Output is correct
3 Correct 77 ms 125680 KB Output is correct
4 Correct 79 ms 125776 KB Output is correct
5 Correct 80 ms 125572 KB Output is correct
6 Correct 79 ms 125680 KB Output is correct
7 Correct 78 ms 125528 KB Output is correct
8 Correct 77 ms 125520 KB Output is correct
9 Correct 76 ms 125524 KB Output is correct
10 Correct 78 ms 125716 KB Output is correct
11 Correct 79 ms 125776 KB Output is correct
12 Correct 80 ms 126288 KB Output is correct
13 Correct 81 ms 126288 KB Output is correct
14 Correct 85 ms 126392 KB Output is correct
15 Correct 83 ms 126288 KB Output is correct
16 Correct 80 ms 126360 KB Output is correct
17 Correct 80 ms 125896 KB Output is correct
18 Correct 80 ms 126208 KB Output is correct
19 Runtime error 480 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -