#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf = 1e14;
const ll mod2 = 1e9 + 7;
const int mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
if(x+y>=mod2) x-=mod2;
if(x+y<0)x+=mod2;
return x+y;
}
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a, b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
ll n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,t,lim,w,l,r,p ;
int kk;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
// modwwe
phongbeo();
// checktime
}
ib minn[18][200001];
int st[17][100001];
ib a[100001];
vector<int> v;
ib mer(ib a,ib b)
{
if(a.a<=b.a) return a;
return b;
}
int getmin(int l,int r)
{
int k=31-__builtin_clz(r-l+1);
return mer(minn[k][l],minn[k][r-mask(k)+1]).b;
}
void phongbeo()
{
cin>>n>>k;
for(int i=1; i<=n; i++)
cin>>a[i].a>>a[i].b,v.pb(a[i].b),v.pb(a[i].a);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
m=v.size();
for(int i=1; i<=n; i++)
{
a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1;
a[i].b=lower_bound(v.begin(),v.end(),a[i].b)-v.begin()+1;
}
for(int i=1; i<=m; i++)
minn[0][i]= {m+1,i};
for(int i=1; i<=n; i++)
{
if(a[i].a<=minn[0][a[i].b].a)
minn[0][a[i].b]= {a[i].a,i};
}
for(int i=1; i<18; i++)
for(int j=1; j+mask(i)-1<=m; j++)
minn[i][j]=mer(minn[i-1][j],minn[i-1][j+mask(i-1)]);
for(int i=1; i<=n; i++)
{
st[0][i]=getmin(a[i].a,a[i].b);
}
for(int i=1; i<17; i++)
for(int j=1; j<=n; j++)
st[i][j]=st[i-1][st[i-1][j]];
while(k--)
{
down
cin>>l>>r;
if(a[l].b>a[r].b)
{
cout<<"impossible";
continue;
}
else if(l==r)
{
cout<<0;
continue;
}
else if(a[l].b>=a[r].a&&a[r].b>=a[l].b)
{
cout<<1;
continue;
}
else
{
s4=0;
for(int i=16; i>=0; --i)
if(a[st[i][r]].a>a[l].b)
{
s4=s4+(1<<i);
r=st[i][r];
}
if(s4==131071)
{
cout<<"impossible";
continue;
}
cout<<s4+2;
}
}
}
Compilation message
events.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
75 | main()
| ^~~~
events.cpp: In function 'void phongbeo()':
events.cpp:124:59: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
124 | minn[i][j]=mer(minn[i-1][j],minn[i-1][j+mask(i-1)]);
| ~^~
events.cpp:16:21: note: in definition of macro 'mask'
16 | #define mask(k) (1<<k)
| ^
events.cpp: In function 'int main()':
events.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
events.cpp:79:9: note: in expansion of macro 'fin'
79 | fin(task);
| ^~~
events.cpp:14:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define fou(x) freopen(x".ans","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
events.cpp:80:9: note: in expansion of macro 'fou'
80 | fou(task);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
98 ms |
45764 KB |
Output is correct |
3 |
Correct |
110 ms |
46028 KB |
Output is correct |
4 |
Correct |
139 ms |
46016 KB |
Output is correct |
5 |
Correct |
124 ms |
49868 KB |
Output is correct |
6 |
Correct |
127 ms |
50888 KB |
Output is correct |
7 |
Correct |
130 ms |
51904 KB |
Output is correct |
8 |
Correct |
139 ms |
73932 KB |
Output is correct |
9 |
Correct |
135 ms |
73856 KB |
Output is correct |
10 |
Correct |
103 ms |
45504 KB |
Output is correct |
11 |
Correct |
110 ms |
56764 KB |
Output is correct |
12 |
Correct |
61 ms |
45760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
4432 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
2 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4900 KB |
Output is correct |
7 |
Correct |
2 ms |
4944 KB |
Output is correct |
8 |
Correct |
2 ms |
4944 KB |
Output is correct |
9 |
Correct |
2 ms |
4688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
4432 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
2 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4900 KB |
Output is correct |
7 |
Correct |
2 ms |
4944 KB |
Output is correct |
8 |
Correct |
2 ms |
4944 KB |
Output is correct |
9 |
Correct |
2 ms |
4688 KB |
Output is correct |
10 |
Correct |
1 ms |
4432 KB |
Output is correct |
11 |
Correct |
1 ms |
4688 KB |
Output is correct |
12 |
Correct |
2 ms |
6992 KB |
Output is correct |
13 |
Correct |
2 ms |
6992 KB |
Output is correct |
14 |
Correct |
2 ms |
4944 KB |
Output is correct |
15 |
Correct |
2 ms |
4944 KB |
Output is correct |
16 |
Correct |
2 ms |
4944 KB |
Output is correct |
17 |
Correct |
2 ms |
5200 KB |
Output is correct |
18 |
Correct |
1 ms |
4688 KB |
Output is correct |
19 |
Correct |
23 ms |
8096 KB |
Output is correct |
20 |
Correct |
26 ms |
7796 KB |
Output is correct |
21 |
Correct |
33 ms |
8028 KB |
Output is correct |
22 |
Correct |
23 ms |
8272 KB |
Output is correct |
23 |
Correct |
22 ms |
8272 KB |
Output is correct |
24 |
Correct |
19 ms |
8956 KB |
Output is correct |
25 |
Correct |
22 ms |
7504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6480 KB |
Output is correct |
2 |
Correct |
1 ms |
4432 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
2 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4900 KB |
Output is correct |
7 |
Correct |
2 ms |
4944 KB |
Output is correct |
8 |
Correct |
2 ms |
4944 KB |
Output is correct |
9 |
Correct |
2 ms |
4688 KB |
Output is correct |
10 |
Correct |
2 ms |
4568 KB |
Output is correct |
11 |
Correct |
2 ms |
4688 KB |
Output is correct |
12 |
Correct |
2 ms |
4944 KB |
Output is correct |
13 |
Correct |
2 ms |
6992 KB |
Output is correct |
14 |
Correct |
2 ms |
4944 KB |
Output is correct |
15 |
Correct |
3 ms |
4944 KB |
Output is correct |
16 |
Correct |
2 ms |
4944 KB |
Output is correct |
17 |
Correct |
2 ms |
4944 KB |
Output is correct |
18 |
Correct |
2 ms |
4688 KB |
Output is correct |
19 |
Correct |
76 ms |
43900 KB |
Output is correct |
20 |
Correct |
75 ms |
42432 KB |
Output is correct |
21 |
Correct |
85 ms |
43720 KB |
Output is correct |
22 |
Correct |
87 ms |
53952 KB |
Output is correct |
23 |
Correct |
100 ms |
71616 KB |
Output is correct |
24 |
Correct |
99 ms |
70604 KB |
Output is correct |
25 |
Correct |
26 ms |
20424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
46708 KB |
Output is correct |
2 |
Correct |
125 ms |
42952 KB |
Output is correct |
3 |
Correct |
132 ms |
45244 KB |
Output is correct |
4 |
Correct |
141 ms |
73916 KB |
Output is correct |
5 |
Correct |
113 ms |
46272 KB |
Output is correct |
6 |
Correct |
134 ms |
73664 KB |
Output is correct |
7 |
Correct |
139 ms |
73544 KB |
Output is correct |
8 |
Correct |
124 ms |
71616 KB |
Output is correct |
9 |
Correct |
100 ms |
71576 KB |
Output is correct |
10 |
Correct |
145 ms |
73088 KB |
Output is correct |
11 |
Correct |
124 ms |
73080 KB |
Output is correct |
12 |
Correct |
130 ms |
72744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
98 ms |
45764 KB |
Output is correct |
3 |
Correct |
110 ms |
46028 KB |
Output is correct |
4 |
Correct |
139 ms |
46016 KB |
Output is correct |
5 |
Correct |
124 ms |
49868 KB |
Output is correct |
6 |
Correct |
127 ms |
50888 KB |
Output is correct |
7 |
Correct |
130 ms |
51904 KB |
Output is correct |
8 |
Correct |
139 ms |
73932 KB |
Output is correct |
9 |
Correct |
135 ms |
73856 KB |
Output is correct |
10 |
Correct |
103 ms |
45504 KB |
Output is correct |
11 |
Correct |
110 ms |
56764 KB |
Output is correct |
12 |
Correct |
61 ms |
45760 KB |
Output is correct |
13 |
Correct |
1 ms |
6480 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
2 ms |
4944 KB |
Output is correct |
16 |
Correct |
2 ms |
4944 KB |
Output is correct |
17 |
Correct |
2 ms |
4944 KB |
Output is correct |
18 |
Correct |
3 ms |
4900 KB |
Output is correct |
19 |
Correct |
2 ms |
4944 KB |
Output is correct |
20 |
Correct |
2 ms |
4944 KB |
Output is correct |
21 |
Correct |
2 ms |
4688 KB |
Output is correct |
22 |
Correct |
1 ms |
4432 KB |
Output is correct |
23 |
Correct |
1 ms |
4688 KB |
Output is correct |
24 |
Correct |
2 ms |
6992 KB |
Output is correct |
25 |
Correct |
2 ms |
6992 KB |
Output is correct |
26 |
Correct |
2 ms |
4944 KB |
Output is correct |
27 |
Correct |
2 ms |
4944 KB |
Output is correct |
28 |
Correct |
2 ms |
4944 KB |
Output is correct |
29 |
Correct |
2 ms |
5200 KB |
Output is correct |
30 |
Correct |
1 ms |
4688 KB |
Output is correct |
31 |
Correct |
23 ms |
8096 KB |
Output is correct |
32 |
Correct |
26 ms |
7796 KB |
Output is correct |
33 |
Correct |
33 ms |
8028 KB |
Output is correct |
34 |
Correct |
23 ms |
8272 KB |
Output is correct |
35 |
Correct |
22 ms |
8272 KB |
Output is correct |
36 |
Correct |
19 ms |
8956 KB |
Output is correct |
37 |
Correct |
22 ms |
7504 KB |
Output is correct |
38 |
Correct |
2 ms |
4568 KB |
Output is correct |
39 |
Correct |
2 ms |
4688 KB |
Output is correct |
40 |
Correct |
2 ms |
4944 KB |
Output is correct |
41 |
Correct |
2 ms |
6992 KB |
Output is correct |
42 |
Correct |
2 ms |
4944 KB |
Output is correct |
43 |
Correct |
3 ms |
4944 KB |
Output is correct |
44 |
Correct |
2 ms |
4944 KB |
Output is correct |
45 |
Correct |
2 ms |
4944 KB |
Output is correct |
46 |
Correct |
2 ms |
4688 KB |
Output is correct |
47 |
Correct |
76 ms |
43900 KB |
Output is correct |
48 |
Correct |
75 ms |
42432 KB |
Output is correct |
49 |
Correct |
85 ms |
43720 KB |
Output is correct |
50 |
Correct |
87 ms |
53952 KB |
Output is correct |
51 |
Correct |
100 ms |
71616 KB |
Output is correct |
52 |
Correct |
99 ms |
70604 KB |
Output is correct |
53 |
Correct |
26 ms |
20424 KB |
Output is correct |
54 |
Correct |
99 ms |
46708 KB |
Output is correct |
55 |
Correct |
125 ms |
42952 KB |
Output is correct |
56 |
Correct |
132 ms |
45244 KB |
Output is correct |
57 |
Correct |
141 ms |
73916 KB |
Output is correct |
58 |
Correct |
113 ms |
46272 KB |
Output is correct |
59 |
Correct |
134 ms |
73664 KB |
Output is correct |
60 |
Correct |
139 ms |
73544 KB |
Output is correct |
61 |
Correct |
124 ms |
71616 KB |
Output is correct |
62 |
Correct |
100 ms |
71576 KB |
Output is correct |
63 |
Correct |
145 ms |
73088 KB |
Output is correct |
64 |
Correct |
124 ms |
73080 KB |
Output is correct |
65 |
Correct |
130 ms |
72744 KB |
Output is correct |
66 |
Correct |
2 ms |
6480 KB |
Output is correct |
67 |
Correct |
94 ms |
45756 KB |
Output is correct |
68 |
Correct |
117 ms |
45896 KB |
Output is correct |
69 |
Correct |
130 ms |
45772 KB |
Output is correct |
70 |
Correct |
117 ms |
48504 KB |
Output is correct |
71 |
Correct |
114 ms |
48840 KB |
Output is correct |
72 |
Correct |
123 ms |
51836 KB |
Output is correct |
73 |
Correct |
148 ms |
73844 KB |
Output is correct |
74 |
Correct |
137 ms |
73856 KB |
Output is correct |
75 |
Correct |
111 ms |
46204 KB |
Output is correct |
76 |
Correct |
113 ms |
56776 KB |
Output is correct |
77 |
Correct |
62 ms |
45764 KB |
Output is correct |
78 |
Correct |
1 ms |
6480 KB |
Output is correct |
79 |
Correct |
2 ms |
6992 KB |
Output is correct |
80 |
Correct |
2 ms |
4944 KB |
Output is correct |
81 |
Correct |
2 ms |
4944 KB |
Output is correct |
82 |
Correct |
2 ms |
4944 KB |
Output is correct |
83 |
Correct |
2 ms |
6992 KB |
Output is correct |
84 |
Correct |
2 ms |
4944 KB |
Output is correct |
85 |
Correct |
1 ms |
4688 KB |
Output is correct |
86 |
Correct |
23 ms |
8008 KB |
Output is correct |
87 |
Correct |
26 ms |
7760 KB |
Output is correct |
88 |
Correct |
29 ms |
8016 KB |
Output is correct |
89 |
Correct |
24 ms |
8284 KB |
Output is correct |
90 |
Correct |
20 ms |
8952 KB |
Output is correct |
91 |
Correct |
19 ms |
8776 KB |
Output is correct |
92 |
Correct |
22 ms |
8264 KB |
Output is correct |
93 |
Correct |
70 ms |
43968 KB |
Output is correct |
94 |
Correct |
68 ms |
43196 KB |
Output is correct |
95 |
Correct |
73 ms |
43968 KB |
Output is correct |
96 |
Correct |
82 ms |
53952 KB |
Output is correct |
97 |
Correct |
91 ms |
71468 KB |
Output is correct |
98 |
Correct |
91 ms |
71616 KB |
Output is correct |
99 |
Correct |
24 ms |
18624 KB |
Output is correct |
100 |
Correct |
128 ms |
73452 KB |
Output is correct |
101 |
Correct |
133 ms |
73408 KB |
Output is correct |
102 |
Correct |
124 ms |
73600 KB |
Output is correct |
103 |
Correct |
131 ms |
73160 KB |
Output is correct |
104 |
Correct |
117 ms |
72924 KB |
Output is correct |
105 |
Correct |
130 ms |
73152 KB |
Output is correct |
106 |
Correct |
102 ms |
39104 KB |
Output is correct |
107 |
Correct |
121 ms |
45256 KB |
Output is correct |
108 |
Correct |
104 ms |
46072 KB |
Output is correct |
109 |
Correct |
110 ms |
46072 KB |
Output is correct |
110 |
Correct |
136 ms |
73416 KB |
Output is correct |
111 |
Correct |
119 ms |
73444 KB |
Output is correct |