답안 #1016722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016722 2024-07-08T11:05:39 Z dosts Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
370 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);
    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++) {
      |                      ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 4216 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 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4240 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 4216 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 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4240 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 3 ms 4700 KB Output is correct
12 Correct 5 ms 5468 KB Output is correct
13 Correct 5 ms 5468 KB Output is correct
14 Correct 6 ms 5468 KB Output is correct
15 Correct 6 ms 5468 KB Output is correct
16 Correct 5 ms 5468 KB Output is correct
17 Correct 4 ms 5212 KB Output is correct
18 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 370 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 27416 KB Output is correct
2 Correct 102 ms 27216 KB Output is correct
3 Correct 80 ms 23380 KB Output is correct
4 Correct 73 ms 23380 KB Output is correct
5 Correct 72 ms 23380 KB Output is correct
6 Correct 71 ms 23380 KB Output is correct
7 Correct 65 ms 23380 KB Output is correct
8 Correct 59 ms 23352 KB Output is correct
9 Correct 27 ms 4440 KB Output is correct
10 Correct 56 ms 23132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 4216 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 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4240 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 3 ms 4700 KB Output is correct
12 Correct 5 ms 5468 KB Output is correct
13 Correct 5 ms 5468 KB Output is correct
14 Correct 6 ms 5468 KB Output is correct
15 Correct 6 ms 5468 KB Output is correct
16 Correct 5 ms 5468 KB Output is correct
17 Correct 4 ms 5212 KB Output is correct
18 Correct 3 ms 5212 KB Output is correct
19 Correct 306 ms 56972 KB Output is correct
20 Correct 280 ms 56972 KB Output is correct
21 Correct 247 ms 56764 KB Output is correct
22 Correct 253 ms 56976 KB Output is correct
23 Correct 242 ms 56776 KB Output is correct
24 Correct 189 ms 56920 KB Output is correct
25 Correct 222 ms 56776 KB Output is correct
26 Correct 231 ms 56776 KB Output is correct
27 Correct 218 ms 56776 KB Output is correct
28 Correct 222 ms 56776 KB Output is correct
29 Correct 220 ms 56776 KB Output is correct
30 Correct 235 ms 56920 KB Output is correct
31 Correct 221 ms 56780 KB Output is correct
32 Correct 237 ms 56780 KB Output is correct
33 Correct 227 ms 56920 KB Output is correct
34 Correct 195 ms 56776 KB Output is correct
35 Correct 190 ms 56844 KB Output is correct
36 Correct 192 ms 56884 KB Output is correct
37 Correct 195 ms 57028 KB Output is correct
38 Correct 194 ms 56884 KB Output is correct
39 Correct 196 ms 56776 KB Output is correct
40 Correct 133 ms 36816 KB Output is correct
41 Correct 134 ms 42268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 4216 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 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4240 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 3 ms 4700 KB Output is correct
12 Correct 5 ms 5468 KB Output is correct
13 Correct 5 ms 5468 KB Output is correct
14 Correct 6 ms 5468 KB Output is correct
15 Correct 6 ms 5468 KB Output is correct
16 Correct 5 ms 5468 KB Output is correct
17 Correct 4 ms 5212 KB Output is correct
18 Correct 3 ms 5212 KB Output is correct
19 Runtime error 370 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -