Uvalive 5052, uvalive

Source: Internet
Author: User

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 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.