0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 21:25:24 +00:00

#6277. 数列分块入门 1

https://loj.ac/s/1464321
This commit is contained in:
Baoshuo Ren 2022-05-16 20:05:48 +08:00
parent 64f36cd111
commit 33053a3e5f
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
21 changed files with 125 additions and 0 deletions

65
LibreOJ/6277/6277.cpp Normal file
View File

@ -0,0 +1,65 @@
#include <cmath>
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 50005;
int n, b, a[N], pos[N], st[N], ed[N], add[N];
void change(int l, int r, int d) {
int p = pos[l], q = pos[r];
if (p == q) {
for (int i = l; i <= r; i++) {
a[i] += d;
}
return;
}
for (int i = p + 1; i <= q - 1; i++) add[i] += d;
for (int i = l; i <= ed[p]; i++) a[i] += d;
for (int i = st[q]; i <= r; i++) a[i] += d;
}
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
b = std::sqrt(n);
for (int i = 1; i <= b; i++) {
st[i] = (i - 1) * b + 1;
ed[i] = i * b;
}
if (ed[b] < n) {
b++;
st[b] = ed[b - 1] + 1;
ed[b] = n;
}
for (int i = 1; i <= b; i++) {
for (int j = st[i]; j <= ed[i]; j++) {
pos[j] = i;
}
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1, op, l, r, d; i <= n; i++) {
cin >> op >> l >> r >> d;
if (op == 0) {
change(l, r, d);
} else { // op == 1
cout << a[r] + add[pos[r]] << endl;
}
}
return 0;
}

BIN
LibreOJ/6277/data/a1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/6277/data/a9.out (Stored with Git LFS) Normal file

Binary file not shown.