-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |