题目链接: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 ;
}

最新文章

  1. 从Insider计划看Win10的发展
  2. 一些有意思的VR设备介绍
  3. 低功耗蓝牙4.0BLE编程-nrf51822开发(6)-Battery Service
  4. TCP connection status
  5. webstorm下设置sass
  6. gitcafe 使用hexo搭建博客
  7. 就是一段程序,可以求出N个不等长列表中取N个元素形成的所有组合
  8. 使用JSONObject生成和解析json
  9. hdu_4717: The Moving Points 【三分】
  10. zabbix 配置发送邮件报警
  11. 在Entity Framework 中用 Code First 创建新的数据库
  12. Spring框架浅析
  13. python数据结构与算法之单链表
  14. linux上安装mysql5.7
  15. hello.cpp 第一个C++程序(本博客没有特指都是以QT测试)
  16. ajax常见的面试问题
  17. SQL注入之Sqli-labs系列第二十七关(过滤空格、注释符、union select)和第二十七A
  18. linux之cut
  19. 论 Python Opencv 中文路径及中文文件名图像文件读取的两种方式
  20. Linux入门进阶第四天——服务管理

热门文章

  1. Android app 别用中文名
  2. yaf框架流程四
  3. JVM——新生代与老年代
  4. 【转】Xcode添加静态库以及编译选项配置常见问题
  5. jad安装
  6. freemaker转word xml注意事项
  7. MongoDB Auto-Sharding(自动分片)入门介绍
  8. android面试题(转)
  9. Golang官方图片库
  10. C#读写文件总结