Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Help Ashu problem solution

YASH PAL, 31 July 202414 February 2026
In this HackerEarth Help Ashu problem solution Ashu and Shanu are best buddies. One day Shanu gives Ashu a problem to test his intelligence.He gives him an array of N natural numbers and asks him to solve the following queries:-
  1. Query 0:- modify the element present at index i to x.
  2. Query 1:- count the number of even numbers in range l to r inclusive.
  3. Query 2:- count the number of odd numbers in range l to r inclusive.
 
HackerEarth Help Ashu problem solution

 

 

HackerEarth Help Ashu problem solution.

#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
int BIT[MAX];
void upd(int idx,int val){
for(int i=idx;i<MAX;i+=i&(-i))
BIT[i]+=val;
}
int query(int val){
int ret=0;
while(val){
ret+=BIT[val];
val-=val&(-val);
}
return ret;
}
int a[MAX];
int main(){
int n,i;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]%2==0)
upd(i,1);
}
int q,l,r,ch;
cin>>q;
while(q--){
cin>>ch>>l>>r;
if(ch==0){
if(r%2==1&&a[l]%2==0)
upd(l,-1);
if(r%2==0&&a[l]%2==1)
upd(l,1);
a[l]=r;
}
else if(ch==1){
int cnt=query(r)-query(l-1);
cout<<cnt<<endl;
}
else{
int cnt=query(r)-query(l-1);
cout<<(r-l+1)-cnt<<endl;
}
}
return 0;
}
 
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes