Patrik
Posted godrose
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Patrik相关的知识,希望对你有一定的参考价值。
题面:
思路:
代码:
var i,j,n,m,x,y,tail,tt:longint; a,q,f,id,b:array[0..500005] of longint; ans:int64; procedure sort(l,r: longint); var i,j,x,y: longint; begin i:=l; j:=r; x:=b[(l+r) div 2]; repeat while b[i]<x do inc(i); while x<b[j] do dec(j); if not(i>j) then begin y:=b[i]; b[i]:=b[j]; b[j]:=y; y:=id[i]; id[i]:=id[j]; id[j]:=y; inc(i); j:=j-1; end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; begin assign(input,‘patrik.in‘); reset(input); assign(output,‘patrik.out‘); rewrite(output); read(n); for i:=1 to n do begin read(b[i]); id[i]:=i; end; sort(1,n); tt:=0; for i:=1 to n do if b[i]=b[i-1] then a[id[i]]:=tt else begin inc(tt); a[id[i]]:=tt; end; tail:=1; q[1]:=a[1]; f[a[1]]:=1; for i:=2 to n do begin while (a[i]>q[tail]) and (1<=tail) do begin dec(f[q[tail]]); dec(tail); inc(ans); end; inc(tail); q[tail]:=a[i]; inc(ans,f[a[i]]); inc(f[a[i]]); if q[1]<>a[i] then inc(ans); end; writeln(ans); close(input);close(output); end.
以上是关于Patrik的主要内容,如果未能解决你的问题,请参考以下文章