답안 #672968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672968 2022-12-19T08:20:43 Z Alihan_8 돌 무게 재기 (IZhO11_stones) C++17
100 / 100
53 ms 10700 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];
        T[v][1] += lazy[v];
        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 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 33 ms 5716 KB Output is correct
12 Correct 52 ms 9632 KB Output is correct
13 Correct 41 ms 10572 KB Output is correct
14 Correct 41 ms 10668 KB Output is correct
15 Correct 43 ms 10576 KB Output is correct
16 Correct 48 ms 10700 KB Output is correct
17 Correct 44 ms 10560 KB Output is correct
18 Correct 45 ms 10576 KB Output is correct
19 Correct 42 ms 10676 KB Output is correct
20 Correct 41 ms 10580 KB Output is correct
21 Correct 45 ms 10660 KB Output is correct
22 Correct 46 ms 10680 KB Output is correct
23 Correct 53 ms 10572 KB Output is correct
24 Correct 46 ms 10664 KB Output is correct
25 Correct 47 ms 10572 KB Output is correct