-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathABC338E.cpp
73 lines (71 loc) · 1.85 KB
/
ABC338E.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
#include <bits/extc++.h>
using namespace std;
namespace pbds = __gnu_pbds;
using ui = unsigned int;
using uli = unsigned long long int;
using li = long long int;
class FenwickTree {
#ifdef debug
public:
#endif
vector<int> tree;
int prefix_sum(size_t p) const {
int res = 0;
for (--p; p < tree.size(); p = (p & p + 1) - 1) res += tree[p];
return res;
}
public:
FenwickTree(size_t n): tree(n) {}
void add_point(size_t p, int const& val) {
for (; p < tree.size(); p |= p + 1) tree[p] += val;
}
int get_sum(size_t l, size_t r) const {
return prefix_sum(r) - prefix_sum(l);
}
size_t size(void) const { return tree.size(); }
};
class DifferenceFenwick {
#ifdef debug
public:
#endif
FenwickTree tree;
public:
DifferenceFenwick(size_t n): tree(n) {}
friend istream& operator>>(istream& in, DifferenceFenwick& t) {
for (size_t i = 0; i < t.size(); i++) {
int x;
in >> x;
t.add_point(i, x);
}
#ifdef debug
cout << "\033[31m";
for (auto& i : t.tree.tree) cout << i << ' ';
cout << "\033[0m\n";
#endif
return in;
}
void add_interval(size_t l, size_t r, int const& val) {
tree.add_point(l, val), tree.add_point(r, -val);
}
void add_point(size_t p, int const& val) { add_interval(p, p + 1, val); }
int get_val(size_t p) { return tree.get_sum(0, p + 1); }
size_t size(void) { return tree.size(); }
};
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
size_t n;
cin >> n;
vector<pair<ui, ui>> a(n);
for (pair<ui, ui>& i : a) {
cin >> i.first >> i.second;
if (--i.first > --i.second) swap(i.first, i.second);
}
sort(a.begin(), a.end());
DifferenceFenwick d(n * 2);
for (pair<ui, ui> i : a) {
if (d.get_val(i.first) != d.get_val(i.second)) cout << "Yes", exit(0);
d.add_interval(i.first, i.second, 1);
}
cout << "No";
return 0;
}