UnknownPeople @ 2024-03-30 22:26:44
88pts代码
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct tie{
int ts,id;
}a[100005];
bool cmp(tie a,tie b){
if(a.id==b.id)
return a.ts<b.ts;
return a.id<b.id;
}
vector<int>v;
int q[100005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,d,b;
cin>>n>>d>>b;
for(int i=0;i<n;i++)
cin>>a[i].ts>>a[i].id;
sort(a,a+n,cmp);
for(int k=1;k<n;k++){
int i=k-1;
while(k<n&&a[k].id==a[k-1].id)
k++;
int l=1,r=0;
for(;i<k;i++){
while(l<=r&&a[i].ts-a[q[l]].ts>=d)
l++;
q[++r]=i;
if(r-l+1>=b){
v.push_back(a[i].id);
break;
}
}
}
for(int i=0;i<v.size();i++)
cout<<v[i]<<"\n";
return 0;
}
100pts代码
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct tie{
int ts,id;
}a[100005];
bool cmp(tie a,tie b){
if(a.id==b.id)
return a.ts<b.ts;
return a.id<b.id;
}
vector<int>v;
int q[100005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,d,b;
cin>>n>>d>>b;
for(int i=0;i<n;i++)
cin>>a[i].ts>>a[i].id;
sort(a,a+n,cmp);
for(int k=0;k<n;k++){
int i=k;
while(k<n&&a[k].id==a[k+1].id)
k++;
int l=1,r=0;
for(;i<=k;i++){
while(l<=r&&a[i].ts-a[q[l]].ts>=d)
l++;
q[++r]=i;
if(r-l+1>=b){
v.push_back(a[i].id);
break;
}
}
}
for(int i=0;i<v.size();i++)
cout<<v[i]<<"\n";
return 0;
}
二者唯一的区别在于24行到38行的循环。求大佬指教或给出第一份代码的hack,非常感谢!