hiho week 153 register

Ended

Participants:259

Verdict:Accepted
Score:100 / 100
Submitted:2017-06-03 20:54:58

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int a[500001], d[500001], armq[500001][20][2];
int cnt, left;
void add(int t, int p) {
    d[cnt] = t;
    a[cnt] = p;
    armq[cnt][0][0] = armq[cnt][0][1] = p;
    ++cnt;
    int log = 1;
    while (true) {
        int dt = 1 << log;
        int l = cnt - dt;
        if (l < left) break;
        armq[l][log][0] = max(armq[l][log-1][0], armq[l + dt/2][log-1][0]);
        armq[l][log][1] = min(armq[l][log-1][1], armq[l + dt/2][log-1][1]);
        ++log;
    }
}
void remove(int t) {
    int l = upper_bound(d + left, d + cnt, t) - d;
    left = max(left, l);
}
void query() {
    int length = cnt - left;
    int log = 0;
    while ((1<<log+1) < length) ++log;
    int ret1 = max(armq[left][log][0], armq[cnt-(1<<log)][log][0]);
    int ret2 = min(armq[left][log][1], armq[cnt-(1<<log)][log][1]);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX