답안 #444880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444880 2021-07-15T17:35:36 Z JovanB 돌 무게 재기 (IZhO11_stones) C++17
100 / 100
65 ms 6520 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define pb push_back
 
struct Segment{
    int val[1000005], open[1000005], closed[1000005];
    Segment(){
 
    }
    void mrg(int node){
        int g = min(open[node*2], closed[node*2+1]);
        open[node] = open[node*2] + open[node*2+1]- g;
        closed[node] = closed[node*2] + closed[node*2+1] - g;
        val[node] = val[node*2] + val[node*2+1] + g;
    }
    void upd(int node, int l, int r, int x, int g){
        if(l == r){
            if(g == -1) open[node] = 1;
            else closed[node] = 1;
            return;
        }
        int mid = (l+r)/2;
        if(x <= mid) upd(node*2, l, mid, x, g);
        else upd(node*2+1, mid+1, r, x, g);
        mrg(node);
    }
};
 
int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;
 
    int n;
    cin >> n;
    Segment *prvi = new Segment();
    Segment *drugi = new Segment();
    int prvih = 0, drugih = 0;
    for(int i=1; i<=n; i++){
        int a, b;
        cin >> a >> b;
        if(b == 1){
            prvih++;
            prvi->upd(1, 1, n, a, -1);
            drugi->upd(1, 1, n, a, 1);
        }
        else{
            drugih++;
            prvi->upd(1, 1, n, a, 1);
            drugi->upd(1, 1, n, a, -1);
        }
        if(prvi->val[1] == prvih) cout << "<\n";
        else if(drugi->val[1] == drugih) cout << ">\n";
        else cout << "?\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 5 ms 972 KB Output is correct
11 Correct 36 ms 3404 KB Output is correct
12 Correct 65 ms 6332 KB Output is correct
13 Correct 51 ms 6384 KB Output is correct
14 Correct 51 ms 6340 KB Output is correct
15 Correct 52 ms 6376 KB Output is correct
16 Correct 52 ms 6440 KB Output is correct
17 Correct 53 ms 6376 KB Output is correct
18 Correct 53 ms 6348 KB Output is correct
19 Correct 54 ms 6452 KB Output is correct
20 Correct 52 ms 6468 KB Output is correct
21 Correct 53 ms 6372 KB Output is correct
22 Correct 55 ms 6520 KB Output is correct
23 Correct 52 ms 6336 KB Output is correct
24 Correct 53 ms 6392 KB Output is correct
25 Correct 52 ms 6396 KB Output is correct