數列分塊入門2

2021-08-20 19:03:05 字數 891 閱讀 1843

題目鏈結

給出乙個長為 n 的數列,以及 n 個操作,操作涉及區間加法,詢問區間內小於某個值 *** 的元素個數。

根據數列分塊入門1的思想,把n個數分為根號n塊,不完整塊的去暴力求和和查詢,完整塊用加法標進行標記,查詢排序後進行二分查詢。

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using

namespace

std;

typedef

long

long

int ll;

const

int n=500+10;

int m,n;

vector

s[n];

int pos[n*100],a[n*100],tag[n*100];

void uppdate(int x)

void add(int l,int r,int c)

for(int i=pos[l]+1;i<=pos[r]-1;i++)

tag[i]+=c;//整塊內的元素進行加法標記

}int query(int l,int r,int c)

return sum;

}int main()

for(int i=1;i<=pos[n];i++)

sort(s[i].begin(),s[i].end());//每個塊首先進行排序

for(int i=1;i<=n;i++)

return

0;}

數列分塊入門 2

題目描述 給出乙個長為n的數列,以及n個操作,操作涉及區間加法,詢問區間內小於某個值x的元素個數。輸入格式 第一行輸入乙個數字n。第二行輸入n個數字,第i個數字為ai,以空格隔開。接下來輸入n行詢問,每行輸入四個數字 opt l r c,以空格隔開。若opt 0 表示將位於 l,r 的之間的數字都加...

數列分塊入門 2

這道題他們說不用分塊就用平衡樹,所以暴力拆解就用分塊。做了兩道分塊已經漸漸明白分塊的一些模板在這裡就放一下吧 用vector比用陣列md方便多了 1 void 修改操作 查詢操作 int l,int r.int val 修改的要素 2 8if l 和 r 不在同乙個區間 就把 r 所在的角區間列舉修...

6278 數列分塊入門 2

題目描述 給出乙個長為 nn 的數列,以及 nn 個操作,操作涉及區間加法,詢問區間內小於某個值 xx 的元素個數。輸入格式 第一行輸入乙個數字 nn。第二行輸入 nn 個數字,第 ii 個數字為 a iai 以空格隔開。接下來輸入 nn 行詢問,每行輸入四個數字 mathrmopt ll rr c...