#SRD0000021. Truy vấn ngưỡng trực tuyến (K-query Online)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Truy vấn ngưỡng trực tuyến (K-query Online)
K-query Online
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an immutable positive integer array . Queries are encoded using the preceding answer and must be processed online. Each query provides three integers . Let last be the previous query answer, initially zero. Decode
Then set and . If , answer . Otherwise count elements strictly greater than in . Replace last with this answer. xor means bitwise exclusive OR, not exponentiation.
Input
The first line gives , the next gives the array, and the next gives . Each of the following lines holds three encoded nonnegative integers .
Output
Print the count after each query, or 0 if the adjusted interval is empty.
Subtasks
- Subtask 1 (10 points): ; ; ; encoded values are nonnegative signed 32-bit integers; apply the specified endpoint adjustment after decoding.
- Subtask 2 (20 points): ; ; ; encoded values are nonnegative signed 32-bit integers; apply the specified endpoint adjustment after decoding.
- Subtask 3 (30 points): ; ; ; encoded values are nonnegative signed 32-bit integers; apply the specified endpoint adjustment after decoding.
- Subtask 4 (40 points): ; ; ; encoded values are nonnegative signed 32-bit integers; apply the specified endpoint adjustment after decoding.
Examples
Input
6
8 9 3 5 1 9
5
2 3 5
3 3 7
0 0 11
0 0 2
3 7 4
Output
1
1
0
0
2
Explanation
The first query has last = 0, so it examines with threshold and returns . The second query must first be XOR-decoded using that answer. Decoded endpoints outside the array are adjusted; an empty resulting interval returns .