During several decades, scientists from planet Nibiru are working to create an engine that would allow spacecrafts to fall into hyperspace and move there with superluminal velocity. To check whether their understanding of properties of hyperspace is right, scientists have developed the following experiment.
A chain of n particles is placed in hyperspace. Positions of particles in the chain are numbered from 1 to n. Initially, ith particle has charge a i.
According to the current theory, if particle number i got special radiation with power d, oscillations would spread by hyperspace and increase by d charge of particles with numbers i, 2 i, 3 i and so on (i.e. with numbers divisible by i).
Using a special device, scientists can direct the radiation of the same power at a segment of adjacent particles. For example, suppose that initially there were 6 particles with zero charges, and scientists have sent radiation with power five to particles with numbers 2 and 3. Then charge of 2nd, 3rd, and 4th particles will increase to five, and charge of 6th particle will increase to ten (the oscillations will reach it twice). Charge of other particles won’t change.
Charge of particles can’t change without impact of the device.
During the experiment, the scientists plan to perform actions of the following types:
  1. Measure current charge of the particle number i.
  2. Direct radiation with power d at particles with numbers from l to r inclusive.
Your program will be given a list of performed actions. For every action of the first type the program should output value of expected charge of the particle calculated in accordance with the current theory described above.
If the expected charges of the particles coincide with charges measured during the experiment, it will turn out that scientists’ understanding of hyperspace is right, and they will be able to start building of the hyperdrives. Then inhabitants of Nibiru will finally meet their brothers from Earth in just a few years!

Input

The first line contains a single integer n — number of particles (1 ≤ n ≤ 3 · 10 5).
The second line contains n integers a i separated by spaces — initial charges of the particles (0 ≤ a i ≤ 10 6).
The third line contains a single integer q — number of actions in the experiment (1 ≤ q ≤ 3 · 10 5).
Each of the following q lines contain two or four integers — a description of the next action in one of the following formats:
  • i — measure current charge of the particle number i (1 ≤ i ≤ n).
  • l r d — direct radiation with power d at particles with numbers from l to r inclusive (1 ≤ l ≤ r ≤ n, 0 ≤ d ≤ 106).

Output

For each query output the expected charge of the ith particle.

Example

input output
3
1 2 3
2
2 1 3 5
1 2
12
6
1 2 1 4 5 6
5
2 2 4 2
1 3
1 4
2 3 5 1
1 5
3
8
6
这题花了三个小时没做出来,可能是最近有点脑残。。刚开始用树状数组做了tle,又改成线段树,发现线段树还是tle,最后又改成树状数组。。有一点技巧
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const int N=+,maxn=+,inf=1e9+; ll a[N],m[N];
void add(int i,int v)
{
while(i<=N){
m[i]+=v;
i+=i&(-i);
}
}
ll sum(int i)
{
ll ans=;
while(i>){
ans+=m[i];
i-=i&(-i);
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n;
cin>>n;
memset(m,,sizeof m);
for(int i=;i<=n;i++)cin>>a[i];
int k;
cin>>k;
while(k--){
int p,l,r,d;
cin>>p;
if(p==)
{
cin>>d;
ll ans=;
for(int i=;i*i<=d;i++)
{
if(d%i==)
{
ans+=sum(i);
if(i*i!=d)ans+=sum(d/i);
}
}
cout<<ans+a[d]<<endl;
}
else
{
cin>>l>>r>>d;
add(l,d);
add(r+,-d);
}
}
return ;
}

最新文章

  1. js内存泄露的几种情况详细探讨
  2. (翻译)开始iOS 7中自动布局教程(二)
  3. 如何用Ajax加载服务器的图片
  4. Boundaries
  5. V4L2读取摄像头程序流程【转】
  6. shell 编程基础
  7. wp上一款应用的出生与死亡
  8. Android Bundle传递简单数据、对象数据
  9. Linux 命令 - kill: 向进程发送信号
  10. C#实现IDispose模式
  11. 在Qt中使用sleep(包含为win and *nix下sleep函数的实现及用法)
  12. WebStorm快捷键收集
  13. MD5的加密和解密(总结)
  14. SVN 在 Xcode中的状态说明
  15. 迭代器&amp;生成器
  16. golang数据类型与转换
  17. 【java】多态
  18. Android手机插上usb能充电但不能识别的一种解决方法
  19. all about
  20. geth工作运行程序转后台

热门文章

  1. Linux基础命令---ar
  2. PowerDesigner 教程
  3. servlet+jsp+java实现Web应用
  4. 04: 使用BeautifulSoup封装的xss过滤模块
  5. oracle一些工作笔记
  6. 20145321《网络对抗》Exp2 后门原理与实践
  7. 20145324王嘉澜《网络对抗技术》Web基础
  8. 20145208蔡野 《网络对抗》逆向及BOF基础实践
  9. 判断某个ImageView的背景图是否是已知的背景图相等
  10. win10中mount和unmount iso文件