Time Limit: / MS (Java/Others)    Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): 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[],a[],...,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. 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[],a[],...,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]
<=T<=
<=N, M<=
<=a[i]<= -
<=X<=N
<=Y<= -
<=L<=R<=N
<=D<=
<=P<= Output
For each operation Q, output a line contains the answer. Sample Input Q
Q
Q
Q
Q
S
Q Sample Output Source
BestCoder Round # (Div. ) 之前用线段树一直MLE(在码之前看了下内存限制,就觉得会开不下的了),知道可以用分块做之后,就看了下大白的一道分块题,再想这道题就比较简单了
~num[b][a][b]表示第b块所有的数在第a位为b的个数,这些都可以简单预处理出来,然后只是单点修改,把原来的值和新值对比一下更新一下就好了
#include <bits/stdc++.h> using namespace std;
const int N = 1e5 + ;
const int SIZE = ;
int n, m;
int A[N];
int block[N / SIZE + ][SIZE + ];
int num[N / SIZE + ][][];
void pre(int b, int j)
{
int *B = &block[b][];
for(int i = ; i < j; ++i) {
int tmp = B[i];
int cnt = ;
while(cnt <= ) {
int x = tmp % ;
tmp /= ;
num[b][cnt][x]++;
cnt++;
}
}
}
void init()
{
memset(num, , sizeof num);
scanf("%d%d", &n, &m);
int j = , b = ;
for(int i = ; i < n; ++i) {
scanf("%d", &A[i]);
block[b][j] = A[i];
if(++j == SIZE) {
pre(b, j);
b++; j = ;
}
}
if(j) { pre(b, j); ++b; }
}
int get(int x, int d) {
int cnt = ;
while(cnt < d) {
x /= ;
cnt++;
}
return x % ;
}
int query(int L, int R, int D, int p)
{
int res = ;
int lb = L / SIZE, rb = R / SIZE;
if(lb == rb) {
for(int i = L; i <= R; ++i) {
if(get(A[i], D) == p) res++;
}
}
else {
for(int i = L; i < (lb + ) * SIZE; ++i) if(get(A[i], D) == p) res++;
for(int i = rb * SIZE; i <= R; ++i) if(get(A[i], D) == p) res++;
for(int i = lb + ; i < rb; ++i) res += num[i][D][p];
}
return res;
}
void modify(int x, int y)
{
if(A[x] == y) return;
int old = A[x], now = y, b = x / SIZE, cnt = ;
int c1[], c2[];
A[x] = y;
while(cnt <= ) {
c1[cnt] = old % ;
c2[cnt] = now % ;
old /= ;
now /= ;
cnt++;
}
for(int i = ; i <= ; ++i) {
if(c1[i] != c2[i]) {
num[b][i][ c2[i] ]++;
num[b][i][ c1[i] ]--;
}
}
}
int main()
{
int _; scanf("%d", &_);
while(_ --)
{
init();
char op[];
int L, R, D, P;
while(m --)
{
scanf("%s", op);
if(op[] == 'Q') {
scanf("%d%d%d%d", &L, &R, &D, &P);
L--; R--;
printf("%d\n", query(L, R, D, P));
}else {
scanf("%d%d", &D, &P);
D--;
modify(D, P);
}
}
}
return ;
}
  

hdu5057 Argestes and Sequence 分块的更多相关文章

  1. hdu 5057 Argestes and Sequence(分块算法)

    Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. 【分块】hdu5057 Argestes and Sequence

    分块,v[i][j][k]表示第i块内第j位是k的元素数.非常好写.注意初始化 要注意题意,①第i位是从右往左算的. ②若x没有第i位,则用前导零补齐10位.比如103---->00000001 ...

  3. hdu 5057 Argestes and Sequence

    Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. HDU 5057 Argestes and Sequence --树状数组(卡内存)

    题意:给n个数字,每次两种操作: 1.修改第x个数字为y. 2.查询[L,R]区间内第D位为P的数有多少个. 解法:这题当时被卡内存了,后来看了下别人代码发现可以用unsigned short神奇卡过 ...

  5. hdu_5286_wyh2000 and sequence(分块)

    题目链接:hdu_5286_wyh2000 and sequence 题意: 给一段长度为N的序列,每次询问l-r(l和r和上一次询问的答案有关)内 不同的数的 出现次数的次方 的和.强制在线 题解: ...

  6. HDU - 6395 Sequence (分块+快速矩阵幂)

    给定递推式: 求Fn. 分析:给出的公式可以用快速矩阵幂运算得到,但 P/n 整除对于不同的i,值是不同的. 可以根据P将3-n分成若干块,每块中P整除n的值是相同的.分块的时候要注意判断. 将每块的 ...

  7. [hdu-6395]Sequence 分块+矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6395 因为题目数据范围太大,又存在递推关系,用矩阵快速幂来加快递推. 每一项递推时  加的下取整的数随 ...

  8. 【HDOJ】5057 Argestes and Sequence

    树状数组,其实很简单.只是MLE. #include <iostream> #include <cstdio> #include <cstring> using n ...

  9. Sequence( 分块+矩阵快速幂 )

    题目链接 #include<bits/stdc++.h> using namespace std; #define e exp(1) #define pi acos(-1) #define ...

随机推荐

  1. 35. Search Insert Position

    题目: Given a sorted array and a target value, return the index if the target is found. If not, return ...

  2. [网络流24题]餐巾(cogs 461)

    [问题描述] 一个餐厅在相继的N天里,第i天需要Ri块餐巾(i=l,2,-,N).餐厅可以从三种途径获得餐巾. (1)购买新的餐巾,每块需p分: (2)把用过的餐巾送到快洗部,洗一块需m天,费用需f分 ...

  3. Innodb之拷贝InnoDB表从一服务器到另一台服务器

    将Innodb类型的表从一台服务器拷贝到另一台服务器,或从一个库拷贝到另一个库. 前提是:innodb_file_per_table =ON. 1 先在目标服务器(库)上创建一个相同的表结构. 如: ...

  4. 使用vsphere client 克隆虚拟机

    免费的VMWare ESXi5.0非常强大,于是在vSphere5.0平台中ESXi取代了ESX.,使用ESXi经常会遇到这样的问题,我需要建立多个虚拟机,都是windows2003操作系统,难道必须 ...

  5. redis配置详情

    # Redis configuration file example # Note on units: when memory size is needed, it is possible to sp ...

  6. android的JNI 、 NDK 学习!

    转载的! Java Native Interface (JNI)标准是java平台的一部分,它允许Java代码和其他语言写的代码进行交互.JNI 是本地编程接口,它使得在 Java 虚拟机 (VM) ...

  7. 2.2 顺序容器-list

    list(双向链表) 1) *  :包含头文件list **:不支持随机存取:增删元素时间是常数,只需要修改指针 2)成员函数 *  :vector的成员函数list基本都有 **:以下是部分独有成员 ...

  8. 关于logcat日志

    最近学习android,碰到了logcat,个人总结一下. 当不出日志是解决办法: ProjectMenu---后台设置----LOG设置---LOG开关 Logcat(deprecated)和Log ...

  9. hdu 1513

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 思路:正反分别求一次LCS,利用滚动数组对二取余滚动 #include<stdio.h&g ...

  10. .net学习笔记----WebConfig常用配置节点介绍

    一.配置文件入门 .Net提供了一种保存项目配置信息的办法,就是利用配置文件,配置文件的后缀一般是.config.在WinForm程序中配置文件一般是App.config.在Asp.net中一般默认是 ...