PR是双关键字(pair<int,int>)
struct node{int l,r;PR m;};
PR min(PR a,PR b)
{
if (a<b) return a;
return b;
}
struct segtree
{
node tree[4*N];
void update(int x)
{tree[x].m=min(tree[x<<1].m,tree[(x<<1)+1].m);}
void build(int x,int L,int R)
{
tree[x].l=L;tree[x].r=R;int M=(L+R)>>1;
if (L==R) {tree[x].m=mp(a[L],L);return;}
build(x<<1,L,M);build((x<<1)+1,M+1,R);
update(x);
}
PR query(int x,int L,int R)
{
if (tree[x].l==L&&tree[x].r==R) return tree[x].m;
int M=(tree[x].l+tree[x].r)>>1;
if (R<=M) return query(x<<1,L,R);
Views:
403
|
Added by:
dhy0077
|
Date:
10.05.2013