# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
219531 | MKopchev | Triple Jump (JOI19_jumps) | C++14 | 4070 ms | 33896 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nmax=(1<<19)+42,MX=20;
int n,q;
int inp[nmax];
vector< pair<int,int> > start;
pair<int,int> table[20][nmax];
int mem[nmax];
pair<int/*value*/,int/*id*/> take_mx(int l,int r)
{
int st=mem[r-l+1];
return max(table[st][l],table[st][r-(1<<st)+1]);
}
int query()
{
int l,r;
scanf("%i%i",&l,&r);
int ret=0;
for(auto k:start)
{
int a=k.first;
int b=k.second;
if(l<=a&&b+b-a<=r)
{
ret=max(ret,inp[a]+inp[b]+take_mx(b+b-a,r).first);
}
}
return ret;
}
stack<int> active;
int main()
{
scanf("%i",&n);
for(int i=1;i<=n;i++)scanf("%i",&inp[i]);
for(int i=1;i<=n;i++)
table[0][i]={inp[i],i};
for(int st=1;(1<<st)<=n;st++)
for(int i=1;i+(1<<st)-1<=n;i++)
table[st][i]=max(table[st-1][i],table[st-1][i+(1<<(st-1))]);
for(int i=1;i<=n;i++)
{
while((1<<(mem[i]+1))<=i)mem[i]++;
}
for(int i=1;i<=n;i++)
{
while(active.size()&&inp[active.top()]<=inp[i])
{
start.push_back({active.top(),i});
active.pop();
}
if(active.size())start.push_back({active.top(),i});
active.push(i);
}
scanf("%i",&q);
for(int i=1;i<=q;i++)
printf("%i\n",query());
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... |