Skip to content

Commit 44b236b

Browse files
authored
Merge branch 'master' into master
2 parents f2cb0ee + 7ef4ae8 commit 44b236b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1470
-12
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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
#define mod 1000000007
5+
int main() {
6+
ios_base::sync_with_stdio(false);
7+
cin.tie(nullptr);
8+
cout.tie(nullptr);
9+
int t ;
10+
cin >> t ;
11+
ll n;
12+
while (t--) {
13+
cin>>n;
14+
vector<ll> vec;
15+
ll z,profit=0;
16+
for (ll i = 0; i < n; ++i) {
17+
cin>>z;
18+
vec.emplace_back(z);
19+
}
20+
sort(vec.begin(),vec.end(),greater<>());
21+
profit+=vec[0];
22+
for (ll j = 1; j < n; ++j) {
23+
if(vec[j]-j>0)
24+
profit+=(vec[j]-j);
25+
else
26+
break;
27+
}
28+
cout<<profit%mod<<"\n";
29+
}
30+
return 0;
31+
}
32+
33+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
#define mod 1000000007
5+
int main() {
6+
ios_base::sync_with_stdio(false);
7+
cin.tie(nullptr);
8+
cout.tie(nullptr);
9+
int t ;
10+
cin >> t ;
11+
ll n,z;
12+
while (t--) {
13+
cin>>n;
14+
vector<ll> vec;
15+
bool poss= false;
16+
ll count=0;
17+
for (ll i = 0; i <n ; ++i) {
18+
cin>>z;
19+
if(z==1)
20+
count++;
21+
vec.emplace_back(z);
22+
}
23+
ll prev=0,pos1=0;
24+
if(count==1)
25+
poss=true;
26+
else
27+
{
28+
if(n>=6){
29+
for (ll j = 0; j <n ; ++j) {
30+
if(vec[j]==1){
31+
if(prev==0){
32+
prev=1;
33+
pos1=j;
34+
}
35+
else{
36+
if(j-pos1>=6)
37+
{
38+
poss=true;
39+
pos1=j;
40+
41+
} else{
42+
poss= false;
43+
break;
44+
}
45+
}
46+
47+
}
48+
}
49+
}}
50+
if(poss)
51+
cout<<"YES\n";
52+
else
53+
cout<<"NO\n";
54+
}
55+
return 0;
56+
}
57+
58+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
#define mod 1000000007
5+
int main() {
6+
ios_base::sync_with_stdio(false);
7+
cin.tie(nullptr);
8+
cout.tie(nullptr);
9+
int t ;
10+
cin >> t ;
11+
ll x,k;
12+
while (t--) {
13+
cin>>x>>k;
14+
unordered_map<ll,ll> umap;
15+
ll n=x;
16+
while (n % 2 == 0)
17+
{
18+
umap[2]++;
19+
n = n/2;
20+
}
21+
for (ll i = 3; i <= sqrt(n); i = i + 2)
22+
{
23+
while (n % i == 0)
24+
{
25+
umap[i]++;
26+
n = n/i;
27+
}
28+
}
29+
ll sum=0;
30+
if (n > 2)
31+
umap[n]++;
32+
for (auto part : umap){
33+
sum+=part.second;
34+
}
35+
if(x>=pow(2,k)&&k<=sum)
36+
cout<<"1\n";
37+
else
38+
cout<<"0\n";
39+
40+
}
41+
return 0;
42+
}
43+
44+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
int main(){
5+
ios_base::sync_with_stdio(false);
6+
cin.tie(nullptr);
7+
int t;
8+
cin>>t;
9+
ll n;
10+
while (t--){
11+
cin>>n;
12+
if(n==1)
13+
cout<<"1\n1 1\n";
14+
else
15+
{
16+
cout<<n/2<<"\n";
17+
if(n%2==0)
18+
cout<<"2 1 2\n";
19+
else
20+
cout<<"3 1 2 "<<n<<"\n";
21+
for (ll i = 3; i <n ; i+=2) {
22+
cout<<"2 "<<i<<" "<<i+1<<"\n";
23+
}
24+
}
25+
}
26+
return 0;
27+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
ll sumArr(vector<ll>arr, ll n, ll sum)
5+
{
6+
unordered_map<ll, ll> prevSum;
7+
8+
ll res = 0;
9+
10+
// Sum of elements so far.
11+
ll currsum = 0;
12+
13+
for (ll i = 0; i < n; i++) {
14+
15+
currsum += arr[i];
16+
if (currsum == sum)
17+
res++;
18+
19+
if (prevSum.find(currsum - sum) !=
20+
prevSum.end())
21+
res += (prevSum[currsum - sum]);
22+
prevSum[currsum]++;
23+
}
24+
25+
return res;
26+
}
27+
int main(){
28+
ios_base::sync_with_stdio(false);
29+
cin.tie(nullptr);
30+
int t;
31+
cin>>t;
32+
ll n,z;
33+
ll count,mul,odd,even4,even;
34+
while (t--){
35+
cin>>n;
36+
odd=0;even4=0;
37+
even=0;
38+
vector<ll> vec,arr;
39+
ll total =(n*(n+1))/2;
40+
for (ll i = 0; i <n ; ++i) {
41+
cin >> z;
42+
// vec.emplace_back(abs(z));
43+
if(z%4==0)
44+
arr.emplace_back(2);
45+
else if(z%2==0)
46+
arr.emplace_back(1);
47+
else
48+
arr.emplace_back(0);
49+
}
50+
for (ll j = 0; j <n ; ++j) {
51+
52+
}
53+
ll minus=sumArr(arr,n,1);
54+
55+
cout<<total-minus<<"\n";
56+
}
57+
return 0;
58+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
#define ll long long int
4+
ll printRandoms(ll lower, ll upper)
5+
{
6+
ll num = (rand() %(upper - lower + 1)) + lower;
7+
}
8+
int main(){
9+
ios_base::sync_with_stdio(false);
10+
cin.tie(nullptr);
11+
int t;
12+
cin>>t;
13+
ll n,m,k;
14+
while(t--){
15+
cin>>n>>m>>k;
16+
vector<vector<ll>> vec(n,vector<ll>(k,0));
17+
for (ll i = 0; i <n ; ++i) {
18+
vector<int> mp(m+1,1);
19+
for (ll j = 0; j < k; ++j) {
20+
cin>>vec[i][j];
21+
mp[vec[i][j]]++;
22+
}
23+
sort(mp.begin(),mp.end(),greater<>());
24+
int pos=distance(mp.begin(),max_element(mp.begin(), mp.end()));
25+
// ll pos=printRandoms(1,m);
26+
cout<< pos<<" ";
27+
}
28+
cout<<'\n';
29+
}
30+
return 0;
31+
}

0 commit comments

Comments
 (0)