Created
June 8, 2018 14:30
-
-
Save Flaze07/2d544f82b2f06c5f91e6410e8b27e4ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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