hiho week 177 register

Ended

Participants:499

Verdict:Accepted
Score:100 / 100
Submitted:2017-11-23 14:11:12

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
#include <iostream>
#include <algorithm>
using namespace std;
int xl, yl, xr, yr;
int get_bias(int h) {
    if (h == 1) return 0;
    if (h == 2) return 2;
    return 3 * pow(2, h-3);
}
int search(int h, int x, int y) {
    int cnt = 0, bias = get_bias(h);
    if (x >= xl && x <= xr && y >= yl && y <= yr) cnt += 1;
    if (bias != 0) cnt += search(h-1, x+bias, y-bias) + search(h-1, x+bias, y+bias);
    return cnt;
}
int main() {
    // freopen("../input.txt", "r", stdin);
    int n, m; cin >> n >> m;
    while(m--) {
        cin >> xl >> yl >> xr >> yr;
        cout << search(n, 0, 0) << endl;
    }
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX