| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 99326 | TadijaSebez | Railway Trip (JOI17_railway_trip) | C++11 | 349 ms | 17392 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
const int N=100050;
const int L=18;
int a[N],S[N],c,mx[N][L],mn[N][L],n,k,q,s,t,m,l,r;
int main()
{
	scanf("%i %i %i",&n,&k,&q);
	for(int i=1;i<=n;i++) scanf("%i",&a[i]);
	for(int i=1;i<=n;i++){ while(c && a[S[c]]<a[i]) c--;mn[i][0]=c?S[c]:i;S[++c]=i;}c=0;
	for(int i=n;i>=1;i--){ while(c && a[S[c]]<a[i]) c--;mx[i][0]=c?S[c]:i;S[++c]=i;}c=0;
	for(int j=1;j<L;j++) for(int i=1;i<=n;i++)
	{
		mn[i][j]=min(mn[mn[i][j-1]][j-1],mn[mx[i][j-1]][j-1]);
		mx[i][j]=max(mx[mn[i][j-1]][j-1],mx[mx[i][j-1]][j-1]);
	}
	while(q--)
	{
		scanf("%i %i",&s,&t);
		if(s>t) swap(s,t);
		int ans=0;
		l=r=s;
		for(int j=L-1;~j;j--) if(max(mx[l][j],mx[r][j])<t)
		{
			ans+=1<<j;
			tie(l,r)=mp(min(mn[l][j],mn[r][j]),max(mx[l][j],mx[r][j]));
		}
		m=r;l=r=t;
		for(int j=L-1;~j;j--) if(min(mn[l][j],mn[r][j])>m)
		{
			ans+=1<<j;
			tie(l,r)=mp(min(mn[l][j],mn[r][j]),max(mx[l][j],mx[r][j]));
		}
		printf("%i\n",ans);
	}
	return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
