-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1016d.cpp
More file actions
65 lines (52 loc) · 1.65 KB
/
1016d.cpp
File metadata and controls
65 lines (52 loc) · 1.65 KB
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
60
61
62
63
64
65
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, q;
cin >> n >> q;
while (q--) {
string op;
cin >> op;
if (op == "->") {
ll x, y;
cin >> x >> y;
ll d = 0;
for (int k = n; k >= 1; --k) {
ll half = 1LL << (k - 1);
ll block = 1LL << (2 * (k - 1));
int id;
if (x <= half && y <= half) id = 0;
else if (x > half && y > half) id = 1;
else if (x > half && y <= half) id = 2;
else id = 3;
d += id * block;
if (x > half) x -= half;
if (y > half) y -= half;
}
cout << d + 1 << '\n';
}
else {
ll d;
cin >> d;
d--;
ll x = 1, y = 1;
for (int k = n; k >= 1; --k) {
ll half = 1LL << (k - 1);
ll block = 1LL << (2 * (k - 1));
ll id = d / block;
d %= block;
if (id == 1) { x += half; y += half; }
else if (id == 2) x += half;
else if (id == 3) y += half;
}
cout << x << " " << y << '\n';
}
}
}
return 0;
}