cf#368-E. Garlands-(二维树状数组)
来源:互联网 发布:53端口攻击 编辑:程序博客网 时间:2024/06/06 04:36
http://codeforces.com/contest/707/problem/E
题意:
给n*m矩阵,给k条链,链的每个节点有一个权值,每次查询一个子矩阵,求子矩阵之和
n,m,k都是2000以内,链的长度也是2000以内
每次操作 要么查询子矩阵,要么把一条链抹去,或恢复
由于链长只有2000,暴力模拟
对于查询矩阵和与单点更新就用二维树状数组咯
更新链的时候注意,每次直接更新链会T,要标记一下,在查询时统一更新才可以水过去。。正解看不懂、2333
1.6s/3S
//poj1195#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <set>#include <map>#include <vector>#include <iostream>using namespace std;const double pi=acos(-1.0);double eps=1e-5;int n,m;const int maxn=2005;struct tree{ long long num[maxn][maxn]; inlineint lowbit(int x) { return x&-x; } void add(int x,int y,long long a) { int i,j; for (i=x; i<=n; i+=lowbit(i)) { for (j=y; j<=m; j+=lowbit(j)) num[i][j]+=a; } } long long query(int x,int y) { long long ans=0,i,j; for (i=x; i>0; i-=lowbit(i)) { for (j=y; j>0; j-=lowbit(j)) ans+=num[i][j]; } return ans; }};struct node{ int x,y, w;};struct line{ int len; vector<node> p;};line llo[2005];tree tp;long long query(int l,int b,int r,int t){ long long ret=tp.query(r,t); ret-=tp.query(l-1,t); ret-=tp.query(r,b-1); ret+=tp.query(l-1,b-1); return ret;}int vis[2005];int real[2005];int main(){ int k; cin>>n>>m>>k; for (int i=1; i<=k; i++) { scanf("%d",&llo[i].len); node tmp; for (int j=1; j<=llo[i].len; j++) { scanf("%d%d%d",&tmp.x,&tmp.y,&tmp.w); llo[i].p.push_back(tmp); tp.add(tmp.x,tmp.y,tmp.w); } } int q; cin>>q; char op[10]; for (int i=1; i<=q; i++) { scanf("%s",op); if(op[0]=='A') { int l,r,b,t; for (int h=1; h<=k; h++) { if (real[h]==vis[h]) continue; for (int j=0; j<llo[h].p.size(); j++) { int xx=llo[h].p[j].x; int yy=llo[h].p[j].y; int w=llo[h].p[j].w; if (vis[h]==1) w=-w; tp.add(xx,yy,w); real[h]=vis[h]; } } scanf("%d%d%d%d",&l,&b,&r,&t); long long ret=query(l,b,r,t); printf("%lld\n",ret); } else { int x; scanf("%d",&x); vis[x]^=1; } } return 0;}
0 0
- cf#368-E. Garlands-(二维树状数组)
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组
- Codeforces Round #368 (Div. 2) E. Garlands(二维树状数组)
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组
- Codeforces 707E Garlands(二维树状数组)
- codeforces--707E. Garlands(二维树状数组)
- [二维树状数组] codeforces 707E. Garlands
- Codeforces Round #368 (Div. 2) E Garlands(二维树状数组+暴力)
- Codeforces Round #368 (Div. 2) E Garlands(二维树状数组+暴力)
- Codeforces Round #368 (Div. 2) E. Garlands (树状数组)
- 树状数组(Garlands,codeforces 707e)
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力
- CF - 61E - Enemy is weak(树状数组)
- CF 121E Lucky Array 【树状数组】
- codeforces 869E(哈希&二维树状数组)
- 树状数组(二维)
- cf#348-E. Little Artem and Time Machine-树状数组+map节点(动态开点树状数组)
- CF 341D - Iahub and Xors(二维树状数组)
- HBase的Write Ahead Log (WAL) —— 整体架构、线程模型
- shell编程之if判断的总结
- 06margin外边距基本使用
- Java线程监听,意外退出线程后自动重启
- php 查看数组占用的内存大小
- cf#368-E. Garlands-(二维树状数组)
- mysql prompt的用法详解
- linux C编程(四)int占用字节数/大小端模式/数据类型自动转换/结构体内存占用
- Some RGBD datasets
- 【11】Java集合:HashMap深度解析(一)
- Java 大整数运算
- iOS开发问题----使用XIB文件布局获取并更改某控件frame的问题
- Android资源分类和适配
- LightOJ 1182 Parity