File tree Expand file tree Collapse file tree 2 files changed +77
-0
lines changed Expand file tree Collapse file tree 2 files changed +77
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ for _ in range (int (input ())):
3
+ n = int (input ())
4
+ a = list (map (int ,input ().split ()))
5
+ b = [0 ]* n
6
+ l = []
7
+ r = []
8
+ for i in range (n ):
9
+ if (a [i ]% 2 != 0 ):
10
+ b [i ] = 1
11
+ else :
12
+ if (a [i ]% 4 == 0 ):
13
+ b [i ] = 4
14
+ else :
15
+ b [i ] = 2
16
+ count = 0
17
+ for i in range (n ):
18
+ if (b [i ] == 1 ):
19
+ count += 1
20
+ if (b [i ]== 4 ):
21
+ count = 0
22
+ elif (b [i ]== 2 ):
23
+ l .append (count + 1 )
24
+ count = 0
25
+ count = 0
26
+ for i in range (- 1 ,- n - 1 ,- 1 ):
27
+ if (b [i ] == 1 ):
28
+ count += 1
29
+ elif (b [i ]== 4 ):
30
+ count = 0
31
+ elif (b [i ]== 2 ):
32
+ r .append (count + 1 )
33
+ count = 0
34
+ c = 0
35
+ for i in range (len (r )):
36
+ c += l [i ]* r [- i - 1 ]
37
+ print ((n * (n + 1 )// 2 )- c )
Original file line number Diff line number Diff line change
1
+
2
+ #include < iostream>
3
+ using namespace std ;
4
+
5
+ int main ()
6
+ {
7
+ int n;
8
+ cin>>n;
9
+ for (int i=0 ;i<n;++i){
10
+ int a;
11
+ cin>>a;
12
+
13
+ if (a>=4 ){
14
+ cout<<a/2 <<" \n " ;
15
+ if (a%2 ==0 ){
16
+ for (int j=0 ;j<a;j+=2 ){
17
+ cout<<2 <<" " <<j+1 <<" " <<j+2 <<" \n " ;
18
+ }
19
+ }
20
+ else {
21
+ cout<<3 <<" " <<1 <<" " <<2 <<" " <<a<<" \n " ;
22
+ for (int j=2 ;j<a-2 ;j+=2 ){
23
+ cout<<2 <<" " <<j+1 <<" " <<j+2 <<" \n " ;
24
+ }
25
+ }
26
+ }
27
+ else {
28
+ cout<<1 <<" \n " ;
29
+ if (a==1 ){
30
+ cout<<1 <<" " <<1 <<" \n " ;
31
+ }
32
+ else if (a==2 ){
33
+ cout<<2 <<" " <<1 <<" " <<2 <<" \n " ;
34
+ }
35
+ else {
36
+ cout<<3 <<" " <<1 <<" " <<2 <<" " <<3 <<" \n " ;
37
+ }
38
+ }
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments