Untitled
unknown
python
23 days ago
2.6 kB
6
Indexable
import sys
def solve():
d=sys.stdin.buffer.read().split()
i=0
N=int(d[i]);i+=1
L={};S=set();R=[]
M=3650000
for _ in range(N):
o=d[i];i+=1
D=int(d[i]);i+=1
k=d[i];i+=1
c=d[i];i+=1
if c==b'CREATE_LOAN':e=2
elif c in(b'CHARGE_FEE',b'WAIVE_FEE',b'CHANGE_RATE',b'REPAY'):e=1
else:e=0
if o in S:
R.append('DUPLICATE')
i+=e
continue
S.add(o)
l=L.get(k)
if l is not None and l[6]==0:
ed=D-l[5]
if ed>0:
n=l[0]*l[4]*ed+l[3]
l[1]+=n//M
l[3]=n%M
l[5]=D
if c==b'CREATE_LOAN':
p=int(d[i]);i+=1
r=int(d[i]);i+=1
if l is not None or p<=0 or r<0:
R.append('INVALID')
else:
L[k]=[p,0,0,0,r,D,0]
R.append('SUCCESS')
elif c==b'CHARGE_FEE':
a=int(d[i]);i+=1
if l is None or l[6]!=0 or a<=0:
R.append('INVALID')
else:
l[2]+=a
R.append('SUCCESS')
elif c==b'WAIVE_FEE':
a=int(d[i]);i+=1
if l is None or l[6]!=0 or a<=0 or a>l[2]:
R.append('INVALID')
else:
l[2]-=a
R.append('SUCCESS')
elif c==b'CHANGE_RATE':
r=int(d[i]);i+=1
if l is None or l[6]!=0 or r<0:
R.append('INVALID')
else:
l[4]=r
R.append('SUCCESS')
elif c==b'REPAY':
a=int(d[i]);i+=1
if l is None or l[6]!=0 or a<=0 or a>l[0]+l[1]+l[2]:
R.append('INVALID')
else:
t=min(a,l[2]);l[2]-=t;a-=t
t=min(a,l[1]);l[1]-=t;a-=t
l[0]-=a
if l[0]==0:l[3]=0
R.append('SUCCESS')
elif c==b'QUERY':
if l is None:
R.append('INVALID')
else:
s='ACTIVE'if l[6]==0 else'CLOSED'
R.append(f'SNAPSHOT {k.decode()} {l[0]} {l[1]} {l[2]} {l[4]} {s}')
else:
if l is None or l[6]!=0 or l[0]!=0 or l[1]!=0 or l[2]!=0:
R.append('INVALID')
else:
l[6]=1;l[3]=0
R.append('SUCCESS')
for k in sorted(L):
l=L[k]
s='ACTIVE'if l[6]==0 else'CLOSED'
R.append(f'{k.decode()} {l[0]} {l[1]} {l[2]} {l[4]} {s}')
sys.stdout.write('\n'.join(R))
solve()Editor is loading...
Leave a Comment