포럼
문제 ICPC00225

F. Flowing Fountain

설명

Last week, Bill filled a champagne fountain for the first time. Delighted by the champagne pouring from one glass into another, he decided that he wants to organize an even bigger champagne fountain for the next World Finals. He already ordered \(n\) glass bowls with different capacities to stack on top of each other to form a huge glass fountain. However, he is still unsure how to pour the champagne into the fountain. One bottle will not be enough and just pouring from the top might not fill every bowl. Bill wants to try out different ways to fill the fountain, but wasting any champagne would be such a shame.

This is your time to shine! You are tasked with writing a program that simulates the process of pouring champagne into a given fountain. With this program, Bill can now pretend to pour certain amounts of champagne into different levels. If a bowl in some level is already filled up, then the champagne spills over to the first level below it with larger capacity. If the next larger level is also filled, the champagne spills over even further until eventually seeping into the ground, wasting the good champagne. Additionally, Bill also wants to know at some times during the simulation process how much champagne currently is in a certain level.
- pour \(x\) litres of champagne into level \(\ell\).
- print the amount of champagne in level \(\ell\).

제약
입력 형식

The input consists of:
- One line with two integers \(n\) and \(q\) (\(1\leq n, q \leq 3 \cdot 10^5\)), the number of levels and the number of queries.
- One line with \(n\) distinct integers \(c\) (\(1\leq c \leq 10^9\)), the capacity of each level in litres. The levels are given in order from top to bottom.
- \(q\) lines, each describing a query. The first symbol \(t\) (\(t \in \{\text{`\texttt{+}'}, \text{`\texttt{?}'}\}\)) describes the type of the query. The format of the rest of the line depends on \(t\):

[leftmargin=1.95cm]
- Two integers \(\ell\) and \(x\) follow (\(1 \leq \ell \leq n\), \(1 \leq x \leq 10^9\)), the level into which Bill wants to pour \(x\) litres of champagne.
- One integer \(\ell\) follows (\(1 \leq \ell \leq n\)), the level for which Bill requests the current amount of champagne in litres.

It is guaranteed that there is at least one query of type '?'.

출력 형식

For each query of type '?', output the amount of champagne in the requested level in litres.

예제 1
입력
4 4
1 2 3 4
+ 1 6
? 4
+ 1 6
? 4
출력
0
4
예제 2
입력
4 8
2 4 3 5
+ 1 4
? 2
+ 2 3
? 4
+ 3 4
? 4
+ 2 10
? 4
출력
2
1
2
5
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NWERC 2024

평가 및 의견

F. Flowing Fountain

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

F. Flowing Fountain

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8