QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188588 | #4206. Event Hopping | danielkou5855 | 0 | 231ms | 31088kb | C++17 | 2.3kb | 2023-09-26 03:13:28 | 2023-09-26 03:13:28 |
Judging History
answer
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
const int K = 31;
const int inf = (int) 1e9;
int main() {
int N, Q; cin >> N >> Q;
vector<pair<pair<int, int>, int>> events(N);
map<int, int> compress;
for (int i = 0; i < N; i++) {
cin >> events[i].first.first >> events[i].first.second; events[i].second = i;
compress[events[i].first.first] = 0; compress[events[i].first.second] = 0;
}
vector<vector<int>> lift(N, vector<int>(K, -1));
vector<int> order(N);
for (int i = 0; i < N; i++) {
order[i] = i;
}
sort(order.begin(), order.end(), [&](int a, int b){
if (events[a].first.second == events[b].first.second) {
return events[a].first.first < events[b].first.first;
}
return events[a].first.second < events[b].first.second;
});
vector<int> on_stack;
for (int i : order) {
while (!on_stack.empty() && events[on_stack.back()].first.first >= events[i].first.first) {
on_stack.pop_back();
}
on_stack.push_back(i);
int l = -1, r = (int) on_stack.size() - 1;
while (l + 1 < r) {
int m = l + (r - l) / 2;
if (events[on_stack[m]].first.second < events[i].first.first) {
l = m;
} else {
r = m;
}
}
lift[i][0] = on_stack[r];
}
for (int d = 1; d < K; d++) {
for (int i = 0; i < N; i++) {
lift[i][d] = lift[lift[i][d - 1]][d - 1];
}
}
while (Q--) {
int a, b; cin >> a >> b; a--; b--; swap(a, b);
if (a == b) {
cout << 0 << "\n"; continue;
} else if (events[b].first.second > events[a].first.second) {
cout << "impossible\n"; continue;
} else if (events[b].first.second >= events[a].first.second) {
cout << 1 << "\n"; continue;
}
int ans = 0;
for (int d = K - 1; d >= 0; d--) {
if (events[lift[a][d]].first.first > events[b].first.second) {
ans += (1 << d);
a = lift[a][d];
}
}
if (events[lift[a][0]].first.first <= events[b].first.second) {
cout << ans + 2 << "\n"; continue;
} else {
cout << "impossible\n"; continue;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 231ms
memory: 26388kb
input:
100000 100000 825913690 825916363 333322014 333324481 302015784 302018251 841002775 841005448 810249910 810252583 803554045 803556718 379590599 379593066 413477311 413479778 304105333 304107800 856802878 856805551 355907399 355909866 365590374 365592841 813775597 813778270 816058339 816061012 383873...
output:
2 impossible 2 impossible impossible impossible 31336 impossible impossible impossible impossible 27166 16274 impossible impossible impossible impossible impossible impossible 21353 17890 impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible 67...
result:
wrong answer 1st lines differ - expected: '1', found: '2'
Subtask #2:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 2ms
memory: 3724kb
input:
1000 100 67878298 387720407 270457472 922959000 286470357 618323410 260791474 282940414 301337446 553875076 478221503 724555102 380447228 437131400 191801427 465825895 366088873 431222136 49483883 103442781 699926238 720636919 253150351 291688158 411085513 727726933 444078045 496386017 420626857 822...
output:
2 2 2 impossible 2 2 2 2 impossible 2 2 impossible impossible impossible 2 impossible impossible impossible impossible impossible 2 impossible 2 impossible 2 2 impossible 2 2 2 2 impossible 2 impossible 2 impossible 2 2 impossible impossible impossible 2 2 impossible impossible 2 2 impossible imposs...
result:
wrong answer 1st lines differ - expected: '1', found: '2'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Wrong Answer
Test #35:
score: 20
Accepted
time: 209ms
memory: 31084kb
input:
100000 100000 903318459 905410836 903528407 905653109 925180437 927048927 473524826 475597377 362562616 364539688 644980844 646918450 242583398 244653279 506338025 508361063 481496693 483530832 970053326 972147109 794840350 796900045 130664210 132709680 634100524 636336820 844429264 846504591 652483...
output:
500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 ...
result:
ok 100000 lines
Test #36:
score: -20
Wrong Answer
time: 227ms
memory: 31088kb
input:
100000 100000 280978238 281996879 128582305 129520369 326480847 327450886 613575910 614525870 773187456 774194521 499427531 500501109 206817453 207828231 147432355 148457712 276397611 277442951 238269352 239211898 864332415 865500617 189404293 190348043 898692256 899607594 395766418 396755456 306101...
output:
impossible 434 impossible 248 338 332 390 impossible 607 771 246 impossible 421 impossible 628 117 549 impossible impossible impossible 382 impossible 495 impossible impossible 357 impossible 522 impossible 54 impossible impossible impossible 464 impossible impossible 225 255 484 60 86 244 579 363 7...
result:
wrong answer 2804th lines differ - expected: '1', found: '2'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%