Codeforces 707E Garlands
我怎么感觉好水啊。
因为询问只有2000组, 离线询问, 枚举联通块再枚举询问, 二维树状数组更新答案。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, m, k, q, cntq;
LL ans[N];
pair<PII, PII> qus[N];
bool on[N], can[N][N];
vector<pair<PII, int>> vc[N];
char op[]; struct Bit {
LL a[N][N];
void modify(int x, int y, int v) {
for(int i = x; i < N; i += i & -i)
for(int j = y; j < N; j += j & -j)
a[i][j] += v;
}
LL sum(int x, int y) {
LL ans = ;
for(int i = x; i; i -= i & -i)
for(int j = y; j; j -= j & -j)
ans += a[i][j];
return ans;
}
LL query(int x1, int y1, int x2, int y2) {
return sum(x2, y2) - sum(x2, y1 - ) - sum(x1 - , y2) + sum(x1 - , y1 - );
}
} bit; int main() {
scanf("%d%d%d", &n, &m, &k);
for(int i = ; i <= k; i++) {
int len; scanf("%d", &len);
for(int j = ; j <= len; j++) {
int x, y, w;
scanf("%d%d%d", &x, &y, &w);
vc[i].push_back(mk(mk(x, y), w));
}
}
memset(on, true, sizeof(on));
scanf("%d", &q);
while(q--) {
scanf("%s", op);
if(op[] == 'A') {
cntq++;
scanf("%d%d", &qus[cntq].fi.fi, &qus[cntq].fi.se);
scanf("%d%d", &qus[cntq].se.fi, &qus[cntq].se.se);
memcpy(can[cntq], on, sizeof(on));
} else {
int x;
scanf("%d", &x);
on[x] = !on[x];
}
}
for(int i = ; i <= k; i++) {
for(auto& t : vc[i]) bit.modify(t.fi.fi, t.fi.se, t.se);
for(int j = ; j <= cntq; j++) {
if(!can[j][i]) continue;
ans[j] += bit.query(qus[j].fi.fi, qus[j].fi.se, qus[j].se.fi, qus[j].se.se);
}
for(auto& t : vc[i]) bit.modify(t.fi.fi, t.fi.se, -t.se);
}
for(int i = ; i <= cntq; i++) printf("%lld\n", ans[i]);
return ;
} /*
*/
Codeforces 707E Garlands的更多相关文章
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- Garlands CodeForces - 707E (离线树状数组)
大意: 给定n*m矩阵, k条链, 链上每个点有权值, 每次操作可以关闭或打开一条链或询问一个子矩阵内未关闭的权值和. 关键询问操作比较少, 可以枚举每条链, 暴力算出该条链对每个询问的贡献. 最后再 ...
- Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力
E. Garlands 题目连接: http://www.codeforces.com/contest/707/problem/E Description Like all children, Ale ...
- Codeforces 707 E. Garlands (二维树状数组)
题目链接:http://codeforces.com/problemset/problem/707/E 给你nxm的网格,有k条链,每条链上有len个节点,每个节点有一个值. 有q个操作,操作ask问 ...
- Three Garlands~Educational Codeforces Round 35
C. Three Garlands time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Educational Codeforces Round 35 B/C/D
B. Two Cakes 传送门:http://codeforces.com/contest/911/problem/B 本题是一个数学问题. 有a个Ⅰ类球,b个Ⅱ类球:有n个盒子.将球放入盒子中,要 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- 收集服务器网卡和IP信息
收集服务器网卡和IP信息 Python2环境 #!/usr/bin/python2 # -*- coding:utf-8 -*- import os,sys import socket, fcntl, ...
- webuploader
https://www.cnblogs.com/study-fanzeng/p/8930939.html http://fex.baidu.com/webuploader/doc/index.html ...
- Keil5下载STM32库
1.http://www.keil.com/dd2 2.3.以STM32L051C8为例 下载即可.
- KillerBee
KillerBee介绍 KillerBee----是攻击zigbee和IEEE 802.15.4网络的框架和工具.使用killerBee工具和一个兼容的IEEE 802.15.4无线接口,你就能窃取z ...
- 20155332 2016-2017-2 《Java程序设计》第8周学习总结
20155332 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 创建Logger对象 static Logger getLogger(String name ...
- OpenCV入门(1)- 简介
1.图像的表示 在计算机看来,图像只是一些亮度各异的点,一副M*N的图片可以用M*N的矩阵来表示,矩阵的值表示这个位置上像素的亮度. 一般灰度图用二维矩阵来表示,彩色(多通道)图用三维矩阵表示,大部分 ...
- hashMap之jdk1.7和jdk1.8
参考链接: http://allenwu.itscoder.com/hashmap-analyse https://tech.meituan.com/java-hashmap.html
- dubbo系列七、dubbo @Activate 注解使用和实现解析
一.用法 Activate注解表示一个扩展是否被激活(使用),可以放在类定义和方法上,dubbo用它在spi扩展类定义上,表示这个扩展实现激活条件和时机. @Activate(group = Cons ...
- jenkins cobertura单元测试
1.1 Maven 工程 pom.xml 修改 1.2 Build添加插件目标 此时构建项目,会在项目 targer/site/cobertura 目录中生成 html 与 xml ...
- Oracle 同步
原文出处:http://www.cnblogs.com/zeromyth/archive/2009/08/19/1549661.html Oracle备份功能包括: 高级复制(Advanced Rep ...