-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCppFuncsSILVER.cpp
94 lines (83 loc) · 2.42 KB
/
CppFuncsSILVER.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
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
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define is insert
#define lb lower_bound
#define ll long long
#define V vector
#define MS multiset
#define PL pair<ll, ll>
#define F first
#define S second
#define PQ priority_queue
#define f0r(i, begin, end) for (ll i = begin; i < end; i ++)
#define For(i, end, begin) for (ll i = end; i > begin; i --)
#define all(X) x.begin(), x.end()
#define INF 1000000000000000000
#define inf 1000000000
#define MOD 1000000009
#define len(x) (ll)x.size()
#define fileread(file) ifstream fin; fin.open((string)file + ".in"); ofstream fout; fout.open((string)file + ".out")
#define fastio ios_base::sync_with_stdio(0); cin.tie(nullptr)
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {for(auto &x : a) out << x << ' '; return out;};
template<typename T> istream& operator>>(istream& in, pair<T, T>& a) {in >> a.F >> a.S; return in;};
template<typename T> ostream& operator<<(ostream& out, pair<T, T>& a) {out << a.F << ' ' << a.S << endl; return out;};
int N;
ios_base::sync_with_stdio(0); cin.tie(nullptr);
// COORD COMPRESS
void twodcoordcomp() {
vector<ll> xs, ys;
vector<PL> inps;
for (int i = 0; i < N; i ++) {
ll a, b;
cin >> a >> b;
xs.pb(a); ys.pb(b);
inps.pb({a, b});
}
sort(all(xs));
sort(all(ys));
for (auto pair : inps) {
ll cx = lower_bound(all(xs), pair.F) - xs.begin(), cy = lower_bound(all(ys), pair.S) - ys.begin();
if (seen[cx][cy]) continue;
seen[cx][cy] = 1;
}
}
// C++ SETS CUSTOM COMPARATORS
bool cmp(tuple<int, int> a, tuple<int, int> b) {
return get<1>(a) < get<1>(b);
}
set<tuple<int, int>, decltype(cmp)*> alpha(cmp); // set custom compare
// BINARY SEARCH
int lowerbound(vector<int> array, int x){
return lower_bound(array.begin(), array.end(), x) - array.begin();
}
ll first_true(ll lo, ll hi) {
hi++;
while (lo < hi) {
ll mid = lo + (hi - lo) / 2;
if (test(mid)) {
hi = mid;
} else {
lo = mid + 1;
}
}
return lo;
}
ll last_true(ll lo, ll hi) {
lo--;
while (lo < hi) {
ll mid = lo + (hi - lo + 1) / 2;
if (test(mid)) lo = mid;
else hi = mid - 1;
}
return lo;
}
// FLOOD FILL PROCESSER
void process1 (ll x, ll y, ll dist) {
if ((x < 0) || (y < 0) || (x >= N) || (y >= N) || grid[x][y] || walldist[x][y] != INF) {
return;
}
walldist[x][y] = dist;
q1.push({x, y});
}