Submission #882183

# Submission time Handle Problem Language Result Execution time Memory
882183 2023-12-02T18:46:16 Z Mr_Husanboy Weighting stones (IZhO11_stones) C++17
100 / 100
42 ms 7716 KB
#include <bits/stdc++.h>
using namespace std;



#ifdef LOCAL
#include "debugger.cpp"
#else
#define debug(...)
#endif
template<class T>
int len(T &a){
    return a.size();
}

using ll = long long;
using pii = pair<int,int>;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
string fileio = "";


mt19937 mt(time(nullptr));
const int mod = 1e9 + 7;
const int inf = 1e9;
const ll infl = 1e18;
const int maxn = 1e5 + 1;




struct SegmentTree{

    //To change
    struct Node{
        //defaults
        int mn = 0, mx = 0;
        int add = 0;
        bool marked = false;
        void apply(int x){
            mx += x; mn += x;
            add += x;
            marked = true;
        }
    };

    void push(int x){
        if(t[x].marked){
            t[x << 1].apply(t[x].add);
            t[x << 1 | 1].apply(t[x].add);
            t[x].add = 0; t[x].marked = false;
        }
    }

    Node merge(Node a, Node b){
        return {min(a.mn, b.mn), max(a.mx, b.mx), 0, false};
    }

    Node neutral = {inf, -inf, 0, false};
    vector<Node> t;
    int n;

    //construction

    void init(int _n){
        n = _n;
        t.resize(4 * n);
    }


    void upd(int x, int lx, int rx, int l, int r, int val){
        if(rx < l || r < lx) return;
        if(l <= lx && rx <= r){
            t[x].apply(val); return;
        }
        push(x);
        int mx = (lx + rx) >> 1;
        upd(x << 1, lx, mx, l, r, val);
        upd(x << 1 | 1, mx + 1, rx, l, r, val);
        t[x] = merge(t[x << 1], t[x << 1 | 1]);
    }

    Node get(int x, int lx, int rx, int l, int r){
        if(rx < l || r < lx){
            return neutral;
        }
        if(l <= lx && rx <= r){
            return t[x];
        }
        push(x);
        int mx = (lx + rx) >> 1;
        return merge(get(x << 1, lx, mx, l, r), get(x << 1 | 1, mx + 1, rx, l, r));
    }

    // lessen

    void upd(int l, int r, int val){
        upd(1, 0, n - 1, l, r, val);
    }

    Node get(int l, int r){
        return get(1, 0, n - 1, l, r);
    }
};


void solve(){
    int n;
    cin >> n;

    SegmentTree t;
    t.init(n);

    for(int _ = 0; _ < n; _ ++){
        int l, r; cin >> l >> r;
        l --; 
        t.upd(0, l, (r == 1 ? -1 : 1));
        auto k = t.get(0, n - 1);
        cout << (k.mx <= 0 ? ">" : k.mn >= 0 ? "<" : "?") << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    auto start = chrono::high_resolution_clock::now();
    #ifndef LOCAL
    if(fileio.size()){
        freopen((fileio + ".in").c_str(), "r", stdin);
        freopen((fileio + ".out").c_str(), "w", stdout);
    }
    #endif
    int testcases = 1;
    #ifdef Tests
    cin >> testcases;
    #endif
    while(testcases --){
        solve();
        cout << '\n';
        #ifdef LOCAL
        cout << "_________________________" << endl;
        #endif
    }
    #ifdef LOCAL
    auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
    
    cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
    #endif
    return 0;
}   

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:126:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
  126 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
stones.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 31 ms 4188 KB Output is correct
12 Correct 37 ms 6748 KB Output is correct
13 Correct 35 ms 7624 KB Output is correct
14 Correct 35 ms 7612 KB Output is correct
15 Correct 37 ms 7516 KB Output is correct
16 Correct 35 ms 7516 KB Output is correct
17 Correct 34 ms 7568 KB Output is correct
18 Correct 35 ms 7672 KB Output is correct
19 Correct 34 ms 7504 KB Output is correct
20 Correct 35 ms 7512 KB Output is correct
21 Correct 35 ms 7504 KB Output is correct
22 Correct 42 ms 7512 KB Output is correct
23 Correct 35 ms 7612 KB Output is correct
24 Correct 36 ms 7716 KB Output is correct
25 Correct 38 ms 7516 KB Output is correct