#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
const int N=1000+5;
int n,k,Q;
struct event
{
bool in;
/// in = 1; in = 0 <=> out = 1
int x;
int t;
int when;
int i;
};
bool operator < (event f,event s)
{
return f.when>s.when;
}
priority_queue<event>q;
struct ask
{
int x;
int when;
int i;
};
bool operator < (ask f,ask s)
{
if(f.when==s.when)
{
return f.i<s.i;
}
else
{
return f.when<s.when;
}
}
ask a[N];
multiset<int>p[N];
int f[N],cnt=0;
void upd(int when)
{
/// cout<<"SZ = "<<q.size()<<" , "<<when<<"\n";
while(!q.empty())
{
event aux=q.top();
if(aux.when>when) break;
q.pop();
if(aux.in)
{
f[aux.t]++;
p[aux.t].insert(aux.x);
/// cout<<"HI "<<aux.when<<" , "<<aux.t<<" "<<aux.x<<"\n";
if(f[aux.t]==1)
{
cnt++;
}
}
else
{
auto it=p[aux.t].find(aux.x);
/// cout<<"BYE "<<aux.when<<" , "<<aux.t<<" "<<aux.x<<"\n";
p[aux.t].erase(it);
f[aux.t]--;
if(f[aux.t]==0)
{
cnt--;
}
}
}
}
int d(int a,int b)
{
if(a<b)
{
return b-a;
}
else
{
return a-b;
}
}
int lol[N];
int main()
{
/// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("input","r",stdin);
// freopen("output","w",stdout);
cin>>n>>k>>Q;
for(int i=1;i<=n;i++)
{
int x,t,a,b;
cin>>x>>t>>a>>b;
q.push({1,x,t,a,i});
q.push({0,x,t,b,i});
}
for(int i=1;i<=Q;i++)
{
int x;
int when;
cin>>x>>when;
a[i]={x,when,i};
}
sort(a+1,a+Q+1);
for(int i=1;i<=Q;i++)
{
upd(a[i].when);
if(cnt!=k)
{
lol[a[i].i]=-1;
continue;
}
int ans=0;
for(int j=1;j<=k;j++)
{
auto it=p[j].lower_bound(a[i].x);
int cur=(1<<30);
if(it!=p[j].end())
{
cur=min(cur,d(*it,a[i].x));
}
if(it!=p[j].begin())
{
it--;
cur=min(cur,d(*it,a[i].x));
}
ans=max(ans,cur);
}
lol[a[i].i]=ans;
}
for(int i=1;i<=Q;i++)
{
cout<<lol[i]<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5061 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5061 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
451 ms |
24584 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
410 ms |
33356 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5061 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5061 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |