Topic background
After Remilia Hongwu mutation fails, it can not be reconciled.
Title Description
After the last failure, Remilia decided to launch Hongwu mutation again, but in order to prevent back rule spiritual dream, she decided to release the Hongwu strange battle.
We will be seen as a fantasy village of n * m grid area, the beginning none of the area is covered Hongwu. Remilia each standing on one area, each issued a infinitely long Hongwu four directions truck, can affect the whole row / entire column, but does not affect that area of her station. If the two patches Hongwu collision, because the density is too large and will settle disappear. Reimu aware of this mutation, the decision to solve it. But before solving, spiritual dreams to understand a range of density Hongwu. Two operations can be simply described as:
1 xy coordinates Remilia standing (x, y) position of an infinitely long release Hongwu four directions.
Within the rectangle interrogation 2 x1 y1 x2 y2 of the upper left point (x1, y1), a lower right point (x2, y2), the number of areas covered by Hong Wu.
Input Format
The first row of three integers n, m, q, represents the illusion of size rural n * m, the q interrogation there.
Next q lines, each line an integer of 3 or 5, separated by spaces, have the meaning described in the subject.
Output Format
For each operation 2, the output line an integer representing the corresponding answer to the query.
Sample input and output
4 4 3 1 2 2 1 4 4 2 1 1 4 4
8
Description / Tips
Sample explained:
With o means no Hongwu, x expressed Hongwu, after the release of two Hongwu fantasy Township map as follows:
oxox
xoxo
oxox
xoxo
data range:
For 20% of the data, 1 <= n, m, q <= 200
For 40% of the data, 1 <= n, m, q <= 1000
To 100% of the data, 1 <= n, m, q <= 100000
1<=x1,x2,x<=n x1<=x2
1<=y1,y2,y<=m y1<=y2
by-orangebird
Ideas: prefix and area, think of Fenwick tree, repeated twice to offset that intersection, is the inclusion and exclusion theorem, pay attention to the impact point is not to close the station, which will cancel the last stand again this effect, it needs to be recorded
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
typedef long long LL; typedef pair<LL, LL> PLL; const int maxm = 1e5+5; int Cx[maxm], Cy[maxm], ax[maxm], ay[maxm]; void add(int *C, int x, int val) { for(; x <= C[0]; x += lowbit(x)) C[x] += val; } int getsum(int *C, int x) { int ret = 0; for(; x; x -= lowbit(x)) ret += C[x]; return ret; } int main() { ios::sync_with_stdio(false), cin.tie(0); int n, m, q, type, x1, x2, y1, y2; cin >> n >> m >> q; Cx[0] = n, Cy[0] = m; while(q--) { cin >> type; if(type == 1) { cin >> x1 >> y1; if(ax[x1]) { ax[x1] = 0; add(Cx, x1, -1); } else { ax[x1] = 1; add(Cx, x1, 1); } if(ay[y1]) { ay[y1] = 0; add(Cy, y1, -1); } else { ay[y1] = 1; add(Cy, y1, 1); } } else if(type == 2) { cin >> x1 >> y1 >> x2 >> y2; int s1 = getsum(Cx, x2) - getsum(Cx, x1-1); int s2 = getsum(Cy, y2) - getsum(Cy, y1-1); cout << 1LL*(y2-y1+1)*s1 + 1LL*(x2-x1+1)*s2-1LL*s1*s2*2<<"\n"; } } return 0; }