# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
882183 | Mr_Husanboy | Weighting stones (IZhO11_stones) | C++17 | 42 ms | 7716 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |