Skip to content

Instantly share code, notes, and snippets.

@Flaze07
Created June 8, 2018 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Flaze07/2d544f82b2f06c5f91e6410e8b27e4ad to your computer and use it in GitHub Desktop.
Save Flaze07/2d544f82b2f06c5f91e6410e8b27e4ad to your computer and use it in GitHub Desktop.
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