题意:给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. poi excel export 乱码

    1. Question Description: ~前端是get方式提交的,参数含有中文“测试” ~导出的excel,文件名正常, 而标题乱码 2. Solution: ~断点发现, 参数接收就是乱码 ...

  2. 被混淆的C#类库的反编译

    今天看公司以前的代码,用的是.NRT Reactor v4.4.7.5进行的混淆,直接使用.NET Reflector v8.5.0.179 是无法查看的,提示:Invalid number of d ...

  3. 关于Fragment 不响应onActivityResult的情况分析 (

    大家都知道,可以通过使用 startActivityForResult() 和 onActivityResult() 方法来传递或接收参数. 但你是否遭遇过onActivityResult()不执行或 ...

  4. JAVA-插入排序

    插入排序 package com.pb.string.demo1; /** * 插入排序 * @author Denny * */ public class Demo { public static ...

  5. Mac上的软件的一些对开发者有用的使用技巧(持续更新)

    内容大纲: Google浏览器设置开发者模式 正文: 1.Google浏览器设置开发者模式

  6. 在XcodeGhost事件之后,获取更纯净的Xcode的方法。

    正值Xcode 7正式版本的更新,IOS界就冒出了个甚至可以说成涉及国家安全的大事也不为过的事件: 也可以点击网址链接看总结的更完整的文章:众多知名 APP 都中毒了,XCodeGhost 病毒事件汇 ...

  7. eclipse执行单元测试报CreateProcess error=87的解决方法

    原因是classpath的路径过长导致,在网上看了很多文章,发现解决方法有2种: 1.更改项目路径 或者 maven本地库的路径,减少classpath的深度. 2.由于这是eclipse自身的bug ...

  8. SAM4E单片机之旅——17、通过UART进行标准IO

    交互还是很有必要的,而且使用键盘和显示器的交互效率还是很高的.当然,可以直接使用UART进行字符的输入和输出.但是又何必浪费了C的标准输入输出的格式控制之类的功能呢? 这次内容就是使用scanf() ...

  9. node中简单scoket介绍

    /*socket.io是一个基于 node.js 的项目,其主要作用是将WebScoket 协议应用到所有的浏览器.该模块主要应用于实时的长连接 多请求的项目中,例如在线联网游戏中.实时聊天.实施股票 ...

  10. Buffer篇

    // var buf1 = new Buffer(26);/*返回一个新的buffer对象,这个新buffer和老buffer公用一个内存.但是被start和end索引偏移缩减了.(比如,一个buff ...