#include <bits/stdc++.h>
#define lli long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const int N = 1e5 + 5;
const int INF = 1e9 + 500;
const int K = 405;
int n, k, q;
vector<array<int, 2> > qu;
vector<vector<int> > ev(N);
vector<array<int, 3> > eve; // occ, x, 0 or 1
vector<int> pt(N, 0);
void solve() {
cin >> n >> k >> q;
REP(i, n) {
int x, t, a, b;
cin >> x >> t >> a >> b;
ev[t].pb(x);
}
qu.resize(q);
REP(i, q) {
int tmp;
cin >> qu[i][0] >> tmp;
qu[i][1] = i;
}
sort(all(qu));
bool emp = 0;
for(int i = 1; i <= k; i++) {
sort(all(ev[i]));
if(ev[i].empty()) {
emp = 1;
break;
}
int tm = 1;
for(int j = 0; j < ev[i].size(); j++) {
eve.pb({tm, ev[i][j], 1});
if(j == ev[i].size() - 1) continue;
tm = (ev[i][j + 1] + ev[i][j] - 1) / 2 + 1;
eve.pb({tm, ev[i][j], 0});
}
}
if(emp) {
REP(i, q) cout << "-1\n";
return;
}
sort(all(eve));
multiset<int> st;
int ind = 0;
vector<int> res(q, 0);
for(auto c : qu) {
while(ind < eve.size() && eve[ind][0] <= c[0]) {
if(eve[ind][2]) {
st.insert(eve[ind][1]);
}
else {
st.erase(st.lower_bound(eve[ind][1]));
}
ind++;
}
int mx = 0;
mx = max(mx, abs(c[0] - (*st.begin())));
mx = max(mx, abs((*prev(st.end())) - c[0]));
res[c[1]] = mx;
}
REP(i, q) {
cout << res[i] << "\n";
}
}
signed main() {
fastio();
solve();
}
Compilation message
new_home.cpp: In function 'void solve()':
new_home.cpp:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int j = 0; j < ev[i].size(); j++) {
| ~~^~~~~~~~~~~~~~
new_home.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | if(j == ev[i].size() - 1) continue;
| ~~^~~~~~~~~~~~~~~~~~~
new_home.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | while(ind < eve.size() && eve[ind][0] <= c[0]) {
| ~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5034 ms |
3164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5034 ms |
3164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
370 ms |
37072 KB |
Output is correct |
2 |
Correct |
260 ms |
32128 KB |
Output is correct |
3 |
Runtime error |
5 ms |
5976 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
312 ms |
34240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5034 ms |
3164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5034 ms |
3164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |