Task: | Coins |
Sender: | Ukkonen Fan Club |
Submission time: | 2018-05-26 11:53:26 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.45 s | details |
#2 | ACCEPTED | 0.43 s | details |
#3 | ACCEPTED | 0.47 s | details |
#4 | ACCEPTED | 0.45 s | details |
#5 | ACCEPTED | 0.47 s | details |
Code
#include <iostream> const int N = 2 * 1e5; int min[4 * N]; int max[4 * N]; int add[4 * N]; int h = 1; void push(int i) { min[i] += add[i]; max[i] += add[i]; if (i < h) { add[2*i] += add[i]; add[2*i+1] += add[i]; } add[i] = 0; } void update(int i) { min[i] = std::min(min[2*i], min[2*i+1]); max[i] = std::max(max[2*i], max[2*i+1]); } void inc(int a, int b, int v, int i = 1, int ia = 0, int ib = h - 1) { push(i); if (b < ia || ib < a) return; if (a <=ia && ib<= b) { add[i] += v; push(i); } else { int mid = (ia + ib) >> 1; inc(a, b, v, 2 * i, ia, mid); inc(a, b, v, 2 * i + 1, mid + 1, ib); update(i); } } int main() { int n; std::cin >> n; while(h < n) h <<= 1; for (int i = 0; i < n; ++i) { int a, b; std::cin >> a >> b; a = (n - a); int v = (b == 1 ? 1 : -1); inc(a, n - 1, v); if (min[1] >= 0) { std::cout << ">\n"; } else if (max[1] <= 0) { std::cout << "<\n"; } else { std::cout << "?\n"; } } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
200000 175878 1 146174 1 4939 2 181388 1 ... |
correct output |
---|
> > > > > ... |
user output |
---|
> > > > > ... |
Test 2
Verdict: ACCEPTED
input |
---|
200000 1 2 2 1 3 2 4 1 ... |
correct output |
---|
< > < > < ... |
user output |
---|
< > < > < ... |
Test 3
Verdict: ACCEPTED
input |
---|
200000 1 1 2 1 3 1 4 1 ... |
correct output |
---|
> > > > > ... |
user output |
---|
> > > > > ... |
Test 4
Verdict: ACCEPTED
input |
---|
200000 1 1 2 1 3 1 4 1 ... |
correct output |
---|
> > > > > ... |
user output |
---|
> > > > > ... |
Test 5
Verdict: ACCEPTED
input |
---|
200000 188909 2 58944 1 26824 1 143263 2 ... |
correct output |
---|
< < ? < < ... |
user output |
---|
< < ? < < ... |