【题目链接】:http://codeforces.com/contest/707/problem/E

【题意】



给你一个n*m的方阵;

里面有k个联通块;

这k个联通块,每个连通块里面都是灯;

给你q个操作;

有以下两种类型

①将第i个连通块里面灯取反

②询问你(x1,y1)(x2,y2)这个矩形区域内灯的权值的和;

【题解】



要用到二维的树状数组;

取反操作只要O(1)就能完成;

即先不管它是什么,取反就是了;

然后在询问的时候,直接用二维树状数组累加;

这里的累加可能是减也可能是加;

也可能不变;

搞根据flag数组的值和cha数组的值来判断;

然后就是一个二维的前缀和了;

具体的看代码吧。



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int K = 2e3+100; struct abc{
int x, y, w;
}; int n, m, k, num[K],cha[K],flag[K];
abc a[K][K];
char s[7];
LL sum[K][K]; int lowbit(int x) {return x&(-x);} void add(int x, int y, LL t){
while (x <= n){
int j = y;
while (j <= m) {
sum[x][j] += t;
j += lowbit(j);
}
x += lowbit(x);
}
} LL get_sum(int x, int y)
{
LL temp = 0;
while (x > 0){
int j = y;
while (j > 0){
temp += sum[x][j];
j -= lowbit(j);
}
x -= lowbit(x);
}
return temp;
} int main(){
//freopen("F:\\rush.txt", "r", stdin);
rei(n), rei(m), rei(k);
rep1(i, 1, k){
rei(num[i]);
rep1(j, 1, num[i]) rei(a[i][j].x), rei(a[i][j].y), rei(a[i][j].w);
cha[i] = 1;
}
int q;
rei(q);
while (q--) {
scanf("%s", s);
if (s[0] == 'S'){
int k; rei(k);
cha[k] = 1 - cha[k];
}
else{
rep1(i, 1, k)
if (cha[i]){
rep1(j, 1, num[i]) add(a[i][j].x, a[i][j].y, a[i][j].w*((flag[i] == 0) ? 1 : -1));
cha[i] = 0, flag[i] = 1 - flag[i];
}
int x1, y1, x2, y2;
rei(x1), rei(y1), rei(x2), rei(y2);
printf("%lld\n", get_sum(x2, y2) - get_sum(x1-1, y2) - get_sum(x2, y1-1) + get_sum(x1-1, y1-1));
}
}
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 707E】Garlands的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  3. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  4. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  5. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  6. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  7. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  8. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

  9. 【codeforces 515C】Drazil and Factorial

    [题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...

随机推荐

  1. 在visual studio code和visual studio中编写TypeScript文件自动生成JavaScript文件

    注:此处的自动生成都为保存ts文件时自动生成js文件 VS CODE 只需要在TypeScript的终端控制台中输入如下命令即可,并注意需要将其中的*换成对应的文件名,此处的*似乎不能作为通用匹配. ...

  2. P1266 速度限制(分层图spfa)

    P1266 速度限制 题目描述 在这个繁忙的社会中,我们往往不再去选择最短的道路,而是选择最快的路线.开车时每条道路的限速成为最关键的问题.不幸的是,有一些限速的标志丢失了,因此你无法得知应该开多快. ...

  3. Java多线程(八) synchronized 抛出异常锁自动解除

    当一个线程执行的代码出现异常时,其所持有的锁会自动释放 public class MyObject { private int i = 1; synchronized public void meth ...

  4. Android 性能优化(20)多核cpu入门:SMP Primer for Android

    SMP Primer for Android 1.In this document Theory Memory consistency models Processor consistency CPU ...

  5. java https客户端请求

    String pathname = Test3.class.getResource("/client.jks").getFile(); System.out.println(pat ...

  6. leetcode650 2 Keys Keyboard

    思路: 把给定的数分解质因子之后,对于每一个质因子x,都需要x次操作(一次copy all操作和x-1次paste),所以答案就是对分解后的所有质因子求和. 实现: class Solution { ...

  7. 网页内容爬取:如何提取正文内容 BEAUTIFULSOUP的输出

    创建一个新网站,一开始没有内容,通常需要抓取其他人的网页内容,一般的操作步骤如下: 根据url下载网页内容,针对每个网页的html结构特征,利用正则表达式,或者其他的方式,做文本解析,提取出想要的正文 ...

  8. python生成动态个性二维码

    1 安装工具2 生成普通二维码3 带图片的二维码4 动态 GIF 二维码5 在Python程序中使用 一.安装 首先在python环境下运行, 打开cmd进入python27 进入scripts 然后 ...

  9. Assembly之instruction之Status register

    The status register (SR/R2), used as a source or destination register, can be used in the register m ...

  10. Extensions can add new functionality to a type, but they cannot override existing functionality.

    Extensions can add new functionality to a type, but they cannot override existing functionality.