Submission #2630

#TimeUsernameProblemLanguageResultExecution timeMemory
2630jihoon공장 (KOI13_factory)C++98
14.77 / 20
1000 ms16712 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...