-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsegment_tree_2d_pointadd.test.cpp
55 lines (51 loc) · 1.47 KB
/
segment_tree_2d_pointadd.test.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
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2842"
#include "../segment_tree_2d.hpp"
#include <cstdio>
#include <iostream>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
int main() {
int H, W, T, Q;
cin >> H >> W >> T >> Q;
// Point add, range sum (like binary-indexed-tree)
vector<vector<int>> mat(H, vector<int>(W));
auto f = [](int l, int r) { return l + r; };
auto g = [](int x, int q) { return x; };
SegmentTree2D<int, int, int, decltype(f), decltype(g), decltype(f)> s1(mat, 0, f, g, f),
s2(mat, 0, f, g, f);
queue<pair<int, pair<int, int>>> q;
while (Q--) {
int t, c, h, w;
cin >> t >> c >> h >> w;
h--, w--;
while (q.size() and q.front().first <= t) {
int x, y;
tie(x, y) = q.front().second;
mat[x][y] = 2;
s1.update(x, y, 0);
s2.update(x, y, 1);
q.pop();
}
if (c == 0) {
mat[h][w] = 1;
s1.update(h, w, 1);
q.emplace(t + T, make_pair(h, w));
}
if (c == 1) {
if (mat[h][w] == 2) {
mat[h][w] = 0;
s2.update(h, w, 0);
}
}
if (c == 2) {
int h2, w2;
cin >> h2 >> w2;
int m = s2.get(h, h2, w, w2, -1);
int n = s1.get(h, h2, w, w2, -1);
printf("%d %d\n", m, n);
}
}
}