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
| #include<set> #include<map> #include<ctime> #include<queue> #include<cmath> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define inf 1000000000 #define ll long long using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m; struct data{ int l,r,ans; double val,lx,mx; }t[400005]; void build(int k,int l,int r) { t[k].l=l;t[k].r=r;int mid=(l+r)>>1; if(l==r)return; build(k<<1,l,mid); build(k<<1|1,mid+1,r); } int cal(int k,double val) { int l=t[k].l,r=t[k].r; if(l==r)return t[k].val>val; if(t[k<<1].val<=val)return cal(k<<1|1,val); return t[k].ans-t[k<<1].ans+cal(k<<1,val); } void modify(int k,int pos,double val) { int l=t[k].l,r=t[k].r,mid=(l+r)>>1; if(l==r) { t[k].ans=1; t[k].val=val; return; } if(pos<=mid)modify(k<<1,pos,val); else modify(k<<1|1,pos,val); t[k].val=max(t[k<<1].val,t[k<<1|1].val); t[k].ans=t[k<<1].ans+cal(k<<1|1,t[k<<1].val); } int main() { n=read();m=read(); build(1,1,n); while(m--) { int x=read(),y=read(); modify(1,x,(double)y/x); printf("%d\n",t[1].ans); } return 0; }
|