답안 #672966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672966 2022-12-19T08:11:49 Z Alihan_8 돌 무게 재기 (IZhO11_stones) C++17
0 / 100
0 ms 212 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 = 1e5+1;
struct SegTree{
    vector <array<int,2>> T;
    vector <int> lazy;
    const int inf = numeric_limits <int>::max();
    void re_size(int n){
        T.resize(n*4+1);
        lazy.resize(n*4+1);
    }
    void push(int v, int l, int r){
        if ( !lazy[v] ) return;
        if ( l != r ){
            lazy[v*2] += lazy[v];
            lazy[v*2+1] += lazy[v];
        }
        T[v][0] += lazy[v]*(r-l+1);
        T[v][1] += lazy[v]*(r-l+1);
        lazy[v] = 0;
    }
    void upd(int v, int l, int r, int tl, int tr, int val){
        push(v, l, r);
        if ( l > tr or tl > r ) return;
        if ( tl <= l and tr >= r ){
            lazy[v] += val;
            push(v, l, 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][0] = min(T[v*2][0], T[v*2+1][0]);
        T[v][1] = max(T[v*2][1], T[v*2+1][1]);
    }
    int get_min(int v, int l, int r, int tl, int tr){
        push(v, l, r);
        if ( l > tr or tl > r ) return inf;
        if ( tl <= l and tr >= r ) return T[v][0];
        int md = (l+r)>>1;
        return min(get_min(v*2, l, md, tl, tr), get_min(v*2+1, md+1, r, tl, tr));
    }
    int get_max(int v, int l, int r, int tl, int tr){
        push(v, l, r);
        if ( l > tr or tl > r ) return -inf;
        if ( tl <= l and tr >= r ) return T[v][1];
        int md = (l+r)>>1;
        return max(get_max(v*2, l, md, tl, tr), get_max(v*2+1, md+1, r, tl, tr));
    }
} T;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int q, n; cin >> q;
    T.re_size(q+1); n = q;
    auto ins = [&](int x, int s){
        int sign = 1;
        if ( s == 2 ) sign *= -1;
        T.upd(1, 1, n, 1, x, sign);
    };
    auto get = [&](int it){
        if ( it == 0 ) return T.get_min(1, 1, n, 1, n);
        return T.get_max(1, 1, n, 1, n);
    };
    while ( q-- ){
        int x, s; cin >> x >> s;
        ins(x, s);
        if ( get(0) >= 0 ) cout << ">\n";
        else if ( get(1) <= 0 ) cout << "<\n";
        else cout << "?\n";
    }

    cout << '\n';
}

Compilation message

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