Title Link: Http://codeforces.com/problemset/problem/707/E
Give you the Nxm grid, there are k bars, each chain has Len nodes, each node has a Value.
There is a Q operation, the operation ask asks you a sub-matrix of the and is how much, the operation switch will be the first chain of the value 0 to change the original number or the original number 0.
A more obvious two-dimensional array of arrays of violence, Note that the ask operation will not exceed 2000, so when the switch operation can not be update operation, otherwise it will time Out. So when you ask, the update will save Time.
Complexity is probably 2000*2000*log2 (*log2*), CF on 3s is duly completed.
1 //#pragma comment (linker, "/stack:102400000, 102400000")2#include <algorithm>3#include <iostream>4#include <cstdlib>5#include <cstring>6#include <cstdio>7#include <vector>8#include <cmath>9#include <ctime>Ten#include <list> one#include <Set> a#include <map> - using namespacestd; -typedefLong LongLL; thetypedef pair <int,int>P; - Const intN = 2e3 +5; - intn, m; - LL bit[n][n]; + structData { - intx[n], y[n], w[n], len; + }a[n]; a BOOLchange[n]; at intflag[n]; - - voidUpdateintXinty, LL Val) { - for(inti = x; I <= n; i + = (i&-I)) { - for(intj = y; J <= m; J + = (j&-j)) { -bit[i][j] + =val; in } - } to } + -LL sum (intXintY) { theLL s =0; * for(inti = x; I >=1; i-= (i&-I)) { $ for(intj = y; J >=1; j-= (j&-j)) {Panax Notoginsengs + =bit[i][j]; - } the } + returns; a } the + intMain () - { $ intk, q; $scanf" %d%d%d", &n, &m, &k); - for(inti =1; I <= k; ++I) { -scanf"%d", &a[i].len); the for(intj =1; J <= a[i].len; ++J) { -scanf" %d%d%d", &a[i].x[j], &a[i].y[j], &a[i].w[j]);Wuyi update (a[i].x[j], a[i].y[j], (LL) a[i].w[j]); the } - } wuscanf"%d", &q); - Charquery[Ten]; about intx1, y1, x2, y2, c; $ for(inti =1; I <= q; ++I) { -scanf"%s", query); - if(query[0] =='A') { -scanf"%d %d%d%d", &x1, &y1, &x2, &y2); a for(intID =1; ID <= k; ++Id) { + if(change[id]) { the if(flag[id]%2) { - for(intj =1; J <= a[id].len; ++J) { $ update (a[id].x[j], a[id].y[j], (LL) a[id].w[j]); the } the}Else { the for(intj =1; J <= a[id].len; ++J) { theUpdate (a[id].x[j], a[id].y[j], (LL)-a[id].w[j]); - } in } thechange[id] = change[id]?false:true; the++flag[id]; about } the } theprintf"%lld\n", Sum (x2, y2)-sum (x2, y1-1)-sum (x1-1, Y2) + sum (x1-1, y1-1)); the}Else { +scanf"%d", &c); -change[c] = change[c]?false:true; the }Bayi } the return 0; the}
View Code
Codeforces 707 E. Garlands (two-dimensional tree-like Array)