题目链接: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. 在Eclipse中运行cmd

    第一步:设置一个新的外部配置工具 在 Eclipse 中,选择 “Run -> External Tools -> External Tools Configurations”  第二步: ...

  2. phonegap 退出确认

    实现 再按一次退出  ,这里只针对 主active继承 DroidGap 或者CordovaActive 以下有2种 方案1: 重写CordovaWebView类 新建类NobackWebView p ...

  3. 502 Bad Gateway nginx 解决

    打开 /usr/local/php/etc/php-fpm.conf 调大以下两个参数(根据服务器实际情况,过大也不行) <value name=”max_children”>5120&l ...

  4. 挺好看的CSS

    <?php header("content-type:text/html;charset=utf-8"); echo "<style>h1{ color ...

  5. 抛弃EF,20分构建一个属于自己的ORM框架

    Poiuyt_cyc 博客园首页新随笔联系订阅管理随笔 - 11  文章 - 0  评论 - 111 抛弃EF,20分构建一个属于自己的ORM框架 相信EF大家都不陌生了,因为数据库表跟程序实体是一一 ...

  6. Eclipse插件安装的三种方法

    转自:http://www.blogjava.net/tangzurui/archive/2008/06/30/211669.html  整理了一下格式. (前两种安装方式以多国语言包的安装为例) 1 ...

  7. Windows下配置使用WinPcap

     0.前提 windows: win7 x64 WinPcap版本:4.1.3 WinPcap开发包:4.1.2 目标:在VS2010中配置使用winpcap 获取目标计算机中安装的网卡列表  1.下 ...

  8. 【DWT笔记】傅里叶变换与小波变换

    [DWT笔记]傅里叶变换与小波变换 一.前言 我们经常接触到的信号,正弦信号,余弦信号,甚至是复杂的心电图.脑电图.地震波信号都是时域上的信号,我们也成为原始信号,但是通常情况下,我们在原始信号中得到 ...

  9. SynchronousQueue

    SynchronousQueue是一个没有数据缓冲的BlockingQueue,生产者线程对其的插入操作put必须等待消费者的移除操作take,反过来也一样. 不像ArrayBlockingQueue ...

  10. Android开源图表库介绍

    XCL-Charts XCL-Charts V1.8     Android开源图表库(XCL-Charts is a free charting library for Android platfo ...