题目:http://www.tsinsen.com/A1377
题解:分块大法好。每块维护一个有序表,修改暴力修改,查询从前往后跳即可。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 2000000000
#define maxn 250000+5
#define maxm 5005
#define eps 1e-10
#define ll long long
#define ull unsigned long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)
#define for5(n,m) for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)
#define mod 1000000007
#define lch k<<1,l,mid
#define rch k<<1|1,mid+1,r
#define sqr(x) (x)*(x)
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,l[maxn],r[maxn],b[maxn],s[maxn];
double a[maxn],c[maxm][maxm];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();int T=read();m=sqrt(n*log2(n));
for1(i,n)b[i]=(i-)/m+;
for1(i,b[n])l[i]=(i-)*m+,r[i]=min(i*m,n),c[i][]=inf;
while(T--)
{
int x=read(),y=read(),t=b[x];
a[x]=(double)y/(double)x;
s[t]=;for2(i,l[t],r[t])if(a[i]>c[t][s[t]])c[t][++s[t]]=a[i];
c[t][s[t]+]=inf;
double tmp=;int ans=;
for1(i,b[n])ans+=s[i]-(upper_bound(c[i]+,c[i]+s[i]+,tmp)-c[i])+,tmp=max(tmp,c[i][s[i]]);
printf("%d\n",ans);
}
return ;
}