【题目链接】: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. 02_cfork分叉进程

    fork函数.调用它就可以在当前的进程当中给它分叉出一个新的进程.分叉出的进程就可以看看它有什么特点?

  2. oracle给用户授权

    1.在PLSQL里,用sys(oracle系统用户)登陆,登陆的时候一定要选择SYSDBA.普通用户登陆选择normal就可以了 2.创建用户 *也可以给普通用户授权为dba即数据库管理员.在导入导出 ...

  3. bzoj 1700: [Usaco2007 Jan]Problem Solving 解题【dp】

    很像贪心的dp啊 这个定金尾款的设定让我想起了lolita和jk制服的尾款地狱-- 设f[i][j]为从j到i的付定金的最早月份然后从f[k][j-1]转移来,两种转移f[i][j]=min(f[i] ...

  4. bzoj 1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果【tarjan+记忆化搜索】

    对这个奇形怪状的图tarjan,然后重新连边把图变成DAG,然后记忆化搜索即可 #include<iostream> #include<cstdio> using namesp ...

  5. 10.16NOIP模拟赛

    /* 我是一个大sb */ #include<iostream> #include<cstdio> #include<cstring> #include<qu ...

  6. [Swift]Array数组的swapAt函数

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. Juicer.js模板引擎问题

    由于jsp中的EL表达式语法和jquery.tmpl十分类似,,所以单纯的使用${name},数据是渲染不上tmpl的. SO.. 要加上转义: ${'${'}amount} 或者 \${amount ...

  8. spring-redis-data的一个坑

    事故原因: 运维报告redis内存直线上升,然后查询发现都是setrange操作,review代码,没法发现setrange操作 代码如下: redisTemplate.opsForValue().s ...

  9. java 分解整数 【个 十 百】(数组案例)

    求一个数两位数的个位数,十位数,百位数及千位: int num = 53; int g = (num / 1) % 10;  //个位 int s = (num / 10) % 10; //十位 in ...

  10. 连接oracle出现的问题以及解决办法

    连接oracle出现过的问题: 1,ORA-12514::监听程序当前无法识别链接描述符中请求的服务 1)重启服务,看是否解决 2)测试网络监听是否能监听成功,监听不成功的话,查看下面几个点:服务名( ...