标签:
题目:http://www.tsinsen.com/A1377
题解:分块大法好。每块维护一个有序表,修改暴力修改,查询从前往后跳即可。
代码:
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set> 10 #include<queue> 11 #include<string> 12 #define inf 2000000000 13 #define maxn 250000+5 14 #define maxm 5005 15 #define eps 1e-10 16 #define ll long long 17 #define ull unsigned long long 18 #define pa pair<int,int> 19 #define for0(i,n) for(int i=0;i<=(n);i++) 20 #define for1(i,n) for(int i=1;i<=(n);i++) 21 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 22 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 23 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) 24 #define for5(n,m) for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) 25 #define mod 1000000007 26 #define lch k<<1,l,mid 27 #define rch k<<1|1,mid+1,r 28 #define sqr(x) (x)*(x) 29 using namespace std; 30 inline int read() 31 { 32 int x=0,f=1;char ch=getchar(); 33 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} 34 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();} 35 return x*f; 36 } 37 int n,m,l[maxn],r[maxn],b[maxn],s[maxn]; 38 double a[maxn],c[maxm][maxm]; 39 int main() 40 { 41 freopen("input.txt","r",stdin); 42 freopen("output.txt","w",stdout); 43 n=read();int T=read();m=sqrt(n*log2(n)); 44 for1(i,n)b[i]=(i-1)/m+1; 45 for1(i,b[n])l[i]=(i-1)*m+1,r[i]=min(i*m,n),c[i][1]=inf; 46 while(T--) 47 { 48 int x=read(),y=read(),t=b[x]; 49 a[x]=(double)y/(double)x; 50 s[t]=0;for2(i,l[t],r[t])if(a[i]>c[t][s[t]])c[t][++s[t]]=a[i]; 51 c[t][s[t]+1]=inf; 52 double tmp=0;int ans=0; 53 for1(i,b[n])ans+=s[i]-(upper_bound(c[i]+1,c[i]+s[i]+2,tmp)-c[i])+1,tmp=max(tmp,c[i][s[i]]); 54 printf("%d\n",ans); 55 } 56 return 0; 57 }
标签:
原文地址:http://www.cnblogs.com/zyfzyf/p/4355351.html