[二维树状数组] codeforces 707E. Garlands
来源:互联网 发布:linux 查看显存占用 编辑:程序博客网 时间:2024/06/05 01:09
E. Garlands
题意:
一个
然后有
- SWITCH i,按第i条链的开关,开变关,关变开
- ASK x1,y1,x2,y2,查询以x1,y1为左上,x2,y2为右下的矩阵的权值,这个操作总数不超过2000
思路:
离线,每条链分开处理,矩阵用二维树状数组维护,依次把第
#include<stdio.h>typedef long long ll;const int N = 2005;ll tree[N][N];void update(int pos1, int pos2, ll val){ for(; pos1 < N; pos1 += pos1&-pos1){ for(int pos = pos2; pos < N; pos += pos&-pos){ tree[pos1][pos] += val; } }}ll getsum(int pos1, int pos2){ ll res = 0; for(; pos1; pos1 -= pos1&-pos1){ for(int pos = pos2; pos; pos -= pos&-pos){ res += tree[pos1][pos]; } } return res;}int x[N][N], y[N][N], w[N][N];int len[N];bool st[N];int X1[N], Y1[N], X2[N], Y2[N], qcnt = 1;int swc[1000006] = {0};ll ans[N][N];char str[10];int main(){ int n, m, k; scanf("%d%d%d", &n, &m, &k); for(int i = 1; i <= k; ++i){ scanf("%d", &len[i]); for(int j = 0; j < len[i]; ++j){ scanf("%d%d%d", &x[i][j], &y[i][j], &w[i][j]); } } int q; scanf("%d", &q); for(int i = 1; i <= q; ++i){ scanf("%s", str); if(str[0] == 'S') scanf("%d", &swc[i]); else{ scanf("%d%d%d%d", &X1[qcnt], &Y1[qcnt], &X2[qcnt], &Y2[qcnt]); qcnt++; } } for(int i = 1; i <= k; ++i){ for(int j = 0; j < len[i]; ++j) update(y[i][j], x[i][j], w[i][j]); for(int j = 1; j < qcnt; ++j){ ans[i][j] = getsum(Y2[j], X2[j])-getsum(Y2[j], X1[j]-1)-getsum(Y1[j]-1, X2[j])+getsum(Y1[j]-1,X1[j]-1); } for(int j = 0; j < len[i]; ++j) update(y[i][j], x[i][j], -w[i][j]); } for(int i = 1, cnt = 1; i <= q; ++i){ if(swc[i]) st[swc[i]] ^= 1; else{ ll tmp = 0; for(int j = 1; j <= k; ++j){ if(!st[j]) tmp += ans[j][cnt]; } cnt++; printf("%lld\n", tmp); } }}
0 0
- [二维树状数组] codeforces 707E. Garlands
- Codeforces 707E Garlands(二维树状数组)
- codeforces--707E. Garlands(二维树状数组)
- 树状数组(Garlands,codeforces 707e)
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组
- Codeforces Round #368 (Div. 2) E. Garlands(二维树状数组)
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组
- Codeforces Round #368 (Div. 2) E Garlands(二维树状数组+暴力)
- Codeforces Round #368 (Div. 2) E Garlands(二维树状数组+暴力)
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力
- cf#368-E. Garlands-(二维树状数组)
- Codeforces Round #368 (Div. 2) E. Garlands (树状数组)
- codeforces 869E(哈希&二维树状数组)
- Codeforces 869 E. The Untended Antiquity 二维树状数组
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity 二维线段树||二维树状数组
- Codeforces 276E(树状数组)
- Codeforces 387E 树状数组
- Codeforces Round #368 (Div. 2)E Garlands
- logstash 根据type 判断输出
- 20160822,新的团队,新的起点,自力更生
- Decorator模式(装饰模式 结构型)
- 【挖坑记】JZOJ 4722 跳楼机
- mysql分别对分一组的数据进行更新
- [二维树状数组] codeforces 707E. Garlands
- JDBC学习入门
- UVA 1608 Non-boring sequence
- 每日一linux命令(56)-------watch命令
- java-JDBC简单的利用存储过程来《查询》或者《插入》
- 用户portal支持https协议,用loadrunner录制登陆脚本时发现未录制到用户名和密码
- Android开发笔记之ListView item点击失效
- Python 之 深拷贝和浅拷贝 2
- hdu oj 题目分类