【HDOJ】5057 Argestes and Sequence
树状数组,其实很简单。只是MLE。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; #define MAXN 100005 short sum[][][MAXN];
char bit[][][MAXN];
int a[MAXN];
int t, n, m;
int d, p;
const int MOD = ; int lowbit(int x) {
return x & -x;
} int getSum(int x, int d, int p) {
int ret = ;
while (x > ) {
ret += (int)sum[d][p][x] + ((int)bit[d][p][x]) * MOD;
x -= lowbit(x);
}
return ret;
} void update(int x, int d, int p, int r) {
int tmp;
while (x <= n) {
tmp = (int)sum[d][p][x] + r;
sum[d][p][x] = tmp%MOD;
bit[d][p][x] += tmp/MOD;
x += lowbit(x);
}
} int query(int l, int r) {
return getSum(r, d-, p) - getSum(l-, d-, p);
} void insert(int x, int i, int delta) {
int j;
for (j=; j<=; ++j) {
update(i, j-, x%, delta);
x /= ;
}
} int main() {
int i, j, ans;
int x, y;
char cmd[]; scanf("%d", &t);
while (t--) {
scanf("%d %d", &n, &m);
for(i=; i<; i++) {
for(j=; j<; j++) {
memset(sum[i][j], , sizeof(short)*(n+));
memset(bit[i][j], , sizeof(char)*(n+));
}
}
for (i=; i<=n; ++i) {
scanf("%d", &a[i]);
insert(a[i], i, );
}
while (m--) {
scanf("%*c%s %d %d", cmd, &x, &y);
if (cmd[] == 'S') {
insert(a[x], x, -);
a[x] = y;
insert(a[x], x, );
} else {
scanf("%d %d", &d, &p);
ans = query(x, y);
printf("%d\n", ans);
}
}
} return ;
}
【HDOJ】5057 Argestes and Sequence的更多相关文章
- 【HDOJ】5288 OO’s Sequence
二分寻找对于指定pos的最左因数点和最右因数点. /* 5288 */ #include <iostream> #include <string> #include <m ...
- 【HDOJ】5063 Operation the Sequence
#include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 100005 #defin ...
- 【分块】hdu5057 Argestes and Sequence
分块,v[i][j][k]表示第i块内第j位是k的元素数.非常好写.注意初始化 要注意题意,①第i位是从右往左算的. ②若x没有第i位,则用前导零补齐10位.比如103---->00000001 ...
- 【BZOJ1345】[Baltic2007]序列问题Sequence 贪心+单调栈
[BZOJ1345][Baltic2007]序列问题Sequence Description 对于一个给定的序列a1, …, an,我们对它进行一个操作reduce(i),该操作将数列中的元素ai和a ...
- hdu 5057 Argestes and Sequence(分块算法)
Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 5057 Argestes and Sequence
Argestes and Sequence Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 【SPOJ】1182 Sorted bit sequence
[算法]数位DP [题解]动态规划 写了预处理函数却忘了调用是一种怎样的体验? #include<cstdio> #include<cstring> #include<a ...
- 【HDOJ】2062 Subset sequence
这道题目非常好,饶了点儿圈子.我的思路是,先按照组排列.例如,1 2 31 2 2 1 3 11 2 3 2 1 3 ...
- 【HDOJ】3397 Sequence operation
线段树的应用,很不错的一道题目.结点属性包括:(1)n1:1的个数:(2)c1:连续1的最大个数:(3)c0:连续0的最大个数:(4)lc1/lc0:从区间左边开始,连续1/0的最大个数:(5)rc1 ...
随机推荐
- 开启.htaccess重写之前先来看看mod_rewrite(转)
Apache的Mode Rewrite模块提供了一个基于正则表达式分析器的重写引擎来实时重写URL请求.在大多数情况下,它和.htaccess文件配合使用.就是说,.htaccess文件的一个主要功能 ...
- 让你的WizFi250适应各种气候
这篇文章会具体描写叙述如何马上得到指定城市的天气状况(比方首尔).由OpenWeatherMap提供. 用JSON(由OpenWeatherMap提供),XML和一个以太网模块.使WIZnet-Wiz ...
- yii phpexcel <转>
原文详情参见 这里 1.下载phpexcel,将压缩包中的classes复制到protected/extensions下并修改为PHPExcel. 2.修改YII配置文件config/main.php ...
- linux 之 yum 介绍 <转>
原文在这里 http://doophp.sinaapp.com/archives/linux/yum-setting-parameter.html 因为是程序员出身,平时虽然经常接触服务器,偶尔也会 ...
- Linux入门之——安装虚拟机软件
/** ****************************************************************************** * @author 暴走的小 ...
- SSH常用命令选项
SSH 是什么 SSH(全称 Secure Shell)是一种加密的网络协议.使用该协议的数据将被加密,如果在传输中间数据泄漏,也可以确保没有人能读取出有用信息.要使用 SSH,目标机器应该安装 SS ...
- oracle 添加自增索引
1.添加一个Sequence,此处为ID_SEQUENCE. 2.添加对应表,并设置主键 3.设置触发器 create or replace trigger sys.id_add before ins ...
- ORACLE 数据库总结
1.表和数据恢复 1.从回收站里查询被删除的表 select object_name,original_name,partition_name,type,ts_name,createtime,drop ...
- retrofit2 使用教程 及 Android 网络架构搭建 (原创)
squareup 推出 retrofit2 已经有一段时间了,现在的版本比较稳定,没有什么大坑了.网络上的教程要么太简单,只是个Demo:要么有些落时,要么复用性比较差,所以自己写个教程,供大家参考. ...
- android - INSTALL_FAILED_MEDIA_UNAVAILABLE
解决方案是将'AndroidManifest.xml'设置 'installLocation'的属性为'auto'即可.