-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLimak_and_the_Binary_Tree.cpp
74 lines (66 loc) · 1.69 KB
/
Limak_and_the_Binary_Tree.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define mod 10e9 + 7
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORL(i, b, n) for (int (i) = (b); (i) <= (n); (i)++)
#define FORR(i, b, n) for (int (i) = (b); (i) >= (n); (i)--)
#define INF 1000000000000000003
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define POB pop_back
#define MP make_pair
void solve()
{
multiset<int>ms;
int n, number, query;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> number;
ms.insert(number);
}
cin >> n;
for (int i = 0; i < n; i++) {
cin >> query >> number;
if (query == 1) {
ms.insert(number);
} else if (query == 2) {
cout << ms.count(number) << endl;
} else if (query == 3) {
if (ms.find(number) == ms.end())
cout << -1 << endl;
else {
auto itrs = ms.upper_bound(number);
if (itrs == ms.end())
cout << -1 << endl;
else
cout << * itrs << endl;
}
} else if (query == 4) {
if (ms.find(number) == ms.end() ) {
cout << -1 << endl;
continue;
}
else{
auto its = ms.equal_range(number);
auto itr = its.first;
itr--;
cout << *itr << endl;
}
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
solve();
return 0;
}