Skip to content

Commit 6a9344b

Browse files
committed
.
1 parent ff738bd commit 6a9344b

14 files changed

+469
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"A. Merging Arrays","group":"Codeforces - ITMO Academy: pilot course - Two Pointers Method - Step 1","url":"https://codeforces.com/edu/course/2/lesson/9/1/practice/contest/307092/problem/A","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1616660753776,"input":"6 7\n1 6 9 13 18 18\n2 3 8 13 15 21 25","output":"1 2 3 6 8 9 13 13 15 18 18 21 25"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"AMergingArrays"}},"batch":{"id":"9417e19c-7a40-46e2-9167-0179f9ebd01e","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Practice\\CodeForces Edu\\Two Pointers\\Step 1\\A_Merging_Arrays.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"B. Number of Smaller","group":"Codeforces - ITMO Academy: pilot course - Two Pointers Method - Step 1","url":"https://codeforces.com/edu/course/2/lesson/9/1/practice/contest/307092/problem/B","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1616661007779,"input":"6 7\n1 6 9 13 18 18\n2 3 8 13 15 21 25","output":"1 1 2 3 4 6 6"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BNumberOfSmaller"}},"batch":{"id":"58330dc3-5037-40a3-b10e-63948a1d2d6a","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Practice\\CodeForces Edu\\Two Pointers\\Step 1\\B_Number_of_Smaller.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"C. Number of Equal","group":"Codeforces - ITMO Academy: pilot course - Two Pointers Method - Step 1","url":"https://codeforces.com/edu/course/2/lesson/9/1/practice/contest/307092/problem/C","interactive":false,"memoryLimit":256,"timeLimit":1000,"tests":[{"id":1616661689655,"input":"8 7\n1 1 3 3 3 5 8 8\n1 3 3 4 5 5 5","output":"11"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CNumberOfEqual"}},"batch":{"id":"cd3e8056-462c-4f3a-9949-8a8f575c77a8","size":1},"srcPath":"c:\\Users\\Dhruv\\myGithub\\Competitive-Programming\\Practice\\CodeForces Edu\\Two Pointers\\Step 1\\C_Number_of_Equal.cpp"}
59 KB
Binary file not shown.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
// #include <algorithm>
8+
// #include <unordered_map>
9+
// #include <map>
10+
// #include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define int long long int
22+
#define mod 1000000007ll
23+
#define endl "\n"
24+
//------------------------------------------------------------------------------
25+
// Any fucntion can be called using Math.function_name();
26+
//------------------------------------------------------------------------------
27+
class Math
28+
{
29+
public:
30+
//Returns gcd of two numbers
31+
int gcd(int a, int b)
32+
{
33+
return (a % b == 0) ? b : gcd(b, a % b);
34+
}
35+
36+
//Returns lcm of two numbers
37+
int lcm(int a, int b)
38+
{
39+
return a * (b / gcd(a, b));
40+
}
41+
42+
// Returns flag array isPrime
43+
// isPrime[i] = true (if i is Prime)
44+
// isPrime[i] = false (if i is not Prime)
45+
vector<bool> *seiveOfEratosthenes(const int N)
46+
{
47+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
48+
(*isPrime)[0] = (*isPrime)[1] = false;
49+
for (int i = 2; i * i <= N; ++i)
50+
if ((*isPrime)[i])
51+
for (int j = i * i; j <= N; j += i)
52+
(*isPrime)[j] = false;
53+
54+
return isPrime;
55+
}
56+
57+
//Returns (x ^ n)
58+
int pow(const int &x, int n)
59+
{
60+
if (n == 0)
61+
return 1;
62+
int h = pow(x, n / 2);
63+
return (n & 1) ? h * h * x : h * h;
64+
}
65+
66+
//Returns (x ^ n) % M
67+
int pow(const int &x, int n, const int &M)
68+
{
69+
if (n == 0)
70+
return 1;
71+
int h = pow(x, n / 2) % M;
72+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
73+
}
74+
75+
//Returns all Primes <= N
76+
vector<int> *primesUptoN(const int N)
77+
{
78+
vector<bool> *isPrime = seiveOfEratosthenes(N);
79+
vector<int> *Primes = new vector<int>;
80+
if (2 <= N)
81+
(*Primes).push_back(2);
82+
for (int i = 3; i <= N; i += 2)
83+
if ((*isPrime)[i])
84+
(*Primes).push_back(i);
85+
return Primes;
86+
}
87+
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
void solve()
91+
{
92+
int m, n;
93+
cin >> m >> n;
94+
v(int) A(m), B(n);
95+
for (int &x : A)
96+
cin >> x;
97+
for (int &x : B)
98+
cin >> x;
99+
int i = 0, j = 0;
100+
101+
while (i < m or j < n)
102+
{
103+
if ((j == n) or (i < m and A[i] < B[j]))
104+
cout << A[i++] << " ";
105+
else
106+
cout << B[j++] << " ";
107+
}
108+
}
109+
//------------------------------------------------------------------------------
110+
int32_t main()
111+
{
112+
FastIO;
113+
114+
// w(T)
115+
solve();
116+
117+
return 0;
118+
}
119+
//------------------------------------------------------------------------------
58.9 KB
Binary file not shown.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
#include <algorithm>
8+
// #include <unordered_map>
9+
// #include <map>
10+
// #include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define int long long int
22+
#define mod 1000000007ll
23+
#define endl "\n"
24+
//------------------------------------------------------------------------------
25+
// Any fucntion can be called using Math.function_name();
26+
//------------------------------------------------------------------------------
27+
class Math
28+
{
29+
public:
30+
//Returns gcd of two numbers
31+
int gcd(int a, int b)
32+
{
33+
return (a % b == 0) ? b : gcd(b, a % b);
34+
}
35+
36+
//Returns lcm of two numbers
37+
int lcm(int a, int b)
38+
{
39+
return a * (b / gcd(a, b));
40+
}
41+
42+
// Returns flag array isPrime
43+
// isPrime[i] = true (if i is Prime)
44+
// isPrime[i] = false (if i is not Prime)
45+
vector<bool> *seiveOfEratosthenes(const int N)
46+
{
47+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
48+
(*isPrime)[0] = (*isPrime)[1] = false;
49+
for (int i = 2; i * i <= N; ++i)
50+
if ((*isPrime)[i])
51+
for (int j = i * i; j <= N; j += i)
52+
(*isPrime)[j] = false;
53+
54+
return isPrime;
55+
}
56+
57+
//Returns (x ^ n)
58+
int pow(const int &x, int n)
59+
{
60+
if (n == 0)
61+
return 1;
62+
int h = pow(x, n / 2);
63+
return (n & 1) ? h * h * x : h * h;
64+
}
65+
66+
//Returns (x ^ n) % M
67+
int pow(const int &x, int n, const int &M)
68+
{
69+
if (n == 0)
70+
return 1;
71+
int h = pow(x, n / 2) % M;
72+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
73+
}
74+
75+
//Returns all Primes <= N
76+
vector<int> *primesUptoN(const int N)
77+
{
78+
vector<bool> *isPrime = seiveOfEratosthenes(N);
79+
vector<int> *Primes = new vector<int>;
80+
if (2 <= N)
81+
(*Primes).push_back(2);
82+
for (int i = 3; i <= N; i += 2)
83+
if ((*isPrime)[i])
84+
(*Primes).push_back(i);
85+
return Primes;
86+
}
87+
88+
} Math;
89+
//------------------------------------------------------------------------------
90+
91+
#define in(A) for(auto &x : A) cin >> x;
92+
93+
void solve()
94+
{
95+
int m, n;
96+
cin >> m >> n;
97+
v(int) A(m), B(n);
98+
in(A);
99+
in(B);
100+
for (int i = 0, j = 0; j < n; j++)
101+
{
102+
while (i < n and A[i] < B[j])
103+
i++;
104+
105+
cout << i << " ";
106+
}
107+
}
108+
//------------------------------------------------------------------------------
109+
int32_t main()
110+
{
111+
FastIO;
112+
113+
// w(T)
114+
solve();
115+
116+
return 0;
117+
}
118+
//------------------------------------------------------------------------------
59.4 KB
Binary file not shown.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
2+
//------------------------------------------------------------------------------
3+
#include <iostream>
4+
#include <vector>
5+
// #include <bits/stdc++.h>
6+
// #include <cmath>
7+
// #include <algorithm>
8+
// #include <unordered_map>
9+
// #include <map>
10+
// #include <set>
11+
// #include <unordered_set>
12+
//------------------------------------------------------------------------------
13+
using namespace std;
14+
//------------------------------------------------------------------------------
15+
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
16+
#define v(Type) vector<Type>
17+
#define w(T) \
18+
int T; \
19+
cin >> T; \
20+
while (T--)
21+
#define in(A) \
22+
for (auto &x : A) \
23+
cin >> x;
24+
#define int long long int
25+
#define mod 1000000007ll
26+
#define endl "\n"
27+
//------------------------------------------------------------------------------
28+
// Any fucntion can be called using Math.function_name();
29+
//------------------------------------------------------------------------------
30+
class Math
31+
{
32+
public:
33+
//Returns gcd of two numbers
34+
int gcd(int a, int b)
35+
{
36+
return (a % b == 0) ? b : gcd(b, a % b);
37+
}
38+
39+
//Returns lcm of two numbers
40+
int lcm(int a, int b)
41+
{
42+
return a * (b / gcd(a, b));
43+
}
44+
45+
// Returns flag array isPrime
46+
// isPrime[i] = true (if i is Prime)
47+
// isPrime[i] = false (if i is not Prime)
48+
vector<bool> *seiveOfEratosthenes(const int N)
49+
{
50+
vector<bool> *isPrime = new vector<bool>(N + 1, true);
51+
(*isPrime)[0] = (*isPrime)[1] = false;
52+
for (int i = 2; i * i <= N; ++i)
53+
if ((*isPrime)[i])
54+
for (int j = i * i; j <= N; j += i)
55+
(*isPrime)[j] = false;
56+
57+
return isPrime;
58+
}
59+
60+
//Returns (x ^ n)
61+
int pow(const int &x, int n)
62+
{
63+
if (n == 0)
64+
return 1;
65+
int h = pow(x, n / 2);
66+
return (n & 1) ? h * h * x : h * h;
67+
}
68+
69+
//Returns (x ^ n) % M
70+
int pow(const int &x, int n, const int &M)
71+
{
72+
if (n == 0)
73+
return 1;
74+
int h = pow(x, n / 2) % M;
75+
return (n & 1) ? (h * h * x) % M : (h * h) % M;
76+
}
77+
78+
//Returns all Primes <= N
79+
vector<int> *primesUptoN(const int N)
80+
{
81+
vector<bool> *isPrime = seiveOfEratosthenes(N);
82+
vector<int> *Primes = new vector<int>;
83+
if (2 <= N)
84+
(*Primes).push_back(2);
85+
for (int i = 3; i <= N; i += 2)
86+
if ((*isPrime)[i])
87+
(*Primes).push_back(i);
88+
return Primes;
89+
}
90+
91+
} Math;
92+
//------------------------------------------------------------------------------
93+
void solve()
94+
{
95+
int m, n;
96+
cin >> m >> n;
97+
v(int) A(m), B(n);
98+
in(A);
99+
in(B);
100+
v(int) C(n);
101+
for (int i = 0, j = 0; j < n; j++)
102+
{
103+
if (j > 0 and B[j] == B[j - 1])
104+
{
105+
C[j] = C[j - 1];
106+
continue;
107+
}
108+
int cur = 0;
109+
while (i < m and A[i] < B[j])
110+
i++;
111+
112+
while (i < m and A[i] == B[j])
113+
i++, cur++;
114+
115+
C[j] = cur;
116+
}
117+
int ans = 0;
118+
for (auto &x : C)
119+
ans += x;
120+
cout << ans << endl;
121+
}
122+
//------------------------------------------------------------------------------
123+
int32_t main()
124+
{
125+
FastIO;
126+
127+
// w(T)
128+
solve();
129+
130+
return 0;
131+
}
132+
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)