Submission #672186

# Submission time Handle Problem Language Result Execution time Memory
672186 2022-12-15T02:13:29 Z Alihan_8 Trading (IZhO13_trading) C++17
0 / 100
8 ms 19080 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 = 3e5+1;
struct segTree{
    int l, val;
    segTree(int l, int val) : l(l), val(val) {}
    segTree() : segTree(0, 0) {}
};
segTree lazy[N*4];
int T[N*4];
void push(int v, int l, int r){
    if ( !lazy[v].val ) return;
    if ( l != r ) lazy[v*2] = lazy[v*2+1] = lazy[v];
    T[v] = max(T[v], lazy[v].val+l-lazy[v].l);
    lazy[v] = segTree();
}
void upd(int v, int l, int r, int tl, int tr, int val){
    push(v, l, r);
    if ( l != r ){
        int md = (l+r)>>1;
        push(v*2, l, md), push(v*2+1, md+1, r);
    }
    if ( l > tr or r < tl ) return;
    if ( tl <= l and tr >= r ){
        lazy[v] = segTree(tl, val);
        push(v, l, r);
        if ( l != r ){
            int md = (l+r)>>1;
            push(v*2, l, md), push(v*2+1, md+1, r);
        }
        return;
    }
    int md = (l+r)>>1;
    upd(v*2, l, md, tl, tr, val), upd(v*2+1, md+1, r, tl, tr, val);
    T[v] = min(T[v*2], T[v*2+1]);
}
int get(int v, int l, int r, int pos){
    push(v, l, r);
    if ( l != r ){
        int md = (l+r)>>1;
        push(v*2, l, md), push(v*2+1, md+1, r);
    }
    if ( l == r ) return T[v];
    int md = (l+r)>>1;
    if ( pos <= md ) return get(v*2, l, md, pos);
    return get(v*2+1, md+1, r, pos);
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, q; cin >> n >> q;
    while ( q-- ){
        int l, r, x; cin >> l >> r >> x;
        upd(1, 1, n, l, r, x);
    }
    for ( int i = 1; i <= n; i++ ) cout << get(1, 1, n, i) << ' ';

    cout << '\n';
}

Compilation message

trading.cpp: In function 'void IO(std::string)':
trading.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);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
trading.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 8 ms 19028 KB Output is correct
2 Incorrect 8 ms 19080 KB Output isn't correct
3 Halted 0 ms 0 KB -