hdu4973 A simple simulation problem.(多校第十场1003)
来源:互联网 发布:淘宝旺旺链接生成器 编辑:程序博客网 时间:2024/06/04 19:04
可以直接用树状数组求和加二分判断l、r属于那一块,然后直接暴力即可,线段树也可做。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define LL __int64using namespace std;LL bit[200005];LL a[50005];int low(int a){return a&(-a);}void merg(int a,int n,int p){ while(a<=n){ bit[a]+=p; a+=low(a); }}LL sum(int a){ LL s=0; while(a>0){ s+=bit[a]; a=a-low(a); } return s;}int get(LL x,int n){ int le,ri,mid; le=1; ri=n; while(le<=ri){ mid=(le+ri)/2; if(sum(mid)<x) le=mid+1; else ri=mid-1; } return le;}int max(int a,int b){ if(a<b) return b; return a;}char cc[5],c;int main(){ int i,j,n,m,t,x1,x2,s,N; LL p,k; cin>>t; N=t; while(t--){ scanf("%d%d",&n,&m); memset(bit,0,sizeof(bit)); for(i=1;i<=n;i++){ a[i]=1; merg(i,n,1); } printf("Case #%d:\n",N-t); for(i=0;i<m;i++){ scanf("%s",cc); c=cc[0]; if(c=='Q'){ scanf("%I64d%I64d",&p,&k); x1=get(p,n); x2=get(k,n); if(x1==x2){ printf("%d\n",k-p+1); continue; } s=0; for(j=x1+1;j<=x2-1;j++) s=max(s,a[j]); s=max(s,sum(x1)-p+1); s=max(s,k-sum(x2-1)); printf("%d\n",s); } else{ scanf("%I64d%I64d",&p,&k); x1=get(p,n); x2=get(k,n); if(x1==x2){ merg(x1,n,k-p+1); a[x1]+=k-p+1; continue; } int w=sum(x1)-(p-1); int q=k-sum(x2-1); for(j=x1+1;j<=x2-1;j++){ merg(j,n,a[j]); a[j]=a[j]<<1; } merg(x1,n,w); a[x1]+=w; merg(x2,n,q); a[x2]+=q; } } }}
0 0
- hdu4973 A simple simulation problem.(多校第十场1003)
- HDU4973 A simple simulation problem.
- HDU4973 A simple simulation problem
- hdu4973 A simple simulation problem. 线段树
- HDU4973:A simple simulation problem.(线段树)
- hdu4973 A simple simulation problem.(成段更新+下标转化)
- hdu 4974 A simple water problem(多校第十场 水题)
- hdu4972 A simple dynamic programming problem(多校第十场1002)
- hdu4975 A simple Gaussian elimination problem.(多校第十场1005)
- HDU 4973 A simple simulation problem.(线段树)
- hdu 4973 A simple simulation problem (多校第10场 线段树)
- 【HDU 4973 多校联合】A simple simulation problem【树状数组】
- hdu 4973 A simple simulation problem 线段树 2014 Multi-University Training Contest 10-1003
- hdu 4973 A simple simulation problem.(2014 Multi-University Training Contest 10)
- hdu - 4973 - A simple simulation problem.(线段树单点更新 + 区间更新)
- hdu 4973 A simple simulation problem(线段树)
- HDU 4973 A simple simulation problem. 线段树
- 【线段树】 HDOJ 4973 A simple simulation problem.
- swift 学习资料
- tomcat 中配置 dbcp pool 连接池技术的使用 及 说明
- Java中求字符串长度length()和codePointCount()的区别
- 算法:C语言实现第三章第一节学习笔记
- Hdu 2579 Dating with girls(2) && hdu 2653 Waiting ten thousand years for Love【Bfs】
- hdu4973 A simple simulation problem.(多校第十场1003)
- 过滤器与拦截器的区别
- pig读取部分列 (全部列中的少部分列)
- NSData与各个类型之间的转换
- SVM中的对偶问题、KKT条件以及对拉格朗日乘子求值得SMO算法
- TKP(BFS)
- iOS中创建,使用动态库(dylib)
- excellent website for programmers
- printf()函数