首页 > 其他分享 >Luogu P1438 无聊的数列

Luogu P1438 无聊的数列

时间:2022-10-25 14:04:19浏览次数:80  
标签:aa return 数列 int Luogu d% tree include P1438


题目链接:​​传送门​​ 还是区间加等差数列

时隔8个月再写一遍这个题
不会的来​这里

#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;
struct node {
int l, r, w, a, d;
}tree[A];
int n, m, a[A], l, r, opt, aa, d;
void build(int k, int l, int r) {
tree[k].l = l; tree[k].r = r;
if (l == r) {
tree[k].w = a[l];
tree[k].a = tree[k].d = 0;
return;
}
int m = (l + r) >> 1;
build(k << 1, l, m);
build(k << 1 | 1, m + 1, r);
tree[k].w = tree[k << 1].w + tree[k << 1 | 1].w;
}
void add(int k, int l, int r, int a, int d) {
tree[k].a += a;
tree[k].d += d;
tree[k].w += (a + a + (r - l) * d) * (r - l + 1) / 2;
}
void down(int k) {
int m = (tree[k].l + tree[k].r) >> 1;
add(k << 1, tree[k].l, m, tree[k].a, tree[k].d);
add(k << 1 | 1, m + 1, tree[k].r, tree[k].a + (m - tree[k].l + 1) * tree[k].d, tree[k].d);
tree[k].a = tree[k].d = 0;
}
void change(int k, int l, int r, int a, int d) {
if (tree[k].l >= l and tree[k].r <= r) {
add(k, tree[k].l, tree[k].r, a + (tree[k].l - l) * d, d);
return;
}
if (tree[k].a or tree[k].d) down(k);
int m = (tree[k].l + tree[k].r) >> 1;
if (l <= m) change(k << 1, l, r, a, d);
if (r > m) change(k << 1 | 1, l, r, a, d);
tree[k].w = tree[k << 1].w + tree[k << 1 | 1].w;
}
int ask(int k, int pos) {
if (tree[k].l == tree[k].r) return tree[k].w;
if (tree[k].a or tree[k].d) down(k);
int m = (tree[k].l + tree[k].r) >> 1;
if (pos <= m) return ask(k << 1, pos);
else return ask(k << 1 | 1, pos);
}

int main(int argc, char const *argv[]) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
build(1, 1, n);
while (m--) {
scanf("%d", &opt);
if (opt == 1) {
scanf("%d%d%d%d", &l, &r, &aa, &d);
change(1, l, r, aa, d);
}
else {
scanf("%d", &aa);
printf("%d\n", ask(1, aa));
}
}
return 0;
}


标签:aa,return,数列,int,Luogu,d%,tree,include,P1438
From: https://blog.51cto.com/lyle/5794665

相关文章

  • COGS 2632. [HZOI 2016] 数列操作d
    题目链接:​​传送门​​区间加等差数列网上没怎么见有解释的把等差数列看成一个三角形mid从中间切开后左儿子加的还是一个三角形右儿子加的是一个梯形其实也不能说是......
  • 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]放棋子
    题目链接:​​传送门​​题目说了每行有一个障碍两个障碍不在同一行也不在同一列那障碍放哪里就没关系了矩阵都不用输入或者这样理解:交换矩阵的某两行对答案是没有影响......
  • Luogu P1772 [ZJOI2006]物流运输
    题目链接:​​传送门​​很麻烦也很难想的一道题数据很小大胆yy详细解释在代码里#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<co......
  • Luogu P4149 [IOI2011]Race
    题目链接:​​传送门​​#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<complex>#include<algorithm>#include<climits>#include<......