이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
new_home.cpp: In function 'int main()':
new_home.cpp:103:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("input","r",stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
new_home.cpp:104:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("output","w",stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |