题目链接:http://codeforces.com/problemset/problem/707/E

给你nxm的网格,有k条链,每条链上有len个节点,每个节点有一个值。

有q个操作,操作ask问你一个子矩阵的和是多少,操作switch将第i条链上的值0变原来的数or原来的数变0。

比较明显的二维数组数组暴力,注意的是ask操作不会超过2000,所以在switch操作的时候不能进行update操作,否则会超时。所以你在ask操作的时候update就会省时。

复杂度大概是2000*2000*log2(2000)*log2*(2000),cf上3s妥妥过。

 //#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 2e3 + ;
int n, m;
LL bit[N][N];
struct data {
int x[N], y[N], w[N], len;
}a[N];
bool change[N];
int flag[N]; void update(int x, int y, LL val) {
for(int i = x; i <= n; i += (i&-i)) {
for(int j = y; j <= m; j += (j&-j)) {
bit[i][j] += val;
}
}
} LL sum(int x, int y) {
LL s = ;
for(int i = x; i >= ; i -= (i&-i)) {
for(int j = y; j >= ; j -= (j&-j)) {
s += bit[i][j];
}
}
return s;
} int main()
{
int k, q;
scanf("%d %d %d", &n, &m, &k);
for(int i = ; i <= k; ++i) {
scanf("%d", &a[i].len);
for(int j = ; j <= a[i].len; ++j) {
scanf("%d %d %d", &a[i].x[j], &a[i].y[j], &a[i].w[j]);
update(a[i].x[j], a[i].y[j], (LL)a[i].w[j]);
}
}
scanf("%d", &q);
char query[];
int x1, y1, x2, y2, c;
for(int i = ; i <= q; ++i) {
scanf("%s", query);
if(query[] == 'A') {
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
for(int id = ; id <= k; ++id) {
if(change[id]) {
if(flag[id] % ) {
for(int j = ; j <= a[id].len; ++j) {
update(a[id].x[j], a[id].y[j], (LL)a[id].w[j]);
}
} else {
for(int j = ; j <= a[id].len; ++j) {
update(a[id].x[j], a[id].y[j], (LL)-a[id].w[j]);
}
}
change[id] = change[id] ? false: true;
++flag[id];
}
}
printf("%lld\n", sum(x2, y2) - sum(x2, y1 - ) - sum(x1 - , y2) + sum(x1 - , y1 - ));
} else {
scanf("%d", &c);
change[c] = change[c] ? false: true;
}
}
return ;
}

Codeforces 707 E. Garlands (二维树状数组)的更多相关文章

  1. Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力

    E. Garlands 题目连接: http://www.codeforces.com/contest/707/problem/E Description Like all children, Ale ...

  2. Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分

    Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...

  3. Codeforces Round #198 (Div. 1) D. Iahub and Xors 二维树状数组*

    D. Iahub and Xors   Iahub does not like background stories, so he'll tell you exactly what this prob ...

  4. Codeforces #590 D 二维树状数组

    题意 给一个10^5之内的字符串(小写字母)时限2s 输入n,有n个操作  (n<10^5) 当操作是1的时候,输入位置x和改变的字母 当操作是2的时候,输入区间l和r,有多少不同的字母 思路 ...

  5. 二维树状数组 BZOJ 1452 [JSOI2009]Count

    题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...

  6. HDU1559 最大子矩阵 (二维树状数组)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)  ...

  7. POJMatrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22058   Accepted: 8219 Descripti ...

  8. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  9. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

随机推荐

  1. Strom Topology执行分析:worker数,Bolt实例数,executor数,task数

    在创建Storm的Topology时,我们通常使用如下代码:builder.setBolt("cpp", new CppBolt(), 3).setNumTasks(5).none ...

  2. BZOJ 1589 采集糖果

    23333怎么调了一晚上.... #include<iostream> #include<cstdio> #include<cstring> #include< ...

  3. VBScript - CUD registry key and value

    http://msdn.microsoft.com/en-us/library/aa384906(v=vs.85).aspx HKEY_LOCAL_MACHINE = &H80000002 s ...

  4. UVa11582 Colossal Fibonacci Numbers!

    #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> us ...

  5. Error accessing PRODUCT_USER_PROFILE

    1.问题现象再现1)创建用户secSQL> create user sec identified by sec; User created. 2)授权SQL> grant connect, ...

  6. ASIFormDataRequest 登录

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL: [NSURL URLWithString: @"http: ...

  7. centos下安装eclipse-c++

    eclipse-c++ 1)编译器及工具链 yum install gcc gcc-c++ 2)开发工具包(JDK):下载网址:http://www.oracle.com/technetwork/ja ...

  8. X86调用约定

    cdecl      C语言默认的调用约定,从右往左压栈,由调用者负责清栈,所以参数个数可以不固定: stdcall    windows默认调用方式,从右往左压栈,由被调用者负责栈操作. pasca ...

  9. 十六进制字符串转化成字符串输出HexToStr(Delphi版、C#版)

    //注意:Delphi2010以下版本默认的字符编码是ANSI,VS2010的默认编码是UTF-8,delphi版得到的字符串须经过Utf8ToAnsi()转码才能跟C#版得到的字符串显示结果一致. ...

  10. selenium-grid2 远程并发控制用例执行

    今天闲来无事,随意看了一下selenium,突然注意到grid这个功能以前都是,在读有关selenium的文档时候知道有这么个grid远程控制的功能,但一直没有去试过.所以呢,今天就简单的做了这么个小 ...