-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathother_tools.cpp
More file actions
62 lines (46 loc) · 1.77 KB
/
other_tools.cpp
File metadata and controls
62 lines (46 loc) · 1.77 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
#include<bits/stdc++.h>
using namespace std;
struct TOOLS {
typedef long long lint;
// {{value, amount}}
//{1, 3, 5, 5, 7} -> {{1, 1}, {3, 1}, {5, 2}, {7, 1}}
vector<pair<lint, lint>> rebute (vector<lint> vec) {
vector<pair<lint, lint>> res;
std::sort(vec.begin(), vec.end());
vector<lint> temp(vec);
temp.erase(unique(temp.begin(), temp.end()), temp.end());
vector<int> cnt(vec.size() + 10, 0);
lint prev = -4e18 ; //dummy value
for (int i=0,idx =-1;i<vec.size();i++) {
if (prev != vec[i]) idx++;
prev = vec[i];
cnt[idx]++;
}
for (int i=0;i<temp.size();i++) {
res.emplace_back(temp[i], cnt[i]);
}
return res;
}
//diff [-INF, 1] ~ [2, INF] 에 대한 판정 0 : 잇지 않겠다, 1 : 잇는 것을 허용한다.
vector<pair<lint, lint>> sweepLine (vector<pair<lint, lint>> vec, int diff) {
typedef pair<lint, lint> pt;
sort(vec.begin(), vec.end(), [&] (pt a, pt b) {
if (a.first == b.first) return a.second < b.second;
return a.first < b.first;
});
vector<pair<lint, lint>> sweeped;
pair<lint, lint> res = vec[0];
for (int i=1;i<vec.size();i++) {
if ((vec[i].first <= res.second) ||
(vec[i].first - 1 == res.second && diff)) {
res.second = max(res.second, vec[i].second);
if (i + 1 == vec.size()) sweeped.push_back(res);
} else {
//sweeping 이 한줄로 이어지지 못함.
sweeped.push_back(res);
res = vec[i];
}
}
return sweeped;
}
};