#pragma GCC optimize("Ofast,unroll-loops")
#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".out","w",stdout)
#define pb push_back
#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 int mod2 = 1e9 + 7;
const int mod1 = 998244353;
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;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, l, r, mid, l2, r2, center;
int i, s10, s12,k1,k2,s11;
int kk;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
///modwwe
phongbeo();
// checktime
}
bool check(int x,int y)
{
if(y<x) return 0;
return 1;
}
int a[100001];
ib st[17][100001];
stack<int>s;
void phongbeo()
{
cin>>n>>k>>m;
for(int i=1; i<=n; i++)
cin>>a[i];
for(int i=1; i<=n; i++)
{
while(!s.empty()&&a[i]>a[s.top()]) s.pop();
if(i==1)st[0][i].a=i;
else st[0][i].a=s.top();
s.push(i);
}
while(!s.empty())s.pop();
for(int i=n; i>=1; --i)
{
while(!s.empty()&&a[i]>a[s.top()]) s.pop();
if(i==n) st[0][i].b=i;
else st[0][i].b=s.top();
s.push(i);
}
for(int i=1; i<17; i++)
for(int j=1; j<=n; j++)
st[i][j].a=min(st[i-1][st[i-1][j].a].a,st[i-1][st[i-1][j].b].a),
st[i][j].b=max(st[i-1][st[i-1][j].a].b,st[i-1][st[i-1][j].b].b);
for(int i=1; i<=m; i++)
{
cin>>l>>r;
if(l>r) swap(l,r);
s4=0;
l2=l;
r2=l;
for(int i=16; i>=0; i--)
{
if(max(st[i][r2].b,st[i][l2].b)<r)
{
s2=min(st[i][l2].a,st[i][r2].a);
s3=max(st[i][l2].b,st[i][r2].b);
l2=s2;
r2=s3;
s4=s4+(1<<i);
}
}
/// r2 =max(l2->r2) or r2=max(l2+1->r2)
///->r go to smal than r2 is l2 or r2
s3=r2;
l2=r;
r2=r;
r=s3;
for(int i=16; i>=0; --i)
{
if(min(st[i][r2].a,st[i][l2].a)>r)
{
s2=min(st[i][l2].a,st[i][r2].a);
s3=max(st[i][l2].b,st[i][r2].b);
l2=s2;
r2=s3;
s4=s4+(1<<i);
}
}
cout<<s4,down
}
}
Compilation message
railway_trip.cpp:36:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+14' to '2147483647' [-Woverflow]
36 | const int inf = 1e14;
| ^~~~
railway_trip.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
67 | main()
| ^~~~
railway_trip.cpp: In function 'int main()':
railway_trip.cpp:12:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
railway_trip.cpp:71:9: note: in expansion of macro 'fin'
71 | fin(task);
| ^~~
railway_trip.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 fou(x) freopen(x".out","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
railway_trip.cpp:72:9: note: in expansion of macro 'fou'
72 | fou(task);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
2508 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
13 ms |
14264 KB |
Output is correct |
3 |
Correct |
14 ms |
14428 KB |
Output is correct |
4 |
Correct |
13 ms |
14428 KB |
Output is correct |
5 |
Correct |
12 ms |
14428 KB |
Output is correct |
6 |
Correct |
13 ms |
14384 KB |
Output is correct |
7 |
Correct |
13 ms |
14684 KB |
Output is correct |
8 |
Correct |
10 ms |
14632 KB |
Output is correct |
9 |
Correct |
11 ms |
14860 KB |
Output is correct |
10 |
Correct |
10 ms |
14684 KB |
Output is correct |
11 |
Correct |
13 ms |
14896 KB |
Output is correct |
12 |
Correct |
11 ms |
14832 KB |
Output is correct |
13 |
Correct |
12 ms |
14856 KB |
Output is correct |
14 |
Correct |
13 ms |
14728 KB |
Output is correct |
15 |
Correct |
15 ms |
14672 KB |
Output is correct |
16 |
Correct |
12 ms |
14936 KB |
Output is correct |
17 |
Correct |
14 ms |
14672 KB |
Output is correct |
18 |
Correct |
14 ms |
14684 KB |
Output is correct |
19 |
Correct |
12 ms |
14684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
16020 KB |
Output is correct |
2 |
Correct |
53 ms |
15956 KB |
Output is correct |
3 |
Correct |
50 ms |
15956 KB |
Output is correct |
4 |
Correct |
52 ms |
15976 KB |
Output is correct |
5 |
Correct |
51 ms |
15804 KB |
Output is correct |
6 |
Correct |
59 ms |
15924 KB |
Output is correct |
7 |
Correct |
53 ms |
15952 KB |
Output is correct |
8 |
Correct |
57 ms |
16204 KB |
Output is correct |
9 |
Correct |
67 ms |
16416 KB |
Output is correct |
10 |
Correct |
69 ms |
16416 KB |
Output is correct |
11 |
Correct |
66 ms |
16412 KB |
Output is correct |
12 |
Correct |
72 ms |
16204 KB |
Output is correct |
13 |
Correct |
68 ms |
16356 KB |
Output is correct |
14 |
Correct |
65 ms |
15952 KB |
Output is correct |
15 |
Correct |
54 ms |
15852 KB |
Output is correct |
16 |
Correct |
50 ms |
15700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
15932 KB |
Output is correct |
2 |
Correct |
68 ms |
15956 KB |
Output is correct |
3 |
Correct |
39 ms |
16004 KB |
Output is correct |
4 |
Correct |
40 ms |
15956 KB |
Output is correct |
5 |
Correct |
83 ms |
16400 KB |
Output is correct |
6 |
Correct |
61 ms |
16528 KB |
Output is correct |
7 |
Correct |
58 ms |
16460 KB |
Output is correct |
8 |
Correct |
62 ms |
16464 KB |
Output is correct |
9 |
Correct |
57 ms |
16468 KB |
Output is correct |
10 |
Correct |
64 ms |
16448 KB |
Output is correct |
11 |
Correct |
61 ms |
16444 KB |
Output is correct |
12 |
Correct |
57 ms |
16468 KB |
Output is correct |
13 |
Correct |
61 ms |
16468 KB |
Output is correct |
14 |
Correct |
61 ms |
16464 KB |
Output is correct |
15 |
Correct |
61 ms |
16468 KB |
Output is correct |
16 |
Correct |
57 ms |
16464 KB |
Output is correct |
17 |
Correct |
59 ms |
16468 KB |
Output is correct |
18 |
Correct |
64 ms |
16388 KB |
Output is correct |
19 |
Correct |
61 ms |
16452 KB |
Output is correct |
20 |
Correct |
60 ms |
16068 KB |
Output is correct |
21 |
Correct |
39 ms |
15952 KB |
Output is correct |
22 |
Correct |
39 ms |
16096 KB |
Output is correct |
23 |
Correct |
39 ms |
15984 KB |
Output is correct |