bestcoder——数组划分

Abelian Period

 
 Accepts: 400
 
 Submissions: 961
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 262144/131072 K (Java/Others)
Problem Description

Let SS be a number string, and occ(S,x)occ(S,x) means the times that number xx occurs in SS.

i.e. S=(1,2,2,1,3),occ(S,1)=2,occ(S,2)=2,occ(S,3)=1S=(1,2,2,1,3),occ(S,1)=2,occ(S,2)=2,occ(S,3)=1.

String u,wu,w are matched if for each number iiocc(u,i)=occ(w,i)occ(u,i)=occ(w,i) always holds.

i.e. (1,2,2,1,3)\approx(1,3,2,1,2)(1,2,2,1,3)(1,3,2,1,2).

Let SS be a string. An integer kk is a full Abelian period of SS if SS can be partitioned into several continous substrings of length kk, and all of these substrings are matched with each other.

Now given a string SS, please find all of the numbers kk that kk is a full Abelian period of SS.

Input

The first line of the input contains an integer T(1\leq T\leq10)T(1T10), denoting the number of test cases.

In each test case, the first line of the input contains an integer n(n\leq 100000)n(n100000), denoting the length of the string.

The second line of the input contains nn integers S_1,S_2,S_3,...,S_n(1\leq S_i\leq n)S1,S2,S3,...,Sn(1Sin), denoting the elements of the string.

Output

For each test case, print a line with several integers, denoting all of the number kk. You should print them in increasing order.

Sample Input
Copy
2
6
5 4 4 4 5 4
8
6 5 6 5 6 5 5 6
Sample Output
3 6
2 4 8


先找其所有约数,然后对每一个约数进行逐一判断



#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set::iterator it=s.begin();it!=s.end();it++)
#define mod 2009
#define INF 9999999999999
#define vi vector
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pii pair
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+10;
using namespace std;
typedef  long long ll;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
ll my_min(ll x,ll y){ return x>y?y:x;};

int main()
{
	int t;
	int n;
	int a[100005];
	int b[100005];
	while(scanf("%d",&t)!=EOF)
	{
		for(int k=1;k<=t;k++)
		{
			int len = 0;
			memset(b,0,sizeof(b));
			memset(a,0,sizeof(a)); 
			scanf("%d",&n);
			for(int i=1;i<=n;i++)
				scanf("%d",&a[i]);
				
			for(int i=1;i<=n-1;i++)//找到约数
			{
				if(n%i==0)
					b[len++] = i;
			}
			//for(int i=1;i



你可能感兴趣的:(bestcoder,ACM_比赛题目)