蓝桥集训之日志统计
-
核心思想: 双指针
- 用对组储存每次的时刻和编号
- 双指针遍历对组 每次记录对应编号的赞+1
- 当该对组区间长度>=d时 将上次记录的赞消掉
- 若最终仍满足赞>=k 则标记true
-
#include<iostream>#include <algorithm>#include <cstring>using namespace std;const int N = 100010;typedef pair<int,int> PII;int n,m,k;PII logs[N];bool st[N];int cnt[N];int main(){cin>>n>>m>>k;for(int i=0;i<n;i++) cin>>logs[i].first>>logs[i].second;sort(logs,logs+n);for(int i=0,j=0;i<n;i++) {int t = logs[i].second; //取当前编号cnt[t] ++; //对应编号的赞+1while(logs[i].first - logs[j].first >=m) //时间差{cnt[logs[j].second] --; //最初记录的赞消掉j++;}if(cnt[t] >= k) st[t] = true;}for (int i = 0; i <= 100000; i ++ ) if (st[i]) cout << i << endl;}