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

HackerEarth The Electric Type problem solution

YASH PAL, 31 July 2024
In this HackerEarth The Electric Type problem solution Everyone knows that some special Pikachus hate evolving into Raichus. (The legend says because Raichu is ugly, and Pikachu looks good!)
The question is how do we find these special Pikachus who hate evolution? The crazy Poke’mon trainer Ash Catch’Em has derived a random algorithm, which is completely wrong, but since he’s your friend, you’ve to humor him and his crazy algorithms.
He thinks if you are given N Pikachus in an array, A1,A2 … AN, where each Pikachu is denoted by an integer. The total number of unique pairs (Ai,Aj) where i < j is the number of Pikachus who hate evolution.
HackerEarth The Electric Type problem solution

HackerEarth The Electric Type problem solution.

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <iomanip>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define f first
#define mp make_pair
#define mod 1000000007
#define s second
#define pb push_back
int A[200011];
int main(){

freopen("in01.txt","r",stdin);
freopen("out01.txt","w",stdout);

int N;
cin >> N;
map<int,int>M;
set<int>s;

rep(i,N){
cin >> A[i];
M[A[i]] = i;
s.insert(A[i]);
}

set<int>consider;
for(map<int,int>::iterator it = M.begin();it!=M.end();it++){
consider.insert((*it).s);
}
ll ans = 0;
rep(i,N){
if(consider.count(i)){
ans += s.size();
}
s.insert(A[i]);
}
cout<<ans;

}
coding problems solutions

Post navigation

Previous post
Next post

Related website

The Computer Science

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes