Submission #481010

# Submission time Handle Problem Language Result Execution time Memory
481010 2021-10-19T07:34:40 Z FatihSolak Weighting stones (IZhO11_stones) C++17
100 / 100
261 ms 7620 KB
#include <bits/stdc++.h>
using namespace std;
struct SegTree{
    vector<int> t,lazy;
    SegTree(int size){
        t.assign(4*size+5,1e9);
        lazy.assign(4*size+5,0);
    }
    void push(int v){
        t[v*2] += lazy[v];
        t[v*2+1] += lazy[v];
        lazy[v*2] += lazy[v];
        lazy[v*2+1] += lazy[v];
        lazy[v] = 0;
    }
    void upd(int v,int tl,int tr,int l,int r,int val){
        if(r  < tl || tr < l)return;
        if(l <= tl && tr <= r){
            t[v] += val;
            lazy[v] += val;
            return;
        }
        push(v);
        int tm = (tl + tr)/2;
        upd(v*2,tl,tm,l,r,val);
        upd(v*2+1,tm+1,tr,l,r,val);
        t[v] = min(t[v*2],t[v*2+1]);
    }
    int get(int v,int tl,int tr,int l,int r){
        if(r < tl || tr < l)return 1e9;
        if(l <= tl && tr <= r)return t[v];
        push(v);
        int tm = (tl + tr)/2;
        return min(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r));
    }
};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef Local
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int n;
    cin >> n;
    SegTree t1(n);
    SegTree t2(n);
    for(int i=1;i<=n;i++){
        int r,s;
        cin >> r >> s;
        if(s == 1){
            t1.upd(1,1,n,1,r-1,-1);
            t1.upd(1,1,n,r,r,-(int)1e9);
            t2.upd(1,1,n,1,r,1);
        }
        if(s == 2){
            t2.upd(1,1,n,1,r-1,-1);
            t2.upd(1,1,n,r,r,-(int)1e9);
            t1.upd(1,1,n,1,r,1);
        }
        if(t1.get(1,1,n,1,n) > 0){
            cout << '<';
        }
        else if(t2.get(1,1,n,1,n) > 0){
            cout << '>';    
        }
        else cout << '?';
        cout << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 21 ms 964 KB Output is correct
11 Correct 137 ms 4344 KB Output is correct
12 Correct 226 ms 6936 KB Output is correct
13 Correct 236 ms 7532 KB Output is correct
14 Correct 229 ms 7496 KB Output is correct
15 Correct 248 ms 7620 KB Output is correct
16 Correct 228 ms 7512 KB Output is correct
17 Correct 235 ms 7568 KB Output is correct
18 Correct 236 ms 7492 KB Output is correct
19 Correct 259 ms 7492 KB Output is correct
20 Correct 241 ms 7504 KB Output is correct
21 Correct 242 ms 7620 KB Output is correct
22 Correct 240 ms 7476 KB Output is correct
23 Correct 247 ms 7568 KB Output is correct
24 Correct 229 ms 7480 KB Output is correct
25 Correct 261 ms 7488 KB Output is correct