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的更多相关文章

  1. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  2. Garlands CodeForces - 707E (离线树状数组)

    大意: 给定n*m矩阵, k条链, 链上每个点有权值, 每次操作可以关闭或打开一条链或询问一个子矩阵内未关闭的权值和. 关键询问操作比较少, 可以枚举每条链, 暴力算出该条链对每个询问的贡献. 最后再 ...

  3. Codeforces Round #368 (Div. 2) E. Garlands 二维树状数组 暴力

    E. Garlands 题目连接: http://www.codeforces.com/contest/707/problem/E Description Like all children, Ale ...

  4. Codeforces 707 E. Garlands (二维树状数组)

    题目链接:http://codeforces.com/problemset/problem/707/E 给你nxm的网格,有k条链,每条链上有len个节点,每个节点有一个值. 有q个操作,操作ask问 ...

  5. Three Garlands~Educational Codeforces Round 35

    C. Three Garlands time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  6. Educational Codeforces Round 35 B/C/D

    B. Two Cakes 传送门:http://codeforces.com/contest/911/problem/B 本题是一个数学问题. 有a个Ⅰ类球,b个Ⅱ类球:有n个盒子.将球放入盒子中,要 ...

  7. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  8. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  9. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

随机推荐

  1. 在Eclipse中利用maven整合搭建ssm框架

    首先说明用到的框架: spring  +  springMVC  +  mybatis 构建工具:maven 开发工具:eclipse 开发环境:win10      java版本:jdk1.8    ...

  2. OpenCV不同类型Mat的at方法访问元素时该如何确定模板函数的typename(转)

    自从OpenCV推出了Mat后越来越像是Matlab了,使用起来方便了很多,但是,在用at方法访问Mat时,如何选用合适的typename类型来访问相应的Mat元素是个头疼的问题. 比如: int H ...

  3. python的特殊方法介绍

    __repr__.__str__ __len__.__getitem__.__setitem__.__delitem__.__contains__ __iter__.__reversed__.__ne ...

  4. IO流总结笔记一

    ​ IO流继承关系图 IO概述 IO流是用来处理设备上数据的输入输出. 具体设备有:硬盘,内存,键盘录入等等. IO流的具体分类: 1,根据处理的数据类型不同分为:字节流和字符流,字节流读取的最小单位 ...

  5. eclips环境下开发spring boot项目,application.properties配置文件下中文乱码解决方案

    如以上,application.properties文件下中文乱码.发生乱码一般都是由于编码格式不一样导致的. 打开Window-Preferences-General-content Types-T ...

  6. android aysncTask面试解析

  7. 【vim】把当前文件转化为网页

    这会生成一个 HTML 文件来显示文本,并在分开的窗口显示源代码: :%TOhtml (译者注:原文是 :%Tohtml,但在我的电脑上是 :%TOhtml) 转载自:https://linux.cn ...

  8. UML和模式应用5:细化阶段(9)---迈向对象设计

    1.前言 开发者如何设计对象,可以采用如下三种方式: 编码:在编码的同时进行设计 绘图然后编码:绘制一些UML,然后转到如上编码方式,在集成开发环境中编码 只绘图,不编码:使用工具从图中生成一切 本章 ...

  9. C语言函数调用栈(二)

    5 函数调用约定 创建一个栈帧的最重要步骤是主调函数如何向栈中传递函数参数.主调函数必须精确存储这些参数,以便被调函数能够访问到它们.函数通过选择特定的调用约定,来表明其希望以特定方式接收参数.此外, ...

  10. Maven介绍及安装与配置

    一.Maven的作用 在开发中,为了保证编译通过,我们会到处去寻找jar包,当编译通过了,运行的时候,却发现"ClassNotFoundException",我们想到的是,难道还差 ...