ADACROP – Ada and Harvest Solution

SPOJ Solution

As you might already know, Ada the Ladybug is a farmer. She has a very long furrow with many kinds of vegetables (represented by integer numbers). Whenever she wants to harvest a single vegetable, she always replace it with anoher vegetable (possibly same kind).

After each replacement, she wants to know the number of vegetables of the same kind (at the new vegetable) which are before it (have lower possition in furrow).


The first line of input containts 1 ≤ N, Q ≤ 2*105 , the length of furrow and number of harvests.

The next line contains numbers 0 ≤ Ai ≤ 109 the kind of vegetable which is currently on ith spot in furrow (indexed from 0).

The next Q lines contains two numbers 0 ≤ i < N (the index of harvested plant) and 0 ≤ a ≤ 109 (the kind of newly planted vegetable)


For each harvest, print the number of vegetables of the same kind before the newly planted vegetable.

You may also like


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.