发现没加build()
先再加上了build() 70pts->30pts草
by AMIRIOX無暝 @ 2021-02-14 17:35:13
这题好像分块只能拿70,~~反正我以前就只用分块拿到了70~~,~~也许手调快长可以过吧~~
by Vomedakth @ 2021-02-14 17:42:29
好家伙 发现C和S写错了 在build里改了之后 0pts了
```cpp
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 5e5 + 10;
int a[maxn], belong[maxn];
int l[maxn], r[maxn];
int sum[maxn], S, C, n, m;
inline int read() {
int val = 0, flg = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
flg = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
val = (val << 1) + (val << 3) + (ch ^ 48);
ch = getchar();
}
return flg * val;
}
inline void build() {
S = (int)sqrt((double)n);
C = n / S;
if (n % S)
C++;
for (register int i = 1; i <= C; i++) {
l[i] = (i - 1) * S + 1;
r[i] = i * S;
}
r[C] = n;
for (register int i = 1; i <= n; i++) {
belong[i] = (i - 1) / S + 1;
}
for (register int i = 1; i <= C; i++)
for (int j = l[i]; j <= r[i]; j++) {
sum[i] += a[i];
}
}
inline void update(int x, int v) {
a[x] += v;
sum[belong[x]] += v;
}
inline int query(int x, int y) {
int ans = 0;
if (belong[x] == belong[y]) {
for (register int i = x; i <= y; i++)
ans += a[i];
return ans;
}
for (register int i = x; i <= r[belong[x]]; i++)
ans += a[i];
for (register int i = belong[x] + 1; i <= belong[y] - 1; i++)
ans += sum[i];
for (register int i = l[belong[y]]; i <= y; i++)
ans += a[i];
return ans;
}
int main() {
n = read();
m = read();
for (register int i = 1; i <= n; i++)
a[i] = read();
build();
for (register int i = 1; i <= m; i++) {
int cmd, hu, hv;
cmd=read();
hu=read();
hv=read();
if (cmd == 1) {
update(hu, hv);
} else {
printf("%d\n", query(hu, hv));
}
}
return 0;
}
```
by AMIRIOX無暝 @ 2021-02-14 17:42:46
@[翊雲](/user/156573) 然而题解有快读+inline分块满分
然而我现在是0分
by AMIRIOX無暝 @ 2021-02-14 17:43:21
@[AMIRIOX無暝](/user/320697) emmm,我来翻下我的代码吧
by Vomedakth @ 2021-02-14 17:45:29
我惊奇的发现我没有加快读,~~加了就过了~~
by Vomedakth @ 2021-02-14 17:51:28
@[AMIRIOX無暝](/user/320697) 38行是sum[i]+=a[j]吧
by Vomedakth @ 2021-02-14 17:53:47
不用谢
by Vomedakth @ 2021-02-14 17:55:16
@[翊雲](/user/156573) 谢谢大佬!!!!
我太脑残了((
~~对着diffing tool和题解代码对比半天才发现这里写错了~~
by AMIRIOX無暝 @ 2021-02-14 17:55:46