#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> using namespace std; const int maxn=110000; int n,m,siz,ans,pre; int t[1000],s[1000],h[maxn],p[1000][1000]; namespace fastIO { #define BUF_SIZE 100000 bool IOerror = 0; inline char nc() { static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE; if(p1 == pend) { p1 = buf; pend = buf + fread(buf, 1, BUF_SIZE, stdin); if(pend == p1) { IOerror = 1; return -1; } } return *p1++; } inline bool blank(char ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; } inline void read(int &x) { char ch; while(blank(ch = nc())); if(IOerror) return; for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0'); } #undef BUF_SIZE }; using namespace fastIO; bool cmp(int a,int b) { if(a==0) return h[b]>0; return (long long)h[a]*b<(long long)h[b]*a; } int main() { read(n), read(m),n++; int i,j,a,b,l,r,mid; siz=int(0.5*sqrt(n*log(1.0*n)/log(2.0))); for(i=1;i<=m;i++) { read(a), read(b); h[a]=b,p[a/siz][0]=0; for(j=a/siz*siz;j<(a/siz+1)*siz;j++) if(cmp(p[a/siz][p[a/siz][0]],j)) p[a/siz][++p[a/siz][0]]=j; for(ans=pre=j=0;j*siz<n;j++) { l=1,r=p[j][0]+1; while(l<r) { mid=l+r>>1; if(cmp(pre,p[j][mid])) r=mid; else l=mid+1; } ans += p[j][0]+1-r; if(p[j][0]>=l) pre=p[j][p[j][0]]; } printf("%d\n",ans); } return 0; }
|