Submission #673272

# Submission time Handle Problem Language Result Execution time Memory
673272 2022-12-20T04:55:16 Z Alihan_8 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1267 ms 116004 KB
#include <bits/stdc++.h>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
const int N = 1e6+1, inf = 1e16+1;
struct SegTree{
    vector <int> T;
    void re_size(int n){
        T.resize(n*4+1);
    }
    void upd(int v, int l, int r, int pos, int val){
        if ( l == r ){
            T[v] = val;
            return;
        }
        int md = (l+r)>>1;
        if ( pos <= md ) upd(v*2, l, md, pos, val);
        else upd(v*2+1, md+1, r, pos, val);
        T[v] = max(T[v*2], T[v*2+1]);
    }
    int get(int v, int l, int r, int tl, int tr){
        if ( r < tl or l > tr ) return 0;
        if ( tl <= l and tr >= r ) return T[v];
        int md = (l+r)>>1;
        return max(get(v*2, l, md, tl, tr), get(v*2+1, md+1, r, tl, tr));
    }
} Tree;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m; cin >> n >> m;
    Tree.re_size(N);
    vector <int> p(n);
    for ( auto &i: p ) cin >> i;
    struct query{
        int l, r, k;
    };
    vector <query> q(m);
    vector <int> g[n+1], res(m);
    for ( auto &[l, r, k]: q ) cin >> l >> r >> k, l--, r--;
    for ( int i = 0; i < m; i++ ){
        g[q[i].r].pb(i);
    }
    stack <int> stk;
    for ( int i = 0; i < n; i++ ){
        while ( !stk.empty() and stk.top() <= p[i] ) stk.pop();
        if ( !stk.empty() ){
            Tree.upd(1, 0, n-1, i, stk.top()+p[i]);
        }
        for ( auto cur: g[i] ){
            res[cur] = Tree.get(1, 0, n-1, q[cur].l, q[cur].r) <= q[cur].k;
        }
        stk.push(p[i]);
    }
    for ( auto i: res ) cout << i << ln;

    cout << '\n';
}

Compilation message

sortbooks.cpp: In function 'void IO(std::string)':
sortbooks.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 31572 KB Output is correct
2 Correct 14 ms 31572 KB Output is correct
3 Incorrect 13 ms 31572 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 31572 KB Output is correct
2 Correct 14 ms 31572 KB Output is correct
3 Incorrect 13 ms 31572 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1267 ms 116004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 92 ms 39884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 31572 KB Output is correct
2 Correct 14 ms 31572 KB Output is correct
3 Incorrect 13 ms 31572 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 31572 KB Output is correct
2 Correct 14 ms 31572 KB Output is correct
3 Incorrect 13 ms 31572 KB Output isn't correct
4 Halted 0 ms 0 KB -