이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
int tree[500001][4]={0}; //1: left, 2: right. 3: gap 0: rightgae
int sn[1000001]={0};
int sv[500000][2]={0};
int n;
long long int p;
int tot(int here,int gap,int wichi){
int cnt=0,pp=-1,i,prev=-1,prevn=-1;
if(wichi>1){
do{
// printf("%d",here);
prevn=here;
if(tree[here][3]>gap){
cnt+=tree[here][0];
here=tree[here][1];
prev=1;
}else{
tree[here][0]++;
here=tree[here][2];
prev=2;
}
}while(here>0);
}
tree[wichi][3]=gap;
tree[wichi][0]=1;
if(prev>-1) tree[prevn][prev]=wichi;
return cnt;
}
int main(){
int im,i;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&im);
sn[im]=i;
}
for(i=0;i<n;i++){
scanf("%d",&im);
// printf("!");
p+=tot(1,sn[im],i+1);
}
printf("%lld",p);
// fclose(stdin);
// fclose(stdout);
}
| # | 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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |