Submission #536431

# Submission time Handle Problem Language Result Execution time Memory
536431 2022-03-13T09:51:29 Z PiejanVDC Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
17 / 100
3000 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
 
const int C = 8;
 
vector<int>w;
vector<int>st;
vector<vector<int>>v;
 
void dbg(vector<int>c) {
    for(auto z : c)
        cout << z << " ";
    cout << "\n\n";
}
 
void build(int i_, int j_, int p_) {
    if(i_ == j_) {
        st[p_] = 0;
        v[p_].push_back(w[i_]);
        return;
    }
    int mid_ = (i_ + j_) >> 1;
    build(i_, mid_, 2 * p_);
    build(mid_ + 1, j_, 2 * p_ + 1);
    int mx = max(st[2 * p_], st[2 * p_ + 1]);
    int p = 0;
  	const int MAX = (v[2 * p_].empty() ? 0 : v[2 * p_].back());
    for(int i = 0 ; i < (int)v[2 * p_].size() ; i++) {
        while(p < (int)v[2 * p_ + 1].size() && v[2 * p_ + 1][p] < v[2 * p_][i]) {
            v[p_].push_back(v[2 * p_ + 1][p]);
            mx = max(mx, MAX + v[p_].back());
            p++;
        }
        v[p_].push_back(v[2 * p_][i]);
    }
    while(p < (int)v[2 * p_ + 1].size())
        v[p_].push_back(v[2 * p_ + 1][p]), p++;
    st[p_] = mx;
}
 
int l_, r_;
int ans;
 
vector<int>query(int i_, int j_, int p_) {
    if(i_ > r_ || j_ < l_)
        return {};
    if(i_ >= l_ && j_ <= r_) {
        ans = max(ans, st[p_]);
        return v[p_];
    }
    int mid_ = (i_ + j_) >> 1;
    vector<int>v1 = query(i_, mid_, 2 * p_),
               v2 = query(mid_ + 1, j_, 2 * p_ + 1),
               v3;
    int p = 0;
    const int MAX = (v1.empty() ? 0 : v1.back());
    for(int i = 0 ; i < (int)v1.size() ; i++) {
        while(p < (int)v2.size() && v2[p] < v1[i]) {
            v3.push_back(v2[p]);
            ans = max(ans, MAX + v3.back());
            p++;
        }
        v3.push_back(v1[i]);
    }
    while(p < (int)v2.size())
        v3.push_back(v2[p++]);
    return v3;
}
 
signed main() {
    int N,Q;
    scanf("%d%d", &N, &Q);
    w.resize(N);
    st.resize(C * N);
    v.resize(C * N);
    for(auto &in : w)
        scanf("%d", &in);
    build(0, N-1, 1);
    while(Q--) {
        int l,r,k;
        scanf("%d%d%d", &l, &r, &k);
        l--,r--;
        l_ = l, r_ = r, ans = 0;
        auto x = query(0, N-1, 1);
        cout << (ans <= k) << "\n";
    }
    return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     scanf("%d%d", &N, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         scanf("%d", &in);
      |         ~~~~~^~~~~~~~~~~
sortbooks.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         scanf("%d%d%d", &l, &r, &k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 37 ms 724 KB Output is correct
12 Correct 108 ms 2104 KB Output is correct
13 Correct 103 ms 2100 KB Output is correct
14 Correct 159 ms 2252 KB Output is correct
15 Correct 169 ms 2144 KB Output is correct
16 Correct 105 ms 2144 KB Output is correct
17 Correct 37 ms 1688 KB Output is correct
18 Correct 85 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 346 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3059 ms 37736 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 37 ms 724 KB Output is correct
12 Correct 108 ms 2104 KB Output is correct
13 Correct 103 ms 2100 KB Output is correct
14 Correct 159 ms 2252 KB Output is correct
15 Correct 169 ms 2144 KB Output is correct
16 Correct 105 ms 2144 KB Output is correct
17 Correct 37 ms 1688 KB Output is correct
18 Correct 85 ms 2132 KB Output is correct
19 Execution timed out 3065 ms 75284 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 37 ms 724 KB Output is correct
12 Correct 108 ms 2104 KB Output is correct
13 Correct 103 ms 2100 KB Output is correct
14 Correct 159 ms 2252 KB Output is correct
15 Correct 169 ms 2144 KB Output is correct
16 Correct 105 ms 2144 KB Output is correct
17 Correct 37 ms 1688 KB Output is correct
18 Correct 85 ms 2132 KB Output is correct
19 Runtime error 346 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -