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 ...
随机推荐
- mysql创建数据库指定编码格式
CREATE DATABASE `databasename` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
- C++中模板的使用
为什么使用模板: C++重载(overloading),重载函数一般含有不同的参数个数或不同的参数类型.如果使用MAX函数对不同类型的求最大值,就要定义不同的重载函数: int max(int x,i ...
- MySQL 之 数据库自动生成ID格式化编号(字符串格式化填充/拼接/时间)
# 用户账号:1-4位:入职年份:5-6位:入职月份:7-11位:员工入职顺序号 select concat( date_format(now(),'%Y'), date_format(now(),' ...
- 记录一个PHP安装redis扩展时的问题
安装过程:https://www.cnblogs.com/pengyunjing/p/8688320.html 由于我之前安装过该扩展,重新安装时没有执行make clean命令,所以安装好出现了下面 ...
- configure编译选项
1.rpath与rpath-link的区别 参考链接:http://blog.csdn.net/xph23/article/details/38157491 rpath 是 运行时候链接的库, rpa ...
- D - 文理分科 (网络流->最小割)
题目链接:https://cn.vjudge.net/contest/281959#problem/D 题目大意:中文题目 具体思路:我们需要求出最大的满意值,从另一方面想,我们可以求出总的满意值,然 ...
- python基础知识~logger模块
一 配置文件模块 import logging ->导入模块 logger = logging.getLogger('mylogger') ->初始化类二 创建句柄 1 文件句柄 fh = ...
- jquery 学习(四) - 标签 添加/删除/修改
HTML代码 <div class="a1"> <div> <span id="a2">aaa</span> & ...
- pandas 定位 loc,iloc,ix
In [114]: df Out[114]: A B C D 2018-06-30 0.318501 0.613145 0.485612 0.918663 2018-07-31 0.614796 0. ...
- SpringBoot三种配置Dubbo的方式
*必须首先导入dubbo-starter (1).使用SpringBoot配置文件(application.properties或application.yml) dubbo.application. ...