@[Land_ER](/user/546558) 当真有90分?$m$ 都没有读啊
by Chen_GY @ 2022-12-23 17:24:11
@[Land_ER](/user/546558)
```cpp
#include <bits/stdc++.h>
#define N 100005
#define i64 long long int
using std::max;
using std::min;
i64 n, m;
i64 a[N], d[N], t[N];
i64 s;
void read(i64 *w) {
*w = 0;
char c = getchar();
while(!isdigit(c))
c = getchar();
while(isdigit(c))
*w = (*w) * 10 + c - '0', c = getchar();
return;
}
#define at(x) (int)(((x) + s - 1) / s)
#define st(x) (int)(((x) - 1) * s + 1)
#define ed(x) (int)((x) * s)
void init(void) {
read(&n);
s = sqrt(n);
for(int i = 1; i <= n; ++ i)
read(a + i);
for(int i = 1; i <= n; ++ i)
d[at(i)] += a[i], t[at(i)] += a[i] > 1;
return;
}
void modify(int l, int r) {
for(int i = l; i <= r; ++ i) {
if(!t[at(i)]){
i = ed(at(i)) + 1 - 1;//<--此处
continue;//<--此处
//跳过的时候记得要判断一下 i 有没有超过修改范围 r
}
if(a[i] <= 1)
continue;
d[at(i)] -= a[i];
a[i] = (long long int)sqrt(a[i]);
d[at(i)] += a[i];
t[at(i)] -= a[i] <= 1;
}
return;
}
i64 query(int l, int r) {
i64 ans = 0;
for(int i = l, p = min(ed(at(l)), r); i <= p; ++ i)
ans += a[i];
for(int i = at(l) + 1, p = at(r); i < p; ++ i)
ans += d[i];
if(at(l) == at(r))
return ans;
for(int i = st(at(r)); i <= r; ++ i)
ans += a[i];
return ans;
}
int main(void) {
init();
read(&m);
for(i64 k, l, r, c, i = 0; i < m; ++ i) {
read(&k), read(&l), read(&r);
if(l > r)
std::swap(l, r);
if(k == 0)
modify(l, r);
else
printf("%lld\n", query(l, r));
}
return 0;
}
```
by Chen_GY @ 2022-12-23 18:02:15
@[aYaKa_forever](/user/666735) m没有读是因为拿这个代码去交了一下loj上的
by Land_ER @ 2022-12-23 18:10:44
过了,谢谢大佬
by Land_ER @ 2022-12-23 18:15:45