Commit 8ecd5fda8de957aacca91e8c42385eb28b60e0fd
Committed by
Ronaldo

1 parent
17e4d46737
Exists in
main
Update project.
Showing 4 changed files with 91 additions and 30 deletions Inline Diff
.idea/Competitive-Programming.iml
View file @
8ecd5fd
<?xml version="1.0" encoding="UTF-8"?> | 1 | 1 | <?xml version="1.0" encoding="UTF-8"?> | |
<module type="CPP_MODULE" version="4"> | 2 | 2 | <module classpath="CIDR" type="CPP_MODULE" version="4" /> | |
<component name="NewModuleRootManager"> | 3 | |||
<content url="file://$MODULE_DIR$" /> | 4 | |||
<orderEntry type="inheritedJdk" /> | 5 | |||
<orderEntry type="sourceFolder" forTests="false" /> | 6 | |||
</component> | 7 | |||
</module> | 8 | |||
NumberTheoryandCombinatorics/ProjectEuler/SumSquareDifference/SumSquareDifference.cpp
View file @
8ecd5fd
// | 1 | 1 | // | |
// Created by ronal on 2/12/2023. | 2 | 2 | // Created by ronal on 2/12/2023. | |
// Problem description Link. | 3 | 3 | // Problem description Link. | |
// https://www.hackerrank.com/contests/projecteuler/challenges/euler006/copy-from/1354371634 | 4 | 4 | // https://www.hackerrank.com/contests/projecteuler/challenges/euler006/copy-from/1354371634 | |
5 | 5 | |||
#include <map> | 6 | 6 | #include <bits/stdc++.h> | |
#include <set> | 7 | |||
#include <list> | 8 | |||
#include <cmath> | 9 | |||
#include <ctime> | 10 | |||
#include <deque> | 11 | |||
#include <queue> | 12 | |||
#include <stack> | 13 | |||
#include <string> | 14 | |||
#include <bitset> | 15 | |||
#include <cstdio> | 16 | |||
#include <limits> | 17 | |||
#include <vector> | 18 | |||
#include <climits> | 19 | |||
#include <cstring> | 20 | |||
#include <cstdlib> | 21 | |||
#include <fstream> | 22 | |||
#include <numeric> | 23 | |||
#include <sstream> | 24 | |||
#include <iostream> | 25 | |||
#include <algorithm> | 26 | |||
#include <unordered_map> | 27 | |||
28 | 7 | |||
using namespace std; | 29 | 8 | using namespace std; | |
30 | 9 | |||
unsigned long long SumSquareDifference(unsigned long long n){ | 31 | 10 | unsigned long long SumSquareDifference(unsigned long long n){ | |
unsigned long long sum_qua = 0; | 32 | 11 | unsigned long long sum_qua = 0; | |
unsigned long long qua_sum = 0; | 33 | 12 | unsigned long long qua_sum = 0; | |
34 | 13 | |||
sum_qua = (n * (n + 1) * (2*n + 1)) / 6; | 35 | 14 | sum_qua = (n * (n + 1) * (2*n + 1)) / 6; | |
qua_sum = n * (n +1 ) / 2; | 36 | 15 | qua_sum = n * (n +1 ) / 2; | |
// for(unsigned long long j = 1; j <= n; j++){ | 37 | 16 | // for(unsigned long long j = 1; j <= n; j++){ | |
// sum_qua += j * j; | 38 | 17 | // sum_qua += j * j; | |
// qua_sum += j; | 39 | 18 | // qua_sum += j; | |
// } | 40 | 19 | // } | |
return (qua_sum * qua_sum) - sum_qua; | 41 | 20 | return (qua_sum * qua_sum) - sum_qua; | |
} | 42 | 21 | } | |
int main(){ | 43 | 22 | int main(){ | |
unsigned long long t; | 44 | 23 | unsigned long long t; | |
cin >> t; | 45 | 24 | cin >> t; | |
for(unsigned long long i = 0; i < t; i++){ | 46 | 25 | for(unsigned long long i = 0; i < t; i++){ | |
unsigned long long n; | 47 | 26 | unsigned long long n; | |
cin >> n; | 48 | 27 | cin >> n; | |
cout << SumSquareDifference(n) << endl; | 49 | 28 | cout << SumSquareDifference(n) << endl; |
SearchingSortingandBasicDataStructures/InbuiltSorting/Problem5/SimpleTask.cpp
View file @
8ecd5fd
File was created | 1 | // | ||
2 | // Created by ronal on 2/25/2023. | |||
3 | // | |||
4 | ||||
5 | #include <bits/stdc++.h> | |||
6 | using namespace std; | |||
7 | ||||
8 | int Posicion(int queries, vector<tuple<int, int, int>>& VT){ | |||
9 | int first, last, type, posicion; | |||
10 | int sum_diff_max = 0; | |||
11 | int sum_diff_currenty = 0; | |||
12 | ||||
13 | for(int i = 0; i < queries; i++){ | |||
14 | cin >> first >> last >> type; | |||
15 | if(i == 0) { | |||
16 | sum_diff_max = last - first; | |||
17 | posicion = i; | |||
18 | }else{ | |||
19 | sum_diff_currenty = last - first; | |||
20 | if(sum_diff_max < sum_diff_currenty){ | |||
21 | sum_diff_max = sum_diff_currenty; | |||
22 | sum_diff_currenty = 0; | |||
23 | posicion = i; | |||
24 | } | |||
25 | } | |||
26 | VT.emplace_back(first, last, type); | |||
27 | } | |||
28 | return posicion; | |||
29 | } | |||
30 | int main(){ | |||
31 | ios_base::sync_with_stdio(false); | |||
32 | cin.tie(NULL); | |||
33 | string S; | |||
34 | int size, queries; | |||
35 | vector<tuple<int, int, int>> VT; | |||
36 | cin >> size >> queries; | |||
37 | cin.ignore(); | |||
38 | getline(cin, S); | |||
39 | ||||
40 | int p = Posicion(queries, VT); | |||
41 | for(int i = p; i < VT.size(); i++) { | |||
42 | if ( get<2>(VT[i]) == 1) { | |||
43 | sort(S.begin() + get<0>(VT[i]) - 1, S.begin() + get<1>(VT[i])); | |||
44 | } else if (get<2>(VT[i]) == 0) { | |||
45 | sort(S.begin() + get<0>(VT[i]) - 1, S.begin() + get<1>(VT[i]), greater<>()); | |||
46 | } | |||
47 | } | |||
48 | // for(const auto & i : S){ | |||
49 | // cout << i; |
SearchingSortingandBasicDataStructures/Set/Problem1/Sets.cpp
View file @
8ecd5fd
File was created | 1 | // | ||
2 | // Created by ronal on 2/25/2023. | |||
3 | // Problem Description Link. | |||
4 | // https://www.hackerrank.com/challenges/cpp-sets/problem | |||
5 | ||||
6 | #include <bits/stdc++.h> | |||
7 | using namespace std; | |||
8 | ||||
9 | ||||
10 | int main() { | |||
11 | int Q, y, x; | |||
12 | set<int> S; | |||
13 | cin >> Q; | |||
14 | for(int i = 0; i < Q; i++){ | |||
15 | cin >> y >> x; | |||
16 | if(y == 1){ | |||
17 | S.insert(x); | |||
18 | }else if(y == 2){ | |||
19 | S.erase(x); | |||
20 | }else if(y == 3){ | |||
21 | auto it = S.find(x); | |||
22 | if(it != S.end()){ | |||
23 | cout << "Yes\n"; | |||
24 | }else{ | |||
25 | cout << "No\n"; | |||
26 | } | |||
27 | } |