Uvalive 5052, uvalive
There are two 1-N orders of a and B. The number of consecutive subsequences of a and B contains the same Integer Set. The subsequence contains at least two elements.
Question: You can first record the positions of each number in array B, then enumerate the start point and sub-sequence length of array a, and then use l and r to limit the range, the initial value is the position of the starting point of array a in array B. Because it is a continuous subsequence, l and r can be updated if a larger range exists. If r-l = len, increase the number of solutions by 1 ,.
# Include <stdio. h> # include <math. h> const int n= 3005; int N, a [n], B [N], pos [N]; int main () {while (scanf ("% d ", & n) {for (int I = 0; I <n; I ++) scanf ("% d", & a [I]); for (int I = 0; I <n; I ++) {scanf ("% d", & B [I]); pos [B [I] = I;} int res = 0, l, r; for (int I = 0; I <n; I ++) {l = pos [a [I]; r = pos [a [I]; for (int j = 1; j <n-I; j ++) {if (pos [a [I + j] <l) l = pos [a [I + j]; else if (pos [a [I + j]> r) r = pos [a [I + j]; if (r-l = j) res ++;} printf ("% d \ n", res);} return 0 ;}