Submission #1016721

# Submission time Handle Problem Language Result Execution time Memory
1016721 2024-07-08T11:05:03 Z dosts Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
367 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 {
    vi v;
    int ans,mx;
};
int get_smaller(const vi& v, const int x) {
    auto it = lower_bound(v.begin(),v.end(),x);
    if (it == v.begin()) return -inf;
    return *(--it);
}
 
Node merge(const Node& n1,const Node& n2) {
    int n = n1.v.size(),m = n2.v.size();
    int ptr = 0,ptr2 = 0;
    Node ret;
    while (ptr < n && ptr2 < m) {
        if (n1.v[ptr] < n2.v[ptr2]) ret.v.push_back(n1.v[ptr++]);
        else if (n1.v[ptr] == n2.v[ptr2]) ptr2++;
        else ret.v.push_back(n2.v[ptr2++]);
    }
    while (ptr < n) {
        if (n1.v[ptr] != ret.v.back()) ret.v.push_back(n1.v[ptr++]);
        else ptr++;
    }
    while (ptr2 < m) {
        if (n2.v[ptr2] != ret.v.back()) ret.v.push_back(n2.v[ptr2++]);
        else ptr2++;
    }
    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] = {vi{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:86:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         for (int i=1;i<vv.size();i++) {
      |                      ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4184 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 1 ms 4188 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Runtime error 7 ms 8540 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4184 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 1 ms 4188 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Runtime error 7 ms 8540 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 367 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 33880 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4184 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 1 ms 4188 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Runtime error 7 ms 8540 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4184 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 1 ms 4188 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Runtime error 7 ms 8540 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -