#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int n, m, len;
int pos[5211314], add[5211314], num[5211314];
inline void Add(int LiftPos, int RightPos, int val) {
int l = pos[LiftPos], r = pos[RightPos];
if (l == r) {
add[l] += val;
}
else {
for (int i = l + 1; i <= r - 1; ++ i)
add[i] += val;
for (int i = LiftPos; i <= l * len; ++ i)
num[i] += val;
for (int i = (r - 1) * len + 1;i <= RightPos; ++ i)
num[i] += val;
}
}
inline int Get(int id) {
return num[id] + add[pos[id]];
}
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch - '0');
ch = getchar();
}
return x * f;
}
void write(int x) {
if (x < 0) putchar('-'), x *= -1;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
return;
}
int main() {
n = read();
m = read();
len = sqrt(n);
for (int i = 1; i <= n; ++ i) {
num[i] = read();
pos[i] = (i - 1) / len + 1;
}
for (int i = 1, opt, x, y, k; i <= m; ++ i) {
opt = read();
if (opt == 1) {
x = read(), y = read(), k = read();
Add(x, y, k);
}
if (opt == 2) {
x = read();
write(Get(x));
putchar('\n');
}
}
return 0;
}
标签:ch,分块,Loj,pos,int,5211314,include,模板
From: https://www.cnblogs.com/jueqingfeng/p/17411534.html