Submission #735139

#TimeUsernameProblemLanguageResultExecution timeMemory
735139keisuke6New Home (APIO18_new_home)C++14
12 / 100
5059 ms69848 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,K,Q;
  cin>>N>>K>>Q;
  vector<int> X(N),T(N),A(N),B(N);
  vector<vector<tuple<int,int,int>>> G(K);
  vector<multiset<tuple<int,int,int>>> sta(K);
  vector<multiset<int>> Z(K);
  vector<int> I(K,0);
  for(int i=0;i<N;i++){
    cin>>X[i]>>T[i]>>A[i]>>B[i];
    T[i]--;
    G[T[i]].push_back({A[i],B[i],X[i]});
  }
  for(int i=0;i<K;i++){
    sort(G[i].begin(),G[i].end());
  }
  vector<pair<int,int>> Que(Q);
  for(int i=0;i<Q;i++) cin>>Que[i].second>>Que[i].first;
  vector<pair<int,int>> Que_ = Que;
  sort(Que.begin(),Que.end());
  map<pair<int,int>,int> m_ans;
  for(int i=0;i<Q;i++){
    int t = Que[i].first, x = Que[i].second;
    for(int j=0;j<K;j++){
      while(I[j] != G[j].size()){
        int aa,bb,cc;
        tie(aa,bb,cc) = G[j][I[j]];
        if(aa > t) break;
        sta[j].insert({bb,aa,cc});
        Z[j].insert(cc);
        I[j]++;
      }
    }
    for(int j=0;j<K;j++){
      while(!sta[j].empty()){
        auto pos = *sta[j].begin();
        int bb,aa,cc;
        tie(bb,aa,cc) = pos;
        if(bb >= t) break;
        sta[j].erase(sta[j].find(pos));
        Z[j].erase(Z[j].find(cc));
      }
    }
    int ans = 0;
    for(int j=0;j<K;j++){
      int now = 1e18;
      if(sta[j].empty()){
        ans = 1e18;
        continue;
      }
      auto a = Z[j].lower_bound(x);
      if(a != Z[j].end()){
        now = min(now,abs(x-(*a)));
      }
      if(a != Z[j].begin()){
        a--;
        now = min(now,abs(x-(*a)));
      }
      ans = max(ans,now);
    }
    if(ans == 1e18) ans = -1;
    m_ans[Que[i]] = ans;
  }
  for(int i=0;i<Q;i++) cout<<m_ans[Que_[i]]<<endl;
  cout<<endl;
}

Compilation message (stderr)

new_home.cpp: In function 'int main()':
new_home.cpp:28:18: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |       while(I[j] != G[j].size()){
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...