YODANESS - Yodaness Level
Yoda is the wisest, and perhaps the most powerful Jedi of his time. Yoda is a mysterious figure and he has many oddities. One of them is that Yoda often changes the order of words in the sentence. For example, one of such phrases is "Or I will help you not." Let's call the yodaness level of any statement the number of pairs of words that changed their order, as to the order in which they were supposed to go in a normal statement. Write a program that determines the yodaness level of different statement of Yoda.
Input
The first line of input contains the number t - the number of tests. Next comes the description of t tests. Each test consists of three rows. The first line of the test contains an integer n - number of words in the statement. The next line contains n words separated by spaces - the statement as Yoda says it. The next line is n words separated by spaces - the same statement as it should be said normally. All the words in the statement are different and consist of small latin letters.
Constraints
1 <= t <= 10
1 <= n <= 30000
the length of each word does not exceed 20 characters
Output
For each test print the yodaness level of the statement.
Example
Input: 2 6 in the force strong you are you are strong in the force 6 or i will help you not or i will not help you Output: 11 2
hide comments
mj2266:
2019-09-14 05:05:56
2nd AC of my life on spoj :o |
|
fardin_abir:
2019-09-08 22:21:46
easily with inversion count using merge sort... |
|
harsh_pandey:
2019-08-26 15:52:16
Use inversion count using segment tree. for reference use https://www.geeksforgeeks.org/counting-inversions-in-an-array-using-segment-tree/ |
|
smiling_addu:
2019-07-11 08:51:55
Moonwalk!!! |
|
abhimanyu_1998:
2019-05-26 19:02:25
cakewalk
|
|
aman_sachin200:
2018-05-28 22:55:19
Cakewalk! :D |
|
kocko:
2018-04-04 19:57:41
classic :) |
|
chetan4060:
2018-01-08 04:50:58
easy one:) |
|
shiv2111:
2018-01-01 16:37:06
inv count
|
|
lord_poseidon:
2017-06-19 07:38:17
AC in one go |
Added by: | Spooky |
Date: | 2010-03-09 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: NODEJS OBJC PERL6 SQLITE VB.NET |
Resource: | Advancement Spring 2010, http://sevolymp.uuuq.com/ |