hdu 4973 A simple simulation problem.(2014 Multi-University Training Contest 10)
来源:互联网 发布:黑屏手机坏了导出数据 编辑:程序博客网 时间:2024/05/05 04:34
A simple simulation problem.
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 392 Accepted Submission(s): 155
Problem Description
There are n types of cells in the lab, numbered from 1 to n. These cells are put in a queue, the i-th cell belongs to type i. Each time I can use mitogen to double the cells in the interval [l, r]. For instance, the original queue is {1 2 3 3 4 5}, after using a mitogen in the interval [2, 5] the queue will be {1 2 2 3 3 3 3 4 4 5}. After some operations this queue could become very long, and I can’t figure out maximum count of cells of same type. Could you help me?
Input
The first line contains a single integer t (1 <= t <= 20), the number of test cases.
For each case, the first line contains 2 integers (1 <= n,m<= 50000) indicating the number of cell types and the number of operations.
For the following m lines, each line represents an operation. There are only two kinds of operations: Q and D. And the format is:
“Q l r”, query the maximum number of cells of same type in the interval [l, r];
“D l r”, double the cells in the interval [l, r];
(0 <= r – l <= 10^8, 1 <= l, r <= the number of all the cells)
For each case, the first line contains 2 integers (1 <= n,m<= 50000) indicating the number of cell types and the number of operations.
For the following m lines, each line represents an operation. There are only two kinds of operations: Q and D. And the format is:
“Q l r”, query the maximum number of cells of same type in the interval [l, r];
“D l r”, double the cells in the interval [l, r];
(0 <= r – l <= 10^8, 1 <= l, r <= the number of all the cells)
Output
For each case, output the case number as shown. Then for each query "Q l r", print the maximum number of cells of same type in the interval [l, r].
Take the sample output for more details.
Take the sample output for more details.
Sample Input
15 5D 5 5Q 5 6D 2 3D 1 2Q 1 7
Sample Output
Case #1:23
树状数组做的
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;const int maxn=50010;long long sum[maxn];long long coun[maxn];int n,m;int low(int k){ return k&(-k);}void add(int i,long long v){ while(i<=n) { sum[i]+=v; i+=low(i); }}long long getsum(int k){ long long ans=0; while(k>0) { ans+=sum[k]; k-=low(k); } return ans;}int find(long long k){ int mid,l=1,r=n; while(l<r) { mid=(l+r)>>1; long long temp=getsum(mid); if(k>temp) { l=mid+1; } else r=mid; } return l;}void update(long long l,long long r){ int L=find(l); int R=find(r); if(L==R) { add(L,r-l+1); coun[L]+=(r-l+1); return; } long long x=getsum(L); long long y=getsum(R-1); add(L,x-l+1); coun[L]+=(x-l+1); add(R,r-y); coun[R]+=(r-y); for(int i=L+1;i<R;i++) { add(i,coun[i]); coun[i]+=coun[i]; } return;}void quarry(long long l,long long r){ int L=find(l); int R=find(r); if(L==R) { printf("%I64d\n",r-l+1); return; } long long maxn; maxn=max(getsum(L)-l+1,r-getsum(R-1)); for(int i=L+1;i<R;i++) { if(maxn<coun[i]) maxn=coun[i]; } printf("%I64d\n",maxn); return;}int main(){ int t,ca=1; scanf("%d",&t); while(t--) { char s; long long x,y; scanf("%d%d",&n,&m); memset(sum,0,sizeof(sum)); for(int i=1;i<=n;i++) { add(i,1); coun[i]=1; } printf("Case #%d:\n",ca++); while(m--) { scanf(" %c%I64d%I64d",&s,&x,&y); if(s=='D') { update(x,y); } else quarry(x,y); } }}
0 0
- hdu 4973 A simple simulation problem.(2014 Multi-University Training Contest 10)
- 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 4947 A simple dynamic programming problem(2014 Multi-University Training Contest 10)
- 2015 Multi-University Training Contest 5 - MZL's simple problem
- HDU 5349 MZL's simple problem (2015 Multi-University Training Contest 5 2015多校联合)
- HDU--5349--2015 Multi-University Training Contest 5--MZL's simple problem
- hdu 5349 MZL's simple problem 2015 Multi-University Training Contest 5
- hdu 5858 Hard problem(2016 Multi-University Training Contest 10——数学题)
- hdu 5867 Water problem(2016 Multi-University Training Contest 10——水题)
- 2016 多校 Multi-University Training Contest 6 A Simple Chess
- 【2016 Multi-University Training Contest 6】【1002】【A Simple Chess】
- HDU 5795 A Simple Nim(SG打表找规律)——2016 Multi-University Training Contest 6
- (HDU 5795)2016 Multi-University Training Contest 6 A Simple Nim (SG函数、博弈)
- (HDU 5794)2016 Multi-University Training Contest 6 A Simple Chess (Lucas、容斥)
- hdu 5795 A Simple Nim(2016 Multi-University Training Contest 6——博弈)
- hdu 4911 Inversion ( 2014 Multi-University Training Contest 5)
- hdu 5328 Problem Killer 2015 Multi-University Training Contest 4
- 银行业务调度系统
- Eclipse超级联想和alt+/ 联想的实现方法
- lis nlogn
- LeetCode——Search a 2D Matrix
- LeetCode: Partition List
- hdu 4973 A simple simulation problem.(2014 Multi-University Training Contest 10)
- 【C++ Primer每日刷】之三 标准库 string 类型
- 关于矩阵的乘法和相似矩阵的一点思考
- poj1416~简单dfs枚举题
- KVO(两页面传值)
- Tyvj 1125
- 二值图像连通区域标记(OpenCV版)
- Error -26366的几个解决方法
- 关于vim不能粘贴到系统剪贴板与无法打开并写入文件