-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pixelated.cpp
77 lines (67 loc) · 1.57 KB
/
Pixelated.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
75
76
77
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
struct Point {
int val;
int id;
bool v;
bool tail;
bool operator<(const Point & rhs) const {
return id < rhs.id;
}
};
bool compareVal(const Point & a, const Point & b) {
if (a.val == b.val)
return a.tail < b.tail;
return a.val < b.val;
}
Point list[400000];
int main() {
int size, temp;
char orr;
cin >> size;
size *= 2;
for (int i = 0; i < size; i+=2) {
list[i].id = i / 2;
list[i + 1].id = i / 2;
list[i].tail = true;
list[i + 1].tail = false;
cin >> orr;
if (orr == 'v') {
list[i].v = true;
list[i + 1].v = true;
} else {
list[i].v = false;
list[i + 1].v = false;
}
cin >> temp;
list[i].val = temp;
list[i + 1].val = temp;
cin >> temp;
list[i + 1].val += temp;
cin >> temp;
list[i].val -= temp;
list[i + 1].val -= temp;
}
std::sort(list, list + size, compareVal);
long long count = 0, v = 0, h = 0;
for (int i = 0; i < size; i++) {
if (list[i].tail) {
if (list[i].v) {
v++;
count += h;
} else {
h++;
count += v;
}
} else {
if (list[i].v)
v--;
else
h--;
}
}
cout << count << endl;
return 0;
}