cp-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub kobejean/cp-library

:warning: cp_library/ds/cnt/distinct_counter_cls.py

Required by

Code

import cp_library.__header__
from collections import Counter
import cp_library.ds.__header__
import cp_library.ds.cnt.__header__

class DistinctCounter:
    def __init__(dc, Amax: int):
        dc.cnt = 0
        dc.freq = [0]*(Amax+1) if Amax < 5_000_000 else Counter()

    def add(dc, a):
        dc.cnt += dc.freq[a] == 0
        dc.freq[a] += 1

    def remove(dc, a):
        dc.freq[a] -= 1
        dc.cnt -= dc.freq[a] == 0
    
    def count(dc): return dc.cnt
'''
╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸
             https://kobejean.github.io/cp-library               
'''
from collections import Counter



class DistinctCounter:
    def __init__(dc, Amax: int):
        dc.cnt = 0
        dc.freq = [0]*(Amax+1) if Amax < 5_000_000 else Counter()

    def add(dc, a):
        dc.cnt += dc.freq[a] == 0
        dc.freq[a] += 1

    def remove(dc, a):
        dc.freq[a] -= 1
        dc.cnt -= dc.freq[a] == 0
    
    def count(dc): return dc.cnt
Back to top page