PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000027. Danh sách tin nhắn gần nhất (Messenger Simulator)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Danh sách tin nhắn gần nhất (Messenger Simulator)
Messenger Simulator
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are friends initially ordered in a recent-chat list, with the topmost friend at position . Whenever friend sends a message, that friend moves to the top and the friends previously above them shift down by one position. For every friend, determine the smallest and largest positions ever occupied, including the initial state.
Input
The first line contains . The next line contains sender IDs .
Output
Print lines. Line contains the minimum and maximum one-based positions ever held by friend .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
5 4
3 5 1 4
Output
1 3
2 5
1 4
1 5
1 5
Explanation
The list changes by moving each sender to the front. Friend 2 visits positions 2,3,4,4,5, so their minimum and maximum are 2 and 5.