답안 #1016709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016709 2024-07-08T10:47:46 Z dosts Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
358 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 ret.v.push_back(n2.v[ptr2++]);
    }
    while (ptr < n) ret.v.push_back(n1.v[ptr++]);
    while (ptr2 < m) ret.v.push_back(n2.v[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:79:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for (int i=1;i<vv.size();i++) {
      |                      ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 1 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 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 1 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 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4384 KB Output is correct
11 Correct 3 ms 4700 KB Output is correct
12 Correct 5 ms 5724 KB Output is correct
13 Correct 5 ms 5724 KB Output is correct
14 Correct 6 ms 5724 KB Output is correct
15 Correct 6 ms 5720 KB Output is correct
16 Correct 7 ms 5696 KB Output is correct
17 Correct 4 ms 5244 KB Output is correct
18 Correct 4 ms 5724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 358 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 31436 KB Output is correct
2 Correct 112 ms 32204 KB Output is correct
3 Correct 94 ms 32160 KB Output is correct
4 Correct 94 ms 32204 KB Output is correct
5 Correct 94 ms 32204 KB Output is correct
6 Correct 88 ms 31888 KB Output is correct
7 Correct 88 ms 31948 KB Output is correct
8 Correct 80 ms 31936 KB Output is correct
9 Correct 27 ms 5868 KB Output is correct
10 Correct 90 ms 31892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 1 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 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4384 KB Output is correct
11 Correct 3 ms 4700 KB Output is correct
12 Correct 5 ms 5724 KB Output is correct
13 Correct 5 ms 5724 KB Output is correct
14 Correct 6 ms 5724 KB Output is correct
15 Correct 6 ms 5720 KB Output is correct
16 Correct 7 ms 5696 KB Output is correct
17 Correct 4 ms 5244 KB Output is correct
18 Correct 4 ms 5724 KB Output is correct
19 Correct 278 ms 63604 KB Output is correct
20 Correct 265 ms 63432 KB Output is correct
21 Correct 241 ms 63432 KB Output is correct
22 Correct 243 ms 63368 KB Output is correct
23 Correct 243 ms 63432 KB Output is correct
24 Correct 201 ms 63228 KB Output is correct
25 Correct 197 ms 63172 KB Output is correct
26 Correct 217 ms 63684 KB Output is correct
27 Correct 211 ms 63432 KB Output is correct
28 Correct 230 ms 63356 KB Output is correct
29 Correct 226 ms 63404 KB Output is correct
30 Correct 225 ms 63616 KB Output is correct
31 Correct 232 ms 63456 KB Output is correct
32 Correct 225 ms 63428 KB Output is correct
33 Correct 238 ms 63428 KB Output is correct
34 Correct 193 ms 63044 KB Output is correct
35 Correct 193 ms 63064 KB Output is correct
36 Correct 202 ms 63016 KB Output is correct
37 Correct 191 ms 62920 KB Output is correct
38 Correct 192 ms 63176 KB Output is correct
39 Correct 212 ms 62404 KB Output is correct
40 Correct 124 ms 41092 KB Output is correct
41 Correct 179 ms 61644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 1 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 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4384 KB Output is correct
11 Correct 3 ms 4700 KB Output is correct
12 Correct 5 ms 5724 KB Output is correct
13 Correct 5 ms 5724 KB Output is correct
14 Correct 6 ms 5724 KB Output is correct
15 Correct 6 ms 5720 KB Output is correct
16 Correct 7 ms 5696 KB Output is correct
17 Correct 4 ms 5244 KB Output is correct
18 Correct 4 ms 5724 KB Output is correct
19 Runtime error 358 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -