From 20ceb54bb8ed4cd62b5dbb2d0f2bc05cb782f77e Mon Sep 17 00:00:00 2001 From: Deepali Rathi <44741707+DeepaliRathi@users.noreply.github.com> Date: Fri, 8 Oct 2021 00:09:47 +0530 Subject: [PATCH 1/5] Added Prefix sum algorithm in c++ I used Prefix sum algorithm in solving a Codeforces problem(248 div2 problem B). Kindly accept my request.It will be of great help. --- C++/Language/Prefix_sum_Hacktoberfest2021.cpp | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 C++/Language/Prefix_sum_Hacktoberfest2021.cpp diff --git a/C++/Language/Prefix_sum_Hacktoberfest2021.cpp b/C++/Language/Prefix_sum_Hacktoberfest2021.cpp new file mode 100644 index 0000000..9572278 --- /dev/null +++ b/C++/Language/Prefix_sum_Hacktoberfest2021.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; +const int N=1e5+5; +int ar[N]; +long long p[N]; +long long q[N]; +int main() +{ +int n; ////Taking input of number of stones +cin>>n; +for(int i=1;i<=n;++i)//Taking input of cost of each stones +{ +cin>>ar[i]; +p[i]=p[i-1]+ar[i]; +} +sort(ar+1,ar+n+1);//sorting stones in increasing order for second type question +for(int i=1;i<=n;i++) +q[i]=q[i-1]+ar[i]; + //taking input of number of question raised by Kuriyama Mirai +int g; +cin>>g; +while(g--) +{ +int t , l , r; +cin>>t>>l>>r;//taking input of type of queston raised by Kuriyama Mirai +if(t==1) +cout< Date: Fri, 8 Oct 2021 10:52:43 +0530 Subject: [PATCH 2/5] Added a Pefix sum algorithm in c++ Edited : changed file name , moved it in c++/Algorithm folder ,formatted code as per instruction. I have added edited Prefix sum algorithm solving a codechef problem(248 div2 problem B) Kindly accept my request ,it would be of great help :) --- C++/Algorithm/prefixsum.cpp.cpp | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 C++/Algorithm/prefixsum.cpp.cpp diff --git a/C++/Algorithm/prefixsum.cpp.cpp b/C++/Algorithm/prefixsum.cpp.cpp new file mode 100644 index 0000000..80e7790 --- /dev/null +++ b/C++/Algorithm/prefixsum.cpp.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; +const int N=1e5+5; +int ar[N]; +long long p[N]; +long long q[N]; +int main() { + +int n; ////Taking input of number of stones +cin >> n; + +for(int i = 1;i <= n; ++i){//Taking input of cost of each stones + cin >> ar[i]; + p[i] = p[i-1] + ar[i]; +} + +sort(ar+1,ar+n+1); //sorting stones in increasing order for second type question + +for(int i = 1;i <= n; i++){ + q[i] = q[i-1] + ar[i]; +} + //taking input of number of question raised by Kuriyama Mirai +int g; +cin >> g; +while(g--){ + int t , l , r; + cin >> t >> l >> r;//taking input of type of queston raised by Kuriyama Mirai + if(t == 1) + cout << p[r] - p[l-1] << endl; //printngi out sum of type 1 question raised by Kuriyama Mirai + else + cout << q[r] - q[l-1] << endl; //printngi out sum of type 2 question raised by Kuriyama Mirai +} + +} + From 1e52eb0720715b239fe7c550ab6b8d2a34de54d0 Mon Sep 17 00:00:00 2001 From: Deepali Rathi <44741707+DeepaliRathi@users.noreply.github.com> Date: Fri, 8 Oct 2021 10:56:22 +0530 Subject: [PATCH 3/5] Deleted the previous file Added new file in specified folder. --- C++/Language/Prefix_sum_Hacktoberfest2021.cpp | 32 ------------------- 1 file changed, 32 deletions(-) delete mode 100644 C++/Language/Prefix_sum_Hacktoberfest2021.cpp diff --git a/C++/Language/Prefix_sum_Hacktoberfest2021.cpp b/C++/Language/Prefix_sum_Hacktoberfest2021.cpp deleted file mode 100644 index 9572278..0000000 --- a/C++/Language/Prefix_sum_Hacktoberfest2021.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -using namespace std; -const int N=1e5+5; -int ar[N]; -long long p[N]; -long long q[N]; -int main() -{ -int n; ////Taking input of number of stones -cin>>n; -for(int i=1;i<=n;++i)//Taking input of cost of each stones -{ -cin>>ar[i]; -p[i]=p[i-1]+ar[i]; -} -sort(ar+1,ar+n+1);//sorting stones in increasing order for second type question -for(int i=1;i<=n;i++) -q[i]=q[i-1]+ar[i]; - //taking input of number of question raised by Kuriyama Mirai -int g; -cin>>g; -while(g--) -{ -int t , l , r; -cin>>t>>l>>r;//taking input of type of queston raised by Kuriyama Mirai -if(t==1) -cout< Date: Fri, 8 Oct 2021 10:59:28 +0530 Subject: [PATCH 4/5] Delete prefixsum.cpp.cpp Deleted previous file due wrong file name. --- C++/Algorithm/prefixsum.cpp.cpp | 35 --------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 C++/Algorithm/prefixsum.cpp.cpp diff --git a/C++/Algorithm/prefixsum.cpp.cpp b/C++/Algorithm/prefixsum.cpp.cpp deleted file mode 100644 index 80e7790..0000000 --- a/C++/Algorithm/prefixsum.cpp.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -using namespace std; -const int N=1e5+5; -int ar[N]; -long long p[N]; -long long q[N]; -int main() { - -int n; ////Taking input of number of stones -cin >> n; - -for(int i = 1;i <= n; ++i){//Taking input of cost of each stones - cin >> ar[i]; - p[i] = p[i-1] + ar[i]; -} - -sort(ar+1,ar+n+1); //sorting stones in increasing order for second type question - -for(int i = 1;i <= n; i++){ - q[i] = q[i-1] + ar[i]; -} - //taking input of number of question raised by Kuriyama Mirai -int g; -cin >> g; -while(g--){ - int t , l , r; - cin >> t >> l >> r;//taking input of type of queston raised by Kuriyama Mirai - if(t == 1) - cout << p[r] - p[l-1] << endl; //printngi out sum of type 1 question raised by Kuriyama Mirai - else - cout << q[r] - q[l-1] << endl; //printngi out sum of type 2 question raised by Kuriyama Mirai -} - -} - From 309f27bdb28777766e27bd89539a7425d5ccde18 Mon Sep 17 00:00:00 2001 From: Deepali Rathi <44741707+DeepaliRathi@users.noreply.github.com> Date: Fri, 8 Oct 2021 11:04:17 +0530 Subject: [PATCH 5/5] Added Prefix sum Algorithm in c++ Added edited file after renaming it correctly. I added renamed file of problem of prefix sum algorithm from Codeforces(248 div2 problem B. Kindly accept my request ,it would be of great help :) --- C++/Algorithm/prefixsum.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 C++/Algorithm/prefixsum.cpp diff --git a/C++/Algorithm/prefixsum.cpp b/C++/Algorithm/prefixsum.cpp new file mode 100644 index 0000000..80e7790 --- /dev/null +++ b/C++/Algorithm/prefixsum.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; +const int N=1e5+5; +int ar[N]; +long long p[N]; +long long q[N]; +int main() { + +int n; ////Taking input of number of stones +cin >> n; + +for(int i = 1;i <= n; ++i){//Taking input of cost of each stones + cin >> ar[i]; + p[i] = p[i-1] + ar[i]; +} + +sort(ar+1,ar+n+1); //sorting stones in increasing order for second type question + +for(int i = 1;i <= n; i++){ + q[i] = q[i-1] + ar[i]; +} + //taking input of number of question raised by Kuriyama Mirai +int g; +cin >> g; +while(g--){ + int t , l , r; + cin >> t >> l >> r;//taking input of type of queston raised by Kuriyama Mirai + if(t == 1) + cout << p[r] - p[l-1] << endl; //printngi out sum of type 1 question raised by Kuriyama Mirai + else + cout << q[r] - q[l-1] << endl; //printngi out sum of type 2 question raised by Kuriyama Mirai +} + +} +