模拟 双指针
cpp
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
#define int long long
const int N = 1e5+10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
int n,m,ts;
bool vis[N];
int a[N];
int last[N];
pair<int,int>query[N];
void solve()
{
cin>>n>>m>>ts;
for(int i=1;i<=m;i++){
int a,b;cin>>a>>b;
query[i] = {a,b};
}
sort(query+1,query+1+m);
for(int i=1;i<=m;){
int j = i;
while(j+1<=m&&query[j+1].second==query[i].second)j++;
int len = j-i+1;
int t = query[i].first,id = query[i].second;
//t-1 last[t]+1
a[id] -= t-1-last[id];
if(a[id]<0)a[id] = 0;
if(a[id]<=3)vis[id] = 0;
last[id] = t;
a[id] += len*2;
if(a[id]>5)vis[id] = 1;
i = j+1;
}
for(int i=1;i<=n;i++){
if(vis[i]&&a[i]-ts+last[i]<=3)vis[i] = 0;
}
int cnt = 0;
for(int i=1;i<=n;i++)if(vis[i]){cnt++;}
cout<<cnt;
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _;
//cin>>_;
_ = 1;
while(_--)solve();
return 0;
}