题意:给n个数字,每次两种操作: 1.修改第x个数字为y。 2.查询[L,R]区间内第D位为P的数有多少个。

解法:这题当时被卡内存了,后来看了下别人代码发现可以用unsigned short神奇卡过,于是学习了。

这种区间求和的问题很容易想到树状数组,根据第i位为j(i<10,j<10)建立100棵树状数组(由于内存100*100000被卡,且看到个数,即c[10][10][100000]的值最多为100000,那么最多分两个unsigned short (0~65535),记录一下就可以了)。 然后两种操作都非常常规,就不讲了。

限时2500ms,结果跑了2250MS,限内存32768K,结果内存30008K,纯粹是卡过去的。

好像正解是离线算法或者分块,但是不会写,以后会写了再更新吧。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 100003 unsigned short c[][][N];
bool f[][][N];
int n,m;
int a[N];
int ten[] = {,,,,,,,,,}; int lowbit(int x) { return x&-x; } void modify(int D,int P,int x,int val)
{
while(x <= n)
{
c[D][P][x] += val;
if(c[D][P][x] > ) c[D][P][x] -= , f[D][P][x] = ;
x += lowbit(x);
}
} int getsum(int D,int P,int x)
{
int res = ;
while(x > )
{
res += c[D][P][x];
if(f[D][P][x]) res += ;
x -= lowbit(x);
}
return res;
} int main()
{
int i,j,t;
char ss[];
int x,y,L,R,D,P;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(c,,sizeof(c));
memset(f,,sizeof(f));
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
for(j=;j<;j++)
{
int num = a[i]/ten[j];
num %= ;
modify(j,num,i,);
}
}
while(m--)
{
scanf("%s",ss);
if(ss[] == 'Q')
{
scanf("%d%d%d%d",&L,&R,&D,&P);
D--;
printf("%d\n",getsum(D,P,R) - getsum(D,P,L-));
}
else
{
scanf("%d%d",&x,&y);
for(i=;i<;i++)
{
int num = a[x]/ten[i];
num %= ;
modify(i,num,x,-);
}
for(i=;i<;i++)
{
int num = y/ten[i];
num %= ;
modify(i,num,x,);
}
a[x] = y;
}
}
}
return ;
}

HDU 5057 Argestes and Sequence --树状数组(卡内存)的更多相关文章

  1. hdu 5057 Argestes and Sequence (数状数组+离线处理)

    题意: 给N个数.a[1]....a[N]. M种操作: S X Y:令a[X]=Y Q L R D P:查询a[L]...a[R]中满足第D位上数字为P的数的个数 数据范围: 1<=T< ...

  2. HDU 4893 Wow! Such Sequence! (树状数组)

    题意:给有三种操作,一种是 1 k d,把第 k 个数加d,第二种是2 l r,查询区间 l, r的和,第三种是 3 l r,把区间 l,r 的所有数都变成离它最近的Fib数, 并且是最小的那个. 析 ...

  3. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  4. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  5. HDU 6078 Wavel Sequence 树状数组优化DP

    Wavel Sequence Problem Description Have you ever seen the wave? It's a wonderful view of nature. Lit ...

  6. HDU 1394 Minimum Inversion Number ( 树状数组求逆序数 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number                         ...

  7. hdu 5057 Argestes and Sequence

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

  8. HDU 2689 Sort it【树状数组】

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  9. HDU 5862 Counting Intersections (树状数组)

    Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...

随机推荐

  1. 一个小笔记(7):EN_1

    For nearly ten years, the Unified Modeling Language(UML) has been the industry standard for visualiz ...

  2. ahjesus SSHkey登陆linux服务器,无需密码,ubuntu

    cd ~/.ssh/如果目录不存在就新建一个 mkdir ~/.ssh 制作公匙 ssh-keygen -t rsa默认会生成id_rsa.pub的公匙 将公匙推送到指定的服务器 scp id_rsa ...

  3. [转]MVC、MVP、MVVM

    界面之下:还原真实的 MVC.MVP.MVVM 模式 [日期:2015-10-28] 来源:github.com/livoras  作者:戴嘉华 [字体:大 中 小]   前言 做客户端开发.前端开发 ...

  4. SQL数据库基础(五)

    字符串函数: 时间日期函数: SELECT @@DATEFIRST AS '1st Day', DATEPART(dw, GETDATE()) AS 'Today' SELECT GETDATE() ...

  5. copy 和 strong(或retain)的区别

    http://stackoverflow.com/questions/18526909/whether-i-should-use-propertynonatomic-copy-or-propertyn ...

  6. 在 SharePoint Server 2013 中配置建议和使用率事件类型

    http://technet.microsoft.com/zh-cn/library/jj715889.aspx 适用于: SharePoint Server 2013 利用使用事件,您可以跟踪用户与 ...

  7. Jsoup解析Html中文文档

    jsoup 简介Java 程序在解析 HTML 文档时,相信大家都接触过 htmlparser 这个开源项目,我曾经在 IBM DW 上发表过两篇关于 htmlparser 的文章,分别是:从 HTM ...

  8. Fresco 使用笔记(一):加载gif图片并播放

    项目总结 --------------------------------------------------------------------- 前言: 项目中图文混合使用的太多太多了,但是绝大部 ...

  9. 学习android学习必备的java基础知识--四大内部类

    学习android必备的java基础知识--四大内部类 今天学习android课程,因为我的主专业是JAVA,但是兴趣班却有这其他专业的同学,学习android 需要具备一些java的基础知识,因此就 ...

  10. Android bitmap高效显示和优化

    第一部分:Bitmap高效显示 应用场景:有时候我们想在界面上显示一个网络图片或者显示一张本地的图片,但是图片本身是很大的有几兆,但是显示的位置很小或者说我们可以用更小的图片来满足这样的需求,如果把整 ...