hdu 5057 Argestes and Sequence(BestCoder Round #11)
来源:互联网 发布:知乎 商城模块 编辑:程序博客网 时间:2024/05/22 20:28
Argestes and Sequence
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 640 Accepted Submission(s): 163
Problem Description
Argestes has a lot of hobbies and likes solving query problems especially. One day Argestes came up with such a problem. You are given a sequence a consisting of N nonnegative integers, a[1],a[2],...,a[n].Then there are M operation on the sequence.An operation can be one of the following:
S X Y: you should set the value of a[x] to y(in other words perform an assignment a[x]=y).
Q L R D P: among [L, R], L and R are the index of the sequence, how many numbers that the Dth digit of the numbers is P.
Note: The 1st digit of a number is the least significant digit.
S X Y: you should set the value of a[x] to y(in other words perform an assignment a[x]=y).
Q L R D P: among [L, R], L and R are the index of the sequence, how many numbers that the Dth digit of the numbers is P.
Note: The 1st digit of a number is the least significant digit.
Input
In the first line there is an integer T , indicates the number of test cases.
For each case, the first line contains two numbers N and M.The second line contains N integers, separated by space: a[1],a[2],...,a[n]—initial value of array elements.
Each of the next M lines begins with a character type.
If type==S,there will be two integers more in the line: X,Y.
If type==Q,there will be four integers more in the line: L R D P.
[Technical Specification]
1<=T<= 50
1<=N, M<=100000
0<=a[i]<=$2^{31}$ - 1
1<=X<=N
0<=Y<=$2^{31}$ - 1
1<=L<=R<=N
1<=D<=10
0<=P<=9
For each case, the first line contains two numbers N and M.The second line contains N integers, separated by space: a[1],a[2],...,a[n]—initial value of array elements.
Each of the next M lines begins with a character type.
If type==S,there will be two integers more in the line: X,Y.
If type==Q,there will be four integers more in the line: L R D P.
[Technical Specification]
1<=T<= 50
1<=N, M<=100000
0<=a[i]<=$2^{31}$ - 1
1<=X<=N
0<=Y<=$2^{31}$ - 1
1<=L<=R<=N
1<=D<=10
0<=P<=9
Output
For each operation Q, output a line contains the answer.
Sample Input
15 710 11 12 13 14Q 1 5 2 1Q 1 5 1 0Q 1 5 1 1Q 1 5 3 0Q 1 5 3 1S 1 100Q 1 5 3 1
Sample Output
511501
以为是很简单的树状数组,开了个三维的,直接MLE了,可以离线处理,通过枚举每一位降低空间消耗。
代码:
//1296ms#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int maxn=100000+1000;int a[11][maxn];int b[maxn];int c[maxn];int ans[maxn];int n,m;struct node{ int kind; int l,r,d,p,pos,value;}op[maxn];int low(int k){ return k&(-k);}void update(int x,int k,int v){ while(k<maxn) { a[x][k]+=v; k+=low(k); }}int getsum(int x,int k){ int ans=0; while(k>0) { ans+=a[x][k]; k-=low(k); } return ans;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&b[i]); c[i]=b[i]; } char s[10]; for(int i=0;i<m;i++) { scanf("%s",s); if(s[0]=='Q') { op[i].kind=0; scanf("%d%d%d%d",&op[i].l,&op[i].r,&op[i].d,&op[i].p); } else { op[i].kind=1; scanf("%d%d",&op[i].pos,&op[i].value); } } int po=1; for(int i=1;i<=10;i++)//按位枚举 { memset(a,0,sizeof(a)); for(int j=1;j<=n;j++) { b[j]=c[j];//每次恢复为原来的值 int temp=(b[j]/po)%10; update(temp,j,1); } for(int j=0;j<m;j++) { if(op[j].kind==1)//更改操作 { int temp=(b[op[j].pos]/po)%10; update(temp,op[j].pos,-1); temp=(op[j].value/po)%10; update(temp,op[j].pos,1); b[op[j].pos]=op[j].value; } else { if(op[j].d==i)//对应位的查询 ans[j]=getsum(op[j].p,op[j].r)-getsum(op[j].p,op[j].l-1); else ; } } po=po*10; } for(int j=0;j<m;j++) if(op[j].kind==0) { printf("%d\n",ans[j]); } } return 0;}
0 0
- BestCoder Round #11 (Div. 2) Argestes and Sequence (hdu 5057)
- hdu 5057 Argestes and Sequence(BestCoder Round #11)
- 【BestCoder】 HDOJ 5057 Argestes and Sequence
- hdu 5057 Argestes and Sequence
- 20140929 【 树状数组 】 BestCoder Round #11 (Div. 2) Argestes and Sequence
- Argestes and Sequence HDU
- HDU 5057 Argestes and Sequence 分块
- HDU 5057 Argestes and Sequence(平方分割)
- HDOJ 5057 Argestes and Sequence
- hdu 5057 Argestes and Sequence(树状数组)
- HDU 5057 Argestes and Sequence --树状数组(卡内存)
- hdu 5057 Argestes and Sequence (离散的树状数组)
- HDU 5057 Argestes and Sequence (离线树状数组 || 分块)
- hdu 5057 Argestes and Sequence(离线处理树状数组)
- HDU 5057 Argestes and Sequence(树状数组)
- HDU 5057 Argestes and Sequence 树状数组+离线
- HDU 5057 Argestes and Sequence 离线处理+树状数组
- hdu 5504 GT and sequence【BestCoder Round #60 】
- 轻松学算法7:Dijkstra最短路算法
- 深入理解javascript原型和闭包(16)——完结
- JScrollPane,JComboBox透明
- 数据结构--堆排序
- 算法8:图还可以这样存——邻接表的数组实现
- hdu 5057 Argestes and Sequence(BestCoder Round #11)
- Matlab常用函数(1)
- 加州理工学院公开课:机器学习与数据挖掘_线性模型 II(第九课)
- 算法9:开启“树”之旅
- 比较对象的时候复写equals方法
- unicode和UTF-8的不同(The difference between UTF-8 and Unicode?)
- 深入理解javascript原型和闭包(17)——补this
- html在文本框中加入滚动条
- 笔记---Linux---Vim自动补齐的配置