I Don't Want to Be Late
InterviewTime limit1sMemory limit1024 MB
Given route populations under point updates, report the first and second route numbers of a fastest Aeji Hall to ITBT path, breaking ties by smallest index.
- Level
Medium4 of 10
- Topics
- Segment tree, Array
- Solved
- No attempts yet
Problem
Kim Hanyang became a third-year student, but he is still late all the time. He even had to retake a course twice in order to get a P in the Inyebon lecture. Tired of being late, Kim Hanyang wants to write a program that finds the fastest route from Aeji Hall to the ITBT building and keeps updating it.
To get from Aeji Hall to the ITBT building, you must pass through the Grand Playground. There are routes from Aeji Hall to the Grand Playground, numbered 1 to . There are routes from the Grand Playground to the ITBT building, numbered to . The population on each route changes over time, and the time it takes to cross a route is proportional to its population. Given the population changes, write a program that performs the following two operations.
U: Changes the population of route to . (, )L: Suppose the fastest path from Aeji Hall to the ITBT building goes through route to the Grand Playground and then through route to the ITBT building. Print and separated by a space. If several fastest paths exist, print the one with the smallest . If several fastest paths with the smallest exist, print the one with the smallest .
Input
The first line contains () and (), separated by a space. is the number of routes from Aeji Hall to the Grand Playground, and is the number of routes from the Grand Playground to the ITBT building.
The second line contains the initial populations of the routes from Aeji Hall to the Grand Playground, separated by spaces.
The third line contains the initial populations of the routes from the Grand Playground to the ITBT building, separated by spaces.
The fourth line contains the number of operations (). The following lines each contain one operation.
Output
For each L operation, print the result on its own line.