PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000027. Nghịch thế đoạn trực tuyến (Inversions query 3)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Nghịch thế đoạn trực tuyến (Inversions query 3)
Inversions query 3
Source: MarisaOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a permutation of and online queries. Each query contains . Let lastans be the preceding answer, initially . Compute
Swap when . Output the number of pairs with , then update lastans. Query reordering is not valid because the decoded range depends on previous results.
Input
The first line contains , the next line contains the permutation, and the following lines each contain .
Output
Print one inversion count per query, in the original order.
Subtasks
- Subtask 1 (10 points): ; ; The array is a permutation of ; . Inversion counts and additions involving
lastansrequire 64-bit integers. - Subtask 2 (20 points): ; ; The array is a permutation of ; . Inversion counts and additions involving
lastansrequire 64-bit integers. - Subtask 3 (30 points): ; ; The array is a permutation of ; . Inversion counts and additions involving
lastansrequire 64-bit integers. - Subtask 4 (40 points): ; ; The array is a permutation of ; . Inversion counts and additions involving
lastansrequire 64-bit integers.
Examples
Input
8 5
6 5 2 3 8 1 4 7
6 4
5 4
5 4
3 8
8 5
Output
2
0
1
2
5
Explanation
The first query uses lastans=0 and decodes to , which has two inversions. That answer is used to decode the second range, whose answer is zero. The remaining outputs are .