头条后端编程题 2ac
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <set>
using namespace std;
int main(){
int n, m, c;
cin >> n >> m >> c;
vector<set<int>> vec(c + 1, set<int>());
for (int i = 1; i <= n; i++){
int num_i;
scanf("%d", &num_i);
for (int j = 0; j < num_i; j++){
int x;
scanf("%d", &x);
vec[x].insert(i);
}
}
int cnt = 0;
for (int i = 1; i <= c; i++){
if (vec[i].size() <= 1){
continue;
}
set<int>::iterator it;
vector<int> v;
for (it = vec[i].begin(); it != vec[i].end(); ++it)
v.push_back(*it);
for (int j = 1; j < v.size(); j++){
if (v[j] - v[j - 1] < m){
cnt++;
break;
}
}
}
cout << cnt;
return 0;
}
#include <iostream>
#include <vector>
#include <cstdio>
#include <set>
using namespace std;
int main(){
int n;
cin >> n;
int arr[300001];
for (int i = 1; i < n; i++)
scanf("%d", &arr[i]);
int q;
cin >> q;
for (int index = 0; index < q; index++){
int l, r, k;
int cnt = 0;
scanf("%d %d %d", &l, &r, &k);
for (int i = l; i <= r; i++){
if (arr[i] == k)
cnt++;
}
printf("%d", cnt);
}
return 0;
}