题目链接————
Dima’s got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≤ a1 ≤ a2 ≤ … ≤ an).

Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width wi and height hi. Dima throws each box vertically down on the first wi stairs of the staircase, that is, the box covers stairs with numbers 1, 2, …, wi. Each thrown box flies vertically down until at least one of the two following events happen:

the bottom of the box touches the top of a stair;
the bottom of the box touches the top of a box, thrown earlier.
We only consider touching of the horizontal sides of stairs and boxes, at that touching with the corners isn’t taken into consideration. Specifically, that implies that a box with width wi cannot touch the stair number wi + 1.

You are given the description of the staircase and the sequence in which Dima threw the boxes at it. For each box, determine how high the bottom of the box after landing will be. Consider a box to fall after the previous one lands.

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of n integers, a1, a2, …, an (1 ≤ ai ≤ 109; ai ≤ ai + 1).

The next line contains integer m (1 ≤ m ≤ 105) — the number of boxes. Each of the following m lines contains a pair of integers wi, hi (1 ≤ wi ≤ n; 1 ≤ hi ≤ 109) — the size of the i-th thrown box.

The numbers in the lines are separated by spaces.

Output
Print m integers — for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given 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 or the %I64d specifier.

Examples
Input

5
1 2 3 6 6
4
1 1
3 1
1 1
4 3
Output
1
3
4
6
Input
3
1 2 3
2
1 1
3 1
Output
1
3
Input
1
1
5
1 2
1 10
1 10
1 10
1 10
Output
1
3
13
23
33
Note
The first sample are shown on the picture.

原理类似俄罗斯方块,每次维护矩形能落在最低的高度,在线输出即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1000000];
ll n,m,w1,h1,hh,r,l;
int main()
{ios::sync_with_stdio(false);cin>>n;for (int i=1; i<=n; i++)cin>>a[i];cin>>m;for (int i=0; i<m; i++){cin>>l>>r;hh=max(hh+h1,a[l]);cout<<hh<<endl;w1=l;h1=r;}return 0;
}

Codeforces - 272C Dima and Staircase(思维)相关推荐

  1. Codeforces 272C Dima and Staircase 思维 or 线段树

    点击打开链接 题意:给出n个物品高度ai,ai<=1e9,ai非递减,n,m<=1e5,m个方块的宽度和高度,问m个方块依次落下时达到的高度 每次都从左端点1开始叠放,第i个方块肯定落在第 ...

  2. CODEFORCES 272C Dima and Staircase 细节理解题+简单技巧

    传送门:http://codeforces.com/problemset/problem/272/C C. Dima and Staircase time limit per test 2 secon ...

  3. CodeForces - 272C Dima and Staircase (线段树区间更新)

    题意: 见以下样例,给出 5 个区间,每个区间的高度已知.一共 4 次操作.每次操作都是从最左边开始向下垒一个宽为 w 高为h 的木块,过程见下图. 问每次垒木块的高度是多少? Input 5 1 2 ...

  4. Codeforces 1077B Disturbed People(思维题)

    Codeforces 1077B Disturbed People(思维题) There is a house with nn flats situated on the main street of ...

  5. C. Dima and Staircase(思维)

    题目链接---- 类似于俄罗斯方块,但是每次方块的左端点总在最左,让你输出每个方块落下时的高度. 思路:这个题目很重要的两点,一个是每次方块都靠最左,二是给的楼梯都是递增的. 所以综上两点,只需要维护 ...

  6. CodeForces - 160D Edges in MST(思维+tarjan/树链剖分+线段树)

    题目链接:点击查看 题目大意:给出一张 n 个点 m 条边组成的带权无向图,现在对于每条边来说,确定一下其分类: 一定是最小生成树上的边 可能是最小生成树上的边 一定不是最小生成树的边 题目分析:两种 ...

  7. Codeforces 846 A Curriculum Vitae 思维 暴力

    题目链接: http://codeforces.com/contest/846/problem/A 题目描述: 给你一个串, 你可以做删除操作, 要求结果串0不能在1的右边, 问最多可以剩几个数字 解 ...

  8. codeforces 400D Dima and Bacteria 并查集+floyd

    题目链接:http://codeforces.com/problemset/problem/400/D 题目大意: 给定n个集合,m步操作,k个种类的细菌, 第二行给出k个数表示连续的xi个数属于i集 ...

  9. Codeforces 861 B Which floor? 思维

    题目链接: http://codeforces.com/contest/861/problem/B 题目描述: 每个楼梯上有相同数量的数, 都是从1开始, 给你m个不矛盾的信息, 问你能不能判断n在第 ...

最新文章

  1. html页面获取get传递过来的值,在HTML中用js获取通过GET、POST方法(就是在网址后加?a=bc=d之类)传过来的表单值...
  2. activeMQ 安装部署文档
  3. Android View 事件分发机制详解
  4. 数论基础之快速幂(详细教程)
  5. 【机器学习】逻辑回归代码练习
  6. 以嵌入式系统设计师考试成绩,开始嵌入式博客之旅
  7. 背景图处理,这是个好东西记录一下
  8. CSS 属性选择器备忘
  9. 15行代码抓取兰亭序全文单字高清字帖
  10. 【学习笔记】莫队算法
  11. C++实现的大整数分解Pollard's rho算法程序
  12. 安卓网络连接全解:包括网络连接状态的监听、网络数据使用状态的监听、获取当前网络连接情况、启动wifi、获取当前连接wifi的网络情况、扫描wifi热点
  13. 新浪搜索Tabpage
  14. 代数——近世代数知识点思维导图(附Visio原文件)
  15. 企业微信接口上传临时素材
  16. 存储区域网络(Storage Area Network,简称SAN)
  17. 影响计算机性能的决定因素,影响cpu性能的因素有哪些
  18. 使用redis存储全球IP库
  19. iphonex 底部遮挡返回键 解决方法
  20. lisp语言cond和if套用_lisp语言入门

热门文章

  1. CentOS8迁移TencentOS 3.1实践
  2. 链路追踪译文学习记录(Dapper!!!非原创!!!学习记录)
  3. 2021-08-04 jQuery基础整理 17-30 代码复制即可运行
  4. OC继承详解与使用规则
  5. 名词用作动词举例_中学文言文词类活用详解:名词活用作动词(一)
  6. 一种重复命名自动更名机制
  7. 第三方账号登录功能接入完全流程
  8. NANDFLASH与PSRAM
  9. 机器学习中用到的概率知识_学习机器学习前,你首先要掌握这些概率论基础知识...
  10. 折腾家里的龟速网络有感