forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
104 lines (90 loc) · 2.84 KB
/
D.cpp
File metadata and controls
104 lines (90 loc) · 2.84 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define DEBUG(x) { cout << #x << " = "; cout << (x) << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
using namespace std;
struct Query {
int level;
long long l, r;
int ans;
} a[100111];
int h, q;
long long getMin(int level, long long x) {
FOR(i,level+1,h) {
x = x * 2;
}
return x;
}
long long getMax(int level, long long x) {
FOR(i,level+1,h) {
x = x * 2 + 1;
}
return x;
}
void solve() {
long long from = getMin(1, 1);
long long to = getMax(1, 1);
// cout << from << " --> " << to << endl;
FOR(i,1,q) if (a[i].ans == 1) {
long long l = getMin(a[i].level, a[i].l);
long long r = getMax(a[i].level, a[i].r);
if (r < from || to < l) {
cout << "Game cheated!" << endl;
return ;
}
from = max(from, l);
to = min(to, r);
}
// cout << from << " --> " << to << endl;
set< pair<long long, long long> > all;
all.insert(make_pair(from, to));
FOR(i,1,q) if (a[i].ans == 0) {
long long l = getMin(a[i].level, a[i].l);
long long r = getMax(a[i].level, a[i].r);
while (all.lower_bound(make_pair(l, 0)) != all.end()) {
auto it = all.lower_bound(make_pair(l, 0));
if (it->first <= r) {
auto bad = *it;
long long from = r+1, to = bad.second;
if (from <= to) all.insert(make_pair(from, to));
all.erase(bad);
}
else break;
}
auto it = all.lower_bound(make_pair(l, 0));
if (it != all.begin()) {
--it;
if (it->second >= l) {
auto bad = *it;
long long from = bad.first, to = l - 1;
if (from <= to) all.insert(make_pair(from, to));
if (r < bad.second) {
from = r + 1, to = bad.second;
if (from <= to) all.insert(make_pair(from, to));
}
all.erase(bad);
}
}
}
long long sum = 0;
for(auto p : all) sum += p.second - p.first + 1;
if (sum == 0) {
cout << "Game cheated!" << endl;
}
else if (sum > 1) {
cout << "Data not sufficient!" << endl;
}
else cout << all.begin()->first << endl;
}
int main() {
ios :: sync_with_stdio(false);
while (cin >> h >> q) {
FOR(i,1,q) cin >> a[i].level >> a[i].l >> a[i].r >> a[i].ans;
solve();
}
}