QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#491803 | #4206. Event Hopping | kimmoqt# | 20 | 220ms | 64416kb | C++20 | 3.5kb | 2024-07-25 22:26:39 | 2024-07-25 22:26:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=2e5+5;
int N,Q;
int L[MX], R[MX];
int up[MX][20];
map<int,int> id;
vector<pair<int,int>> open[MX], cl[MX];
struct segtree {
pair<int,int> t[4*MX];
set<pair<int,int>> S[MX];
void upd(int v, int l, int r, int pos) {
if(pos<l || r<pos) return;
if(l==r) {
t[v]=*S[l].begin();
return;
}
int m=(l+r)/2;
upd(v*2+0,l,m+0,pos);
upd(v*2+1,m+1,r,pos);
t[v]=min(t[v*2+0],t[v*2+1]);
}
pair<int,int> que(int v, int l, int r, int ql, int qr) {
if(r<ql || qr<l) return {1e9,1e9};
if(ql<=l && r<=qr) return t[v];
int m=(l+r)/2;
return min(que(v*2+0,l,m+0,ql,qr),que(v*2+1,m+1,r,ql,qr));
}
void add(int p, pair<int,int> val) {
S[p].insert(val);
upd(1,1,2*N,p);
}
void del(int p, pair<int,int> val) {
S[p].erase(val);
upd(1,1,2*N,p);
}
void prep() {
for(int i=1;i<MX;i++) {
S[i].insert({1e9,1e9});
}
for(int i=1;i<4*MX;i++) {
t[i]={1e9,1e9};
}
}
} st;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>N>>Q;
for(int i=1;i<=N;i++) {
cin>>L[i]>>R[i];
id[L[i]]=0;
id[R[i]]=0;
}
int cnt=1;
for(auto &[x,y]:id) y=cnt++;
for(int i=1;i<=N;i++) {
L[i]=id[L[i]];
R[i]=id[R[i]];
open[R[i]].push_back({L[i],i});
cl[L[i]].push_back({R[i],i});
}
st.prep();
for(int r=2*N;r>=1;r--) {
for(auto [l,id]:open[r]) {
st.add(r,make_pair(l,id));
}
for(auto [R,id]:cl[r]) {
int qry=st.que(1,1,2*N,r,R).second;
if(qry!=1e9) up[id][0]=qry;
}
for(auto [R,id]:cl[r]) {
st.del(R,make_pair(r,id));
}
}
for(int k=0;k+1<20;k++) {
for(int i=1;i<=N;i++) {
if(up[i][k]!=0)
up[i][k+1]=up[up[i][k]][k];
}
}
for(int i=0;i<Q;i++) {
int s,e;
cin>>s>>e;
if(s==e) {
cout<<0<<'\n';
continue;
}
if(L[e]<=R[s] && R[s]<=R[e]) {
cout<<1<<'\n';
continue;
}
int cur=e, res=0;
for(int k=19;k>=0;k--) {
if(up[cur][k]!=0 && R[up[cur][k]]>R[s]) {
cur=up[cur][k];
res+=1<<k;
}
}
if(L[cur]<=R[s] && R[s]<=R[cur]) {
res++;
cout<<res<<'\n';
} else {
cout<<"impossible"<<'\n';
}
}
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 173ms
memory: 56896kb
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:
1 impossible 1 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:
ok 100000 lines
Test #2:
score: 10
Accepted
time: 159ms
memory: 58408kb
input:
100000 100000 389680865 389680885 532001242 532004287 460483812 460491583 691010527 691018298 489353103 489356770 593534107 593537042 509433341 509441112 846177578 846179089 586840272 586848043 834393248 834401019 474044207 474051978 614427322 614435093 574678657 574686428 557256443 557262524 502657...
output:
80801 80800 80800 80799 80799 80799 80798 80798 80798 80798 80797 80797 80797 80797 impossible 80796 80796 80796 80796 impossible 80797 80795 80795 80795 80795 impossible 80796 80796 80794 80794 80794 80794 impossible 80795 80795 80795 80794 80793 80793 80793 impossible 80794 80794 80794 80794 80793...
result:
ok 100000 lines
Test #3:
score: 10
Accepted
time: 101ms
memory: 53456kb
input:
100000 100000 1 2 1 2 5 6 5 6 9 10 9 10 13 14 13 14 17 18 17 18 21 22 21 22 25 26 25 26 29 30 29 30 33 34 33 34 37 38 37 38 41 42 41 42 45 46 45 46 49 50 49 50 53 54 53 54 57 58 57 58 61 62 61 62 65 66 65 66 69 70 69 70 73 74 73 74 77 78 77 78 81 82 81 82 85 86 85 86 89 90 89 90 93 94 93 94 97 98 97...
output:
impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible imp...
result:
ok 100000 lines
Test #4:
score: 10
Accepted
time: 147ms
memory: 55320kb
input:
100000 100000 407280099 407284136 197925316 197929353 463232919 463236956 248771331 248775368 314921613 314925650 454125447 454129484 215159269 215163306 376796712 376800749 343418796 343422833 126014235 126018272 315022538 315026575 242069911 242073948 479849211 479853248 414950399 414954436 254079...
output:
99999 99998 99998 99997 99997 99997 99996 99996 99996 99996 99995 99995 99995 99995 99995 99994 99994 99994 99994 99994 99994 99993 99993 99993 99993 99993 99993 99993 99992 99992 99992 99992 99992 99992 99992 99992 99991 99991 99991 99991 99991 99991 99991 99991 99991 99990 99990 99990 99990 99990 ...
result:
ok 100000 lines
Test #5:
score: 10
Accepted
time: 159ms
memory: 56784kb
input:
100000 100000 861047815 861052922 578273225 578278332 622183211 622188318 822908739 822913846 546318726 546323833 461573168 461578275 480101364 480106471 456455954 456461061 575234560 575239667 464851862 464856969 897159412 897164519 722826860 722831967 755036709 755041816 811213709 811218816 445680...
output:
99999 99997 99995 99993 99991 99989 99987 99985 99983 99981 99979 99977 99975 99973 99971 99969 99967 99965 99963 99961 99959 99957 99955 99953 99951 99949 99947 99945 99943 99941 99939 99937 99935 99933 99931 99929 99927 99925 99923 99921 99919 99917 99915 99913 99911 99909 99907 99905 99903 99901 ...
result:
ok 100000 lines
Test #6:
score: 10
Accepted
time: 166ms
memory: 63452kb
input:
100000 100000 107067593 107068563 375121029 375132523 244489164 244489510 371625987 371628227 63502583 63505678 622119714 622149239 792197805 792202711 692512281 692515198 196552919 196554193 677923903 677926489 680041239 680046357 697562945 697565212 206418851 206420890 410143641 410145269 63943786...
output:
impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible imp...
result:
ok 100000 lines
Test #7:
score: 10
Accepted
time: 9ms
memory: 34408kb
input:
8 5 1 2 3 4 1 5 6 7 5 10 10 20 15 20 999999999 1000000000 1 6 1 7 2 4 3 3 5 8
output:
3 4 impossible 0 impossible
result:
ok 5 lines
Test #8:
score: 10
Accepted
time: 143ms
memory: 56520kb
input:
100000 100000 432053319 432056406 486393780 486396867 318945639 318948726 557737437 557740524 505903620 505906707 312861162 312864249 530084091 530087178 378401259 378404346 590749815 590752902 384158514 384161601 397824663 397827750 305937021 305940108 418238994 418242081 311718972 311722059 421174...
output:
99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 99999 ...
result:
ok 100000 lines
Test #9:
score: 10
Accepted
time: 162ms
memory: 57448kb
input:
100000 100000 460767811 460773658 363280780 363286627 318744181 318750028 587618476 587624323 349815139 349820986 654104713 654110560 522640765 522646612 667874398 667880245 722245651 722251498 442864297 442870144 522664153 522670000 660805375 660811222 710639356 710645203 484196740 484202587 355358...
output:
77828 77828 77829 77828 77829 77827 77827 77829 77827 77826 77826 77828 77827 77826 77825 77825 77827 77826 77826 77825 impossible 77824 77826 77825 77825 77825 impossible 77824 77824 77825 77824 77824 77824 impossible 77824 77823 77823 77825 77823 77823 77823 impossible 77824 77823 77822 77823 7782...
result:
ok 100000 lines
Test #10:
score: 0
Wrong Answer
time: 174ms
memory: 64416kb
input:
100000 100000 639515864 639521231 667143094 667144538 647258206 647258690 462233258 462234230 475801547 475802613 524127311 524128428 543287190 543289381 535841282 535843238 585211823 585213845 734658645 734658899 537776171 537783441 730349191 730354503 616233528 616234443 679161417 679162801 660817...
output:
1 1 1048576 1 1048576 impossible 1 1048576 impossible impossible 1 1048576 impossible impossible impossible 1 1048576 impossible impossible impossible impossible 1 1048576 impossible impossible impossible impossible impossible 1 1048576 impossible impossible impossible impossible impossible impossib...
result:
wrong answer 3rd lines differ - expected: '2', found: '1048576'
Subtask #2:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 7ms
memory: 34400kb
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:
1 2 2 impossible 1 2 1 1048576 impossible 1048576 1048576 impossible impossible impossible 1 impossible impossible impossible impossible impossible 2 impossible 1048576 impossible 1 1 impossible 1 1 1 1 impossible 1048576 impossible 1048576 impossible 1 1 impossible impossible impossible 1 1048576 i...
result:
wrong answer 8th lines differ - expected: '2', found: '1048576'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 20
Accepted
Test #35:
score: 20
Accepted
time: 210ms
memory: 64356kb
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
Accepted
time: 211ms
memory: 63804kb
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:
ok 100000 lines
Test #37:
score: 20
Accepted
time: 214ms
memory: 64376kb
input:
100000 100000 315328227 565342348 172493343 423278396 47077854 218308141 77736924 280882803 578420376 829121844 456477365 706164084 572351871 823109648 47238838 218708768 818302749 971917023 250574858 500783122 101021436 327649552 386731775 636229046 560750614 811328057 649806442 888787931 89426598 ...
output:
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ...
result:
ok 100000 lines
Test #38:
score: 20
Accepted
time: 197ms
memory: 64316kb
input:
100000 100000 532703099 533766917 18747285 19717390 259741440 260161102 33247104 34339796 221460611 222216066 101759380 103356345 868641980 869660917 400488522 402221013 626943992 628192337 732367406 733994895 796371835 798306228 496636511 498600178 946211536 947345154 866952254 868236697 743150932 ...
output:
impossible 367 impossible impossible 105 3 impossible 12 impossible impossible 8 impossible 108 impossible impossible impossible 126 impossible impossible impossible impossible impossible 251 impossible impossible impossible impossible impossible 277 54 impossible impossible 50 impossible 34 impossi...
result:
ok 100000 lines
Test #39:
score: 20
Accepted
time: 194ms
memory: 64388kb
input:
100000 100000 92218679 95179758 317492416 320745639 733100351 736164573 961855441 965128977 837782167 840987990 17497768 20657218 448274654 451383491 900836773 903892815 285698089 288672515 717206068 720360660 350272947 353502098 539452749 542535367 320153387 323421078 549859328 552774077 407596307 ...
output:
317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 317 ...
result:
ok 100000 lines
Test #40:
score: 20
Accepted
time: 220ms
memory: 64288kb
input:
100000 100000 744013029 744524903 471220871 471690214 120307805 120799735 926899213 927378946 753737949 754240556 361494837 361945312 133903676 134394731 330399973 330949740 34749028 35247553 430334132 430795521 362526758 363012637 266295097 266798513 702502851 703011578 848053622 848544848 78244603...
output:
impossible 685 impossible 1091 162 impossible impossible impossible 321 345 impossible impossible 369 impossible impossible impossible 945 404 impossible impossible 151 349 impossible 923 impossible 1194 654 impossible impossible impossible 333 89 975 1373 impossible 203 282 537 impossible 579 impos...
result:
ok 100000 lines
Subtask #6:
score: 0
Skipped
Dependency #1:
0%