|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- class AlgoDatValue:
-
- memory = 0
- read = 0
- write = 0
- compare = 0
- add_operation = 0
- sub_operation = 0
- mul_operation = 0
- div_operation = 0
- bit_operation = 0
-
- @staticmethod
- def summary():
- print("*** Summary ***")
- print(f"Memory: {AlgoDatValue.memory}")
- print(f"Read: {AlgoDatValue.read}")
- print(f"Write: {AlgoDatValue.write}")
- print(f"Compare: {AlgoDatValue.compare}")
- print(f"Add: {AlgoDatValue.add_operation}")
- print(f"Sub: {AlgoDatValue.sub_operation}")
- print(f"Mul: {AlgoDatValue.mul_operation}")
- print(f"Div: {AlgoDatValue.div_operation}")
- print(f"Bit: {AlgoDatValue.bit_operation}")
-
-
- def __init__(self, value):
- AlgoDatValue.memory += 1
- AlgoDatValue.write += 1
- self.value = value
-
- def __str__(self):
- AlgoDatValue.read += 1
- return f"{self.value}"
-
- def __repr__(self):
- AlgoDatValue.read += 1
- return f"{self.value}"
-
- def __eq__(self, other):
- AlgoDatValue.compare += 1
- AlgoDatValue.read += 2
- if not isinstance(other, AlgoDatValue):
- return self.value == other
- return self.value == other.value
-
- def __lt__(self, other):
- AlgoDatValue.compare += 1
- AlgoDatValue.read += 2
- if not isinstance(other, AlgoDatValue):
- return self.value < other
- return self.value < other.value
-
- def __le__(self, other):
- AlgoDatValue.compare += 1
- AlgoDatValue.read += 2
- if not isinstance(other, AlgoDatValue):
- return self.value <= other
- return self.value <= other.value
-
- def __gt__(self, other):
- AlgoDatValue.compare += 1
- AlgoDatValue.read += 2
- if not isinstance(other, AlgoDatValue):
- return self.value > other
- return self.value > other.value
-
- def __ge__(self, other):
- AlgoDatValue.compare += 1
- AlgoDatValue.read += 2
- if not isinstance(other, AlgoDatValue):
- return self.value >= other
- return self.value >= other.value
-
- def __add__(self, other):
- AlgoDatValue.add_operation += 1
- AlgoDatValue.read += 2
- return self.value + other.value
-
- def __sub__(self, other):
- AlgoDatValue.sub_operation += 1
- AlgoDatValue.read += 2
- return self.value - other.value
-
- def __mul__(self, other):
- AlgoDatValue.mul_operation += 1
- AlgoDatValue.read += 2
- return self.value * other.value
-
- def __truediv__(self, other):
- AlgoDatValue.div_operation += 1
- AlgoDatValue.read += 2
- return self.value / other.value
-
- def __floordiv__(self, other):
- AlgoDatValue.div_operation += 1
- AlgoDatValue.read += 2
- return self.value // other.value
-
- def __mod__(self, other):
- AlgoDatValue.div_operation += 1
- AlgoDatValue.read += 2
- return self.value % other.value
-
- def __iadd__(self, other):
- AlgoDatValue.add_operation += 1
- AlgoDatValue.read += 1
- AlgoDatValue.write += 1
- self.value += other.value
- return self
-
- def __isub__(self, other):
- AlgoDatValue.sub_operation += 1
- AlgoDatValue.read += 1
- AlgoDatValue.write += 1
- self.value -= other.value
- return self
-
- def __imul__(self, other):
- AlgoDatValue.mul_operation += 1
- AlgoDatValue.read += 1
- AlgoDatValue.write += 1
- self.value *= other.value
- return self
-
- def __itruediv__(self, other):
- AlgoDatValue.div_operation += 1
- AlgoDatValue.read += 1
- AlgoDatValue.write += 1
- self.value /= other.value
- return self
-
- def __ifloordiv__(self, other):
- AlgoDatValue.div_operation += 1
- AlgoDatValue.read += 1
- AlgoDatValue.write += 1
- self.value //= other.value
- return self
-
- def __imod__(self, other):
- AlgoDatValue.div_operation += 1
- AlgoDatValue.read += 1
- AlgoDatValue.write += 1
- self.value %= other.value
- return self
-
- def __neg__(self):
- return -self.value
-
- def __pos__(self):
- return +self.value
-
- def __abs__(self):
- return abs(self.value)
-
- def __invert__(self):
- return ~self.value
-
- def __lshift__(self, other):
- AlgoDatValue.bit_operation += 1
- AlgoDatValue.read += 2
- return self.value << other.value
-
- def __rshift__(self, other):
- AlgoDatValue.bit_operation += 1
- AlgoDatValue.read += 2
- return self.value >> other.value
-
- def __and__(self, other):
- AlgoDatValue.bit_operation += 1
- AlgoDatValue.read += 2
- return self.value & other.value
-
- def __xor__(self, other):
- AlgoDatValue.bit_operation += 1
- AlgoDatValue.read += 2
- return self.value ^ other.value
-
- def __or__(self, other):
- AlgoDatValue.bit_operation += 1
- AlgoDatValue.read += 2
- return self.value | other.value
-
- def __ilshift__(self, other):
- AlgoDatValue.bit_operation += 1
- AlgoDatValue.read += 2
- AlgoDatValue.write += 1
- self.value <<= other.value
- return self
-
- def __irshift__(self, other):
- AlgoDatValue.bit_operation += 1
- AlgoDatValue.read += 2
- AlgoDatValue.write += 1
- self.value >>= other.value
- return self
-
- def __iand__(self, other):
- AlgoDatValue.bit_operation += 1
- AlgoDatValue.read += 2
- AlgoDatValue.write += 1
- self.value &= other.value
- return self
-
- def __ixor__(self, other):
- AlgoDatValue.bit_operation += 1
- AlgoDatValue.read += 2
- AlgoDatValue.write += 1
- self.value ^= other.value
- return self
-
- def __ior__(self, other):
- AlgoDatValue.bit_operation += 1
- AlgoDatValue.read += 2
- AlgoDatValue.write += 1
- self.value |= other.value
- return self
-
- def __int__(self):
- return int(self.value)
-
- def __float__(self):
- return float(self.value)
-
- def __complex__(self):
- return complex(self.value)
-
- def __round__(self, n=0):
- return round(self.value, n)
-
-
- class AlgoDatArray:
-
- def __init__(self, size):
- self.size = size
- self.array = [AlgoDatValue(None)] * size
-
- def set(self, index, value):
- assert isinstance(value, AlgoDatValue)
- assert isinstance(index, int)
- self.array[index] = value
-
- def get(self, index):
- assert isinstance(index, int)
- return self.array[index]
-
- def __str__(self):
- return str(self.array)
-
- def __len__(self):
- return len(self.array)
-
- def __iter__(self):
- return iter(self.array)
-
- def __getitem__(self, index):
- assert isinstance(index, int)
- return self.array[index]
-
- def __setitem__(self, index, value):
- assert isinstance(index, int)
- assert isinstance(value, AlgoDatValue)
- self.array[index] = value
-
-
- def ReadIntSequence(filename):
- with open(filename, "r") as file:
- l = list(map(int, file.read().split()))
- a = AlgoDatArray(len(l))
- for i in range(len(l)):
- a.set(i, AlgoDatValue(l[i]))
- return a
|