首页 > 其他分享 >Luogu P4514 上帝造题的七分钟

Luogu P4514 上帝造题的七分钟

时间:2022-10-25 15:35:52浏览次数:87  
标签:ad int Luogu 七分钟 add delta ask 造题 include


题目链接:​​传送门​

二维树状数组
区间加区间求和
烦人的输入

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define

using namespace std;
typedef long long ll;
int t1[B][B], t2[B][B], t3[B][B], t4[B][B], delta;
int n, m, a, b, c, d; char opt[1];
int lowbit(int x) {return x & -x;}
void add(int x, int y, ll ad) {
for (int i = x; i <= n; i += lowbit(i))
for (int j = y; j <= m; j += lowbit(j)) {
t1[i][j] += ad;
t2[i][j] += ad * x;
t3[i][j] += ad * y;
t4[i][j] += ad * x * y;
}
}
void addval() {
add(a, b, delta); add(a, d + 1, -delta);
add(c + 1, b, -delta); add(c + 1, d + 1, delta);
}
int ask(int x, int y, int ans = 0) {
for (int i = x; i; i -= lowbit(i))
for (int j = y; j; j -= lowbit(j))
ans += (x + 1) * (y + 1) * t1[i][j] - (y + 1) * t2[i][j] - (x + 1) * t3[i][j] + t4[i][j];
return ans;
}

int main(int argc, char const *argv[]) {
scanf("X %d%d", &n, &m);
while (~scanf("%s", &opt)) {
scanf("%d%d%d%d", &a, &b, &c, &d);
if (opt[0] == 'L') scanf("%d", &delta), addval();
else printf("%d\n", ask(c, d) - ask(c, b - 1) - ask(a - 1, d) + ask(a - 1, b - 1));
}
return 0;
}


标签:ad,int,Luogu,七分钟,add,delta,ask,造题,include
From: https://blog.51cto.com/lyle/5794778

相关文章

  • Luogu P2455 [SDOI2006]线性方程组
    题目链接:​​传送门​​高斯消元可以去下面看一下​​​https://www.bilibili.com/video/av4688674​​​听视频比瞅博客有用得多这题算比较标准的板子了各种情况都有......
  • Luogu P3833 [SHOI2012]魔法树
    题目链接:​​传送门​​树剖板子区间加,子树查询树剖里查询的时候x和y地方小于号写反T了一会a,b写成dfn[a],dfn[b]竟然还有50分又WA了一会也就交了二十遍。#include<io......
  • Luogu P1438 无聊的数列
    题目链接:​​传送门​​还是区间加等差数列时隔8个月再写一遍这个题不会的来​这里#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include......
  • Luogu P3980 [NOI2008]志愿者招募
    题目链接:​​传送门​​别人家的建图~~~~好神奇很容易想到志愿者的起始时间和终止时间连边,费用就是他的费用但是每个点还有一个人数限制必须要有那么多个人也就是那么......
  • Luogu P2221 [HAOI2012]高速公路
    题目链接:​​传送门​​维护路径期望值,带区间修改看每条路径会被统计多少次贡献非常不显然是方案数就是上面的是分子下面的是分母现在要把上面的展开看怎么维护直接......
  • Luogu P2342 叠积木
    题目链接:​​传送门​​虽然看着很简单还是计较了好久!fa[]是这堆的最底下那块的编号siz[]是底块所在堆的sizeans[]就是ans,这块底下有多少块在find的时候沿路更新答案即......
  • Luogu P2150 [NOI2015]寿司晚宴
    题目链接:​​传送门​​太难了太难了题意就是问有多少种分案把一个到的排列分配为两组并使组间元素两两互质首先我们只需要考虑根号内的质因子对答案的影响,因为根号外的因......
  • Luogu P2515 [HAOI2010]软件安装
    题目链接:​​传送门​​很明显,如果图中有一个环那么这个环上的点必须都要选那我们一开始就直接缩点因为每个物品有价值有重量还有有重量限制所以是很明显的树上背包我......
  • Luogu P4421 [COCI2017-2018#1] Lozinke
    题目链接:​​传送门​​一开始直接AC自动机每个串暴力跳fail显然会T,44分#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<complex>#i......
  • Luogu P3182 [HAOI2016]放棋子
    题目链接:​​传送门​​题目说了每行有一个障碍两个障碍不在同一行也不在同一列那障碍放哪里就没关系了矩阵都不用输入或者这样理解:交换矩阵的某两行对答案是没有影响......