,

The queue Input file: Output file: Time limit: Memory limit:

A.in A.out 1 second 64 megabytes

There is an interesting queue. Cashier of this queue is not a good one. In fact, he only sells the tickets only when the customer starts to abuse him. Eventually, some rude people gets annoyed of it and goes straight to the front of the queue, to the cashier, to complain. And of course, the cashier has to sell the tickets to that rude person after that. Of course, all the people who were ahead of that rude person starts expressing his/her dissatisfaction by saying some amount of bad words (fixed for each person). Bekzhan was interested of how many bad words each of the rude person receive after he buys the tickets out of turn thinking he is above the law.

Input The fist line contains a single integer N (2 ≤ N ≤ 5 · 105 ) — the number of events occured. Description of each events starts with a single integer type (1 ≤ type ≤ 2). If type = 1, then it is followed by an integer w (1 ≤ w ≤ 109 ). It means that the new person came to the back of the queue, and his ID is the least positive number which wasn’t used as an ID before. The fixed number of bad words he’d say is the number w. If type = 2, then it is followed by an integer x. It means the person with ID x decides to be the rude one and buys the tickets out of turn. It’s guaranteed that the person with ID x exists in the queue at that exact moment. It’s guaranteed that there will be at least one rude person.

Output For each event of type = 2, output the number of bad words he’d hear after he buys the tickets out of turn.

Scoring 1. N ≤ 20, w ≤ 1000 — 10 points. 2. N ≤ 10000 — 40 points. 3. N ≤ 500000 — 50 points.

Page 1 of 2

,

Examples A.in 2 1 2 8 1 1 1 2 1 1 2 1

A.out 0

1 1 8 1 9 2 2 4 5 3

8 19

Note In the first example, the person was the only one in the queue, and respectively he didn’t hear any bad word. In the second example, at first, people, who would say 8, 1 and 9 bad words (with ID-s 1, 2 and 3), respectively, arrive. Then, the person with ID 2 decides to buy the tickets out of turn, and will be complained by the person with ID 1 with 8 bad words. Then, new people arrive, who would say 2 and 4 bad words (with ID-s 4 and 5), respectively. After, the person with ID 5 decides to buy the tickets out of turn, and will be complained by the people with ID-s 1, 3, 4, with 19 bad words overall. And finally, the last person arrives with ID 6 (w is 3).

Page 2 of 2

The queue - GitHub

Input file: A.in. Output file: A.out. Time limit: 1 second. Memory limit: 64 megabytes. There is an interesting queue. Cashier of this queue is not a good one. In fact ...

23KB Sizes 5 Downloads 221 Views

Recommend Documents

Patient Queue - GitHub
If you are using a Notebook computer with Firefox follow these instructions: .... Claim: this option is selected by a clinician in order to start an exam on a patient. 9 ...

Queue & Autoplay UX Developers
next/prev if queue (if available). ○ play/pause or play/stop. ○ timeline scrubber (if possible). ○ volume icon (iOS only). ○ a link to the content entity page or info.

Delay Optimal Queue-based CSMA
space X. Let BX denote the Borel σ-algebra on X. Let X(τ) denote the state of ..... where λ is the spectral gap of the kernel of the Markov process. Hence, from (3) ...

Remote Active Queue Management
work to their Internet provider. The link setup often ... end user's network to the Internet is usually not config- ... deployed in consumer-grade DSL or cable routers.

The Stability of Longest-Queue-First Scheduling With ...
is throughput-optimal if it can stabilize the system for all sets of arrival rates that are stabilizable ... requires IEEE permission. See http://www.ieee.org/publications_standards/publications/rights/index.html for more information. ... cumulative

Data structures part 3 stack, queue, sorting.pdf
STACK – INSERTION- PUSH STACK – DELETION - POP. STEP 1: CHECK STACK “OVERFLOW”. STEP 2: IF TOP < MAX-1 THEN. INCREMENT TOP BY 1.

advanced queue management techniques pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. advanced ...

Heavy Traffic Queue Management Using Policy Based ...
Abstract—Traffic management includes queuing, buffer ... the real time implementation of policy based queue management ..... Publications to his credit.

Queue-based Sub-carrier Grouping For Feedback ...
Hybrid schemes have been considered that combine sub-carrier grouping and channel thresholing. Here, the CSI is reported for the group if its quality exceeds a pre- specified threshold [6]–[8]. Jorsweick et al. [10] consider an uplink MIMO-OFDM sys

The fuzz Manual - GitHub
6. The fuzz manual. This manual describes versions of the fuzz package numbered ..... \plus n. ^{n}. For example, R \star is printed as R∗, and R^{n} is printed as Rn . ...... vs. \hide, 18. SliTEX, 12 space commands, ignored by type checker, 24.

The Book - GitHub
for styling a complex XML document into a PDF with SILE. ... TeX and InDesign, but seeks to be more flexible, extensible and programmable than .... In Chapter 10, we'll look at how the docbook class works, and how you can define processing.

Simulating the Ionosphere - GitHub
Sep 30, 2009 - DEFINITION: Approximating measurements at intermediate scales/positions from scattered measurements. We have sparse measurements.

Measuring The Beam - GitHub
Nominal beam model E accounts for the bulk of the DDE. ... Example: 3C147 field, dE-phase solutions as a ... solutions, but little reduction in imaging artefacts.

The Coco Framework - GitHub
Aug 10, 2017 - failure. In a consortium of banks, members could be large, global, systemically important financial institutions (GSIFIs). ... End users, such as a bank's customers, do not have an identity in the Coco network and cannot transact .....

The Enchiridion - Higginson - GitHub
This pdf was compiled on 8 Oct 2015 .... with nature in this respect, you will be elated with some reason; for you will be elated at some good of your own. ..... you, but also the value of proper courtesy toward your host. Thirty-Seven. If you have .

The Pythonic Way - GitHub
GvR makes a point: code is read more often than it is written, so readability counts. • Python is one of the few languages with a style guide. (PEP-8) since there is ...

The fuzz Manual - GitHub
cations and check them for compliance with the Z scope and type rules. ... For information about Z, and a description of the scope and type rules used by the fuzz ...

Setting the Scene - GitHub
... equations. ○ 4GC: Statistical analysis of the residuals ... Proven software now exists (OMS, WSRT) ... Application (aw-projection vs facet imaging). ○ Topic ...

The AndBug Debugger - GitHub
Many small tools wrapped by "Android" and Eclipse. Includes a ... or emulator. Key dependency of ANY Android debugger. ... AndBug is 90% Python, 10% C.

The Adventure - GitHub
The fourth rulebook in the series is the MASTER ...... the study. In such a case, any attempt at an ability that requires prior learning will result in an ...... Theology. CHA 2+, VIT 5+, MAG 3+. Qualification Test: To qualify for a trade, the charac

The User Manual - GitHub
Defined Wireless Networking Experiments 2017 ..... 1.7.3 Encryption. Mininet-WiFi supports all the common wireless security protocols, such as WEP (Wired Equivalent. Privacy), WPA (Wi-Fi Protected Access) and WPA2. ..... mac80211_hwsim practical exam

The future - GitHub
Domain-specific abstraction. Direct mapping to ... remember to free memcpy(strings[s], buf, i); ..... People want stability and 100% compatibility. – With significant ...