Submission #524102

# Submission time Handle Problem Language Result Execution time Memory
524102 2022-02-08T16:00:53 Z Kalashnikov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1899 ms 38060 KB
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin() , v.end()
const int N = 1e6+55;
int a[N] , lef[N] , mx[4*N] , ans[N];
int n, m;
    
void upd(int pos , int val , int u = 1, int ul = 1, int ur = n) {
    mx[u] = max(mx[u] , val);
    if(ul == ur) {
        mx[u] = val;
        return;
    }
    
    int um = ul+ur >> 1;
    if(pos <= um) upd(pos , val , u<<1 , ul , um);
    else upd(pos , val , u<<1|1 , um+1 , ur);
}

int get(int l , int r , int u = 1 , int ul = 1 , int ur = n) {
    if(l <= ul && ur <= r) return mx[u];
    if(r < ul || ur < l) return 0;
    
    int um = ul+ur >> 1;
    return max(get(l , r , u<<1 , ul , um) , get(l , r , u<<1|1 , um+1 , ur));
}

int main() {
    cin >> n >> m;
    for(int i = 1; i <= n; i ++) {
        cin >> a[i];
    }
    stack<int> st;
    for(int i = 1; i <= n; i ++) {
        while(st.size() && a[i] >= a[st.top()]) {
            st.pop();
        }
        if(st.size())
            lef[i] = st.top();
        st.push(i);
    }
    vector<array<int,4>> q;
    for(int i = 1, l, r, k; i <= m; i ++) {
        cin >> l >> r >> k;
        q.push_back({r , l, k , i});
    }
    sort(all(q));
    for(auto [r , l , k , i]: q) {
        if(lef[r] != 0) {
            upd(lef[r] , a[r] + a[lef[r]]);
            lef[r] = 0;
        }
        ans[i] = (get(l , r) <= k);
    }
    for(int i = 1; i <= m; i ++) {
        cout << ans[i] << '\n';
    }
}

Compilation message

sortbooks.cpp: In function 'void upd(int, int, int, int, int)':
sortbooks.cpp:15:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   15 |     int um = ul+ur >> 1;
      |              ~~^~~
sortbooks.cpp: In function 'int get(int, int, int, int, int)':
sortbooks.cpp:24:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |     int um = ul+ur >> 1;
      |              ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Incorrect 2 ms 312 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Incorrect 2 ms 312 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1868 ms 38060 KB Output is correct
2 Incorrect 1899 ms 38000 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 142 ms 4604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Incorrect 2 ms 312 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Incorrect 2 ms 312 KB Output isn't correct
4 Halted 0 ms 0 KB -