### [UVA - 11572] Unique Snowflakes 題解

1
5
1
2
3
2
1

3

STL set的模板題（大概？）

AC代碼：

``` 1 #include<cstdio>
2 #include<algorithm>
3 #include<cmath>
4 #include<cstring>
5 #include<set>
6
7 const int MAXN = 1000003;
8
10 {
11     char ch = getchar(),c = ch;x = 0;
12     while(ch < '0' || ch > '9') c = ch,ch = getchar();
13     while(ch <= '9' && ch >= '0') x = (x<<1)+(x<<3)+ch-'0',ch = getchar();
14     if(c == '-') x = -x;
15 }
16
17 std::set <int> s;
18 int t,n,l,r,ans,num[MAXN];
19
20 inline int Max(int a,int b)
21 {return a>b?a:b;}
22
23 int main()
24 {
26     for(int T = 1;T <= t;++ T)
27     {
28         s.clear();
29         l = 0,r = 1,ans = 0;
31         for(int i = 1;i <= n;++ i)
33         while(r <= n)
34         {
35             while(s.find(num[r]) == s.end() && r <= n)
36                 s.insert(num[r++]);
37             ans = Max(ans,r-l-1);
38             while(s.find(num[r]) != s.end()) s.erase(num[++l]);
39         }
40         printf("%d\n",ans);
41     }
42     return 0;
43 }```