洛谷3372——分块(add标记)
原题传送门
题目是线段树,属于区间更新的内容,但是分块也能过。
已ac代码:
# include <iostream>
# include <algorithm>
# include <cstdio>
# include <cmath>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;
int a[maxn], l[maxn], r[maxn], pos[maxn];
ll sum[maxn] = {
0 }, add[maxn] = {
0 };
ll block, num, ans;
void bulid(int n) {
block = (int)sqrt(n);
num = n / block;
if (n%block) {
num++;
}
for (int i = 1; i <= n; i++) {
pos[i] = (i-1