3

How to get max integer less than or equal to x in a set ?

 2 years ago
source link: http://codeforces.com/blog/entry/68036
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to get max integer less than or equal to x in a set ?

By shoya, history, 2 years ago,

Consider initially an empty set and there are two types of queries:-
1) Given x, insert integer x in the set.
2) Given x, get the max integer y in the current set such that y<=x.

For Example :-
Suppose after several type 1 queries our set is {3,1,-14,1,5}.
Now type 2 comes with x=6 then answer would be 5.
Now type 1 comes with x=6 then set becomes {3,1,-14,1,5,6}.
Now type 2 comes with x=8 then answer would be 6.

How can we solve this problem without using policy based data structure ?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK