6 2 3 2 1 4 3 5 3 4
Case #1: 2 2
#include <cstdio> #include <cstring> #include <algorithm> #include <set> using namespace std; int const MAX = 1e4 + 5; int a[MAX], ans[MAX]; set <int> s; int main() { int n, m, ca = 1; while(scanf("%d %d", &n, &m) != EOF) { printf("Case #%d:\n", ca ++); memset(ans, 0, sizeof(ans)); for(int i = 0; i < n; i++) scanf("%d", &a[i]); for(int i = 0; i < n; i++) { s.clear(); s.insert(a[i]); ans[1] ++; for(int j = i + 1; j < n; j++) { set <int> :: iterator it; it = s.find(a[j]); if(it != s.end()) break; s.insert(a[j]); int st = *s.begin(); it --; int ed = *it; int sz = s.size(); if(ed - st + 1 == sz) ans[sz] ++; } } for(int i = 0; i < m; i++) { int k; scanf("%d", &k); printf("%d\n", ans[k]); } } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/tc_to_top/article/details/47089085