Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力
来源:互联网 发布:盛势网络剧海外版480p 编辑:程序博客网 时间:2024/05/22 11:46
参考http://www.cnblogs.com/qscqesze/p/5792926.html
题意给你一个nm的矩阵,里面有k条链,你有q次询问每次询问可以使得一条链变成0,或者使得这条链变成原来的值。然后查询一个矩阵的权值和。
分析。。没有卡。不知道为何。。自己的代码错了,直接贴别人的
#include<bits/stdc++.h>using namespace std;const int maxn = 2e3+6;long long d[maxn][maxn];int lowbit(int x){ return x&(-x);}void update(int x,int y,int w){ for(int i=x;i<maxn;i+=lowbit(i)) for(int j=y;j<maxn;j+=lowbit(j)) d[i][j]+=w;}long long get(int x,int y){ long long ans = 0; for(int i=x;i;i-=lowbit(i)) for(int j=y;j;j-=lowbit(j)) ans+=d[i][j]; return ans;}vector<int> px[maxn],py[maxn],pw[maxn];int flag[maxn],la[maxn];char op[25];int main(){ int n,m,k; scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=k;i++) { int num;scanf("%d",&num); la[i]=1; for(int j=1;j<=num;j++) { int x,y,z;scanf("%d%d%d",&x,&y,&z); px[i].push_back(x); py[i].push_back(y); pw[i].push_back(z); } } int q;scanf("%d",&q); for(int i=1;i<=q;i++) { scanf("%s",op); if(op[0]=='S') { int a;scanf("%d",&a); flag[a]^=1; } else{ int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d); for(int j=1;j<=k;j++) { if(la[j]==flag[j])continue; if(flag[j]==0) { for(int i2=0;i2<px[j].size();i2++) update(px[j][i2],py[j][i2],pw[j][i2]); la[j]=flag[j]; } else { for(int i2=0;i2<px[j].size();i2++) update(px[j][i2],py[j][i2],-pw[j][i2]); la[j]=flag[j]; } } printf("%lld\n",get(c,d)+get(a-1,b-1)-get(c,b-1)-get(a-1,d)); } }}
阅读全文
0 0
- 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 二维树状数组 暴力
- 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 #439 (Div. 2) E. The Untended Antiquity 二维线段树||二维树状数组
- cf#368-E. Garlands-(二维树状数组)
- 树状数组(Garlands,codeforces 707e)
- Codeforces Round #439 (Div. 2) E:The Untended Antiquity(Hash+二维树状数组)
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity 二维树状数组 随机化
- Codeforces Round #368 (Div. 2) E. Garlands(查询矩形内的和)
- 9.5题解
- Selenium with Python中文翻译(二)
- NAT模式下无法连接本地VM虚拟机的解决方案
- JVM类加载机制详解
- HBase数据恢复 (总结14)
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力
- c++综述
- Viewpager的竖直切换及其子fragment之间的点击跳转
- 项目2
- HBase原理讲解 (总结15)
- Java线程的5种状态及状态间的转换
- 猜谜 —— 英文回文(递归)
- LeetCode 12. Integer to Roman
- 简单的Filter+Servlet+反射,实现Servlet中有多个方法可以执行