Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
ha4219 committed May 27, 2023
1 parent 02b4072 commit f6496f6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 52 deletions.
79 changes: 79 additions & 0 deletions boj/boj_28078.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from sys import stdin, maxsize, setrecursionlimit
from heapq import *
from bisect import *
from collections import deque
import random
from itertools import combinations, permutations
import math


MAX = 17
MOD = 1000000007
setrecursionlimit(10**6)
input = stdin.readline

N = int(input().strip())
s = [input().strip() for _ in range(N)]

class Q:
cnt = [0, 0]
direction = 0 #
d = deque() # 0: wall, 1: ball

def __init__(self) -> None:
pass

def rotate(self, right: bool):
self.direction = (self.direction + 1) % 4 if right \
else (self.direction - 1) % 4
self.waterfall()

def count(self, v: int):
print(self.cnt[v])

def pop(self):
if self.d:
v = self.d.pop()
self.cnt[v] -= 1
self.waterfall()

def push(self, v: int):
self.cnt[v] += 1
self.d.appendleft(v)
self.waterfall()

def waterfall(self):
if self.direction & 1:
pop = self.d.pop if self.direction == 1 else self.d.popleft
append = self.d.append if self.direction == 1 else self.d.appendleft
while self.d:
v = pop()
self.cnt[v] -= 1
if not v:
self.cnt[v] += 1
append(v)
break



def main():
q = Q()

for l in s:
query = l.split()

match query[0]:
case 'push':
q.push(1 if query[1] == 'b' else 0)
case 'pop':
q.pop()
case 'count':
q.count(1 if query[1] == 'b' else 0)
case 'rotate':
q.rotate(query[1] == 'r')
# print(q.d)
return


if __name__ == "__main__":
main()
26 changes: 8 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,18 @@
setrecursionlimit(10**6)
input = stdin.readline

N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(2)]
W, H, K = map(int, input().split())
N = int(input().strip())
ys = list(map(int, input().split()))
M = int(input().strip())
xs = list(map(int, input().split()))

def main():
wait = [(-1, 0)] # prev, val,
for _ in range(N):
q = []
for (p, v) in wait:
for l in range(3):
if p == l:
q.append((l, v + a[0][l]//2))
q.append((l, v + a[1][l]//2))
else:
q.append((l, v + a[0][l]))
q.append((l, v + a[1][l]))
wait = q
res = 0
for (_, val) in q:
res += 1 if val >= M else 0
print(res)

return


if __name__ == "__main__":
main()


36 changes: 2 additions & 34 deletions tmp.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,2 @@
def tree_update(i,diff):
while i<=N:
tree[i]+=diff
i+=i&-i
def tree_sum(i):
r=0
while i:
r+=tree[i]
i&=i-1
return r
import sys
input=sys.stdin.readline
N=int(input())
tree=[0]*(N+5)
a=[0]*1000005
b=[0]*(N+5)
for idx,i in enumerate(map(int,input().split())):
b[idx+1]=a[i]
a[i]=idx+1
M=int(input())
query=[tuple(map(int,input().split()))+(i,)for i in range(M)]
query.sort(key=lambda x:x[1])
ans=[0]*M
cur=0
for i in range(1,1+N):
if b[i]:
tree_update(b[i],-1)
tree_update(i,1)
while cur<M:
if query[cur][1]!=i:break
ans[query[cur][2]]=tree_sum(query[cur][1])-\
tree_sum(query[cur][0]-1)
cur+=1
print(*ans,sep='\n')
s = input()
print('YES' if sum([i in s for i in 'MOBIS']) > 4 else 'NO')

0 comments on commit f6496f6

Please sign in to comment.