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 Missile Bombing problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Missile Bombing problem solution, There is an N x N field on which missiles are being bombarded. Initially, all the cells in this field have 0 value. There will be M missiles bombarded on this field. the ith missile will have power Pi and it will affect all the cells in the region with (Ai, Bi) as top-left corner and (Ci, Di) as a bottom-right corner. Because of the missile, the value of all the cells in this rectangle will get XOR with Pi.
 
After all the missiles have been bombarded, you have to find out values in each cell of this field.
 
 
HackerEarth Missile Bombing problem solution

 

 

HackerEarth Missile Bombing problem solution.

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fr freopen("in.txt","r",stdin)
#define rep(i,n) for(int i=0;i<n;i++)
#define frep(i,n) for(int i=1;i<=n;i++)

#define pi pair<int,int>
#define f first
#define s second
#define MAXBITS 15
int U[1011][1011];
int main() {

int N;
cin >> N;

int M;
cin >> M;
int a,b,c,d,p;
rep(i,M) {
cin >> p >> a >> b >> c >> d;
U[a][b]^=p;
U[a][d+1]^=p;
U[c+1][b]^=p;
U[c+1][d+1]^=p;
}
frep(i,N) {
frep(j,N) {
U[i][j]^=(U[i-1][j]^U[i][j-1]^U[i-1][j-1]);
cout << U[i][j];
if(j!=N)
cout << " ";
}
if(i!=N)
cout << "n";
}
}
 
 

Second solution

n = int(raw_input())
m = int(raw_input())
grid = [[0 for __ in xrange(n+2)] for ___ in xrange(n+2)]
for i in range(m):
p,a,b,c,d = map(int, raw_input().split())
for i1 in [a-1,c]:
for i2 in [b-1,d]:
grid[i1][i2] ^= p

for i in range(n,-1,-1):
for j in range(n,-1,-1):
grid[i][j] ^= grid[i+1][j]^grid[i][j+1]^grid[i+1][j+1]

for i in range(1,n+1):
print " ".join(map(str,grid[i][1:n+1]))
 
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