# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
673794 | smartmonky | Weighting stones (IZhO11_stones) | C++14 | 181 ms | 4420 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>
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
const int N = 100001;
pair <int,int> t[N * 4];
int add[N * 4], mn;
int n;
void push(int v, int l, int r){
if(l != r && add[v]){
add[v * 2] += add[v];
add[v * 2 + 1] += add[v];
}
t[v].ff += add[v];
t[v].ss += add[v];
add[v] = 0;
}
void update(int l, int r,int val, int v = 1, int tl = 1, int tr = n){
push(v, tl, tr);
if(tl > r || tr < l)
return;
if(tl >= l && tr <= r){
add[v] += val;
push(v, tl, tr);
return;
}
int mid = (tl + tr) >> 1;
update(l, r, val, v * 2, tl, mid);
update(l, r, val, v * 2 + 1, mid + 1, tr);
t[v].ff = min(t[v * 2].ff, t[v * 2 + 1].ff);
t[v].ss = max(t[v * 2].ss, t[v * 2 + 1].ss);
}
pair <int,int> get(int l, int r, int v = 1, int tl = 1, int tr = n){
push(v, tl, tr);
if(tl > r || tr < l)
return {1e9, -1e9};
if(tl >= l && tr <= r){
return t[v];
}
int mid = (tl + tr) >> 1;
pair <int,int> left = get(l, r, v * 2, tl, mid);
pair <int,int> right = get(l, r, v * 2 + 1, mid + 1, tr);
return {min(left.ff, right.ff), max(left.ss, right.ss)};
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
int r, s;
cin >> r >> s;
int dob = 1;
if(s == 2)
dob = -1;
update(1, r, dob);
pair <int,int> res = get(1, n);
if(res.ss <= 0){
cout << "<";
}else if(res.ff >= 0){
cout << ">";
}else
cout <<"?";
cout << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |