-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroundtruth.cpp
More file actions
73 lines (67 loc) · 1.57 KB
/
groundtruth.cpp
File metadata and controls
73 lines (67 loc) · 1.57 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
63
64
65
66
67
68
69
70
71
72
73
#include <cstdint>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <ctime>
#include <cmath>
#include <iostream>
#include "../src/util.h"
using namespace std;
int get_val(ull t, const vector<point> &v) {
auto len = v.size();
//if (t < 0) return 0;
if (t >= v[len - 1].x) return v[len - 1].y;
int l = 0, r = len - 1;
while (l < r) {
int m = (l + r) / 2;
if (v[m].x < t) {
l = m + 1;
}
else {
r = m;
}
}
return v[l].y;
}
int point_query(ull t, ull tau, const vector<point> &v) {
auto x1 = get_val(t, v);
if (t < tau) return x1;
auto x2 = get_val(t - tau, v);
if (t < 2 * tau) return x1 - 2 * x2;
auto x3 = get_val(t - 2 * tau, v);
return x1 - 2 * x2 + x3;
}
vector<int> heavy_hitter(ull theta, ull tau, const vector<point> &v) {
vector<int> res;
for (int i = 0; i < v.size(); ++i) {
if (point_query(i, tau, v) > theta) {
res.push_back(i);
}
}
return move(res);
}
void read_file(const char* filename, vector<point> &v) {
ifstream f(filename);
ull x, y, z;
while (f) {
f >> x >> y >> z;
v.push_back({x, (double)z});
}
}
vector<point> v;
int main(int argc, char **argv) {
if (argc == 1) {
read_file("../data/swimming.dat", v);
}
else {
read_file(argv[1], v);
}
auto &of = cout;
for (auto i = 0; i < 50000; i += 1440) {
of << i << " " << point_query(i, 1440, v) << endl;
}
}