1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| #include <iostream> #include <cstdio> #include <cctype>
using namespace std;
typedef double db;
inline int read() { int x=0,f=1; char ch=getchar(); while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar(); while (isdigit(ch)) x=x*10+ch-'0',ch=getchar(); return x*f; }
int buf[30];
inline void write(int x) { if (x<0) putchar('-'),x=-x; for (;x;x/=10) buf[++buf[0]]=x%10; if (!buf[0]) buf[++buf[0]]=0; for (;buf[0];putchar('0'+buf[buf[0]--])); }
const int N=1000005;
inline int max(int x,int y){return x>y?x:y;}
int a[N]; int T,n,q;
struct segment_tree { int cnt[N<<2],mx[N<<2];
int querymax(int x,int st,int en,int l,int r) { if (st==l&&en==r) return mx[x]; int mid=l+r>>1; if (en<=mid) return querymax(x<<1,st,en,l,mid); else if (mid+1<=st) return querymax(x<<1|1,st,en,mid+1,r); else return max(querymax(x<<1,st,mid,l,mid),querymax(x<<1|1,mid+1,en,mid+1,r)); }
int querycnt(int x,int st,int en,int l,int r,db p) { if (l==r) return (mx[x]>p)+1; int mid=l+r>>1;bool cvr=st==l&&en==r; if (en<=mid) return querycnt(x<<1,st,en,l,mid,p); else if (mid+1<=st) return querycnt(x<<1|1,st,en,mid+1,r,p); else { int rmx=cvr?mx[x<<1|1]:querymax(x<<1|1,mid+1,en,mid+1,r); if (rmx>p) return (cvr?cnt[x]:querycnt(x<<1,st,mid,l,mid,rmx))+querycnt(x<<1|1,mid+1,en,mid+1,r,p)-1; else return querycnt(x<<1,st,mid,l,mid,p); } }
void update(int x,int l,int r) { int mid=l+r>>1; mx[x]=max(mx[x<<1],mx[x<<1|1]),cnt[x]=querycnt(x<<1,l,mid,l,mid,mx[x<<1|1]); }
void modify(int x,int y,int l,int r,int delta) { if (l==r) { mx[x]+=delta; return; } int mid=l+r>>1; if (y<=mid) modify(x<<1,y,l,mid,delta); else modify(x<<1|1,y,mid+1,r,delta); update(x,l,r); }
void build(int x,int l,int r) { if (l==r) { mx[x]=a[n-l+1]; return; } int mid=l+r>>1; build(x<<1,l,mid),build(x<<1|1,mid+1,r),update(x,l,r); } }t;
int main() { freopen("shtarr.in","r",stdin),freopen("shtarr.out","w",stdout); for (T=read();T--;) { n=read(),q=read(); for (int i=1;i<=n;++i) a[i]=read(); t.build(1,1,n); for (int i=1;i<=q;++i) { char opt=getchar(); for (;opt!='?'&&opt!='+';opt=getchar()); if (opt=='?') { int x=read(),l=read(),r=read(); write(t.querycnt(1,1,n-x+1,1,n,l-.5)-t.querycnt(1,1,n-x+1,1,n,r-.5)+(t.querymax(1,1,n-x+1,1,n)>r-.5)),putchar('\n'); } else { int x=read(),y=read(); t.modify(1,n-x+1,1,n,y); } } } fclose(stdin),fclose(stdout); return 0; }
|