QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#204160 | #7182. Very Sparse Table | NemanjaSo2005 | AC ✓ | 1650ms | 46524kb | C++14 | 1.7kb | 2023-10-07 04:32:31 | 2023-10-07 04:32:32 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int N;
set<pair<int,int>> E;
vector<pair<int,int>> V;
set<int> S[70000];
bool cmp(pair<int,int> a,pair<int,int> b){
int x=a.second-a.first;
int y=b.second-b.first;
return x<y;
}
void dodaj(int a,int b){
if(b==a+1)
return;
E.insert({a,b});
return;
}
void resi(int L,int R){
if(R-L+1<=4)
return;
vector<int> H;
H.push_back(L-1);
int sq=round(sqrt(R-L+1));
for(int i=L+sq-1;i<=R;i+=sq){
H.push_back(i);
// cout<<i<<endl;
}
H.push_back(R+1);
for(int i=1;i+1<H.size();i++){
for(int j=H[i-1]+1;j<H[i];j++)
dodaj(j,H[i]);
for(int j=H[i]+1;j<H[i+1];j++)
dodaj(H[i],j);
}
for(int i=1;i+1<H.size();i++)
for(int j=i+1;j+1<H.size();j++)
dodaj(H[i],H[j]);
for(int i=1;i<H.size();i++)
resi(H[i-1]+1,H[i]-1);
}
int main(){
cin>>N;
for(int i=0;i<N;i++)
S[i].insert(i+1);
resi(0,N);
for(auto it=E.begin();it!=E.end();it++)
V.push_back(*it);
sort(V.begin(),V.end(),cmp);
cout<<V.size()<<"\n";
for(int i=0;i<V.size();i++){
int a=V[i].first;
int c=V[i].second;
int b;
for(auto it=S[a].begin();it!=S[a].end();it++){
int k=*it;
if(S[k].find(c)!=S[k].end()){
b=k;
break;
}
}
cout<<a<<" "<<b<<" "<<c<<endl;
S[a].insert(c);
}
int Q;
cin>>Q;
while(Q--){
int a,b;
cin>>a>>b;
cout<<a<<" ";
while(a!=b){
auto it=S[a].upper_bound(b);
it--;
a=*it;
cout<<a<<" ";
}
cout<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6684kb
input:
9 45 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 4 3 5 3 6 3 7 3 8 3 9 4 5 4 6 4 7 4 8 4 9 5 6 5 7 5 8 5 9 6 7 6 8 6 9 7 8 7 9 8 9
output:
8 0 1 2 2 3 4 3 4 5 5 6 7 6 7 8 2 3 5 5 6 8 2 5 8 0 1 0 2 0 2 3 0 2 4 0 2 5 0 2 5 6 0 2 5 7 0 2 8 0 2 8 9 1 2 1 2 3 1 2 4 1 2 5 1 2 5 6 1 2 5 7 1 2 8 1 2 8 9 2 3 2 4 2 5 2 5 6 2 5 7 2 8 2 8 9 3 4 3 5 3 5 6 3 5 7 3 5 8 3 5 8 9 4 5 4 5 6 4 5 7 4 5 8 4 5 8 9 5 6 5 7 ...
result:
ok edges: 8
Test #2:
score: 0
Accepted
time: 0ms
memory: 6784kb
input:
30 465 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 2 3 2 4 2 5 2 6...
output:
51 1 2 3 27 28 29 25 26 27 23 24 25 21 22 23 19 20 21 17 18 19 15 16 17 13 14 15 11 12 13 9 10 11 7 8 9 5 6 7 3 4 5 26 27 29 17 19 20 5 7 8 14 15 17 20 21 23 2 3 5 23 25 26 11 13 14 8 9 11 23 25 27 11 13 15 1 2 5 13 14 17 5 7 9 7 8 11 25 26 29 17 19 21 19 20 23 23 27 28 24 25 29 0 1 5 18 19 23 17 21...
result:
ok edges: 51
Test #3:
score: 0
Accepted
time: 291ms
memory: 7052kb
input:
736 200000 170 268 126 166 565 723 664 735 61 524 226 234 146 314 217 272 294 713 115 381 563 706 74 567 552 614 120 211 472 620 213 432 488 623 447 564 96 129 331 354 79 677 50 547 174 568 56 129 189 227 55 701 244 253 264 715 154 220 380 657 46 390 53 161 325 537 666 696 64 465 391 659 284 448 207...
output:
2687 73 74 75 451 452 453 449 450 451 446 447 448 80 81 82 78 79 80 444 445 446 76 77 78 441 442 443 439 440 441 436 437 438 434 435 436 454 455 456 628 629 630 630 631 632 71 72 73 431 432 433 429 430 431 191 192 193 193 194 195 427 428 429 68 69 70 633 634 635 66 67 68 458 459 460 169 170 171 171 ...
result:
ok edges: 2687
Test #4:
score: 0
Accepted
time: 1648ms
memory: 46156kb
input:
65536 200000 51949 58727 7943 43298 6290 7369 41493 53070 24229 36675 28087 49947 11703 48217 19923 24739 2144 59777 53830 56793 13509 37211 2300 38595 27415 42879 24616 48531 58341 63327 20628 38407 48616 60290 7450 61685 37010 47595 22164 42732 19181 29850 35383 43587 39257 44397 19340 45183 34523...
output:
358274 4245 4246 4247 4243 4244 4245 40727 40728 40729 56127 56128 56129 49475 49476 49477 60289 60290 60291 40729 40730 40731 40731 40732 40733 49473 49474 49475 20513 20514 20515 40733 40734 40735 40735 40736 40737 4247 4248 4249 49471 49472 49473 20511 20512 20513 20509 20510 20511 49469 49470 49...
result:
ok edges: 358274
Test #5:
score: 0
Accepted
time: 0ms
memory: 6768kb
input:
0 0
output:
0
result:
ok edges: 0
Test #6:
score: 0
Accepted
time: 2ms
memory: 6736kb
input:
1 1 0 1
output:
0 0 1
result:
ok edges: 0
Test #7:
score: 0
Accepted
time: 1ms
memory: 6708kb
input:
2 3 0 1 0 2 1 2
output:
0 0 1 0 1 2 1 2
result:
ok edges: 0
Test #8:
score: 0
Accepted
time: 2ms
memory: 6748kb
input:
3 6 0 1 0 2 0 3 1 2 1 3 2 3
output:
0 0 1 0 1 2 0 1 2 3 1 2 1 2 3 2 3
result:
ok edges: 0
Test #9:
score: 0
Accepted
time: 1588ms
memory: 46524kb
input:
65535 200000 35006 46944 17075 57351 24605 50445 5938 60705 15221 40233 28599 38915 1132 35574 8555 31494 13644 35806 44940 55401 9503 59206 21011 26540 41156 62487 57510 64305 9254 25610 17301 47249 34083 49167 48018 64394 38855 62175 15464 22525 23728 60275 54028 63810 22711 53902 5984 48625 5838 ...
output:
358274 4245 4246 4247 4243 4244 4245 40727 40728 40729 56127 56128 56129 49475 49476 49477 60289 60290 60291 40729 40730 40731 40731 40732 40733 49473 49474 49475 20513 20514 20515 40733 40734 40735 40735 40736 40737 4247 4248 4249 49471 49472 49473 20511 20512 20513 20509 20510 20511 49469 49470 49...
result:
ok edges: 358274
Test #10:
score: 0
Accepted
time: 1650ms
memory: 46108kb
input:
64800 200000 55124 62263 24992 39760 32262 37059 25987 42889 10413 64701 7223 43221 45810 63205 11437 29357 10814 52096 1154 36319 10730 54157 18473 26729 9152 23374 5426 12744 3502 37577 5559 37160 30503 62433 12426 47332 14933 62086 8781 21527 27180 53773 29658 46742 20592 61553 8337 27197 8024 38...
output:
354285 46256 46257 46258 26191 26192 26193 4753 4754 4755 26193 26194 26195 46262 46263 46264 46260 46261 46262 26195 26196 26197 26197 26198 26199 4755 4756 4757 46258 46259 46260 46264 46265 46266 26199 26200 26201 4757 4758 4759 26201 26202 26203 46254 46255 46256 26203 26204 26205 46252 46253 46...
result:
ok edges: 354285
Extra Test:
score: 0
Extra Test Passed