题目链接: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. 51nod1199 Money out of Thin Air

    链剖即可.其实就是利用了链剖后子树都在一段连续的区间内所以可以做到O(logn)查询和修改. 线段树细节打错了..要专心!肉眼差错都能找出一堆出来显然是不行的!. #include<cstdio ...

  2. App开放接口api安全性—Token签名sign的设计与实现

    前言 在app开放接口api的设计中,避免不了的就是安全性问题,因为大多数接口涉及到用户的个人信息以及一些敏感的数据,所以对这些接口需要进行身份的认证,那么这就需要用户提供一些信息,比如用户名密码等, ...

  3. c#Winform程序,让pictureBox显示图像(包含GIF),并且不被占用,能即时删除图片。

    最近在做一个图片浏览的工具, 需要在PictureBox中显示图像文件, 包括gif播放.  且不能被程序独占, 就算winform的程序正在显示这张图, 也能在资源管理器里delete它. 看了看网 ...

  4. scala学习笔记(9):Scala函数(2)

    1 指令式编程&函数式编程 指令式:imperative 风格编程.指令式风格,是你常常使用像 Java,C++和 C 这些语言里用的风格,一次性发出一个指令式的命令,用循环去枚举,并经常改变 ...

  5. Java正则表达式之语法规则

    正则表达式是一种强大而灵活的文本处理工具,使用正则表达式能够以编程的方式,构造复杂的文本模式,并对输入的字符串进行搜索.一旦找到了匹配这些模式的部分,就能够随心所欲地它们进行处理.正则表达式提供了一种 ...

  6. robotframework学习

    下载地址: https://pypi.python.org/pypi/robotframework Installation If you already have Python with pip i ...

  7. 【转】linux mknod命令解析

    转自:http://www.cnblogs.com/cobbliu/archive/2011/07/05/2389014.html 个人觉得linux的软件设计思想异常强大,比如把所有的设备都当做文件 ...

  8. 为什么大型网站前端使用PHP后台逻辑用Java

    前两周参加完 ThinkInLamp 的 PHP 架构师大会,听鸟哥一上午的分享,感慨很多,PHP 业界虽然方向不明荒废了两三年的时间,终究还是又重新崛起了. 其实包括 Java 的重启问题,现在也已 ...

  9. mac 配置Python集成开发环境(Eclipse +Python+Pydev)

    1.下载Mac版64位的Eclipse. 进入到Eclipse官方网站的下载页面(http://www.eclipse.org/downloads/),我选择了下图所示的软件包, 浏览器在下载过程中使 ...

  10. 【LeetCode】242 - Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...