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
| #include<iostream> #include<cstdio> using namespace std; const int N=1e5+10; template<class T> inline void read(T &x) { x=0;bool f=0; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();} while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); if(f)x=-x; } template<class T,class ...T1> inline void read(T &x,T1 &...x1) { read(x),read(x1...); } struct Node { int l,r; double val; int len; }tr[N<<2]; int n,m; int get(int x,double k) { if(tr[x].val<=k)return 0; if(tr[x].l==tr[x].r)return 1; int mid=tr[x].l+tr[x].r>>1; if(tr[x<<1].val<=k)return get(x<<1|1,k); return get(x<<1,k)+tr[x].len-tr[x<<1].len; }
inline void pushup(int x) { tr[x].val=max(tr[x<<1].val,tr[x<<1|1].val); tr[x].len=tr[x<<1].len+get(x<<1|1,tr[x<<1].val); } void bulid(int x,int l,int r) { tr[x].l=l,tr[x].r=r; if(l==r)return ; int mid=l+r>>1; bulid(x<<1,l,mid),bulid(x<<1|1,mid+1,r); } void modify(int x,int pos,double k) { if(tr[x].l==tr[x].r)return tr[x].val=k,tr[x].len=1,void(); int mid=tr[x].l+tr[x].r>>1; if(pos<=mid)modify(x<<1,pos,k); else modify(x<<1|1,pos,k); pushup(x); } int main() { read(n,m); bulid(1,1,n); while(m--) { int x,y; read(x,y); modify(1,x,1.0*y/x); printf("%d\n",tr[1].len); } return 0; }
|