题目链接:hdu 5147 Sequence II
预处理每个位置作为b和c可以组成的对数,然后枚举b的位置计算。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 50005;
int N, arr[maxn], fenw[maxn], lef[maxn], rig[maxn];
#define lowbit(x) ((x)&(-x))
void add(int x, int v) {
while (x <= N) {
fenw[x] += v;
x += lowbit(x);
}
}
int sum(int x) {
int ret = 0;
while (x) {
ret += fenw[x];
x -= lowbit(x);
}
......
阅读全文