分塊模板題

2021-09-26 04:59:30 字數 1086 閱讀 6143

題目描述

給出乙個長為n的數列,以及n個操作,操作涉及區間加法,單點查值。 

輸入格式

第一行輸入乙個數字 n 第二行輸入 n 個數字,第 i 個數字為a[i],以空格隔開 接下來輸入 n 行詢問,每行輸入四個數字 opt, l,r,c, 以空格隔開 若 opt = 0,表示將 [l,r] 的之間的數都加 c 若 opt = 1,表示詢問 a[r] 的值(l 和 c 忽略) 

輸出格式

對於每次詢問,輸出一行乙個數字表示答案 

樣例資料

input 

4 1 2 2 3 

0 1 3 1 

1 0 1 0 

0 1 2 2 

1 0 2 0 

output 2 5

直接上分塊的模板就行了

#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;

typedef long long ll;

typedef double ld;

const int inf = 0x3f3f3f3f;

const int n=1000010;

int a[n],sum[n],add[n];

int l[n],r[n]; //每一段的左右端點

int pos[n]; //每個位置屬於哪一段

int n,t,m,op;

int l,r,c;

void change(int l,int r,int d)

else

}int ask(int k)

int main()

if(r[t]for(int i=1; i<=t; i++)

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

else

}return 0;

}

分塊模板 模板題

嗯 直接貼板子了,注釋寫了點 include using namespace std const int maxn 1e5 10 int a maxn belong maxn l 1010 r 1010 block,num a陣列訪問原始資料,belong陣列表示每個數屬於哪一塊方便呼叫,l和r表示...

BZOJ 1806 樹分塊 模板題

time limit 10 sec memory limit 162 mbsec special judge submit 2685 solved 1635 submit status discuss 餘 人國的國王想重新編制他的國家。他想把他的國家劃分成若干個省,每個省都由他們王室聯邦的乙個成 員...

分塊 分塊練習三題

分塊嘛 馮巨道德午餐講過的 唯一不同的是可能需要st n ed n 來記錄一下範圍 例教主的魔法 板 include using namespace std define in read int in const int n 1e6 5 int n,q,a n b n add n int siz,m...