-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_Rooks_Defenders.cpp
More file actions
66 lines (50 loc) · 1.55 KB
/
C_Rooks_Defenders.cpp
File metadata and controls
66 lines (50 loc) · 1.55 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
// Mohit Verma "mohitvdx"
// Problem: C. Rooks Defenders
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace std;
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
const int INF = LLONG_MAX >> 1;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve() {
int n, q;
cin >> n >> q;
vector<int> row(n, 0), col(n, 0);
oset<int> free_rows, free_cols;
for (int i = 0; i < n; i++) {
free_rows.insert(i);
free_cols.insert(i);
}
while (q--) {
int type;
cin >> type;
if (type == 1) {
int x, y;
cin >> x >> y;
--x, --y;
if (++row[x] == 1) free_rows.erase(x);
if (++col[y] == 1) free_cols.erase(y);
} else if (type == 2) {
int x, y;
cin >> x >> y;
--x, --y;
if (--row[x] == 0) free_rows.insert(x);
if (--col[y] == 0) free_cols.insert(y);
} else {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
--x1, --y1, --x2, --y2;
bool row_covered = (free_rows.order_of_key(x2 + 1) - free_rows.order_of_key(x1)) == 0;
bool col_covered = (free_cols.order_of_key(y2 + 1) - free_cols.order_of_key(y1)) == 0;
cout << (row_covered || col_covered ? "Yes" : "No") << '\n';
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
solve();
}