Garlands CodeForces - 707E (离线树状数组)
大意: 给定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 (离线树状数组)的更多相关文章
- Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化
D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...
- Codeforces Round #365 (Div. 2) D - Mishka and Interesting sum(离线树状数组)
http://codeforces.com/contest/703/problem/D 题意: 给出一行数,有m次查询,每次查询输出区间内出现次数为偶数次的数字的异或和. 思路: 这儿利用一下异或和的 ...
- CodeForces - 220B Little Elephant and Array (莫队+离散化 / 离线树状数组)
题意:N个数,M个查询,求[Li,Ri]区间内出现次数等于其数值大小的数的个数. 分析:用莫队处理离线问题是一种解决方案.但ai的范围可达到1e9,所以需要离散化预处理.每次区间向外扩的更新的过程中, ...
- POJ 3416 Crossing --离线+树状数组
题意: 给一些平面上的点,然后给一些查询(x,y),即以(x,y)为原点建立坐标系,一个人拿走第I,III象限的点,另一个人拿II,IV象限的,点不会在任何一个查询的坐标轴上,问每次两人的点数差为多少 ...
- HDU 2852 KiKi's K-Number(离线+树状数组)
题目链接 省赛训练赛上一题,貌似不难啊.当初,没做出.离线+树状数组+二分. #include <cstdio> #include <cstring> #include < ...
- 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) ,问在每个区间里所有 ...
- 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 ...
- HDU3333 Turing Tree 离线树状数组
题意:统计一段区间内不同的数的和 分析:排序查询区间,离线树状数组 #include <cstdio> #include <cmath> #include <cstrin ...
- 离线树状数组 hihocoder 1391 Countries
官方题解: // 离线树状数组 hihocoder 1391 Countries #include <iostream> #include <cstdio> #include ...
随机推荐
- tomcat性能调优 大赞
从“第三天”的性能测试一节中,我们得知了决定性能测试的几个重要指标,它们是: ü 吞吐量 ü Responsetime ü Cpuload ü MemoryUsage 我 们也在第三天的学习中对Apa ...
- Python之路----迭代器与生成器
一.迭代器 L=[1,,2,3,4,5,] 取值:索引.循环for 循环for的取值:list列表 dic字典 str字符串 tuple元组 set f=open()句柄 range() enumer ...
- 浏览器内核、排版引擎、js引擎
[定义] 浏览器最重要或者说核心的部分是“Rendering Engine”,可大概译为“渲染引擎”,不过我们一般习惯将之称为“浏览器内核”.负责对网页语法的解释(如标准通用标记语 言下的一个应用HT ...
- 09:Linux 中各个文件夹的作用
参考博客 / 根目录 包含了几乎所的文件目录.相当于中央系统.进入的最简单方法是:cd /. /boot 引导程序,内核等存放的目录 这个目录,包括了在引导过程中所必需的文件.在最开始的启动阶段, ...
- 自定义LisetView
1.ListView listview=findViewById(R.id.listview); 2.public class MyAdapter extends BaseAdapter{ priva ...
- React 回忆录(一)为什么使用 React?
Hi 各位,欢迎来到 React 回忆录!
- Hadoop Hive概念学习系列之hive里的分区(九)
为了对表进行合理的管理以及提高查询效率,Hive可以将表组织成“分区”. 分区是表的部分列的集合,可以为频繁使用的数据建立分区,这样查找分区中的数据时就不需要扫描全表,这对于提高查找效率很有帮助. 分 ...
- Uncaught TypeError: $(...).daterangepicker is not a function
本文为博主原创,未经允许不得转载: 在用bootstrap做一个日期插件的时候,代码和js,css等都是拷贝网上下载下来的实例,但是在 调试的时候,浏览器控制台一直报错 Uncaught TypeEr ...
- com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
作者原创,转载请注明转载地址 第一次遇到该异常,在网上搜了很长时间也没找到解决答案,特此记录 1.异常展示: com.fasterxml.jackson.databind.JsonMappingExc ...
- vim E437: terminal capability "cm" required
报错E437: terminal capability "cm" required 解决方法:# export TERM=xterm