树状数组。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. System.Web.Mvc.Html 命名空间小计(转)

    最近在看MVC框架,发现这个博文对初学者可能有帮助,故转之. 1,Html.Action    使用指定参数调用指定子操作方法并以 HTML 字符串形式返回结果. Html.Action() < ...

  2. mac配置svn服务器

    1创建svn库:mudydeMacBook-Air:~ mudy$   svnadmin create /Users/mudy/svn   2进行配置,配置我们的svn a.将svnsever.con ...

  3. Xcode中 xx duplicate symbols for architecture i386错误提示

    今天在编译iOS项目时Xcode报如下错误: ld: 15 duplicate symbols for architecture i386 clang: error:linker command fa ...

  4. (poj)1806 Currency Exchange

    题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...

  5. Java中的面向对象

    Java中的面向对象 在软件开发的学习中, 我最先接触的开发语言就是java,但都是简单的函数和循环数组的应用.说道面向对象,第一次看到这个词的时候还是在C#的学习过程中,我记得当时PPT上霸气的解释 ...

  6. C++中const修饰基本数据类型、指针、引用、对象

    const修饰基本数据类型 #include <iostream> using namespace std; void main(){ const int a = 1; const cha ...

  7. Java知识总结--三大框架

    1 应用服务器有哪些:weblogic,jboss,tomcat 2 Hibernate优于JDBC的地方 1)对jdbc访问数据库进行了封装,简化了数据访问层的重复代码 2)Hibernate 操作 ...

  8. Visual Studio 2010下载 + 附破解方法

    Visual Studio 2010下载 + 附破解方法 1.Microsoft Visual Studio 2010下载 旗舰版(Ultimate) http://download.microsof ...

  9. x86与x64与x86_64

    x86是指intel的开发的一种32位指令集,从386开始时代开始的,一直沿用至今,是一种cisc指令集,所有intel早期的cpu,amd早期的cpu都支持这种指令集,ntel官方文档里面称为“IA ...

  10. CentOS下shell显示-bash-4.1#不显示用户名路径的解决方法

    CentOS下shell显示-bash-4.1$不显示用户名路径的解决方法 问题描述: CentOS下新增一个用户,登录进去之后shell脚本的信息如下: 而不是我们经常看到的username@hos ...