树状数组。Easy.

 /* 4267 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = ;
const int maxm = ;
int n; inline int lowest(int x) {
return -x & x;
} typedef struct arr_t {
int s[maxn]; void clr() {
memset(s, , sizeof(s));
} void update(int x, int delta) {
while (x <= n) {
s[x] += delta;
x += lowest(x);
}
} int sum(int x) {
int ret = ; while (x) {
ret += s[x];
x -= lowest(x);
}
return ret;
}
} arr_t; arr_t ts[maxm];
int A[maxn], M[][maxn];
int ID[][]; void init_() {
int cnt = ; rep(i, , ) {
rep(j, , i) {
ID[i][j] = cnt++;
}
} rep(i, , ) {
int k = i-;
rep(j, , maxn) {
M[k][j] = M[k][j-] + ;
if (M[k][j] == i)
M[k][j] = ;
}
}
} void init() {
rep(i, , maxm)
ts[i].clr();
} void update(int a, int b, int k, int delta) {
int from = a;
int to = a+(b-a)/k*k;
int findex = (from+k-)/k;
int tindex = (to+k-)/k;
int id = ID[k][a%k]; ts[id].update(findex, delta);
ts[id].update(tindex+, -delta);
} int sum(int x) {
int id, index, delta;
int ret = ; rep(i, , ) {
index = (x+i-)/i;
id = ID[i][M[i-][x]];
delta = ts[id].sum(index);
ret += delta;
}
return ret;
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int type;
int a, b, k, c;
int q;
int ans; init_();
while (scanf("%d", &n)!=EOF) {
rep(i, , n+)
scanf("%d", &A[i]);
init();
scanf("%d", &q);
while (q--) {
scanf("%d %d", &type, &a);
if (type == ) {
scanf("%d %d %d", &b, &k, &c);
update(a, b, k, c);
} else {
ans = sum(a) + A[a];
printf("%d\n", ans);
}
}
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【HDOJ】4267 A Simple Problem with Integers的更多相关文章

  1. 【POJ】3468 A Simple Problem with Integers ——线段树 成段更新 懒惰标记

    A Simple Problem with Integers Time Limit:5000MS   Memory Limit:131072K Case Time Limit:2000MS Descr ...

  2. 【POJ】3468 A Simple Problem with Integers

    这题用线段树轻松解了,重新用树状数组解,关键点是区间更新.公式推导如下:sum[x] = org_sum[x] + delta[1]*x + delta[2]*(x-1) + delta[x]*1   ...

  3. HDU 4267 A Simple Problem with Integers

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  4. HDU 4267 A Simple Problem with Integers(树状数组区间更新)

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  5. 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers

    http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...

  6. 【HDOJ】4972 A simple dynamic programming problem

    水题. #include <cstdio> #include <cstring> #include <cstdlib> int abs(int x) { ? -x: ...

  7. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  8. HDOJ 4267 A Simple Problem with Integers (线段树)

    题目: Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of opera ...

  9. 【HDOJ】3828 A + B problem

    显然需要贪心,重叠越长越好,这样最终的串长尽可能短.需要注意的是,不要考虑中间结果,显然是个状态dp.先做预处理去重,然后求任意一对串的公共长度. /* 3828 */ #include <io ...

随机推荐

  1. 关于windows10调试应用注册失败

    搜索了一些方法,都是win8系统的应用程序解决方案,修改应用程序的包名.也尝试修改了一些,但是失败,任然报错,以前在这个机器上面是能正常调试的,唯一的不同点是就是系统升级到10166了,于是去设置里面 ...

  2. C# ACM poj1003

    这题很有内涵,先用简单方法 public static void acm1003(double a) { ) { return; } ; ) { / b; a = a - c; b++; } Cons ...

  3. linux 下使用crontab 定时打包日志并删除已被打包的日志

    crontab是和用户相关的,每个用户有自己对应的crontab . cron是Linux下的定时执行工具,以下是重启/关闭等等的命令 #/sbin/service crond start //启动服 ...

  4. centos 6.4 安装php-fpm 及常用扩展,(转)

    今天又装了一次开发环境,以前忘记记录了 这次记录一下 ---------------------------------------- centos6 yum安装nginx.php-fpm 时间201 ...

  5. Linux C 程序 函数,数组,指针,gdb调试器(SEVEN)

    函数,数组,指针,gdb调试器 1.函数定义 如果明确指定返回类型,默认为int 参数传递:实参对形参的参数传递是单向的,实参只是把自己的值赋给形参.                      形参的 ...

  6. Web前端新人笔记之文本属性

    前一段时间因工作时间减缓了更新笔记的时间.我也不知道有没有会观看并且能不能帮到一些初学者,这只是我的一些小随笔而已.当然我也希望的的每一篇随笔都可以帮到更多的想要学习前端开发的初学者们,更希望你们也可 ...

  7. MSChart实例

    MSChart是VS中自带的图表控件,功能比较强大,效果也比较丰富.下面只提供一个例子,以供新接触的朋友参考. 先看下效果图: 看完效果图上代码啦. 使用这个控件需要先在页面注册一下. <%@ ...

  8. power designer

    概述 Power Designer 是Sybase公司的CASE工具集,使用它可以方便地对管理信息系统进行分析设计,他几乎包括了数据库模型设计的全过程.利用Power Designer可以制作数据流程 ...

  9. Cassandra1.2文档学习(8)—— 数据管理

    数据参考:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/dml/dml_manage ...

  10. jsoup 对网页中图片解析

    Elements article = new Elements(); Elements Img = new Elements(); article = doc.select("div#con ...