#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
vector<vector<int> >num;
vector<pair<int , int > >cmp;
vector<int>pow2;
int ind[200000] , platz[200000];
int lift[300000][20], seg[20][800000];
unordered_map<int , int>trans;
int sucher(int id , int l , int r , int gewl , int gewr , int ver){
if(gewl > r || l > gewr){
return mod;
}
if(gewl <= l && r <= gewr){
return seg[ver][id];
}
int m = (l + r)/2;
return min(sucher(id * 2 , l , m , gewl , gewr , ver) , sucher(id * 2 + 1 , m + 1 , r , gewl ,gewr , ver));
}
int main(){
int menge , numm , nummer , que , len;
cin >> menge >> que;
for(int i = 1 ; i < 1000000 ; i*= 2){
pow2.push_back(i);
}
for(len = 1 ; len < 100000 ; len *= 2);
for(int i = 0 ; i < menge ; i++){
platz[i + 1] = -1;
cin >> numm >> nummer;
num.push_back({nummer , numm , i + 1});
cmp.push_back({numm , 0});
cmp.push_back({nummer , 1});
}
int pl = 0;// does matter sort begin?
sort(cmp.begin() , cmp.end());
sort(num.begin() , num.end());
for(int i = cmp.size() - 1 ; i >= 0; i--){
if(trans[cmp[i].first] == 0 && cmp[i].second == 1){
// cout << cmp[i].first << ' ';
pl++;
}//////////////////////////////////////////////////////////////
trans[cmp[i].first] = pl;
}
pl++;
// cout << "\n";
for(int i = 0 ; i < num.size() ; i++){
// cout << num[i][0] << ' ' << num[i][1] << "\n";
num[i][0] = pl - trans[num[i][0]];
num[i][1] = pl - trans[num[i][1]];
ind[num[i][2]] = i;
if(platz[num[i][0]] == -1){
platz[num[i][0]] = i;
}
lift[i][0] = num[i][1];
// cout << num[i][0]<< ' ' << num[i][1]<< "\n\n";
}
for(int i = 1 ; i < 20 ; i++){
// cout << i << ' ';
for(int j = 0 ; j < 100000; j++){
seg[i - 1][j + len] = lift[j][i - 1];
}
for(int j = len - 1 ; j > 0 ; j--){
seg[i - 1][j] = min(seg[i - 1][j * 2] , seg[i - 1][j * 2 + 1]);
}
for(int j = 0 ; j < num.size(); j++){
lift[j][i] = sucher(1 , 1 , len , platz[lift[j][i - 1]] + 1 , j + 1 , i - 1);
}
// cout << i << " \n";
}
// for(int i = 0 ; i < menge ; i++){
// for(int j = 0 ; j < 20 ; j++){
// cout << lift[i][j] << ' ';
// }
// cout << "\n";
// }
int erg;
while(que--){
erg = 0;
cin >> numm >> nummer;
if(numm == nummer){
cout << 0 << "\n";
continue;
}
numm = ind[numm];
nummer = ind[nummer];
// cout << numm <<' ' << nummer << "\n";
if(num[numm][0] > num[nummer][0]){
cout << "impossible\n";
continue;
}
int be = nummer , en = nummer;
for(int i = 19 ; i >= 0 ; i--){
int comp = sucher(1 , 1, len , be + 1 , en + 1 , i ) ;
// cout << comp << " ";
if( comp > num[numm][0]){
// cout << i << ' ' ;
erg += pow2[i];
be = platz[comp];
}
}
// cout << "\n";
// cout << nummer << " \n";
be = platz[sucher(1 , 1, len , be + 1 , en + 1 , 0 )];
// cout << numm << ' ' << be << ' ' << en << "\n";
if(numm >= be){
cout << erg + 1 << "\n";
}
else{
cout << "impossible\n";
}
}
}
Compilation message
events.cpp: In function 'int main()':
events.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0 ; i < num.size() ; i++){
| ~~^~~~~~~~~~~~
events.cpp:65:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j = 0 ; j < num.size(); j++){
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
17620 KB |
Output is correct |
2 |
Correct |
986 ms |
38776 KB |
Output is correct |
3 |
Correct |
1065 ms |
38624 KB |
Output is correct |
4 |
Correct |
1077 ms |
38592 KB |
Output is correct |
5 |
Correct |
1095 ms |
38828 KB |
Output is correct |
6 |
Correct |
1051 ms |
39084 KB |
Output is correct |
7 |
Correct |
1033 ms |
39388 KB |
Output is correct |
8 |
Correct |
799 ms |
43868 KB |
Output is correct |
9 |
Correct |
811 ms |
43920 KB |
Output is correct |
10 |
Correct |
967 ms |
39148 KB |
Output is correct |
11 |
Correct |
944 ms |
40120 KB |
Output is correct |
12 |
Correct |
687 ms |
39056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
17620 KB |
Output is correct |
2 |
Correct |
12 ms |
17592 KB |
Output is correct |
3 |
Correct |
16 ms |
17848 KB |
Output is correct |
4 |
Correct |
16 ms |
17784 KB |
Output is correct |
5 |
Correct |
16 ms |
17876 KB |
Output is correct |
6 |
Correct |
19 ms |
17792 KB |
Output is correct |
7 |
Correct |
15 ms |
17856 KB |
Output is correct |
8 |
Correct |
16 ms |
17872 KB |
Output is correct |
9 |
Correct |
15 ms |
17792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
17620 KB |
Output is correct |
2 |
Correct |
12 ms |
17592 KB |
Output is correct |
3 |
Correct |
16 ms |
17848 KB |
Output is correct |
4 |
Correct |
16 ms |
17784 KB |
Output is correct |
5 |
Correct |
16 ms |
17876 KB |
Output is correct |
6 |
Correct |
19 ms |
17792 KB |
Output is correct |
7 |
Correct |
15 ms |
17856 KB |
Output is correct |
8 |
Correct |
16 ms |
17872 KB |
Output is correct |
9 |
Correct |
15 ms |
17792 KB |
Output is correct |
10 |
Correct |
12 ms |
17620 KB |
Output is correct |
11 |
Correct |
11 ms |
17620 KB |
Output is correct |
12 |
Correct |
18 ms |
17876 KB |
Output is correct |
13 |
Correct |
16 ms |
17876 KB |
Output is correct |
14 |
Correct |
16 ms |
17876 KB |
Output is correct |
15 |
Correct |
16 ms |
17824 KB |
Output is correct |
16 |
Correct |
16 ms |
17876 KB |
Output is correct |
17 |
Correct |
19 ms |
17820 KB |
Output is correct |
18 |
Correct |
16 ms |
17764 KB |
Output is correct |
19 |
Correct |
522 ms |
20184 KB |
Output is correct |
20 |
Correct |
557 ms |
20160 KB |
Output is correct |
21 |
Correct |
376 ms |
20516 KB |
Output is correct |
22 |
Correct |
326 ms |
20492 KB |
Output is correct |
23 |
Correct |
315 ms |
20504 KB |
Output is correct |
24 |
Correct |
304 ms |
20528 KB |
Output is correct |
25 |
Correct |
483 ms |
20076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
17620 KB |
Output is correct |
2 |
Correct |
12 ms |
17592 KB |
Output is correct |
3 |
Correct |
16 ms |
17848 KB |
Output is correct |
4 |
Correct |
16 ms |
17784 KB |
Output is correct |
5 |
Correct |
16 ms |
17876 KB |
Output is correct |
6 |
Correct |
19 ms |
17792 KB |
Output is correct |
7 |
Correct |
15 ms |
17856 KB |
Output is correct |
8 |
Correct |
16 ms |
17872 KB |
Output is correct |
9 |
Correct |
15 ms |
17792 KB |
Output is correct |
10 |
Correct |
13 ms |
17620 KB |
Output is correct |
11 |
Correct |
12 ms |
17620 KB |
Output is correct |
12 |
Correct |
16 ms |
17836 KB |
Output is correct |
13 |
Correct |
17 ms |
17784 KB |
Output is correct |
14 |
Correct |
17 ms |
17768 KB |
Output is correct |
15 |
Correct |
16 ms |
17876 KB |
Output is correct |
16 |
Correct |
17 ms |
17876 KB |
Output is correct |
17 |
Correct |
16 ms |
17912 KB |
Output is correct |
18 |
Correct |
16 ms |
17748 KB |
Output is correct |
19 |
Correct |
467 ms |
39996 KB |
Output is correct |
20 |
Correct |
430 ms |
39064 KB |
Output is correct |
21 |
Correct |
416 ms |
39664 KB |
Output is correct |
22 |
Correct |
470 ms |
40644 KB |
Output is correct |
23 |
Correct |
441 ms |
44612 KB |
Output is correct |
24 |
Correct |
476 ms |
44700 KB |
Output is correct |
25 |
Correct |
327 ms |
34448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
997 ms |
38612 KB |
Output is correct |
2 |
Correct |
1071 ms |
38564 KB |
Output is correct |
3 |
Correct |
1125 ms |
38592 KB |
Output is correct |
4 |
Correct |
825 ms |
43892 KB |
Output is correct |
5 |
Correct |
1059 ms |
38968 KB |
Output is correct |
6 |
Correct |
1099 ms |
43496 KB |
Output is correct |
7 |
Correct |
1223 ms |
43568 KB |
Output is correct |
8 |
Correct |
1222 ms |
43644 KB |
Output is correct |
9 |
Correct |
507 ms |
42836 KB |
Output is correct |
10 |
Correct |
1181 ms |
43208 KB |
Output is correct |
11 |
Correct |
1056 ms |
43056 KB |
Output is correct |
12 |
Correct |
1096 ms |
43216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
17620 KB |
Output is correct |
2 |
Correct |
986 ms |
38776 KB |
Output is correct |
3 |
Correct |
1065 ms |
38624 KB |
Output is correct |
4 |
Correct |
1077 ms |
38592 KB |
Output is correct |
5 |
Correct |
1095 ms |
38828 KB |
Output is correct |
6 |
Correct |
1051 ms |
39084 KB |
Output is correct |
7 |
Correct |
1033 ms |
39388 KB |
Output is correct |
8 |
Correct |
799 ms |
43868 KB |
Output is correct |
9 |
Correct |
811 ms |
43920 KB |
Output is correct |
10 |
Correct |
967 ms |
39148 KB |
Output is correct |
11 |
Correct |
944 ms |
40120 KB |
Output is correct |
12 |
Correct |
687 ms |
39056 KB |
Output is correct |
13 |
Correct |
11 ms |
17620 KB |
Output is correct |
14 |
Correct |
12 ms |
17592 KB |
Output is correct |
15 |
Correct |
16 ms |
17848 KB |
Output is correct |
16 |
Correct |
16 ms |
17784 KB |
Output is correct |
17 |
Correct |
16 ms |
17876 KB |
Output is correct |
18 |
Correct |
19 ms |
17792 KB |
Output is correct |
19 |
Correct |
15 ms |
17856 KB |
Output is correct |
20 |
Correct |
16 ms |
17872 KB |
Output is correct |
21 |
Correct |
15 ms |
17792 KB |
Output is correct |
22 |
Correct |
12 ms |
17620 KB |
Output is correct |
23 |
Correct |
11 ms |
17620 KB |
Output is correct |
24 |
Correct |
18 ms |
17876 KB |
Output is correct |
25 |
Correct |
16 ms |
17876 KB |
Output is correct |
26 |
Correct |
16 ms |
17876 KB |
Output is correct |
27 |
Correct |
16 ms |
17824 KB |
Output is correct |
28 |
Correct |
16 ms |
17876 KB |
Output is correct |
29 |
Correct |
19 ms |
17820 KB |
Output is correct |
30 |
Correct |
16 ms |
17764 KB |
Output is correct |
31 |
Correct |
522 ms |
20184 KB |
Output is correct |
32 |
Correct |
557 ms |
20160 KB |
Output is correct |
33 |
Correct |
376 ms |
20516 KB |
Output is correct |
34 |
Correct |
326 ms |
20492 KB |
Output is correct |
35 |
Correct |
315 ms |
20504 KB |
Output is correct |
36 |
Correct |
304 ms |
20528 KB |
Output is correct |
37 |
Correct |
483 ms |
20076 KB |
Output is correct |
38 |
Correct |
13 ms |
17620 KB |
Output is correct |
39 |
Correct |
12 ms |
17620 KB |
Output is correct |
40 |
Correct |
16 ms |
17836 KB |
Output is correct |
41 |
Correct |
17 ms |
17784 KB |
Output is correct |
42 |
Correct |
17 ms |
17768 KB |
Output is correct |
43 |
Correct |
16 ms |
17876 KB |
Output is correct |
44 |
Correct |
17 ms |
17876 KB |
Output is correct |
45 |
Correct |
16 ms |
17912 KB |
Output is correct |
46 |
Correct |
16 ms |
17748 KB |
Output is correct |
47 |
Correct |
467 ms |
39996 KB |
Output is correct |
48 |
Correct |
430 ms |
39064 KB |
Output is correct |
49 |
Correct |
416 ms |
39664 KB |
Output is correct |
50 |
Correct |
470 ms |
40644 KB |
Output is correct |
51 |
Correct |
441 ms |
44612 KB |
Output is correct |
52 |
Correct |
476 ms |
44700 KB |
Output is correct |
53 |
Correct |
327 ms |
34448 KB |
Output is correct |
54 |
Correct |
997 ms |
38612 KB |
Output is correct |
55 |
Correct |
1071 ms |
38564 KB |
Output is correct |
56 |
Correct |
1125 ms |
38592 KB |
Output is correct |
57 |
Correct |
825 ms |
43892 KB |
Output is correct |
58 |
Correct |
1059 ms |
38968 KB |
Output is correct |
59 |
Correct |
1099 ms |
43496 KB |
Output is correct |
60 |
Correct |
1223 ms |
43568 KB |
Output is correct |
61 |
Correct |
1222 ms |
43644 KB |
Output is correct |
62 |
Correct |
507 ms |
42836 KB |
Output is correct |
63 |
Correct |
1181 ms |
43208 KB |
Output is correct |
64 |
Correct |
1056 ms |
43056 KB |
Output is correct |
65 |
Correct |
1096 ms |
43216 KB |
Output is correct |
66 |
Correct |
16 ms |
17620 KB |
Output is correct |
67 |
Correct |
1048 ms |
41572 KB |
Output is correct |
68 |
Correct |
1051 ms |
41664 KB |
Output is correct |
69 |
Correct |
1063 ms |
41600 KB |
Output is correct |
70 |
Correct |
1061 ms |
41932 KB |
Output is correct |
71 |
Correct |
1042 ms |
42284 KB |
Output is correct |
72 |
Correct |
1057 ms |
42308 KB |
Output is correct |
73 |
Correct |
795 ms |
46988 KB |
Output is correct |
74 |
Correct |
799 ms |
46932 KB |
Output is correct |
75 |
Correct |
983 ms |
42064 KB |
Output is correct |
76 |
Correct |
958 ms |
43148 KB |
Output is correct |
77 |
Correct |
681 ms |
41348 KB |
Output is correct |
78 |
Correct |
12 ms |
17620 KB |
Output is correct |
79 |
Correct |
17 ms |
17852 KB |
Output is correct |
80 |
Correct |
17 ms |
17864 KB |
Output is correct |
81 |
Correct |
16 ms |
17876 KB |
Output is correct |
82 |
Correct |
19 ms |
17876 KB |
Output is correct |
83 |
Correct |
15 ms |
17876 KB |
Output is correct |
84 |
Correct |
16 ms |
17848 KB |
Output is correct |
85 |
Correct |
15 ms |
17748 KB |
Output is correct |
86 |
Correct |
514 ms |
20224 KB |
Output is correct |
87 |
Correct |
572 ms |
20116 KB |
Output is correct |
88 |
Correct |
387 ms |
20424 KB |
Output is correct |
89 |
Correct |
338 ms |
20444 KB |
Output is correct |
90 |
Correct |
309 ms |
20544 KB |
Output is correct |
91 |
Correct |
313 ms |
20492 KB |
Output is correct |
92 |
Correct |
477 ms |
20112 KB |
Output is correct |
93 |
Correct |
459 ms |
40080 KB |
Output is correct |
94 |
Correct |
435 ms |
39164 KB |
Output is correct |
95 |
Correct |
421 ms |
39992 KB |
Output is correct |
96 |
Correct |
476 ms |
40800 KB |
Output is correct |
97 |
Correct |
427 ms |
44720 KB |
Output is correct |
98 |
Correct |
490 ms |
44708 KB |
Output is correct |
99 |
Correct |
330 ms |
34552 KB |
Output is correct |
100 |
Correct |
988 ms |
46536 KB |
Output is correct |
101 |
Correct |
1004 ms |
46596 KB |
Output is correct |
102 |
Correct |
1020 ms |
46696 KB |
Output is correct |
103 |
Correct |
995 ms |
46204 KB |
Output is correct |
104 |
Correct |
847 ms |
45940 KB |
Output is correct |
105 |
Correct |
994 ms |
46204 KB |
Output is correct |
106 |
Correct |
888 ms |
39436 KB |
Output is correct |
107 |
Correct |
1004 ms |
41400 KB |
Output is correct |
108 |
Correct |
848 ms |
41816 KB |
Output is correct |
109 |
Correct |
816 ms |
41664 KB |
Output is correct |
110 |
Correct |
823 ms |
46680 KB |
Output is correct |
111 |
Correct |
820 ms |
46740 KB |
Output is correct |