Блог пользователя abcsumits

Автор abcsumits, история, 4 месяца назад, По-английски

It uses radix trie , where each node contains its subtrees leaf node count to index. And lower bound and upper bound are calculated based on last node that had other way to go if the current path doesnt leads to a leaf. Insertion and deletion has complexity of O(log(m)) where m is the integer we want to insert(basically that of a radix trie)

class intOrderedListNode:
    def __init__(self):
        self.zero_next=None
        self.zero_size=0
        self.one_next=None
        self.one_size=0
class intOrderedList(intOrderedListNode):
    def __init__(self):
        self.node=intOrderedListNode()
        self.max_depth=1
        self.size=0
    def insert(self, value: int) -> None:
        while self.max_depth<value:
            temp=self.node
            self.node=intOrderedListNode()
            self.node.zero_next=temp
            self.node.zero_size=temp.zero_size+temp.one_size
            self.max_depth<<=1
        temp=self.max_depth
        itr=self.node
        while temp>0:
            if value&temp:
                itr.one_size+=1
                if itr.one_next is None:
                    itr.one_next=intOrderedListNode()
                itr=itr.one_next
            else:
                itr.zero_size+=1
                if itr.zero_next is None:
                    itr.zero_next=intOrderedListNode()
                itr=itr.zero_next
            temp>>=1
        self.size+=1
    def __iter__(self):
        self.idx=0
        return self
    def __next__(self):
        if self.idx>=self.size:
            raise StopIteration
        result=self.index(self.idx)
        self.idx+=1
        return result
    def index(self, idx: int) -> int:
        if idx<0 or idx>=self.size:
            raise IndexError
        result=0
        temp=self.max_depth
        itr=self.node
        while temp>0:
            if itr.zero_size>idx:
                itr=itr.zero_next
            else:
                result|=temp
                idx-=itr.zero_size
                itr=itr.one_next
            temp>>=1
        return result
    def __len__(self):
        return self.size
    def __contains__(self, value: int) -> bool:
        temp=self.max_depth
        itr=self.node
        while temp>0:
            if value&temp:
                if itr.one_size==0:
                    return False
                itr=itr.one_next
            else:
                if itr.zero_size==0:
                    return False
                itr=itr.zero_next
            temp>>=1
        return True
    def lower_bound(self, value: int) -> int:
        temp=self.max_depth
        itr=self.node
        result=0
        last=None
        last_temp=temp
        chk=1
        while temp>0:
            if value&temp:
                if chk:
                    result+=itr.zero_size
                if itr.one_next :
                    itr=itr.one_next
                else:
                    if last:
                        itr=last
                        itr=itr.zero_next
                        temp=last_temp
                        chk=0
                        value=0
                    else:
                        return self.size
                    
            else:
                if itr.zero_next:
                    if itr.one_next:
                        last=itr
                        last_temp=temp
                    itr=itr.zero_next
                else:
                    itr=itr.one_next
                    chk=0
                    value=0
            temp>>=1
        return result
    def upper_bound(self, value: int) -> int:   
        temp=self.max_depth
        itr=self.node
        result=0
        last=None
        last_temp=temp
        chk=1
        while temp>0:
            if value&temp:
                result+=itr.zero_size
                if itr.one_next :
                    if temp==1 and chk:
                        result+=itr.one_size
                    itr=itr.one_next
                else:
                    if last:
                        itr=last
                        itr=itr.zero_next
                        temp=last_temp
                        value=0
                    else:
                        return self.size
                    
            else:
                if itr.zero_next:
                    if itr.one_next:
                        last=itr
                        last_temp=temp
                    if temp==1 and chk:
                        result+=itr.zero_size
                    itr=itr.zero_next
                else:
                    itr=itr.one_next
                    chk=0
                    value=0
            temp>>=1
        return result
    def pop(self, idx: int) -> int:
        if idx<0 or idx>=self.size:
            raise IndexError
        temp=self.max_depth
        itr=self.node
        result=0
        while temp>0:
            if itr.zero_size>idx:
                itr.zero_size-=1
                if itr.zero_size==0:
                    itr.zero_next=None
                itr=itr.zero_next
            else:
                result|=temp
                itr.one_size-=1
                if itr.one_size==0:
                    itr.one_next=None
                idx-=itr.zero_size
                itr=itr.one_next
            temp>>=1
        self.size-=1
        while self.node.one_size==0:
            self.node=self.node.zero_next
            self.max_depth>>=1
        return result

