ural 2062 Ambitious Experiment
2062. Ambitious Experiment
Memory limit: 128 MB
- Measure current charge of the particle number i.
- Direct radiation with power d at particles with numbers from l to r inclusive.
Input
- 1 i — measure current charge of the particle number i (1 ≤ i ≤ n).
- 2 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
Samples
input | output |
---|---|
3 |
12 |
6 |
3 |
Problem Source: Ural Regional School Programming Contest 2015
/**
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的更多相关文章
- URAL 2062 Ambitious Experiment(分块)
[题目链接] http://acm.timus.ru/problem.aspx?space=1&num=2062 [题目大意] 给出两个操作,操作一给出区间[l,r],对l到r中的每一个下标i ...
- ural2062 Ambitious Experiment
Ambitious Experiment Time limit: 3.0 secondMemory limit: 128 MB During several decades, scientists f ...
- Ural 2062:Ambitious Experiment(树状数组 || 分块)
http://acm.timus.ru/problem.aspx?space=1&num=2062 题意:有n个数,有一个值,q个询问,有单点询问操作,也有对于区间[l,r]的每个数i,使得n ...
- ural Ambitious Experiment 树状数组
During several decades, scientists from planet Nibiru are working to create an engine that would all ...
- 【树状数组】【枚举约数】 - Ambitious Experiment
给定一个序列,支持以下操作: 对区间[l,r]的每个i,将1i,2i,3i,...这些位置的数都加d. 询问某个位置的数的值. 如果把修改看作对区间[l,r]的每个数+d,那么询问x位置上的数时,显然 ...
- URAL 2062 树状数组
一个长度为n的数组 每次对lr区间进行修改 如果要修改i 则对i i*2 i*3...都修改 最后单点查询值 思想是利用树状数组维护每一个区间的更新值 查询的时候得出这个点的所有因子的查询值的和 加上 ...
- An interesting experiment on China’s censorship
This paper presented a very interesting topic. Censorship in China has always drawn people's attenti ...
- 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 ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
随机推荐
- SQL Server多表多列更新
student表: lag表: 要求将student表stu_id列为1的stu_nick列和stu_phont列的数据更新为lag表的lag_nick列和lag_phone列. SQL语句: upd ...
- XMPP框架下微信项目总结(5)花名册获取(好友列表)
---->概念 ---->添加花名册 ps:添加花名册,启动: 客户端发送请求到服务器获取好友列表信息,同时在项目中创建数据表,并保存好友列表到数据表中. ---->获取服务器保存好 ...
- #import、#include、#import<>和#import””的区别
一.#import与#include #import不会引起交叉编译的问题.因为在Objective-C中会存在C/C++和Object-C混编的问题,如果用#include引入头文件,会导致交叉编译 ...
- 趣味C++
用三段 140 字符以内的代码生成一张 1024×1024 的图片 Kyle McCormick 在 StackExchange 上发起了一个叫做TweetableMathematical A ...
- 【翻译六】java-连接和实例
Joins The join method allows one thread to wait for the completion of another. If t is a Thread obje ...
- PHP导出Excel一个方法轻松搞定
/** * 导出数据为excel表格 *@param $data 一个二维数组,结构如同从数据库查出来的数组 *@param $title excel的第一行标题,一个数组,如果为空则没有标题 *@p ...
- [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 ...
- outlook备份及恢复
outlook备份及恢复 Reference: http://wenku.baidu.com/link?url=2gtDkCSDoPdnfx3Ungd6on9wdhUTWgbO_vmmKLv1i4df ...
- vim实现全选功能
转自:http://blog.csdn.net/csh159/article/details/7533872 曾经也在找看看有没有快捷的方法全选,但是网上很多都是重复,并且错误的,比如: 1,$y,这 ...
- ML 07、机器学习中的距离度量
机器学习算法 原理.实现与实践 —— 距离的度量 声明:本篇文章内容大部分转载于July于CSDN的文章:从K近邻算法.距离度量谈到KD树.SIFT+BBF算法,对内容格式与公式进行了重新整理.同时, ...