(White Book Training Program) ultraviolet (11572 unique snowflakes)

Source: Internet
Author: User

Subject address: Ultraviolet A 11572

This method has been used before. It defines two pointers and continuously slides from left to right to determine whether the pointer meets the requirements.

In order to quickly determine whether this number exists, set in STL can be used.

The Code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int a[1100000];int main(){    int t, n, l, r, i, max1;    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        max1=-1;        for(i=0;i<n;i++)        {            scanf("%d",&a[i]);        }        l=r=0;        set<int>q;        while(r!=n)        {            while(q.count(a[r]))            {                q.erase(a[l++]);            }            q.insert(a[r++]);            if(max1<r-l)                max1=r-l;        }        printf("%d\n",max1);    }    return 0;}


(White Book Training Program) ultraviolet (11572 unique snowflakes)

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.