- Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathApplejackAndStorages.py
54 lines (47 loc) · 1.13 KB
/
ApplejackAndStorages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# problem: https://codeforces.com/contest/1393/problem/B
defcheck(tem2, tem4):
if(tem4<1):
returnFalse
if(tem4>=2):
returnTrue
if(tem2>=4):
returnTrue
returnFalse
num=int(input())
init=input().split()
dic= {}
tem4=0
tem2=0
resultado= []
foriininit:
ifiindic:
tem4-=int(dic[i]/4)
tem2-=int(dic[i]/2)
dic[i] +=1
tem4+=int(dic[i]/4)
tem2+=int(dic[i]/2)
else:
dic[i] =1
num=int(input())
foriinrange(num):
a, b=input().split()
if(a=="+"):
ifbindic:
tem4-=int(dic[b]/4)
tem2-=int(dic[b]/2)
dic[b] +=1
tem4+=int(dic[b]/4)
tem2+=int(dic[b]/2)
else:
dic[b] =1
else:
tem4-=int(dic[b]/4)
tem2-=int(dic[b]/2)
dic[b] -=1
tem4+=int(dic[b]/4)
tem2+=int(dic[b]/2)
if(check(tem2, tem4)):
resultado.append("YES")
else:
resultado.append("NO")
print("\n".join(resultado))