Полный текст и комментарии »

  • Проголосовать: нравится
  • -10
  • Проголосовать: не нравится

Автор abcsumits, история, 14 месяцев назад, По-английски

Check Out this playlist for number theory, will be adding new videos (comment missing topics) https://www.youtube.com/playlist?list=PL0PcgO0kAlsGkRntcmWB2H5AAHl1e6bh4

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор abcsumits, 2 года назад, По-английски

Sometimes due to hard problem A , number of participants get reduced which effect the rating change of every user,also some of my friend starts contest with problem d, if they crack it they do submissions, else they don't ,this should also be count as participation as only their best is getting counted.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -45
  • Проголосовать: не нравится

Автор abcsumits, история, 3 года назад, По-английски

Want to find ways to practice that help in fast improvement, Please suggest me. I can give 10 hours a day, Also if I increase difficulty problems takes a lot of time to solve, so I should practice till I am fast at that rating or waste more time by increasing difficulty.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -15
  • Проголосовать: не нравится

Автор abcsumits, история, 3 года назад, По-английски

I request everyone,to bully me until I became master.This will always remind me my goal and will keep me motivated, I am too weak now, but I want to be strong

Полный текст и комментарии »

  • Проголосовать: нравится
  • -27
  • Проголосовать: не нравится

Автор abcsumits, 3 года назад, По-английски

I need number of questions solved by a user and current cf rank but its missing, also number of active users. Can plz someone suggest me something .

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор abcsumits, история, 3 года назад, По-английски

I have to find min value of [a/x]+[b/x]+x-1 ,where x belongs to (1,10^9) ,here [] denotes ceil value. I then observed it is monotonic in nature. Its graph will be like

The only problem i am having is to find slope(from slope i meant if every step is assumed as points ,this will help me to shift l and r) and slope can be find by use of its previous neighbour points to find neighbour of y=f(x),we need to find length of y so for given y=[a/x]+[b/x]+x-1 i need the range of the solution

Полный текст и комментарии »

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

Автор abcsumits, 3 года назад, По-английски

These are some files that will help out in fast i/o, improving recursions, sorted lists,wrap function for collisions in dict and some pre written code that takes time to write. Here is the github link , I will update it with time.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +17
  • Проголосовать: не нравится

Автор abcsumits, история, 3 года назад, По-английски

python doesn't have any library for ordered map and ordered set. We can install sortedContainers module in our pc for that. Please include this module. It would be very helpful for all who code in python.

MikeMirzayanov

Полный текст и комментарии »

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

Автор abcsumits, история, 3 года назад, По-английски

I have been searching for ordered map and orderedset in python , but i didn't got anything other than ordered dictionary, if any one have idea about it please help me. Thanks in advance:)

Полный текст и комментарии »

  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится

Автор abcsumits, история, 4 года назад, По-английски

(huge difference refer to the following submission)

160762368 — accepted (str)

160761953 — tle (int)

both solution are same the only difference is the key in first is string and in 2nd the key is int which is causing tle .....

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор abcsumits, история, 4 года назад, По-английски

i have submitted the code in contest and it was accepted(even the solution was not hacked) and when i submitted the same code in pypy3 it was accepted.Then i saw others solution i found that everyone was having same complexity as me and submitted in python 3 only and their solution was accepted. question- https://mirror.codeforces.com/contest/1675/problem/B my contest submition — https://mirror.codeforces.com/contest/1675/submission/155950529 my pypy3 submition- https://mirror.codeforces.com/contest/1675/submission/156065421 a correct submition for referrence- https://mirror.codeforces.com/contest/1675/submission/156006177

Полный текст и комментарии »

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится