Submission #1016711

# Submission time Handle Problem Language Result Execution time Memory
1016711 2024-07-08T10:54:17 Z dosts Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
1188 ms 262144 KB
//Dost SEFEROĞLU
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " << 
#define vi vector<int>
#define all(xx) xx.begin(),xx.end()
const int N = 1e6+1,inf = 2e9,B = 23,MOD = 998244353,LIM = 1e9;    

struct Node {
    set<int> v;
    int ans,mx;
};
int get_smaller(const set<int>& v, const int x) {
    auto it = v.lower_bound(x);
    if (it == v.begin()) return -inf;
    return *(prev(it));
}

Node merge(const Node& n1,const Node& n2) {
    Node ret;
    for (auto it : n1.v) ret.v.insert(it);
    for (auto it : n2.v) ret.v.insert(it);
    ret.mx = max(n1.mx,n2.mx);
    ret.ans = max({n1.ans,n2.ans,n1.mx+get_smaller(n2.v,n1.mx)});
    return ret;
}

vi vv;
vi a(N);
struct ST {
    vector<Node> t;
    void build(int node,int l,int r){
        if (l == r) {
            t[node] = {set<int>{a[l]},0,a[l]};
            return;
        }
        int m = (l+r) >> 1;
        build(2*node,l,m),build(2*node+1,m+1,r);
        t[node] = merge(t[2*node],t[2*node+1]);
    } 
    ST(int nn) {
        t.resize(4*nn+1);
        build(1,1,nn);
    }

    void get_nodes(int node,int l,int r,int L,int R) {
        if (l > R || r < L) return;
        if (l >= L && r <= R) {
            vv.push_back(node);
            return;
        }
        int m = (l+r) >> 1;
        get_nodes(2*node,l,m,L,R),get_nodes(2*node+1,m+1,r,L,R);
    }
};

void solve() {
    int n,m;
    cin >> n >> m;
    for (int i=1;i<=n;i++) cin >> a[i];
    ST st(n);
    while (m--) {
        int l,r,k;
        cin >> l >> r >> k;
        st.get_nodes(1,1,n,l,r);
        int ans = 0;
        for (auto it : vv) ans = max(ans,st.t[it].ans);
        int curmx = st.t[vv[0]].mx;
        for (int i=1;i<vv.size();i++) {
            ans = max(ans,curmx+get_smaller(st.t[vv[i]].v,curmx));
            curmx = max(curmx,st.t[vv[i]].mx);
        }
        if (ans <= k) cout << 1 << '\n';
        else cout << 0 << '\n';
        vv.clear();
    }
}  

                
                            
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}

Compilation message

sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:73:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for (int i=1;i<vv.size();i++) {
      |                      ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4188 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4188 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 4 ms 5464 KB Output is correct
12 Correct 11 ms 8284 KB Output is correct
13 Correct 11 ms 8284 KB Output is correct
14 Correct 13 ms 8384 KB Output is correct
15 Correct 13 ms 8792 KB Output is correct
16 Correct 10 ms 8540 KB Output is correct
17 Correct 8 ms 7772 KB Output is correct
18 Correct 4 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 220 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 372 ms 78936 KB Output is correct
2 Correct 289 ms 78852 KB Output is correct
3 Correct 97 ms 36432 KB Output is correct
4 Correct 99 ms 36436 KB Output is correct
5 Correct 126 ms 36432 KB Output is correct
6 Correct 76 ms 36468 KB Output is correct
7 Correct 90 ms 36712 KB Output is correct
8 Correct 71 ms 35832 KB Output is correct
9 Correct 28 ms 4696 KB Output is correct
10 Correct 72 ms 35764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4188 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 4 ms 5464 KB Output is correct
12 Correct 11 ms 8284 KB Output is correct
13 Correct 11 ms 8284 KB Output is correct
14 Correct 13 ms 8384 KB Output is correct
15 Correct 13 ms 8792 KB Output is correct
16 Correct 10 ms 8540 KB Output is correct
17 Correct 8 ms 7772 KB Output is correct
18 Correct 4 ms 5724 KB Output is correct
19 Correct 1188 ms 223924 KB Output is correct
20 Correct 1173 ms 224088 KB Output is correct
21 Correct 847 ms 223952 KB Output is correct
22 Correct 847 ms 224152 KB Output is correct
23 Correct 853 ms 224084 KB Output is correct
24 Correct 687 ms 224020 KB Output is correct
25 Correct 650 ms 223996 KB Output is correct
26 Correct 697 ms 223960 KB Output is correct
27 Correct 697 ms 224080 KB Output is correct
28 Correct 742 ms 224008 KB Output is correct
29 Correct 747 ms 224092 KB Output is correct
30 Correct 824 ms 223916 KB Output is correct
31 Correct 742 ms 224084 KB Output is correct
32 Correct 757 ms 223892 KB Output is correct
33 Correct 832 ms 224080 KB Output is correct
34 Correct 590 ms 224080 KB Output is correct
35 Correct 595 ms 224020 KB Output is correct
36 Correct 614 ms 224096 KB Output is correct
37 Correct 604 ms 224012 KB Output is correct
38 Correct 586 ms 223952 KB Output is correct
39 Correct 695 ms 224020 KB Output is correct
40 Correct 434 ms 144172 KB Output is correct
41 Correct 178 ms 67152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4188 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 2 ms 4440 KB Output is correct
10 Correct 2 ms 4440 KB Output is correct
11 Correct 4 ms 5464 KB Output is correct
12 Correct 11 ms 8284 KB Output is correct
13 Correct 11 ms 8284 KB Output is correct
14 Correct 13 ms 8384 KB Output is correct
15 Correct 13 ms 8792 KB Output is correct
16 Correct 10 ms 8540 KB Output is correct
17 Correct 8 ms 7772 KB Output is correct
18 Correct 4 ms 5724 KB Output is correct
19 Runtime error 220 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -