1#include"../../kyopro_library/template.hpp"
3template<
typename Monoid>
5 using Type=Monoid::Type;
12 dat=vector<vector<Type>>(
this->h*2,vector<Type>(
this->w*2,Monoid::id()));
17 void set(
int x,
int y, Type v) {
20 for(
int i=x>>1; i>0; i>>=1) dat[i][y]=Monoid::op(dat[i<<1][y],dat[i<<1|1][y]);
22 for(
int j=y>>1; j>0; j>>=1) dat[x][j]=Monoid::op(dat[x][j<<1],dat[x][j<<1|1]);
29 Type
fold(
int l,
int r,
int u,
int d) {
30 Type ret=Monoid::id();
33 if(l&1) ret=Monoid::op(ret,fold_sub(l++,u,d));
34 if(r&1) ret=Monoid::op(ret,fold_sub(--r,u,d));
42 vector<vector<Type>>dat;
43 Type fold_sub(
int x,
int u,
int d) {
44 Type ret=Monoid::id();
46 if(u&1) ret=Monoid::op(ret,dat[x][u]),u++;
47 if(d&1) d--,ret=Monoid::op(ret,dat[x][d]);
SegmentTree2D(int h, int w)
サイズ h * w の2次元セグメント木を構築する
Type fold(int l, int r, int u, int d)
矩形領域 [l, r) × [u, d) のモノイド積を返す
void set(int x, int y, Type v)
位置 (x, y) の要素を v に更新する