Favorite Sub HairProblem code: FAVSUBS |
All submissions for this problem are available.
|
|
Little Princess Rapunzel is blessed with long (really looong!) hair, which is golden colored and has healing power. After the end of a long happy story, she marries her lover Flynn. They decide to lead a normal life by getting rid of the mysterious hair, which when cut loses its power and turns brown. There are many colorful beads on her hair in order. Rapunzel has some K favorite colors B[1...K] |
For the purpose of this problem, we represent a color as an integer and Hair as an array A[1...N], which has exactly N colored beads in the given order. Could you please tell her the total number of ways she can cut her favorite sub hair (sub-array). Two sub-arrays are different, if their starting or ending index in A differ.
Input
First line contains T [ number of test cases, around 10 ]. Each test case is preceded by a blank line, including the 1st case. [ -2,000,000 <= A[i], B[j] ( colors ) <= 2,000,000 ]
Each test case has 4 lines, as described below.
N [ 1 <= N <= 100,000 ]
< Array A : N integers, separated by spaces >
K [ 1 <= K <= 1,000 ]
< Array B : K integers, separated by spaces, her favorite colors, without repetition >
Output
For each test case, output the number of different sub-arrays, which has her favorite color appearing at least once, in a separate line.
Example
Input: 3 4 1 2 3 1 2 1 2 6 10 20 30 40 50 60 1 20 5 1 2 3 4 5 2 2 6 Output: 4 10 0 Explanation: Case 1 : Favorite sub-arrays in bold [ 1 2 3 1 ], [ 1 2 3 1 ] , [ 1 2 3 1 ], [ 1 2 3 1 ]
Note: Large input, prefer using scanf/printf to cin/cout
There are multiple test sets, and the judge shows the sum of the time taken over all test sets of your submission, if Accepted.
| Author: | rosyish |
| Date Added: | 10-02-2011 |
| Time Limit: | 2 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.


Fetching successful submissions
