-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathf.cpp
66 lines (61 loc) · 1.47 KB
/
f.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
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;
struct rt{
bool a, b;
};
struct st{
int a, b, c;
};
int T;
int N, M;
map<int, rt> b;
map<int, st> dp;
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> T;
while(T--){
cin >> N >> M;
b.clear(), dp.clear();
for(int i = 0; i < M; i++){
int r, c; cin >> r >> c;
if(!b.count(c)) b[c] = {false, false};
if(r == 1) b[c].a = true;
if(r == 2) b[c].b = true;
}
dp[0] = {1, 0, 0};
for(auto it = b.begin(); it != b.end(); it++){
int loc = it->first;
rt bloc = it->second;
auto it2 = dp.rbegin();
int ploc = it2->first;
int m2 = (loc - ploc) % 2;
st pdp = it2->second;
st cdp = {0, 0, 0};
if(bloc.a && bloc.b){
cdp.a = pdp.a;
}else if(bloc.a){
if(m2){
cdp.a = pdp.c;
}else{
cdp.a = pdp.b;
}
cdp.c = pdp.a;
}else{
if(!m2){
cdp.a = pdp.c;
}else{
cdp.a = pdp.b;
}
cdp.b = pdp.a;
}
dp[loc] = cdp;
}
st last = dp.rbegin() -> second;
if(last.a){
cout << "yEs" << endl;
}else{
cout << "nO" << endl;
}
}
}