-
Notifications
You must be signed in to change notification settings - Fork 0
/
3667.cpp
59 lines (51 loc) · 1.16 KB
/
3667.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<cstdio>
#define maxn 100000
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
typedef struct roominfo{
int left, cnt;
} roominfo;
roominfo room[maxn];
void build(int l, int r, int rt){
int m;
if(l == r){
room[rt].left = l;
room[rt].cnt = 1;
}else{
m = (l + r) >> 1;
build(lson);
build(rson);
room[rt].left = l;
room[rt].cnt = room[rt << 1].cnt + room[rt << 1 | 1].cnt;
}
}
roominfo query(int a, int b, int l, int r, int rt){
roominfo ra, rb, ret;
int m;
if(a <= l && b >= r){
return room[rt];
}else{
m = (l + r) >> 1;
if(m >= a)
ra = query(a, b, lson);
if(m < b)
rb = query(a, b, rson);
if(ra.left + ra.cnt == rb.left){
ret.left = ra.left;
ret.cnt = ra.cnt + rb.cnt;
}else{
if(ra.cnt >= rb.cnt){
return ra;
}else{
return rb;
}
}
}
}
int main(){
roominfo r;
build(1, 10, 1);
r = query(3, 7, 1, 10, 1);
printf("left:%d\tcnt:%d\n", r.left, r.cnt);
return 0;
}