急求这样的time limit exceeded怎样解决?

An array of length n, with address from 1 to n inclusive, contains entries from the set {1,2,...,n-1} and there's exactly two elements with the same value. Your task is to find out the value.

Input

Input contains several cases.
Each case includes a number n (1<n<=10^6), which is followed by n integers.
The input is ended up with the end of file.

Output

Your must output the value for each case, one per line.

Sample Input
2
1 1
4
1 2 3 2

Sample Output
1
2

 #include <iostream>
#include<cstdio>
using namespace std;


int main(int argc, char** argv) 
{ 
int n;
while(scanf("%d",&n)!=EOF){
    if(n!=-1){
    int *p=new int[n];
    int t,m;
    while(n--){
        cin>>t;
        if(p[t]==0)
        p[t]=1;
        else
        m=t;
    }
    cout<<m<<endl;
    delete p;
}
else
break;
}
    return 0;
}

http://blog.csdn.net/zheng0518/article/details/8709161

把 else m=t;这一句代码改成:else { m=t; break; }