2062. Ambitious Experiment

Time limit: 3.0 second
Memory limit: 128 MB
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 ai.
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, 2i, 3iand 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 · 105).
The second line contains n integers ai separated by spaces — initial charges of the particles (0 ≤ ai ≤ 106).
The third line contains a single integer q — number of actions in the experiment (1 ≤ q ≤ 3 · 105).
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.

Samples

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
Problem Author: Alexey Danilyuk (prepared by Nikita Sivukhin)
Problem Source: Ural Regional School Programming Contest 2015
Difficulty: 478
 
 
题意:给n个数,两种操作:1、询问x的值,2、修改l~r的值,对于每个l<=i<=r的i,都对 i,2i,3i....这些点加d
分析:首先很容易想到分块做法
对于每个点x,它对于其他点(2x,3x,....)的贡献都是一样的
那么对于每个查询的点x,对它有贡献的点就是是他的因数的那些点
那么修改就分段sqrt(n)暴力修改
查询就sqrt(x)枚举约数,查询到每一个贡献点的值加起来
 
 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mk make_pair inline int getInt()
{
int ret = ;
char ch = ' ';
bool flag = ;
while(!(ch >= '' && ch <= ''))
{
if(ch == '-') flag ^= ;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
ret = ret * + ch - '';
ch = getchar();
}
return flag ? -ret : ret;
} const int N = , M = ;
int n, m;
LL block[N / M + ][M], tag[N / M + ], arr[N]; inline int getBlockIndex(int x)
{
return x / M;
} inline int getIndex(int x)
{
return x % M;
} inline void input()
{
cin >> n;
for(int i = ; i < n; i++) cin >> arr[i];
} inline LL work(int x)
{
int b = getBlockIndex(x), idx = getIndex(x);
return block[b][idx] + tag[b];
} inline LL query(int x)
{
x++;
LL ret = ;
for(int i = ; i * i <= x; i++)
if(x % i == )
{
ret += work(i - );
if(x / i != i) ret += work(x / i - );
}
return ret;
} inline void change(int l, int r, int d)
{
int left = getBlockIndex(l), right = getBlockIndex(r);
for(int i = left + ; i <= right - ; i++) tag[i] += d;
if(left < right)
{
for(int i = getIndex(l); i < M; i++) block[left][i] += d;
for(int i = ; i <= getIndex(r); i++) block[right][i] += d;
}
else
{
for(int i = getIndex(l); i <= getIndex(r); i++)
block[left][i] += d;
}
} inline void solve()
{
for(cin >> m; m--; )
{
int opt, l, r, x;
cin >> opt;
if(opt == )
{
cin >> x;
x--;
cout << query(x) + arr[x] << "\n";
}
else
{
cin >> l >> r >> x;
l--, r--;
change(l, r, x);
}
}
} int main()
{
ios::sync_with_stdio();
input();
solve();
return ;
}

ural 2062 Ambitious Experiment的更多相关文章

  1. URAL 2062 Ambitious Experiment(分块)

    [题目链接] http://acm.timus.ru/problem.aspx?space=1&num=2062 [题目大意] 给出两个操作,操作一给出区间[l,r],对l到r中的每一个下标i ...

  2. ural2062 Ambitious Experiment

    Ambitious Experiment Time limit: 3.0 secondMemory limit: 128 MB During several decades, scientists f ...

  3. Ural 2062:Ambitious Experiment(树状数组 || 分块)

    http://acm.timus.ru/problem.aspx?space=1&num=2062 题意:有n个数,有一个值,q个询问,有单点询问操作,也有对于区间[l,r]的每个数i,使得n ...

  4. ural Ambitious Experiment 树状数组

    During several decades, scientists from planet Nibiru are working to create an engine that would all ...

  5. 【树状数组】【枚举约数】 - Ambitious Experiment

    给定一个序列,支持以下操作: 对区间[l,r]的每个i,将1i,2i,3i,...这些位置的数都加d. 询问某个位置的数的值. 如果把修改看作对区间[l,r]的每个数+d,那么询问x位置上的数时,显然 ...

  6. URAL 2062 树状数组

    一个长度为n的数组 每次对lr区间进行修改 如果要修改i 则对i i*2 i*3...都修改 最后单点查询值 思想是利用树状数组维护每一个区间的更新值 查询的时候得出这个点的所有因子的查询值的和 加上 ...

  7. An interesting experiment on China’s censorship

    This paper presented a very interesting topic. Censorship in China has always drawn people's attenti ...

  8. Reading With Purpose: A grand experiment

    Reading With Purpose: A grand experiment This is the preface to a set of notes I'm writing for a sem ...

  9. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

随机推荐

  1. SQL Server多表多列更新

    student表: lag表: 要求将student表stu_id列为1的stu_nick列和stu_phont列的数据更新为lag表的lag_nick列和lag_phone列. SQL语句: upd ...

  2. XMPP框架下微信项目总结(5)花名册获取(好友列表)

    ---->概念 ---->添加花名册 ps:添加花名册,启动: 客户端发送请求到服务器获取好友列表信息,同时在项目中创建数据表,并保存好友列表到数据表中. ---->获取服务器保存好 ...

  3. #import、#include、#import<>和#import””的区别

    一.#import与#include #import不会引起交叉编译的问题.因为在Objective-C中会存在C/C++和Object-C混编的问题,如果用#include引入头文件,会导致交叉编译 ...

  4. 趣味C++

        用三段 140 字符以内的代码生成一张 1024×1024 的图片 Kyle McCormick 在 StackExchange 上发起了一个叫做TweetableMathematical A ...

  5. 【翻译六】java-连接和实例

    Joins The join method allows one thread to wait for the completion of another. If t is a Thread obje ...

  6. PHP导出Excel一个方法轻松搞定

    /** * 导出数据为excel表格 *@param $data 一个二维数组,结构如同从数据库查出来的数组 *@param $title excel的第一行标题,一个数组,如果为空则没有标题 *@p ...

  7. [Eclipse] Eclipse is running in a JRE, but a JDK is required

    安装Maven后每次启动出现警告信息: Eclipse is running in a JRE, but a JDK is required Some Maven plugins may not wo ...

  8. outlook备份及恢复

    outlook备份及恢复 Reference: http://wenku.baidu.com/link?url=2gtDkCSDoPdnfx3Ungd6on9wdhUTWgbO_vmmKLv1i4df ...

  9. vim实现全选功能

    转自:http://blog.csdn.net/csh159/article/details/7533872 曾经也在找看看有没有快捷的方法全选,但是网上很多都是重复,并且错误的,比如: 1,$y,这 ...

  10. ML 07、机器学习中的距离度量

    机器学习算法 原理.实现与实践 —— 距离的度量 声明:本篇文章内容大部分转载于July于CSDN的文章:从K近邻算法.距离度量谈到KD树.SIFT+BBF算法,对内容格式与公式进行了重新整理.同时, ...