Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
program CountSubarrays;
var
TestCases : integer ;
ArrLen : longint ;
Arr, temp : array of longint ;
i, j, x : integer ;
TotalAscending : longint ;
OuterLoopFlag : boolean ;
begin
ReadLn( TestCases );
while( TestCases > 0 ) do
begin
dec( TestCases );
TotalAscending := 0;
ReadLn( ArrLen );
SetLength( Arr, ArrLen );
for i := 0 to ( ArrLen - 1 ) do
begin
Read( Arr[ i ] );
end;
if( ArrLen = 1 ) then
begin
writeln( 1 );
continue;
end;
for i := 0 to High( Arr ) do
begin
for j := ( i + 1 ) to High( Arr ) do
begin
OuterLoopFlag := false;
SetLength( temp, ( j - 1 ) - i );
x := 0;
while( x < Length( temp ) ) do
begin
temp[ x ] := Arr[ ( j - 1 ) + x ];
Inc( x );
end;
x := 1;
while( x < Length( temp ) ) do
begin
if ( temp[ x - 1 ] > temp[ x ] ) then
begin
OuterLoopFlag := true;
break;
end;
Inc( x );
end;
if( OuterLoopFlag ) then continue;
Inc( TotalAscending );
end;
end;
writeln( TotalAscending );
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.