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 ...
随机推荐
- input单选框多选框时可用的事件
change(): 当元素的值发生改变时,会发生 change 事件. 该事件仅适用于文本域(text field),以及 textarea 和 select 元素. change() 函数触发 ch ...
- buildroot构建项目(三)--- u-boot 2017.11 适配开发板修改 1
当前虽然编译成功了,但是对于我们自己的目标板并不太适用.还得做一系列得修改. 一.lds 文件分析 u-boot 中最重要得链接文件即是,u-boot.lds.我们可以查看我们编译出来得 u-boot ...
- PXC中的GTIDs
基本环境:PXC 5.7.19 Row+Gtid,3节点 一.Galera GTID vs MySQL GTID 1.1.Galera GTID vs MySQL GTID Both kinds of ...
- git进阶命令
首先, clone 一个远端仓库,到其目录下: $ Git clone git://example.com/myproject $ cd myproject 然后,看看你本地有什么分支: $ git ...
- CNN可解释
1 http://bindog.github.io/blog/2018/02/10/model-explanation/ http://www.sohu.com/a/216216094_473283 ...
- Java中ArrayList循环遍历并删除元素的陷阱
ava中的ArrayList循环遍历并且删除元素时经常不小心掉坑里,昨天又碰到了,感觉有必要单独写篇文章记一下. 先写个测试代码: import java.util.ArrayList; public ...
- linux 网卡
查看网卡UUID:nmcli con show 或 nmcli con list 查看网卡mac地址:nmcli dev show 或 nmcli dev list 注:sho ...
- Getting started with machine learning in Python
Getting started with machine learning in Python Machine learning is a field that uses algorithms to ...
- 开源监控系统整合Nagios+Cacti+Nconf详解
1.配置好yum源,为了提高效率建议搭建本地yum源 yum install -y http* yum install -y mysql* yum install -y php-* yum in ...
- POJ 3243 // HDU 2815(改下输出,加个判断)
A^x = B (mod C) 的模板题,不够要用扩展BSGS (虽然AC,但完全理解不了模板0.0,以后学好数学在来慢慢理解555555) #include <iostream> #in ...