답안 #335068

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
335068 2020-12-11T05:11:49 Z limabeans 돌 무게 재기 (IZhO11_stones) C++17
100 / 100
101 ms 13908 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll inf = 1e18;



struct minsegtree {
    vector<ll> t,o;
    int n;
    void init(int _n) {
	n=_n;
	t.resize(4*n);
	o.resize(4*n);
    }

    void push(int v) {
	t[2*v]+=o[v];
	t[2*v+1]+=o[v];
	o[2*v]+=o[v];
	o[2*v+1]+=o[v];
	o[v]=0;
    }

    ll qry(int v, int tl, int tr, int l, int r) {
	if (l>tr||r<tl) return -inf;
	if (l<=tl&&tr<=r) {
	    return t[v];
	} else {
	    push(v);
	    int tm=(tl+tr)/2;
	    return min(qry(2*v,tl,tm,l,r),qry(2*v+1,tm+1,tr,l,r));
	}
    }

    void rangeAdd(int v, int tl, int tr, int l, int r, ll dx) {
	if (l>r) return;
	if (l>tr||r<tl) return;
	if (l<=tl&&tr<=r) {
	    t[v]+=dx;
	    o[v]+=dx;
	} else {
	    push(v);
	    int tm=(tl+tr)/2;
	    rangeAdd(2*v,tl,tm,l,r,dx);
	    rangeAdd(2*v+1,tm+1,tr,l,r,dx);
	    t[v]=min(t[2*v],t[2*v+1]);
	}
    }
};

struct maxsegtree {
    int n;
    vector<ll> t,o;
    void init(int _n) {
	n=_n;
	t.resize(4*n);
	o.resize(4*n);
    }

    void push(int v) {
	t[2*v]+=o[v];
	t[2*v+1]+=o[v];
	o[2*v]+=o[v];
	o[2*v+1]+=o[v];
	o[v]=0;
    }

    ll qry(int v, int tl, int tr, int l, int r) {
	if (l>tr||r<tl) return -inf;
	if (l<=tl&&tr<=r) {
	    return t[v];
	} else {
	    push(v);
	    int tm=(tl+tr)/2;
	    return max(qry(2*v,tl,tm,l,r),qry(2*v+1,tm+1,tr,l,r));
	}
    }

    void rangeAdd(int v, int tl, int tr, int l, int r, ll dx) {
	if (l>r) return;
	if (l>tr||r<tl) return;
	if (l<=tl&&tr<=r) {
	    t[v]+=dx;
	    o[v]+=dx;
	} else {
	    push(v);
	    int tm=(tl+tr)/2;
	    rangeAdd(2*v,tl,tm,l,r,dx);
	    rangeAdd(2*v+1,tm+1,tr,l,r,dx);
	    t[v]=max(t[2*v],t[2*v+1]);
	}
    }
};


minsegtree tmin;
maxsegtree tmax;

int n;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n;
    tmin.init(n);
    tmax.init(n);
    for (int i=1; i<=n; i++) {
	int val,id;
	cin>>val>>id;
	if (id==1) {
	    tmin.rangeAdd(1,1,n,1,val,1);
	    tmax.rangeAdd(1,1,n,1,val,1);
	} else {
	    tmin.rangeAdd(1,1,n,1,val,-1);
	    tmax.rangeAdd(1,1,n,1,val,-1);
	}

	int lo = tmin.qry(1,1,n,1,n);
	int hi = tmax.qry(1,1,n,1,n);

	if (hi>0) {
	    if (lo>=0) cout<<">\n"; else cout<<"?\n";
	} else {
	    if (lo<=0) cout<<"<\n"; else cout<<"?\n";
	}
    }
    
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 7 ms 1516 KB Output is correct
11 Correct 60 ms 7916 KB Output is correct
12 Correct 101 ms 12524 KB Output is correct
13 Correct 96 ms 13804 KB Output is correct
14 Correct 99 ms 13824 KB Output is correct
15 Correct 88 ms 13804 KB Output is correct
16 Correct 85 ms 13908 KB Output is correct
17 Correct 86 ms 13804 KB Output is correct
18 Correct 88 ms 13804 KB Output is correct
19 Correct 86 ms 13732 KB Output is correct
20 Correct 87 ms 13804 KB Output is correct
21 Correct 85 ms 13804 KB Output is correct
22 Correct 89 ms 13804 KB Output is correct
23 Correct 85 ms 13804 KB Output is correct
24 Correct 88 ms 13804 KB Output is correct
25 Correct 87 ms 13804 KB Output is correct