SixtyWithoutSchool's blog

By SixtyWithoutSchool, history, 17 months ago, In English

Heyy!!!!

Today I found something that may be useful to some of you. Maybe most of you already know this.

PS: Lets say you have a vector/array v= {1,3,2,4} and you want to iterate over it in a sorted way and you can't actually change v.

There can be many approaches for such scenario, Some of them I have listed below:

1) Copy v={1,3,2,4} into another vector tmp and then sort it and use.

2) Make an index_cum_value vector<pair<int,int>> v1= {{1,0},{3,1},{2,2},{4,3}} where first element of pair is our value and second element is the index in the original array. You can sort it on the basis of first element to get an sorted array with its original indexes intact. And by sorting on the basis of second element, you can retrieve the original array.

I personally used 2nd approach in most cases but, If you have to handle 3 or 4 array in this manners, you either have to come up with something like vector<pair<pair<pair<x,y>,z>> which is way messy to handle

OR

you can use this:

1) Create an order vector: odr= {0,1,2....n-1} and v= {1,3,2,4}

2) Now you can sort the odr vector with a custom comparator as

sort(odr.begin(),odr.end(), [&](int &i,int &j){ return v[i]<v[j];});

3) Whenever you want to access the elements in sorted order, you can access like v[odr[i]]

4) Doesn't Matter how many vectors you have, All the vectors can be easily addressed with this approach.

You can practice this approach in some of the questions:

Problem 1

Problem 2

That's It! Hope u got to know something new :)

Full text and comments »

  • Vote: I like it
  • +21
  • Vote: I do not like it

By SixtyWithoutSchool, history, 19 months ago, In English

Hii

Recently I resumed giving contests on Codechef and I noticed something very strange. If you look closely at the standings and the delta that they get after getting that range, you will notice it. For example lets take the standings of yesterday's Starters83B (Starters 83B Standings).

  • Rank 2: 3★jointquad (1797 --> 4★jointquad (1879) +82 Ratings
  • Rank 5: 4★ryotori (1859)--> 6★ryotori (2262) +403 Ratings
  • Rank 6: 3★ohameow (1723)--> 5★ohameow (2104) +381 Ratings
  • Rank 9: 4★moscow_wale12 (1917)--> 4★moscow_wale12 (1988) +71 Ratings

Comparing this to CF's rating pattern, you will find these changes strange. Someone is getting a direct jump from lower 4star to mid 6star in just one contest and someone who scores even better doesn't even get a star change. It seems unfair and weird.

Though ratings doesn't matter much to many people but sometimes you feel bad when you get such a less delta compared to people below you getting direct upgrade to 6star in just 2 contests.

Can you explain these changes? I think earlier it used to be better...

Btw Starters 83 had some really great questions.

Full text and comments »

  • Vote: I like it
  • +24
  • Vote: I do not like it