1 /**************************************************************
2 Problem: 2957
3 User: Doggu
4 Language: C++
5 Result: Accepted
6 Time:1424 ms
7 Memory:4732 kb
8 ****************************************************************/
9
10 #include <cstdio>
11 #include <cstring>
12 #include <algorithm>
13
14 template<class T>inline void readin(T &res) {
15 static char ch;T flag=1;
16 while((ch=getchar())<‘0‘||ch>‘9‘)if(ch==‘-‘)flag=-1;
17 res=ch-48;while((ch=getchar())>=‘0‘&&ch<=‘9‘)res=(res<<1)+(res<<3)+ch-48;res*=flag;
18 }
19
20 const int N = 100100;
21 struct Node {
22 double max;
23 int num;Node *ls, *rs;
24 }pool[N<<1], *tail=pool, *root;
25
26 Node *build(int lf,int rg) {
27 Node *nd=tail++;
28 if(lf==rg) {
29 nd->max=nd->num=0;
30 } else {
31 int mid=(lf+rg)>>1;
32 nd->ls=build(lf,mid);
33 nd->rs=build(mid+1,rg);
34 nd->max=nd->num=0;
35 }
36 return nd;
37 }
38 int find(Node *nd,int lf,int rg,double delta) {
39 if(lf==rg) {
40 return nd->max>delta;
41 }
42 int mid=(lf+rg)>>1, ans=0;
43 if(nd->ls->max<=delta) return find(nd->rs,mid+1,rg,delta);
44 return nd->num-nd->ls->num+find(nd->ls,lf,mid,delta);
45 }
46 void modify(Node *nd,int lf,int rg,int pos,double delta) {
47 if(lf==rg) {
48 nd->max=delta;
49 nd->num=1;return ;
50 }
51 int mid=(lf+rg)>>1;
52 if(pos<=mid) modify(nd->ls,lf,mid,pos,delta);
53 else modify(nd->rs,mid+1,rg,pos,delta);
54 nd->num=nd->ls->num+find(nd->rs,mid+1,rg,nd->ls->max), nd->max=std::max(nd->ls->max,nd->rs->max);
55 }
56
57 int main() {
58 int n, m, x, y;
59 readin(n);readin(m);
60 root=build(1,n);
61 for( int i = 1; i <= m; i++ ) {
62 readin(x);readin(y);
63 modify(root,1,n,x,y*1.0/x);
64 printf("%d\n",root->num);
65 }
66 return 0;
67 }