답안 #1016730

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016730 2024-07-08T11:12:21 Z dosts Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
371 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 (ret.v.empty() || n1.v[ptr] != ret.v.back()) ret.v.push_back(n1.v[ptr++]);
        else ptr++;
    }
    while (ptr2 < m) {
        if (ret.v.empty() || 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);
    st.t[1].v.clear();
    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:87:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for (int i=1;i<vv.size();i++) {
      |                      ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 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 2 ms 4188 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4696 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 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 2 ms 4188 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4696 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 3 ms 4700 KB Output is correct
12 Correct 4 ms 5468 KB Output is correct
13 Correct 5 ms 5468 KB Output is correct
14 Correct 6 ms 5664 KB Output is correct
15 Correct 7 ms 5468 KB Output is correct
16 Correct 5 ms 5468 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 371 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 27408 KB Output is correct
2 Correct 102 ms 27304 KB Output is correct
3 Correct 71 ms 23376 KB Output is correct
4 Correct 75 ms 23208 KB Output is correct
5 Correct 69 ms 23384 KB Output is correct
6 Correct 67 ms 23380 KB Output is correct
7 Correct 65 ms 23376 KB Output is correct
8 Correct 60 ms 23292 KB Output is correct
9 Correct 27 ms 4440 KB Output is correct
10 Correct 55 ms 23128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 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 2 ms 4188 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4696 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 3 ms 4700 KB Output is correct
12 Correct 4 ms 5468 KB Output is correct
13 Correct 5 ms 5468 KB Output is correct
14 Correct 6 ms 5664 KB Output is correct
15 Correct 7 ms 5468 KB Output is correct
16 Correct 5 ms 5468 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
19 Correct 320 ms 57008 KB Output is correct
20 Correct 277 ms 56788 KB Output is correct
21 Correct 238 ms 56848 KB Output is correct
22 Correct 242 ms 56776 KB Output is correct
23 Correct 253 ms 56996 KB Output is correct
24 Correct 199 ms 56784 KB Output is correct
25 Correct 196 ms 56956 KB Output is correct
26 Correct 274 ms 56776 KB Output is correct
27 Correct 252 ms 56776 KB Output is correct
28 Correct 238 ms 56948 KB Output is correct
29 Correct 229 ms 56960 KB Output is correct
30 Correct 236 ms 56776 KB Output is correct
31 Correct 305 ms 56924 KB Output is correct
32 Correct 271 ms 56876 KB Output is correct
33 Correct 239 ms 56932 KB Output is correct
34 Correct 225 ms 56972 KB Output is correct
35 Correct 192 ms 56984 KB Output is correct
36 Correct 215 ms 56920 KB Output is correct
37 Correct 205 ms 56784 KB Output is correct
38 Correct 194 ms 56832 KB Output is correct
39 Correct 228 ms 57156 KB Output is correct
40 Correct 138 ms 36740 KB Output is correct
41 Correct 157 ms 42328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 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 2 ms 4188 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4696 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 3 ms 4700 KB Output is correct
12 Correct 4 ms 5468 KB Output is correct
13 Correct 5 ms 5468 KB Output is correct
14 Correct 6 ms 5664 KB Output is correct
15 Correct 7 ms 5468 KB Output is correct
16 Correct 5 ms 5468 KB Output is correct
17 Correct 4 ms 5208 KB Output is correct
18 Correct 4 ms 5208 KB Output is correct
19 Runtime error 371 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -