swjtuoj 2390 Segment Tree

来源:互联网 发布:信访网络舆情工作方案 编辑:程序博客网 时间:2024/06/16 10:44

题目链接:Segment Tree

题目大意:给你n个数,m代表长度,k代表最小出现的次数,n个数,需要你取长度为3的序列,比如[1,2,3],[2,3,4],但是不是数的位置,只是数而已(因为这个题意读错一发),如果这个序列里面出现的数在整个序列的个数大于等于k,就满足条件,问有多少个满足条件的区间

题目思路:处理一下每个数出现的个数,然后处理一下前缀和就好,代表【1,n】这里面所有数出现的次数,直接做就好

#include <bits/stdc++.h>#define eps 1e-6using namespace std;typedef long long ll;typedef double db;const int maxn = 5e2 + 5;const int mod = 1e9 + 7;const int INF = 1e8 + 5;const ll inf = 1e15 + 8;map<int,int>mp;void solve() {    int n,k,q,a[505],sum[505],maxx = -1;    scanf("%d%d%d",&n,&k,&q);    mp.clear();    memset(sum,0,sizeof(sum));    sum[0] = 0;    for(int i = 0;i < n;i++)        scanf("%d",&a[i]),mp[a[i]]++,maxx = max(maxx,a[i]);    maxx += k;    for(int i = 1;i <= maxx;i++)        sum[i] = sum[i-1] + mp[i];    int cot,cott = 0;    for(int i = 1;i <= maxx;i++){        cot = sum[i+k-1]-sum[i-1];        if(cot >= q) cott++;    }    printf("%d\n",cott);}int main(){   // freopen("in.txt", "r", stdin);    int t = 1;    cin >> t;    while (t--) {        solve();    }    return 0;}
原创粉丝点击