Description
有n个小朋友,每个小朋友手里有一些糖块,现在这些小朋友排成一排,编号是由1到n。现在给出m个数,能不能唯一的确定一对值l和r(l <= r),使得这m个数刚好是第l个小朋友到第r个小朋友手里的糖块数?
Input
首先输入一个整数n,代表有n个小朋友。下一行输入n个数,分别代表每个小朋友手里糖的数量。
之后再输入一个整数m,代表下面有m个数。下一行输入这m个数。
Output
如果能唯一的确定一对l,r的值,那么输出这两个值,否则输出-1
Sample
Input
5 1 2 3 4 5 3 2 3 4
Output
2 4
#define maxSize 1000005
#include <iostream>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int a1[maxSize], a2[maxSize];
void getnext(int a[], int n, int next[])
{
int i = 1, j = 0;
next[1] = 0;
while(i < n)
{
if(j == 0 || a[i] == a[j])
{
i++;
j++;
next[i] = j;
}
else
{
j = next[j];