Skip to content

Commit 7ef4ae8

Browse files
authored
Merge pull request #202 from tharani247/master
Added code for codechef long challenge problems
2 parents ca1d3b2 + ce05cf9 commit 7ef4ae8

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

0 commit comments

Comments
 (0)