Submission #701434

# Submission time Handle Problem Language Result Execution time Memory
701434 2023-02-21T08:41:18 Z Abrar_Al_Samit New Home (APIO18_new_home) C++17
0 / 100
122 ms 40344 KB
#include<bits/stdc++.h>
using namespace std;

const int nax = 6e4 + 10;

int l[nax];
int x[nax], t[nax];
int pos[nax];
set<int>live[nax];
int ans[nax];
void PlayGround() {
  int n, q, k;
  cin>>n>>q>>k;

  vector<int>imp;
  map<int, vector<int>>query, shopin, shopout;

  for(int i=0; i<n; ++i) {
    cin>>x[i]>>t[i];

    int a, b;
    cin>>a>>b;
    shopin[a].push_back(i);
    shopout[b].push_back(i);

    imp.push_back(a), imp.push_back(b);
  }

  for(int i=0; i<q; ++i) {
    int x, y;
    cin>>x>>y;

    pos[i] = x;
    query[y].push_back(i);
    imp.push_back(y);
  }

  sort(imp.begin(), imp.end());
  imp.erase(unique(imp.begin(), imp.end()));

  for(int mom : imp) {
    if(shopin.count(mom)) {
      for(int j : shopin[mom]) {
        live[t[j]].insert(x[j]);
      }
    }
    if(query.count(mom)) {
      for(int j : query[mom]) {
        for(int i=1; i<=k; ++i) {
          if(live[i].empty()) {
            ans[j] = -1;
            break;
          }
          int d1 = 1e9, d2 = 1e9;
          auto it = live[i].lower_bound(pos[j]);
          if(it!=live[i].end()) d1 = *it - pos[j];

          if(it!=live[i].begin()) {
            it = prev(it);
            d2 = pos[j] - *it;
          }

          ans[j] = max(ans[j], min(d1, d2));
        }

      }
    }
    if(shopout.count(mom)) {
      for(int j : shopout[mom]) {
        live[t[j]].erase(x[j]);
      }
    }
  }

  for(int i=0; i<q; ++i) {
    cout<<ans[i]<<'\n';
  }
  // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 50 ms 15124 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 122 ms 40344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -