-
Notifications
You must be signed in to change notification settings - Fork 166
/
computing-analytics.cpp
73 lines (64 loc) · 1.23 KB
/
computing-analytics.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
//computing-analytics.cpp
//Computing Analytics
//Addepar Hackathon
//Author: derekhh
#include<iostream>
#include<unordered_set>
using namespace std;
unordered_set<int> l[100001], r[100001];
unordered_set<int> leftMinusOne[100001];
int main()
{
int n, c, q;
cin >> n >> c >> q;
for (int i = 0; i < c; i++)
{
int a, b;
cin >> a >> b;
l[b].insert(a);
leftMinusOne[b].insert(a - 1);
r[a].insert(b);
}
for (int i = 0; i < q; i++)
{
int a, b;
cin >> a >> b;
if (a > b) swap(a, b);
bool found = false;
if (r[a].find(b) != r[a].end())
{
found = true;
goto end;
}
// merge
for (unordered_set<int>::iterator it = r[a].begin(); it != r[a].end(); ++it)
{
if (leftMinusOne[b].find(*it) != leftMinusOne[b].end())
{
found = true;
goto end;
}
}
// [a, c] and [b+1, c]
for (unordered_set<int>::iterator it = r[a].begin(); it != r[a].end(); ++it)
{
if (r[b + 1].find(*it) != r[b + 1].end())
{
found = true;
goto end;
}
}
// [c, a-1] and [c,b]
for (unordered_set<int>::iterator it = l[a - 1].begin(); it != l[a - 1].end(); ++it)
{
if (l[b].find(*it) != l[b].end())
{
found = true;
goto end;
}
}
end:
cout << (found ? "YES" : "NO") << endl;
}
return 0;
}