大意: 给定n*m矩阵, k条链, 链上每个点有权值, 每次操作可以关闭或打开一条链或询问一个子矩阵内未关闭的权值和.

关键询问操作比较少, 可以枚举每条链, 暴力算出该条链对每个询问的贡献. 最后再按询问顺序切换链的状态, 只记录打开的链的贡献即可.

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N = 2e3+20, M = 1e6+10;
int n, m, k, q, cnt;
int len[N], x[N][N], y[N][N], w[N][N], vis[N];
char op[M][10];
int t[M], t1[N], t2[N], t3[N], t4[N];
ll c[N][N], ans[N][N];
void upd(int x, int y, int w) {
for (int i=x; i<=n+1; i+=i&-i) for (int j=y; j<=m+1; j+=j&-j) c[i][j]+=w;
}
ll qry(int x, int y) {
ll r = 0;
for (int i=x; i; i^=i&-i) for (int j=y; j; j^=j&-j) r+=c[i][j];
return r;
} int main() {
scanf("%d%d%d", &n, &m, &k);
REP(i,1,k) {
scanf("%d", len+i);
REP(j,1,len[i]) {
scanf("%d%d%d",&x[i][j],&y[i][j],&w[i][j]);
++x[i][j], ++y[i][j];
}
}
scanf("%d", &q);
REP(i,1,q) {
scanf("%s", op[i]);
if (op[i][0]=='S') scanf("%d",t+i);
else {
++cnt;
scanf("%d%d%d%d",t1+cnt,t2+cnt,t3+cnt,t4+cnt);
++t1[cnt],++t2[cnt],++t3[cnt],++t4[cnt];
}
}
REP(i,1,k) {
REP(j,1,len[i]) upd(x[i][j],y[i][j],w[i][j]);
REP(j,1,cnt) {
int x1=t1[j],y1=t2[j],x2=t3[j],y2=t4[j];
ans[i][j] = qry(x2,y2)-qry(x2,y1-1)-qry(x1-1,y2)+qry(x1-1,y1-1);
}
REP(j,1,len[i]) upd(x[i][j],y[i][j],-w[i][j]);
}
int now = 0;
REP(i,1,q) {
if (op[i][0]=='S') vis[t[i]] ^= 1;
else {
++now;
ll r = 0;
REP(i,1,k) if (!vis[i]) r+=ans[i][now];
printf("%lld\n", r);
}
}
}

Garlands CodeForces - 707E (离线树状数组)的更多相关文章

  1. Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化

    D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...

  2. Codeforces Round #365 (Div. 2) D - Mishka and Interesting sum(离线树状数组)

    http://codeforces.com/contest/703/problem/D 题意: 给出一行数,有m次查询,每次查询输出区间内出现次数为偶数次的数字的异或和. 思路: 这儿利用一下异或和的 ...

  3. CodeForces - 220B Little Elephant and Array (莫队+离散化 / 离线树状数组)

    题意:N个数,M个查询,求[Li,Ri]区间内出现次数等于其数值大小的数的个数. 分析:用莫队处理离线问题是一种解决方案.但ai的范围可达到1e9,所以需要离散化预处理.每次区间向外扩的更新的过程中, ...

  4. POJ 3416 Crossing --离线+树状数组

    题意: 给一些平面上的点,然后给一些查询(x,y),即以(x,y)为原点建立坐标系,一个人拿走第I,III象限的点,另一个人拿II,IV象限的,点不会在任何一个查询的坐标轴上,问每次两人的点数差为多少 ...

  5. HDU 2852 KiKi's K-Number(离线+树状数组)

    题目链接 省赛训练赛上一题,貌似不难啊.当初,没做出.离线+树状数组+二分. #include <cstdio> #include <cstring> #include < ...

  6. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组

    题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...

  7. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)

    转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...

  8. HDU3333 Turing Tree 离线树状数组

    题意:统计一段区间内不同的数的和 分析:排序查询区间,离线树状数组 #include <cstdio> #include <cmath> #include <cstrin ...

  9. 离线树状数组 hihocoder 1391 Countries

    官方题解: // 离线树状数组 hihocoder 1391 Countries #include <iostream> #include <cstdio> #include ...

随机推荐

  1. oracle_存储过程小记

    # 刷新会员标签函数 {color:red} fun_refresh_code{color} {noformat}CREATE OR REPLACE FUNCTION fun_refresh_code ...

  2. selenium自动化定位方法

    用selenium操作浏览器进行自动化操作其实就是通过元素属性执行相关操作.所以,我们要知道怎样去查找元素,定位元素. 常见的定位属性有: #查找元素的id find_elements_by_id(i ...

  3. 编译安装 http

    1. 安装 apr http服务依赖 apr和apr-util ,安装 http 前需先安装这两个程序 apr 简介:http://www.cnblogs.com/Alight/p/3997777.h ...

  4. c++的友元类、方法及其益处

    在java中,我们知道除了public和private,protected外,还有默认的包可见性访问级别,虽然如此,很多时候出于早期设计缺陷的原因,我们需要访问一些包或者protected可见性级别的 ...

  5. html模板生成静态页面及模板分页处理

    它只让你修改页面的某一部分,当然这"某一部分"是由你来确定的.美工先做好一个页面,然后我们把这个页面当作模板(要注意的是这个模板就没必要使用EditRegion3这样的代码了,这种 ...

  6. 20145206邹京儒MSF基础应用

    20145206邹京儒MSF基础应用 一.MS08_067漏洞渗透攻击实践 实验前准备 1.两台虚拟机,其中一台为kali,一台为windows xp sp3(英文版). 2.在VMware中设置两台 ...

  7. C#预处理器指令【转】

    本文转载自:http://www.cnblogs.com/miffylf/p/4005223.html C#有许多名为预处理器指令的命令.这些命令从来不会转化为可执行代码中的命令,但会影响编译过程的各 ...

  8. HDU 3404 Switch lights(Nim积)题解

    题意:在一个二维平面中,有n个灯亮着并告诉你坐标,每回合需要找到一个矩形,这个矩形xy坐标最大的那个角落的点必须是亮着的灯,然后我们把四个角落的灯状态反转,不能操作为败 思路:二维Nim积,看不懂啊, ...

  9. MOOC_Java进阶_翁恺讲_第三周题

    package mooc_java进阶_d3周题; /** * 没有使用HashMap */ import java.util.ArrayList; import java.util.Scanner; ...

  10. 【转载】非Lumia 950/XL机型 强行开启continuum教程

    听说Windows 10 Mobile 的 Continuum 特性很长时间了,但是由于我自己的 Lumia 930 不在支持之列,一直没能体验到这个功能.今天在酷七看到了这篇文章,按文章所述的步骤进 ...