| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 135 | 75 | 66 | 68.750% |
Farmer John's $N$ (1ドル \leq N \leq 5 \cdot 10^5$) cows are standing in a line, with cow 1ドル$ at the front of the line and cow $N$ at the back of the line. FJ's cows also come in many different species. He denotes each species with an integer from 1ドル$ to $N$. The $i$'th cow from the front of the line is of species $a_i$ (1ドル \leq a_i \leq N$).
FJ is taking his cows to a checkup at a local bovine hospital. However, the bovine veterinarian is very picky and wants to perform a checkup on the $i$'th cow in the line, only if it is species $b_i$ (1ドル \leq b_i \leq N$).
FJ is lazy and does not want to completely reorder his cows. He will perform the following operation exactly once.
FJ wants to measure how effective this approach is. Find the sum of the number of cows that are checked by the veterinarian over all $N(N+1)/2$ possible operations.
The first line contains an integer $N$.
The second line contains $a_1, a_2, \ldots, a_N$.
The third line contains $b_1, b_2, \ldots, b_N$.
Output one line with the sum of the number of cows that are checked by the veterinarian over all possible operations.
3 1 3 2 3 2 1
3
If FJ chooses ($l=1,r=1$), ($l=2,r=2$), or ($l=3,r=3$) then no cows will be checked. Note that those operations do not modify the location of the cows.
The following operations result in one cow being checked.
The total number of cows checked over all six operations is 0ドル+0+0+1+1+1=3$.
3 1 2 3 1 2 3
12
There are three possible operations that cause 3ドル$ cows to be checked: ($l=1,r=1$), ($l=2,r=2$), and ($l=3,r=3$). The remaining operations each result in 1ドル$ cow being checked. The total number of cows checked over all six operations is 3ドル+3+3+1+1+1=12$.
7 1 3 2 2 1 3 2 3 2 2 1 2 3 1
60