codeforces 301D Yaroslav and Divisors(树状数组)

题目链接:http://codeforces.com/problemset/problem/301/D

题意 和2019徐州站的ICPC网络赛的I题Query基本一样,稍微一改

只是这个题 说明 自身和自身也是符合题意的数对

#include 
#include 
#include 
#include 
#include 
using namespace std;
#define N 100500
int a[N],p[N],b[N],l[N],r[N],ans[N];
vector L[N], R[N];
int n,m;
inline int lowbit(int x){
    return x & (-x);
}
void update(int x){
    while(x <= n) {
        b[x]++;
        x += lowbit(x);
    }
}

int query(int x){
    int res = 0;
    while(x >= 1) {
        res += b[x];
        x -= lowbit(x);
    }
    return res;
}
int main (){
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i)  {
        scanf("%d", &a[i]);
        p[a[i]] = i;
    }
    for(int i=1;i <= m;++i)  {
        scanf("%d%d",&l[i],&r[i]);
        //ans[i] = - (r[i] - l[i] + 1);//只有这个地方不一样
        L[l[i]].push_back(i);
        R[r[i]].push_back(i);
    }
    for(int i=1;i<=n;++i) {
        for(int j=0;j

 

你可能感兴趣的:(树状数组,树状数组)