-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathS4V2.cpp
78 lines (65 loc) · 1.4 KB
/
S4V2.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
78
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Point{
int x1;
int y1;
int x2;
int y2;
ll t;
};
int main(){
int n;
cin >> n;
ll t;
cin >> t;
int yTop = INT_MAX;
int yDown = 0;
int xLeft = INT_MAX;
int xRight = 0;
queue<Point> cor;
unordered_map<int,unordered_map<int,int>> m;
for(ll i = 0; i < n; i++){
int x1,y1,x2,y2;
ll t;
cin >> x1 >> y1 >> x2 >> y2 >> t;
cor.push({x1,y1,x2,y2,t});
yTop = min(yTop,y1);
yDown = max(yDown,y2);
xLeft = min(xLeft,x1);
xRight = max(xRight,x2);
}
int limY = yDown - yTop;
int limX = xRight - xLeft;
for(int i = 0; i < n; i++){
Point p = cor.front();
cor.pop();
int startY = p.y1 - yTop;
int endY = p.y2 - yTop;
int x1 = p.x1-xLeft;
int x2 = p.x2-xLeft;
int t = p.t;
for(int y = startY; y < endY; y++){
m[y][x1] += t;
m[y][x2] -= t;
}
}
ll ans = 0;
for(int y = 0; y <= limY; y++){
ll sum = 0;
if(!m.count(y)){
continue;
}
for(int x = 0; x <= limX; x++){
if(m[y].count(x)){
sum += m[y][x];
m[y][x];
}
if(sum >= t){
ans++;
}
}
}
cout << ans;
return 0;
}