mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 13:16:26 +00:00
parent
0968dea630
commit
a98b7f0ed3
135
S2OJ/162/162.cpp
Normal file
135
S2OJ/162/162.cpp
Normal file
@ -0,0 +1,135 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* 线段树节点
|
||||
*/
|
||||
struct node {
|
||||
int l, r;
|
||||
long long s, d;
|
||||
|
||||
node(int _l = 0, int _r = 0)
|
||||
: l(_l), r(_r), s(0), d(0) {}
|
||||
|
||||
} tr[100005 << 2];
|
||||
|
||||
int n, m, op, x, y, k, a[100005];
|
||||
|
||||
/**
|
||||
* 上传区间和
|
||||
* @param u 父节点下标
|
||||
*/
|
||||
void pushup(int u) {
|
||||
tr[u].s = tr[u << 1].s + tr[u << 1 | 1].s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下放懒标记
|
||||
* @param u 父节点下标
|
||||
*/
|
||||
void pushdown(int u) {
|
||||
if (!tr[u].d) return;
|
||||
|
||||
// 处理左子树
|
||||
tr[u << 1].d += tr[u].d;
|
||||
tr[u << 1].s += (tr[u << 1].r - tr[u << 1].l + 1) * tr[u].d;
|
||||
|
||||
// 处理右子树
|
||||
tr[u << 1 | 1].d += tr[u].d;
|
||||
tr[u << 1 | 1].s += (tr[u << 1 | 1].r - tr[u << 1 | 1].l + 1) * tr[u].d;
|
||||
|
||||
// 清除懒标记
|
||||
tr[u].d = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 建立线段树
|
||||
* @param u 根节点下标
|
||||
* @param l 左端点
|
||||
* @param r 右端点
|
||||
*/
|
||||
void build(int u, int l, int r) {
|
||||
tr[u] = node(l, r);
|
||||
|
||||
if (l == r) {
|
||||
tr[u].s = a[l];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int mid = l + r >> 1;
|
||||
|
||||
build(u << 1, l, mid);
|
||||
build(u << 1 | 1, mid + 1, r);
|
||||
|
||||
pushup(u);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改区间
|
||||
* @param u 父节点下标
|
||||
* @param l 左端点
|
||||
* @param r 右端点
|
||||
* @param d 增加的值
|
||||
*/
|
||||
void modify(int u, int l, int r, int d) {
|
||||
if (tr[u].l >= l && tr[u].r <= r) { // 被包含直接修改
|
||||
tr[u].d += d;
|
||||
tr[u].s += (tr[u].r - tr[u].l + 1) * d;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int mid = tr[u].l + tr[u].r >> 1;
|
||||
|
||||
pushdown(u); // 下放懒标记
|
||||
|
||||
if (l <= mid) modify(u << 1, l, r, d); // 和左侧有交集
|
||||
if (r > mid) modify(u << 1 | 1, l, r, d); // 和右侧有交集
|
||||
|
||||
pushup(u); // 上传新信息
|
||||
}
|
||||
|
||||
/**
|
||||
* 区间查询
|
||||
* @param u 父节点
|
||||
* @param l 左端点
|
||||
* @param r 右端点
|
||||
*/
|
||||
long long query(int u, int l, int r) {
|
||||
if (tr[u].l >= l && tr[u].r <= r) { // 被包含直接返回
|
||||
return tr[u].s;
|
||||
}
|
||||
int mid = tr[u].l + tr[u].r >> 1;
|
||||
long long s = 0;
|
||||
pushdown(u); // 下放懒标记
|
||||
if (l <= mid) s += query(u << 1, l, r); // 和左侧有交集
|
||||
if (r > mid) s += query(u << 1 | 1, l, r); // 和右侧有交集
|
||||
return s;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
build(1, 1, n);
|
||||
|
||||
for (int i = 0; i < m; i++) {
|
||||
cin >> op >> x >> y;
|
||||
|
||||
if (op == 1) {
|
||||
cin >> k;
|
||||
modify(1, x, y, k);
|
||||
} else if (op == 2) {
|
||||
cout << query(1, x, y) << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/162/data/data1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data11.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data11.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data12.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data12.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data13.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
0
S2OJ/162/data/data13.out
Normal file
0
S2OJ/162/data/data13.out
Normal file
BIN
S2OJ/162/data/data14.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data14.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data15.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data15.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data16.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data16.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data16.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data17.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data17.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data17.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data18.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data18.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data18.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data19.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data19.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data19.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data20.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data20.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data20.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data21.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data21.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data21.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data21.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data22.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data22.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data22.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data22.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data23.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data23.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data23.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data23.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data24.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data24.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data24.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data24.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data25.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data25.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data25.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data25.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data26.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data26.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data26.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data26.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data27.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data27.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data27.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data27.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data28.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data28.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data28.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data28.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data29.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data29.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data29.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data29.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data30.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data30.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data30.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data30.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data31.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data31.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data31.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data31.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data32.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data32.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data32.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data32.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data33.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data33.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data33.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data33.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data34.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data34.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data34.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data34.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data35.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data35.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data35.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data35.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data36.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data36.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data36.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data36.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data37.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data37.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data37.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data37.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data38.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data38.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data38.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data38.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data39.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data39.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data39.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data39.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data40.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data40.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data40.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data40.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data41.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data41.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data41.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data41.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data42.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data42.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data42.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data42.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data43.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data43.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data43.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data43.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data44.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data44.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data44.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data44.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data45.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data45.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data45.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data45.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data46.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data46.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data46.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data46.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data47.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data47.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data47.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data47.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data48.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data48.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data48.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data48.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data49.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data49.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data49.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data49.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data50.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data50.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data50.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data50.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/162/data/data9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/162/data/data9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user