CF295E.Yaroslav and Points
省选/NOI-
通过率:0%
时间限制:5.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yaroslav has n points that lie on the Ox axis. The coordinate of the first point is _x_1, the coordinate of the second point is _x_2, ..., the coordinate of the n-th point is — x__n. Now Yaroslav wants to execute m queries, each of them is of one of the two following types:
- Move the p__j-th point from position x__p__j to position x__p__j + d__j. At that, it is guaranteed that after executing such query all coordinates of the points will be distinct.
- Count the sum of distances between all pairs of points that lie on the segment [l__j, r__j] (l__j ≤ r__j). In other words, you should count the sum of:
.
Help Yaroslav.
雅罗斯拉夫有 n 个位于 Ox 轴上的点。第一个点的坐标为 x1,第二个点的坐标为 x2,……,第 n 个点的坐标为 xn。现在雅罗斯拉夫希望执行 m 个查询,每个查询属于以下两种类型之一:
- 将第 pj 个点从位置 xpj 移动到位置 xpj+dj。注意:执行该查询后,所有点的坐标保证互不相同。
- 计算所有位于区间 [lj,rj](其中 lj≤rj)内的点对之间的距离之和。换言之,需计算如下和式:
。
请帮助雅罗斯拉夫完成上述任务。
输入格式
The first line contains integer n — the number of points (1 ≤ n ≤ 105). The second line contains distinct integers _x_1, _x_2, ..., x__n — the coordinates of points (|x__i| ≤ 109).
The third line contains integer m — the number of queries (1 ≤ m ≤ 105). The next m lines contain the queries. The j-th line first contains integer t__j (1 ≤ t__j ≤ 2) — the query type. If t__j = 1, then it is followed by two integers p__j and d__j (1 ≤ p__j ≤ n, |d__j| ≤ 1000). If t__j = 2, then it is followed by two integers l__j and r__j ( - 109 ≤ l__j ≤ r__j ≤ 109).
It is guaranteed that at any moment all the points have distinct coordinates.
第一行包含一个整数 n —— 点的数量(1 ≤ n ≤ 105)。
第二行包含 n 个互不相同的整数 x1, x2, ..., xn —— 各点的坐标(∣xi∣ ≤ 109)。
第三行包含一个整数 m —— 查询的数量(1 ≤ m ≤ 105)。
接下来的 m 行为查询。第 j 行首先包含一个整数 tj(1 ≤ tj ≤ 2)—— 查询类型。
若 tj=1,则其后跟两个整数 pj 和 dj(1 ≤ pj ≤ n, ∣dj∣ ≤ 1000);
若 tj=2,则其后跟两个整数 lj 和 rj(−109 ≤ lj ≤ rj ≤ 109)。
保证在任意时刻所有点的坐标互不相同。
输出格式
For each type 2 query print the answer on a single line. Print the answers in the order, in which the queries follow in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
对于每个类型 2 的查询,在单独一行输出答案。请按照输入中查询出现的顺序输出答案。
请注意,在 C++ 中读写 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流或 %I64d 说明符。
输入输出样例
输入#1
8 36 50 28 -75 40 -60 -95 -48 20 2 -61 29 1 5 -53 1 1 429 1 5 130 2 -101 -71 2 -69 53 1 1 404 1 5 518 2 -101 53 2 50 872 1 1 -207 2 -99 -40 1 7 -389 1 6 -171 1 2 464 1 7 -707 1 1 -730 1 1 560 2 635 644 1 7 -677
输出#1
176 20 406 1046 1638 156 0
输入解题思路,AI测评打分。不知道怎么写?