# | Problem | Pass Rate (passed user / total user) |
---|---|---|
11447 | Use std::map |
|
13482 | Very beautiful subsequence |
|
13490 | K-unique |
|
Description
This problem will help you understand how to use std::map.
http://en.cppreference.com/w/cpp/container/map
Notice, this time, first and last is [first, last].
目前有五個測資,第三筆測資不算,答題測資看另外四筆
Input
The input consist of series of command. Each commands is insert, range output or range erase.
insert: inserts a string (cmd) with the key (key) to map. If the key has already existed, insert the cmd at the begining of string (the string which the key belongs).
For example,
insert 0 "abc"
insert 1 "def"
the map should contain "abc", "def".
insert 0 "xyz"
the map should contain "xyzabc", "def".
range output: outputs the string from key (first) to key (last). Output a space character (' ') after printing an element.
range erase: erase the string from key (first) to key (last).
operator<<: outputs all strings in map. From the smallest key to biggest key. Output a space character (' ') after printing an element.
Output
Complete insert, output, erase and operator<<.
Sample Input Download
Sample Output Download
Partial Judge Code
11447.cppPartial Judge Header
11447.hTags
Discuss
Description
Given a sequence A = a1, a2, ..., aN.
A continuous subsequence A[L ... R] = aL, ..., aR of A is called very beautiful if every element in A[L...R] is unique.
For example, if A = 3, 1, 2, 3, 4.
Then
- A[1, 3] = 3, 1, 2 is very beautiful.
- A[1, 4] = 3, 1, 2, 3 is not very beautiful because A[1] = A[4].
- A[2, 5] = 1, 2, 3, 4 is very beautiful.
Please find the maximum length of very beautiful continuous subsequence of A.
Input
The first line of the input contains a number T — the number of test cases.
The first line of each test case contains a positive integer N — the length of A.
The second line of each test case contains N numbers — a1, a2, ..., aN.
For each test,
- T ≤ 10, N ≤ 103, |ai| ≤ 109
- T ≤ 10, N ≤ 103, |ai| ≤ 109
- T ≤ 10, N ≤ 103, |ai| ≤ 109
- T ≤ 10, N ≤ 105, |ai| ≤ 109
- T ≤ 10, N ≤ 105, |ai| ≤ 109
- T ≤ 10, N ≤ 105, |ai| ≤ 109
Output
For each test case, print the maximum length of very beautiful continuous subsequence.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
There is a template function unique()
in STL (Standard Template Library), which takes two iterators \(begin, end\) as parameters, removes all except the first element from every consecutive group of equal elements in the left-closed-right-open range hold by the two iterators \([begin, end)\) and return the iterator to the new end, i.e., the next of the last element not removed.
For instance, in the first of the sample input, since \(k=1\), it's equivlent to the ordinary unique()
. So for the string "qqq", you should return the itrerator next to the first 'q'.
And in this problem, your task is to extend this feature more generally, i.e., remove all excpet the first \(k\) elements from every consecutive group.
Note
You should do it in place, returning valid iterator between origin range. Try to use constant extra space only.
If you want to run the code locally, you have to name your implementation Main.cpp. For more detail, please read instructions in the header.
Input
Since this problem is judged partially, you needn't be concerned about the format of input.
In case your're interested, there are several test cases, each of which contain four lines: the first line is two integers \(n, k\) and the following lines are a sring, \(n\) intergers and \(n\) floating point numbers.
\[0<n<10^6\]
\[0<k\leq n\]
Output
Since this problem is judged partially, you needn't be concerned about the format of output.
In case your're interested, for each test case, the judge code would print out the result after calling k_unique()
for the sting, integers and floating point numbers.