#SRD0000057. Động lực học chất lỏng (Fluid Dynamics)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Động lực học chất lỏng (Fluid Dynamics)
Fluid Dynamics
Source: DMOJ
Version: Phuoc Hung OJ Extended
Problem Statement
A jar contains an ordered stack of fluid layers, from bottom to top. Each layer has integer volume and color ; fluids never merge, even if their colors match. Initially empty, the jar receives initial layers one at a time at the top.
When a newly inserted layer sits immediately above , they swap if the change in potential satisfies
If a swap happens, the new layer continues testing against the next layer below until a swap is forbidden or it reaches the bottom. This applies to both initial and later insertions.
Process:
INSERT v c: add a layer on top and perform these swaps.K-TH k: print the volume and color of the -th layer from the bottom (one-indexed).
Every K-TH index is valid.
Input
The first line contains . The next lines contain the initial pairs v_i c_i in pouring order. Each of the following lines is INSERT v c or K-TH k. All volume/color values are in , and .
Output
For every K-TH operation, print the corresponding layer's volume and color.
Subtasks
- Subtask 1 (10 points): ; . Use an integer type wide enough for exact comparisons, with .
- Subtask 2 (90 points): ; . Use an integer type wide enough for exact comparisons, with .
Examples
Input
5 5 7
15 2
20 12
7 16
7 12
20 3
K-TH 2
INSERT 1 10
INSERT 8 1
INSERT 9 1
K-TH 6
Output
20 3
7 12
Explanation
With , placing above gives potential change , so they swap. Layer descends past several layers but stops above . Thus K-TH 2 returns 20 3. After the subsequent insertions, the sixth layer from the bottom is , so the final result is 7 12.