-Wl,--stack=51200000离散化:
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]), b[i] = a[i];
sort(b + 1, b + 1 + n);
tot = unique(b + 1, b + 1 + n) - b - 1;
for(int i = 1; i <= n; i++)
a[i] = lower_bound(b + 1, b + 1 + tot, a[i]) - b;以后线段树照这个写(op是多个树封装后的标记):
namespace SegmentTree {
#define ls(nw) nw<<1
#define rs(nw) nw<<1|1
typedef struct ST {
int l,r,mx,mn,ad;
} ST;
ST st[2][N*4];
void psp(int nw,bool op) {
if(st[op][nw].l==st[op][nw].r) return ;
st[op][nw].mx=max(st[op][ls(nw)].mx,st[op][rs(nw)].mx);
st[op][nw].mn=min(st[op][ls(nw)].mn,st[op][rs(nw)].mn);
}
void blt(int nw,int l,int r,bool op) {
st[op][nw].l=l,st[op][nw].r=r,st[op][nw].ad=st[op][nw].mn=st[op][nw].mx=0;
if(l==r) return;
int md=(l+r)>>1;
blt(ls(nw),l,md,op);
blt(rs(nw),md+1,r,op);
psp(nw,op);
}
void psd(int nw,bool op) {
if(st[op][nw].ad) {
int ad=st[op][nw].ad;
st[op][ls(nw)].mn+=ad;
st[op][ls(nw)].mx+=ad;
st[op][ls(nw)].ad+=ad;
st[op][rs(nw)].mn+=ad;
st[op][rs(nw)].mx+=ad;
st[op][rs(nw)].ad+=ad;
st[op][nw].ad=0;
}
return ;
}
void add() {
st[1][1].ad++,st[1][1].mx++,st[1][1].mn++;
st[0][1].ad++,st[0][1].mx++,st[0][1].mn++;
}
void cvr(int nw,int aim,bool op) {
if(st[op][nw].l==aim&&st[op][nw].r==aim) {
st[op][nw].mn=st[op][nw].mx=0;
return ;
}
psd(nw,op);
int md=(st[op][nw].l+st[op][nw].r)>>1;
if(aim<=md) cvr(ls(nw),aim,op);
if(aim>md) cvr(rs(nw),aim,op);
psp(nw,op);
}
int qry_mx(int nw,int ql,int qr,bool op) {
if(st[op][nw].l>=ql&&st[op][nw].r<=qr) {
return st[op][nw].mx;
}
psd(nw,op);
int md=(st[op][nw].l+st[op][nw].r)>>1,as=-0x3f3f3f3f;
if(ql<=md) as=max(as,qry_mx(ls(nw),ql,qr,op));
if(qr>md) as=max(as,qry_mx(rs(nw),ql,qr,op));
return as;
}
int qry_mn(int nw,int ql,int qr,bool op) {
if(st[op][nw].l>=ql&&st[op][nw].r<=qr) {
return st[op][nw].mn;
}
psd(nw,op);
int md=(st[op][nw].l+st[op][nw].r)>>1,as=0x3f3f3f3f;
if(ql<=md) as=min(as,qry_mn(ls(nw),ql,qr,op));
if(qr>md) as=min(as,qry_mn(rs(nw),ql,qr,op));
return as;
}
int qry_l(int nw,int R,int v,int op) {
if(st[op][nw].l>R) return 0;
if(st[op][nw].mn>v) return 0;
if(st[op][nw].l==st[op][nw].r) return st[op][nw].l;
psd(nw,op);
int lft=qry_l(ls(nw),R,v,op);
if(lft!=0) return lft;
else return qry_l(rs(nw),R,v,op);
}
int qry_r(int nw,int L,int v,int op) {
if(st[op][nw].r<L) return inf;
if(st[op][nw].mn>v) return inf;
if(st[op][nw].l==st[op][nw].r) return st[op][nw].l;
psd(nw,op);
int lft=qry_r(ls(nw),L,v,op);
if(lft!=inf) return lft;
else return qry_r(rs(nw),L,v,op);
}
}
//调用:SegmentTree:NAME神秘模板:
//链式前向星
void add(ll x,ll y/*,z*/) {
tot++;
//ver[tot]=z;
//to[tot]=y;
Next[tot]=head[x];
head[x]=tot;
}头:
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define to0(_a_) memset(_a_,0,sizeof _a_)
#define to_1(_a_) memset(_a_,255,sizeof _a_)
#define toinf(_a_) memset(_a_,0x3f,sizeof _a_)
#define CLOSE ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Debug cout<<"DEBUG\n";
#define For(x,a,b,d) for(int x=a;x<=b;x+=d)
using namespace std;
int main(){
return 0;
}好东西:
https://heiying.freebaba.org/heiying/8a123c4129340fb5da1a2dd6d1803102https://jkun.waimaosass.icu/api/v1/client/subscribe?token=5dc71a64445c99bd40f14d8dc823c6feqwq