codeforces--707E. Garlands(二维树状数组)
来源:互联网 发布:用友数据恢复 编辑:程序博客网 时间:2024/05/21 09:39
cf 707E
题解
参考题解
#include <bits/stdc++.h>using namespace std;const double eps = 1E-8;const int dx[4] = {1, 0, 0, -1};const int dy[4] = {0, -1, 1, 0};const int inf = 0x3f3f3f3f;const int N = 1E5 + 7;#define MS(a, x) memset(a, x, sizeof(a))#define MP make_pair#define fst first#define sec second#define lson l, m, rt << 1#define rson m + 1, r, rt << 1 | 1typedef long long LL;const int maxn = 2000 + 3;// AC info: 1482 ms 72900 KBstruct Cell{ int x, y; LL val;};int n, m, k, q;vector<Cell> garland[maxn];LL c[maxn][maxn];bool on[maxn], last[maxn];int lowbit(int i) { return i & (-i); }void add(int x, int y, int v){ for(int i = x; i <= n; i += lowbit(i)){ for(int j = y; j <= m; j += lowbit(j)) c[i][j] += v; }}LL sum(int x, int y){ LL s = 0; for(int i = x; i ; i -= lowbit(i)){ for(int j = y; j ; j -= lowbit(j)) s += c[i][j]; } return s;}int main(){#ifdef LOCALfreopen("data.in", "r", stdin);#endif // LOCAL scanf("%d %d %d", &n, &m, &k); for(int i = 1; i <= k; ++i){ int lights; scanf("%d", &lights); for(int j = 0; j < lights; ++j){ int x, y, val; scanf("%d %d %d", &x, &y, &val); garland[i].push_back(Cell{x, y, val}); } // turn on on[i] = true; } scanf("%d", &q); char op[8]; int x1, y1, x2, y2; for(int cnt = 0; cnt < q; ++cnt){ scanf("%s", op); if(op[0] == 'S'){ int which; scanf("%d", &which); on[which] ^= 1; } else{ scanf("%d %d %d %d", &x1, &y1, &x2, &y2); // 每一次ASK,都要计算每条链的贡献 for(int i = 1; i <= k; ++i){ // 如果和上一次的状态不同,更新 if(last[i] != on[i]){ for(int j = 0; j < garland[i].size(); ++j){ // 第i条链的第j个灯 if(on[i]) add(garland[i][j].x, garland[i][j].y, garland[i][j].val); else add(garland[i][j].x, garland[i][j].y, -garland[i][j].val); } } // 记录上一次的状态 last[i] = on[i]; } LL ans = sum(x2, y2) - sum(x2, y1 - 1) - sum(x1 - 1, y2) + sum(x1 - 1, y1 - 1); printf("%I64d\n", ans); } } return 0;}
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(二维树状数组+暴力)
- cf#368-E. Garlands-(二维树状数组)
- Codeforces Round #368 (Div. 2) 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(Hash+二维树状数组)
- codeforces 191 E (树状数组+二分)
- Codeforces Round #439 (Div. 2) E. The Untended Antiquity 二维线段树||二维树状数组
- Codeforces 276E(树状数组)
- 下厨房(istringstream的使用)----网易2017内推笔试编程题合集
- MySQL高效分页解决方案集
- 2016暑期LNOI夏令营 T2解题报告
- javascript中新增、修改、删除cookie
- 使用symbolicatecrash分析crash文件
- codeforces--707E. Garlands(二维树状数组)
- HDU 1048 Fire Net
- cocoscreate 官方例子说明 02_ui_01_widget_AlignOnceWidget by:adady
- 安卓谷歌电子市场学习笔记系列——ViewHolder及convertView
- msp430g2533之iic(gpio模拟iic)
- OpenJudge 2705:扩号匹配问题
- 3D玫瑰
- 使用tomcat8.0.36实现的websocket技术,实现向单个以及全部用户实时推送消息的功能
- 常用库的混淆