Skip to content

Commit 3ee87d0

Browse files
committed
[INIT] Topic Specific Programming Problems
1 parent 701c8e4 commit 3ee87d0

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

.replit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
run = "cowsay Configure me!"
2+
3+
[nix]
4+
channel = "stable-22_11"

Prefix Sum/CSUMQ.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Platform: Sphere Online Judge
3+
* Problem: https://www.spoj.com/problems/CSUMQ/
4+
* Solved by mustaquenadim
5+
*/
6+
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
10+
int main()
11+
{
12+
int N, Q;
13+
cin >> N;
14+
int arr[N], sum[N];
15+
for(int i = 0; i < N; i++) {
16+
cin >> arr[i];
17+
if(i == 0) {
18+
sum[i] = arr[i];
19+
} else {
20+
sum[i] = sum[i - 1] + arr[i];
21+
}
22+
}
23+
cin >> Q;
24+
while(Q--) {
25+
int i, j, res;
26+
cin >> i >> j;
27+
if(i == 0) {
28+
res = sum[j];
29+
} else {
30+
res = sum[j] - sum[i - 1];
31+
}
32+
cout << res << endl;
33+
}
34+
return 0;
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Platform: CodeForces
3+
* Problem: https://codeforces.com/contest/816/problem/B
4+
*/
5+
6+
#include <bits/stdc++.h>
7+
using namespace std;
8+
9+
#define MAX_TEMP 200001
10+
11+
int main() {
12+
int n, k, q;
13+
cin >> n >> k >> q;
14+
int arr[MAX_TEMP] = {0}, prefix[MAX_TEMP];
15+
while (n--) {
16+
int l, r;
17+
cin >> l >> r;
18+
arr[l]++;
19+
arr[r + 1]--;
20+
}
21+
prefix[0] = arr[0];
22+
for(int i = 1; i < MAX_TEMP; i++) {
23+
prefix[i] = prefix[i - 1] + arr[i];
24+
// if(prefix[i] > 0) {
25+
// cout << i << " = " << prefix[i] << endl;
26+
// }
27+
}
28+
for(int i = 0; i < MAX_TEMP; i++) {
29+
if(prefix[i] >= k) {
30+
prefix[i] = 1;
31+
} else {
32+
prefix[i] = 0;
33+
}
34+
}
35+
prefix[0] = prefix[0];
36+
for(int i = 1; i < MAX_TEMP; i++) {
37+
prefix[i] = prefix[i - 1] + prefix[i];
38+
}
39+
while(q--) {
40+
int a, b, kount = 0;
41+
cin >> a >> b;
42+
if(a == 0) {
43+
kount = prefix[b];
44+
} else {
45+
kount = prefix[b] - prefix[a - 1];
46+
}
47+
cout << kount << endl;
48+
}
49+
return 0;
50+
}

Prefix Sum/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Prefix Sum
2+
3+
4+
## Problems
5+
6+
1. [CodeForces - 816B — Karen and coffee](https://codeforces.com/contest/816/problem/B)
7+
2. [CodeForces - 296C](https://codeforces.com/contest/296/problem/C)
8+
3. [CodeForces - 479E](https://codeforces.com/contest/479/problem/E)
9+
4. [CodeForces - 433B](https://codeforces.com/contest/433/problem/B)
10+
5. [CodeForces - 610B](https://codeforces.com/contest/610/problem/B)
11+
6. [CodeForces - 1237B](https://codeforces.com/contest/1237/problem/B)
12+
7. [CodeForces - 486D](https://codeforces.com/contest/486/problem/D)
13+
8. [CodeForces - 835C](https://codeforces.com/contest/835/problem/C)
14+
9. [CodeForces - 1043E](https://codeforces.com/contest/1043/problem/E)
15+
10. [CodeChef - Snake Eating](https://www.codechef.com/problems/SNAKEEAT)
16+
11. [UVa - 108 - Maximum Sum](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=44)
17+
12. [SPOJ - CSUMQ - Cumulative Sum Query](https://www.spoj.com/problems/CSUMQ/)
18+
13. [UVa - 983 - Localized Summing for Blurring](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=924)
19+
14. [UVa - 11951](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3102)
20+
15. [UVa - 10533](http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1474)
21+
16. [Hackerrank - KJ and street lights](https://www.hackerrank.com/contests/ab-yeh-kar-ke-dikhao/challenges/kj-and-street-lights/problem)

replit.nix

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{ pkgs }: {
2+
deps = [
3+
pkgs.cowsay
4+
];
5+
}

0 commit comments

Comments
 (0)