#include <bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int n;
int K;int Q;
int xar[500005];
int typ[500005];
int ta[500005];
int tb[500005];
int qpl[500005];
int qt[500005];
int ansl[500005];int ansr[500005];
int anok[500005];
int kcnt;
int freq[500005];
struct mo{
int l;int r;int id;
};
bool cmp(mo i,mo j){
int va=i.l/500;int vb=j.l/500;
if(va<vb){return 1;}
if(va>vb){return 0;}
if(va%2==0){
return i.r<j.r;
}
return i.r>j.r;
}
void add(int v){
freq[v]++;
if(freq[v]==1){
kcnt++;
}
}
void del(int v){
freq[v]--;
if(freq[v]==0){
kcnt--;
}
}
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
cin>>n>>K>>Q;
for(int i=1;i<=n;i++){
cin>>xar[i]>>typ[i]>>ta[i]>>tb[i];
}
for(int i=1;i<=Q;i++){
cin>>qpl[i]>>qt[i];
ansl[i]=0;ansr[i]=1e9;
}
vector<pair<int,int>>event;
vector<int>eventp;
for(int i=1;i<=n;i++){
event.push_back({xar[i],typ[i]});
eventp.push_back(xar[i]);
}
sort(eventp.begin(),eventp.end());
sort(event.begin(),event.end());
for(int ttt=0;ttt<=55;ttt++){
vector<mo>qry;
for(int i=1;i<=Q;i++){
int mi=ansl[i]+(ansr[i]-ansl[i])/2;
anok[i]=0;
mo hi;
hi.id=i;
hi.l=lower_bound(eventp.begin(),eventp.end(),qpl[i]-mi)-eventp.begin();
hi.r=upper_bound(eventp.begin(),eventp.end(),qpl[i]+mi)-eventp.begin();
hi.r--;
// cout<<hi.l<<" "<<hi.r<<endl;
if(hi.l>hi.r){continue;}
qry.push_back(hi);
}
sort(qry.begin(),qry.end(),cmp);
for(int i=1;i<=K;i++){
freq[i]=0;
}
kcnt=0;
int lit=0;int rit=0;
add(event[0].second);
for(int i=0;i<qry.size();i++){
while(lit<qry[i].l){del(event[lit++].second);}
while(rit>qry[i].r){del(event[rit--].second);}
while(lit>qry[i].l){add(event[--lit].second);}
while(rit<qry[i].r){add(event[++rit].second);}
if(kcnt==K){
anok[qry[i].id]=1;
}
}
for(int i=1;i<=Q;i++){
int mi=ansl[i]+(ansr[i]-ansl[i])/2;
if(anok[i]){
ansr[i]=mi;
}else{
ansl[i]=mi+1;
}
// cout<<anok[i]<<" "<<mi<<endl;
}
}
for(int i=1;i<=Q;i++){
if(ansl[i]>1e8){
cout<<-1<<endl;
}else{
cout<<ansl[i]<<endl;
}
}
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:87:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<mo>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int i=0;i<qry.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2889 ms |
52132 KB |
Output is correct |
2 |
Execution timed out |
5091 ms |
48924 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5061 ms |
49100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |