Garlands

我怎么感觉好水啊。

因为询问只有2000组, 离线询问, 枚举联通块再枚举询问, 二维树状数组更新答案。

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mk make_pair
  6. #define PLL pair<LL, LL>
  7. #define PLI pair<LL, int>
  8. #define PII pair<int, int>
  9. #define SZ(x) ((int)x.size())
  10. #define ull unsigned long long
  11.  
  12. using namespace std;
  13.  
  14. const int N = + ;
  15. const int inf = 0x3f3f3f3f;
  16. const LL INF = 0x3f3f3f3f3f3f3f3f;
  17. const int mod = 1e9 + ;
  18. const double eps = 1e-;
  19. const double PI = acos(-);
  20.  
  21. int n, m, k, q, cntq;
  22. LL ans[N];
  23. pair<PII, PII> qus[N];
  24. bool on[N], can[N][N];
  25. vector<pair<PII, int>> vc[N];
  26. char op[];
  27.  
  28. struct Bit {
  29. LL a[N][N];
  30. void modify(int x, int y, int v) {
  31. for(int i = x; i < N; i += i & -i)
  32. for(int j = y; j < N; j += j & -j)
  33. a[i][j] += v;
  34. }
  35. LL sum(int x, int y) {
  36. LL ans = ;
  37. for(int i = x; i; i -= i & -i)
  38. for(int j = y; j; j -= j & -j)
  39. ans += a[i][j];
  40. return ans;
  41. }
  42. LL query(int x1, int y1, int x2, int y2) {
  43. return sum(x2, y2) - sum(x2, y1 - ) - sum(x1 - , y2) + sum(x1 - , y1 - );
  44. }
  45. } bit;
  46.  
  47. int main() {
  48. scanf("%d%d%d", &n, &m, &k);
  49. for(int i = ; i <= k; i++) {
  50. int len; scanf("%d", &len);
  51. for(int j = ; j <= len; j++) {
  52. int x, y, w;
  53. scanf("%d%d%d", &x, &y, &w);
  54. vc[i].push_back(mk(mk(x, y), w));
  55. }
  56. }
  57. memset(on, true, sizeof(on));
  58. scanf("%d", &q);
  59. while(q--) {
  60. scanf("%s", op);
  61. if(op[] == 'A') {
  62. cntq++;
  63. scanf("%d%d", &qus[cntq].fi.fi, &qus[cntq].fi.se);
  64. scanf("%d%d", &qus[cntq].se.fi, &qus[cntq].se.se);
  65. memcpy(can[cntq], on, sizeof(on));
  66. } else {
  67. int x;
  68. scanf("%d", &x);
  69. on[x] = !on[x];
  70. }
  71. }
  72. for(int i = ; i <= k; i++) {
  73. for(auto& t : vc[i]) bit.modify(t.fi.fi, t.fi.se, t.se);
  74. for(int j = ; j <= cntq; j++) {
  75. if(!can[j][i]) continue;
  76. ans[j] += bit.query(qus[j].fi.fi, qus[j].fi.se, qus[j].se.fi, qus[j].se.se);
  77. }
  78. for(auto& t : vc[i]) bit.modify(t.fi.fi, t.fi.se, -t.se);
  79. }
  80. for(int i = ; i <= cntq; i++) printf("%lld\n", ans[i]);
  81. return ;
  82. }
  83.  
  84. /*
  85. */

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. mysql创建数据库指定编码格式

    CREATE DATABASE `databasename` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

  2. C++中模板的使用

    为什么使用模板: C++重载(overloading),重载函数一般含有不同的参数个数或不同的参数类型.如果使用MAX函数对不同类型的求最大值,就要定义不同的重载函数: int max(int x,i ...

  3. MySQL 之 数据库自动生成ID格式化编号(字符串格式化填充/拼接/时间)

    # 用户账号:1-4位:入职年份:5-6位:入职月份:7-11位:员工入职顺序号 select concat( date_format(now(),'%Y'), date_format(now(),' ...

  4. 记录一个PHP安装redis扩展时的问题

    安装过程:https://www.cnblogs.com/pengyunjing/p/8688320.html 由于我之前安装过该扩展,重新安装时没有执行make clean命令,所以安装好出现了下面 ...

  5. configure编译选项

    1.rpath与rpath-link的区别 参考链接:http://blog.csdn.net/xph23/article/details/38157491 rpath 是 运行时候链接的库, rpa ...

  6. D - 文理分科 (网络流->最小割)

    题目链接:https://cn.vjudge.net/contest/281959#problem/D 题目大意:中文题目 具体思路:我们需要求出最大的满意值,从另一方面想,我们可以求出总的满意值,然 ...

  7. python基础知识~logger模块

    一 配置文件模块 import logging ->导入模块 logger = logging.getLogger('mylogger') ->初始化类二 创建句柄 1 文件句柄 fh = ...

  8. jquery 学习(四) - 标签 添加/删除/修改

    HTML代码 <div class="a1"> <div> <span id="a2">aaa</span> & ...

  9. 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. ...

  10. SpringBoot三种配置Dubbo的方式

    *必须首先导入dubbo-starter (1).使用SpringBoot配置文件(application.properties或application.yml) dubbo.application. ...