답안 #673271

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
673271 2022-12-20T04:53:30 Z Alihan_8 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1277 ms 116012 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 p[stk.top()] <= p[i] ) stk.pop();
        if ( !stk.empty() ){
            Tree.upd(1, 1, n, i, p[stk.top()]+p[i]);
        }
        for ( auto cur: g[i] ){
            res[cur] = Tree.get(1, 1, n, q[cur].l, q[cur].r) <= q[cur].k;
        }
        stk.push(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);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 31572 KB Output is correct
2 Correct 15 ms 31592 KB Output is correct
3 Incorrect 13 ms 31652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 31572 KB Output is correct
2 Correct 15 ms 31592 KB Output is correct
3 Incorrect 13 ms 31652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1277 ms 116012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 39840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 31572 KB Output is correct
2 Correct 15 ms 31592 KB Output is correct
3 Incorrect 13 ms 31652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 31572 KB Output is correct
2 Correct 15 ms 31592 KB Output is correct
3 Incorrect 13 ms 31652 KB Output isn't correct
4 Halted 0 ms 0 KB -