input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
import sys input = lambda: sys.stdin.readline().rstrip('\r\n') N, Q = list(map(int, input().split())) C = list(map(int, input().split())) div = max(int(Q**.5), 1) B = N // div Qs = [] for i in range(Q): l, r = [int(s)-1 for s in input().split()] Qs.append((l, r+1, i)) Qs.sort(key=lambda v: (v[0]//B,...
import sys input = lambda: sys.stdin.readline().rstrip('\r\n') N, Q = list(map(int, input().split())) C = list(map(int, input().split())) by_R = [[] for _ in range(N+1)] for i in range(Q): l, r = [int(s)-1 for s in input().split()] by_R[r+1].append((l, i)) s = [0] * N def update(pos, dif): while pos ...
p02599
import sys rd = sys.stdin.readline n,q = list(map(int,rd().split())) c = list(map(int,rd().split())) # セグ木 #使う操作 #####segfunc##### def segfunc1(x, y): return x | y ################# #####ide_ele##### ide_ele1 = set() ################# class SegTree: """ init(init_val, ide_ele): 配列in...
import sys rd = sys.stdin.readline class BIT: def __init__(self,len_A): self.N = len_A + 10 self.bit = [0]*(len_A+10) # sum(A0 ~ Ai) # O(log N) def query(self,i): res = 0 idx = i+1 while idx: res += self.bit[idx] id...
p02599
x=lambda:list(map(int,input().split())) def build(s,e,index): if s==e: seg[index] = {arr[s]} return mid = (s+e)//2 build(s,mid,2*index) build(mid+1,e,2*index+1) seg[index] = set(list(seg[2*index]) + list(seg[2*index+1])) return def query(s,e,qs,qe,index): if qe<s or qs>e: return set() ...
x=lambda:list(map(int,input().split())) n,q = x() arr = x() for _ in range(q): l,r = x() l-=1 print((len(list(set(arr[l:r])))))
p02599
import sys,bisect,string,math,time,functools,random,fractions from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby rep=range;R=range def Golf():n,*t=map(int,open(0).read().split()) def I():return int(input()) def S_()...
import sys,bisect,string,math,time,functools,random,fractions from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter from itertools import permutations,combinations,groupby rep=range;R=range def Golf():n,*t=map(int,open(0).read().split()) def I():return int(input()) def S_()...
p02599
class BIT: def __init__(self, n): self.n = n self.data = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): # assert i > 0 self.el[i] += x while i <= self.n: self.data[i...
from sys import stdin input = stdin.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): w...
p02599
class BIT: def __init__(self, n): self.n = n self.data = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): # assert i > 0 while i <= self.n: self.data[i] += x i += i & -i N, Q = list(map(i...
class BIT: def __init__(self, n): self.n = n self.data = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): while i <= self.n: self.data[i] += x i += i & -i N, Q = list(map(int, input().split())...
p02599
#https://qiita.com/takayg1/items/c811bd07c21923d7ec69 #####segfunc##### def segfunc(x, y): return x+y ################# #####ide_ele##### ide_ele = 0 ################# class SegTree: """ init(init_val, ide_ele): 配列init_valで初期化 O(N) update(k, x): k番目の値をxに更新 O(logN) query(l, r): 区間[l, ...
# Binary Indexed Tree (Fenwick Tree) class BIT: def __init__(self, n): self.n = n self.data = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): i += 1 # assert i > 0 self.el[...
p02599
from collections import Counter N, Q = list(map(int, input().split())) c = list(map(int, input().split())) cs = [] counter = Counter() for ci in c: counter.update([ci]) c2 = Counter(counter) cs.append(c2) memo = [[-1] * (N+1) for _ in range(N+1)] for i in range(Q): l, r = list(map(i...
import math N, Q = list(map(int, input().split())) c = list(map(int, input().split())) M = int(math.sqrt(N)) cs = [] for i in range(0, N, M): cs.append(set(c[i:min(i+M, N)])) for i in range(Q): l, r = list(map(int, input().split())) li = l // M ri = r // M if li == ri: ...
p02599
import math N, Q = list(map(int, input().split())) c = list(map(int, input().split())) M = int(math.sqrt(N)) cs = [] for i in range(0, N, M): cs.append(set(c[i:min(i+M, N)])) for i in range(Q): l, r = list(map(int, input().split())) li = l // M ri = r // M if li == ri: ...
class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n+1) def sum(self, i): # sum in [0, i) s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): # i > 0 assert i > 0 whil...
p02599
def query(i): ''' a[0] + a[1] + … + a[i-1] を求める O(logN) ''' res = 0 while i > 0: res += BIT[i] i -= i & -i return res def update(i, x): ''' a[i-1]にxを加算 O(logN) ''' while i <= n: BIT[i] += x i += i & -i n, q =...
import sys input = sys.stdin.readline def query(i): ''' a[0] + a[1] + … + a[i-1] を求める O(logN) ''' res = 0 while i > 0: res += BIT[i] i -= i & -i return res def update(i, x): ''' a[i-1]にxを加算 O(logN) ''' while i <= n: ...
p02599
import sys input = sys.stdin.readline def query(i): ''' a[0] + a[1] + … + a[i-1] を求める O(logN) ''' res = 0 while i > 0: res += BIT[i] i -= i & -i return res def update(i, x): ''' a[i-1]にxを加算 O(logN) ''' while i <= n: ...
import sys input = sys.stdin.buffer.readline def query(i): ''' a[0] + a[1] + … + a[i-1] を求める O(logN) ''' res = 0 while i > 0: res += BIT[i] i -= i & -i return res def update(i, x): ''' a[i-1]にxを加算 O(logN) ''' while i <= n: ...
p02599
""" Satwik_Tiwari ;) . 30th AUGUST , 2020 - SUNDAY """ #=============================================================================================== #importing some useful libraries. from fractions import Fraction import sys import os from io import BytesIO, IOBase from itertools import * ...
MAX = 1000001 class Query: def __init__(self, l, r, idx): self.l = l self.r = r self.idx = idx # updating the bit array def update(idx, val, bit, n): while idx <= n: bit[idx] += val idx += idx & -idx # querying the bit array def query(idx, ...
p02599
""" Satwik_Tiwari ;) . 12th Sept , 2020 - Saturday """ #=============================================================================================== #importing some useful libraries. # from fractions import Fraction import sys import os from io import BytesIO, IOBase # from itertools impor...
class BIT: def __init__(self,n): self.n = n self.tree = [0]*(n+1) def sum(self,x): sum = 0 while(x>0): sum+=self.tree[x] x-=x&(-x) return sum def update(self,x,k): while(x<=self.n): self.tree[x]+=k ...
p02599
class BIT: def __init__(self,n): self.n = n self.tree = [0]*(n+1) def sum(self,x): sum = 0 while(x>0): sum+=self.tree[x] x-=x&(-x) return sum def update(self,x,k): while(x<=self.n): self.tree[x]+=k ...
class BIT: def __init__(self,n): self.n = n self.tree = [0]*(n+1) def sum(self,x): sum = 0 while(x>0): sum+=self.tree[x] x-=x&(-x) return sum def update(self,x,k): while(x<=self.n): self.tree[x]+=k ...
p02599
""" Satwik_Tiwari ;) . 12th Sept , 2020 - Saturday """ #=============================================================================================== #importing some useful libraries. # from fractions import Fraction import sys import os from io import BytesIO, IOBase # from itertools impor...
""" Satwik_Tiwari ;) . 12th Sept , 2020 - Saturday """ #=============================================================================================== #importing some useful libraries. # from fractions import Fraction import sys import os from io import BytesIO, IOBase # from itertools impor...
p02599
""" Satwik_Tiwari ;) . 12th Sept , 2020 - Saturday """ #=============================================================================================== #importing some useful libraries. # from fractions import Fraction import sys import os from io import BytesIO, IOBase # from itertools impor...
""" Satwik_Tiwari ;) . 12th Sept , 2020 - Saturday """ #=============================================================================================== #importing some useful libraries. # from fractions import Fraction import sys import os from io import BytesIO, IOBase # from itertools impor...
p02599
class FenwickTree: def __init__(self, size): self.size = size self.array = [0]*size def add(self, index, value): while index < self.size: self.array[index] += value index += index&(-index) def sum(self, index): answer = 0 while ...
def solve(): import sys input = sys.stdin.readline class FenwickTree: def __init__(self, size): self.size = size self.array = [0]*size def add(self, index, value): while index < self.size: self.array[index] += value ...
p02599
from collections import deque, defaultdict n, q = list(map(int ,input().split())) c = list(map(int, input().split())) data = [] for i in range(q): data.append([i] + list(map(int, input().split()))) data.sort(key=lambda x : x[2]) ans = [0 for i in range(q)] #####segfunc###### def segfunc(x,y): return x...
from sys import stdin input = stdin.readline n, q = list(map(int ,input().split())) c = list(map(int, input().split())) data = [] for i in range(q): data.append([i] + list(map(int, input().split()))) data.sort(key=lambda x : x[2]) ans = [0 for i in range(q)] #####segfunc###### def segfunc(x,y): retur...
p02599
N, Q = map(int, input().split()) C = list(map(int, input().split())) query = [] for i in range(Q): l, r = map(int, input().split()) query.append((i, l, r)) query.sort(key = lambda x: x[2]) class BIT: from operator import add, sub X_unit = 0 X_f = add X_f_rev = sub def __init__(self, se...
import sys input = sys.stdin.readline N, Q = map(int, input().split()) C = list(map(int, input().split())) query = [] for i in range(Q): l, r = map(int, input().split()) query.append((i, l, r)) query.sort(key = lambda x: x[2]) class BIT: from operator import add, sub X_unit = 0 X_f = add ...
p02599
import sys input = sys.stdin.readline def update(index, value, bit): #print('update', index, value) while index < len(bit): #print('update', index) bit[index] += value index += index & -index #print('done') def cumsum(index, bit): ans = 0 while index > 0: #print('cumsum',...
import sys input = sys.stdin.readline def update(index, value, bit): #print('update', index, value) while index < len(bit): #print('update', index) bit[index] += value index += index & -index #print('done') def cumsum(index, bit): ans = 0 while index > 0: #print('cu...
p02599
import sys input = sys.stdin.readline def main(): n,q=map(int,input().split()) c=list(map(int,input().split())) lr=[list(map(int,input().split())) for _ in range(q)] lri=[[lr[i][0],lr[i][1],i] for i in range(q)] lri.sort(key=lambda x:x[1]) def segfunc(x, y): return x+y ################# ...
import sys input = sys.stdin.readline def main(): n,q=map(int,input().split()) c=list(map(int,input().split())) lr=[list(map(int,input().split())) for _ in range(q)] lri=[[lr[i][0],lr[i][1],i] for i in range(q)] lri.sort(key=lambda x:x[1]) class BIT: def __init__(self, n): se...
p02599
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=list(...
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
p02599
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
p02599
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
p02599
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
p02599
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
p02599
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
p02599
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda: sys.stdin.readline().rstrip() YesNo=lambda b: bool([print('Yes')] if b else print('No')) YESNO=lambda b: bool([print('YES')] if b else print('NO')) int1=lambda x:int(x)-1 N,Q=map(int,input().split()) a=tuple...
p02599
import sys class BinaryIndexedTree(object): ''' 1-indexed ''' def __init__(self, A): self.__n = len(A) self.__node = [0] * (self.__n + 1) self.__data = [0] * (self.__n + 1) S = [0] * (self.__n + 1) for i in range(self.__n): S[i + 1] = ...
import sys class BinaryIndexedTree(): ''' 1-indexed ''' def __init__(self, A): self.__n = len(A) self.__node = [0] * (self.__n + 1) self.__data = [0] * (self.__n + 1) S = [0] * (self.__n + 1) for i in range(self.__n): S[i + 1] = S[i] +...
p02599
import sys class BinaryIndexedTree(): ''' 1-indexed ''' def __init__(self, A): self.__n = len(A) self.__node = [0] * (self.__n + 1) self.__data = [0] * (self.__n + 1) S = [0] * (self.__n + 1) for i in range(1, self.__n + 1): S[i] = S[i...
import sys class BinaryIndexedTree(): ''' 1-indexed ''' def __init__(self, A): self.__n = len(A) self.__node = [0] * (self.__n + 1) self.__data = [0] * (self.__n + 1) S = [0] * (self.__n + 1) for i in range(self.__n): S[i + 1] = S[i] +...
p02599
import sys from operator import add class SegmentTree(): """ update, get を提供するSegmentTree Attributes ---------- __n : int 葉の数。2 ^ i - 1 __dot : Segment function __e: int 単位元 __node: list Segment Tree """ def __init__(self, A, do...
import sys from operator import add, itemgetter class SegmentTree(): """ update, get を提供するSegmentTree Attributes ---------- __n : int 葉の数。2 ^ i - 1 __dot : Segment function __e: int 単位元 __node: list Segment Tree """ def __init...
p02599
class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] ...
class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] ...
p02599
n, q = map(int, input().split()) C = [0] + list(map(int, input().split())) D = [-1]*(n+1) A = [0]*q LR = tuple(tuple(map(int, input().split())) for _ in range(q)) W = sorted((r, i) for i, (l, r) in enumerate(LR)) B = [0]*(1<<n.bit_length()) def add(i, a): while i <= n: B[i] += a i += i & -i def acc...
n, q = map(int, input().split()) C = [0] + list(map(int, input().split())) D = [-1]*(n+1) A = [0]*q U = 10**6 LR = tuple(tuple(map(int, input().split())) for _ in range(q)) W = sorted(r*U+i for i, (l, r) in enumerate(LR)) B = [0]*(1<<n.bit_length()) def add(i, a): while i <= n: B[i] += a i += i & -...
p02599
from collections import deque N,Q=list(map(int, input().split())) #重複分を引く class SegmentTree: def __init__(self, init_value: list, segfunc, ide_ele): n = len(init_value) self.N0 = 1 << (n - 1).bit_length() self.ide_ele = ide_ele self.data = [ide_ele] * (2 * self.N0) ...
from collections import deque N,Q=list(map(int, input().split())) #重複分を引く class BIT: def __init__(self, n): self.n = n self.data = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i...
p02599
from collections import deque N,Q=list(map(int, input().split())) #重複分を引く class BIT: def __init__(self, n): self.n = n self.data = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i...
from collections import deque N,Q=list(map(int, input().split())) #重複分を引く class BIT: def __init__(self, n): self.n = n self.data = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i...
p02599
from collections import deque N,Q=list(map(int, input().split())) #重複分を引く class BIT: def __init__(self, n): self.n = n self.data = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i...
from collections import deque N,Q=list(map(int, input().split())) #重複分を引く class BIT: def __init__(self, n): self.n = n self.data = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i...
p02599
import sys input = sys.stdin.buffer.readline from operator import itemgetter class BIT: """一点加算、区間取得クエリをそれぞれO(logN)で答えるデータ構造""" def __init__(self, n): self.size = n self.bit = [0] * (n + 1) def build(self, array): """arrayを初期値とするBinaryIndexTreeを構築する O(N)""" fo...
import sys input = sys.stdin.buffer.readline from operator import itemgetter class BIT: """一点加算、区間取得クエリをそれぞれO(logN)で答えるデータ構造""" def __init__(self, n): self.size = n self.bit = [0] * (n + 1) def build(self, array): """arrayを初期値とするBinaryIndexTreeを構築する O(N)""" fo...
p02599
import sys input = sys.stdin.buffer.readline from operator import itemgetter class BIT: """一点加算、区間取得クエリをそれぞれO(logN)で答えるデータ構造""" def __init__(self, n): self.size = n self.bit = [0] * (n + 1) def build(self, array): """arrayを初期値とするBinaryIndexTreeを構築する O(N)""" fo...
import sys input = sys.stdin.buffer.readline from operator import itemgetter class BIT: """一点加算、区間取得クエリをそれぞれO(logN)で答えるデータ構造""" def __init__(self, n): self.size = n self.bit = [0] * (n + 1) def build(self, array): """arrayを初期値とするBinaryIndexTreeを構築する O(N)""" fo...
p02599
I = [int(_) for _ in open(0).read().split()] N, Q = I[:2] C = [0] + I[2:2 + N] LR = I[2 + N:] L, R = LR[::2], LR[1::2] class BinaryIndexedTree(): def __init__(self, n): """ constructs binary indexed tree Parameters ---------- n : int maximum inde...
I = [int(_) for _ in open(0).read().split()] N, Q=I[:2] C = I[2:2 + N] LR = I[2 + N:] 2 ** 40 2 ** 20 Query = [] for i, lr in enumerate(zip(LR[::2], LR[1::2])): l, r = lr Query += [r * 2 ** 40 + l * 2 ** 20 + i] for i, c in enumerate(C): Query += [(i + 1) * 2 ** 40 + c] Query.sort() c_i = [-1] ...
p02599
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys def main(N, Q, C, LR): st = SegmentTree(f=lambda x, y: x | y, initial_values=[1 << (c - 1) for c in C]) for l, r in LR: print((popcount(st.query(l - 1, r)))) def popcount(x): x = (x & 0x5555555555555555) + (x >> 1 & 0x555555555555555...
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys def main(N, Q, C, LR): ans = [0] * Q LRi = [(l, r, i) for i, (l, r) in enumerate(LR)] LRi.sort(key=lambda x: x[1]) bit = BinaryIndexedTree(N) MR = [-1] * (N + 1) p = 0 for l, r, i in LRi: l, r = l - 1, r - 1 ...
p02599
NN = 19 XX = [0] * (2**(NN+1)-1) def addvalue(j, x): i = 2**NN + j - 1 while i >= 0: XX[i] += x i = (i-1) // 2 def rangesum(a, b): l = a + (1<<NN) r = b + (1<<NN) s = 0 while l < r: if l%2: s += XX[l-1] l += 1 if r%2: ...
##### https://atcoder.jp/contests/abc174/submissions/15644075 を1次元化 import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.buffer.readline().rstrip() class SegmentTree(object): def __init__(self, A, dot, unit): n = 1 << (len(A) - 1).bit_l...
p02599
I=lambda:list(map(int,input().split())) N=0xfffff n,q=I() c=list(I()) Q=[] for i in range(q):l,r=I();Q.append(l<<40|r<<20|i) Q.sort() A=[[]for i in range(N)] for i,x in enumerate(c):A[x].append(i) B=[0]*N def P(i,x): i+=1 while i<=n:B[i]+=x;i+=i&-i def G(i): s=0 while i:s+=B[i];i-=i&-i return s fo...
I=lambda:list(map(int,input().split())) N=0xfffff n,q=I() c=list(I()) Q=[] for i in range(q):l,r=I();Q.append(l<<40|r<<20|i) Q.sort() A=[[]for i in range(N)] for i in range(n):A[c[i]].append(i) B=[0]*N def P(i,x): i+=1 while i<=n:B[i]+=x;i+=i&-i def G(i): s=0 while i:s+=B[i];i-=i&-i return s for i...
p02599
I=lambda:list(map(int,input().split())) N=0xfffff n,q=I() c=list(I()) Q=[] R=range for i in R(q):l,r=I();Q.append(l<<40|r<<20|i) Q.sort() A=[[]for i in R(N)] for i in R(n):A[c[i]].append(i) B=[0]*N def P(i,x): i+=1 while i<=n:B[i]+=x;i+=i&-i def G(i): s=0 while i:s+=B[i];i-=i&-i return s for i in...
I=lambda:list(map(int,input().split())) N=0xfffff n,q=I() c=list(I()) Q=[] R=range for i in R(q):l,r=I();Q.append(l<<40|r<<20|i) Q.sort() A=[[]for i in R(N)] for i in R(n):A[c[i]].append(i) B=[0]*N def P(i,x): i+=1 while i<=n:B[i]+=x;i+=i&-i for i in A: if i:P(i[0],1);i.reverse() t=0 o=[0]*q for x ...
p02599
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self....
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self....
p02599
N, Q = list(map(int, input().split())) lists = [list(map(int, input().split())) for i in range(Q+1)] master = lists.pop(0) X = [master[l[0]-1:l[1]] for l in lists] for x in X: print((len(set(x))))
N, Q = list(map(int, input().split())) lists = [list(map(int, input().split())) for i in range(Q+1)] master = lists.pop(0) X = [len(set(master[l[0]-1:l[1]])) for l in lists] for x in X: print(x)
p02599
class Bit: def __init__(self,n): self.bl = n.bit_length() self.size = n self.tree = [0]*(n+1) def sum(self,i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self,i,x): while i <= self.size: self.tree[i] += x i += i & -i ...
class Bit: def __init__(self,n): self.bl = n.bit_length() self.size = n self.tree = [0]*(n+1) def sum(self,i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def add(self,i,x): while i <= self.size: self.tree[i] += x i += i & -i ...
p02599
from collections import defaultdict n, q = (int(i) for i in input().split()) nums = [0] # not a color nums = [int(i) for i in input().split()] nums_info = [] colors = defaultdict(lambda: 0) for num in nums: colors[num] += 1 nums_info.append(dict(colors)) #print(nums_info) for _ in range(q): s, ...
n, q = (int(i) for i in input().split()) nums = [int(i) for i in input().split()] #print(nums_info) for _ in range(q): s, e = (int(i) for i in input().split()) s -= 1 ans = set() for i in range(s, e): ans.add(nums[i]) print((len(ans)))
p02599
from sys import stdin #import numpy as np readline = stdin.readline N, Q = map(int, readline().split()) C = list(map(int, readline().split())) S = [list(map(int, readline().split())) for _ in range(Q)] def main(N, Q, C, S): # Binary Indexed Tree # https://juppy.hatenablog.com/entry/2018/11/17/%E8...
from sys import stdin #import numpy as np readline = stdin.readline N, Q = map(int, readline().split()) C = list(map(int, readline().split())) S = [list(map(int, readline().split())) for _ in range(Q)] #print(S) def main(N, Q, C, S): # Binary Indexed Tree # https://juppy.hatenablog.com/entry/20...
p02599
BIT = [0] * ((1 << 19) + 1) def add(i, x): while i <= (1 << 19): BIT[i] += x i += i & (-i) def query(i): res = 0 while i > 0: res += BIT[i] i -= i & (-i) return res n, q = map(int, input().split()) c = list(map(int, input().split())) Q = [[] for i in range(n)...
BIT = [0] * ((1 << 19) + 1) def add(i, x): while i <= (1 << 19): BIT[i] += x i += i & -i def query(i): res = 0 while i > 0: res += BIT[i] i -= i & -i return res n, q = map(int, input().split()) c = list(map(int, input().split())) Q = [[] for i in range(n)] f...
p02599
import sys read=sys.stdin.buffer.readline class BIT: def __init__(self,N): self.N=N self.bit=[0]*N def add(self,a,w): x=a while(x<self.N): self.bit[x]+=w x|=x+1 def get(self,a): ret,x=0,a-1 while(x>=0): ret+=...
import sys read=sys.stdin.buffer.readline class BIT: def __init__(self,N): self.N=N self.bit=[0]*N def add(self,a,w): x=a while(x<self.N): self.bit[x]+=w x|=x+1 def get(self,a): ret,x=0,a-1 while(x>=0): ret+=...
p02599
import sys read=sys.stdin.buffer.readline class BIT: def __init__(self,N): self.N=N self.bit=[0]*N def add(self,a,w): x=a while(x<self.N): self.bit[x]+=w x|=x+1 def get(self,a): ret,x=0,a-1 while(x>=0): ret+=...
import sys read=sys.stdin.buffer.readline class BIT: def __init__(self,N): self.N=N self.bit=[0]*N def add(self,a,w): x=a while(x<self.N): self.bit[x]+=w x|=x+1 def get(self,a): ret,x=0,a-1 while(x>=0): ret+=...
p02599
def main(): import sys input = sys.stdin.readline class BIT: def __init__(self,n): self.tree = [0]*(n+1) self.size = n def add(self,i,x): while i <= self.size: self.tree[i] += x i += i&-i ...
def main(): import sys input = sys.stdin.readline class BIT: def __init__(self,n): self.tree = [0]*(n+1) self.size = n def add(self,i,x): while i <= self.size: self.tree[i] += x i += i&-i ...
p02599
def main(): import sys input = sys.stdin.readline class BIT: def __init__(self,n): self.tree = [0] * (n+1) self.size = n def add(self,i,x): while i <= self.size: self.tree[i] += x i += i&-i ...
def main(): import sys input = sys.stdin.readline class BIT: def __init__(self,n): self.tree = [0]*(n+1) self.size = n def add(self,i,x): while i <= self.size: self.tree[i] += x i += i&-i ...
p02599
# Date [ 2020-09-06 11:56:02 ] # Problem [ f.py ] # Author Koki_tkg import sys # import math # import bisect # import numpy as np # from decimal import Decimal # from numba import njit, i8, u1, b1 #JIT compiler # from itertools import combinations, product from collections import Counter, deque, defaultdict...
import sys # import math # import bisect # import numpy as np # from decimal import Decimal # from numba import njit, i8, u1, b1 #JIT compiler # from itertools import combinations, product from collections import Counter, deque, defaultdict # sys.setrecursionlimit(10 ** 6) MOD = 10 ** 9 + 7 INF = 10 ** 9 P...
p02599
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 # Reference: https://www.geeksforgeeks.org/queries-number-distinct-elements-subarray/ # Python3 code to find number of # distinct numbers in a subarra...
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 class BIT: def __init__(self, n): self.n = n self.data = [0] * (n + 1) def add(self, i, x=1): i += 1 w...
p02599
import sys input = sys.stdin.buffer.readline n, q = list(map(int, input().split())) C = list(map(int, input().split())) def popcnt(n): c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555) c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333) c = (c & 0x0F0F0F0F0F0F0F0F) + ((c...
import sys input = sys.stdin.buffer.readline n, q = map(int, input().split()) C = list(map(int, input().split())) LR = [] for i in range(q): l, r = map(int, input().split()) LR.append((l, r, i)) LR.sort(key=lambda x: x[1]) BIT = [0] * (n + 1) def update(idx, val): while idx <= n: ...
p02599
from operator import or_ import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) class SparseTable: def __init__(self, N, arr, op): self.N = N self.depth = N.bit_length() self.op = op self.arr = tuple(arr) self._build() def __call__(se...
class SegmentTree: def __init__(self, N, arr=None, op=None): """ INPUT N: 配列のサイズ segment tree: 1-indexedで構築 original array: 0-indexed 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ---------------------...
p02599
import sys input = sys.stdin.readline class BIT: def __init__(self, n): self.size = n self.array = [0] * (n + 1) self.e = [0] * n def sum(self, i): s = 0 tmp = i while tmp > 0: s += self.array[tmp] tmp -= tmp & -tmp ...
import sys input = sys.stdin.readline class BIT: def __init__(self, n): self.array = [0] * (n + 1) self.size = n def sum(self, i): s = 0 tmp = i while tmp > 0: s += self.array[tmp] tmp -= tmp & -tmp return s def add...
p02599
class BIT: def __init__(self, n): self.array = [0] * (n + 1) self.size = n def sum(self, i): s = 0 tmp = i while tmp > 0: s += self.array[tmp] tmp -= tmp & -tmp return s def add(self, i, x): tmp = i + 1 ...
import sys input = sys.stdin.readline class BIT: def __init__(self, n): self.array = [0] * (n + 1) self.size = n def sum(self, i): s = 0 tmp = i while tmp > 0: s += self.array[tmp] tmp -= tmp & -tmp return s def add...
p02599
N,M,X,Y=list(map(int,input().split())) x=list(map(int,input().split())) y=list(map(int,input().split())) x.sort() y.sort() if y[0]>x[N-1] and y[0]>X and x[N-1]<Y: print('No War') else: print('War')
N,M,X,Y=list(map(int,input().split())) x=list(map(int,input().split())) y=list(map(int,input().split())) x.sort() y.sort() for i in range(x[N-1]+1,y[0]+1): if i>X and i<=Y: print('No War') exit() print('War')
p03251
# coding: utf-8 N, M, X, Y = list(map(int, input().split())) x = max(list(map(int, input().split()))) y = min(list(map(int, input().split()))) ans = "War" for z in range(X+1, Y+1): if x < z <= y: ans = "No War" print(ans)
# coding: utf-8 N, M, X, Y = list(map(int, input().split())) lst_x = list(map(int, input().split())) lst_x.append(X) lst_y = list(map(int, input().split())) lst_y.append(Y) x = max(lst_x) y = min(lst_y) ans = "War" if x < y: ans = "No War" print(ans)
p03251
n,m,X,Y = list(map(int,input().split())) x = max(list(map(int,input().split()))) y = min(list(map(int,input().split()))) if X<x<y<=Y:print('No War') else:print('War')
n,m,x,y = list(map(int,input().split())) x_max = sorted(list(map(int,input().split())))[-1] y_min = sorted(list(map(int,input().split())))[0] if x<=x_max<y_min<=y: print('No War') else: print('War')
p03251
n,m,x,y=list(map(int,input().split()));a,b=list(map(int,input().split())),list(map(int,input().split()));a.sort();b.sort();print(("No War"if max(a[-1],x)<min(y,b[0])else"War"))
n,m,x,y=list(map(int,input().split())) x=list(map(int,input().split()))+[x] y=list(map(int,input().split()))+[y] if max(x)<min(y):print("No War") else:print("War")
p03251
# 2019-11-10 15:45:20(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # from scipy.misc import comb # float ...
import sys n, m, X, Y = list(map(int, sys.stdin.readline().split())) *x, = list(map(int, sys.stdin.readline().split())) *y, = list(map(int, sys.stdin.readline().split())) def main(): return 'No War' if max(X, max(x)) < min(Y, min(y)) else 'War' if __name__ == '__main__': ans = main() print(ans...
p03251
N,M,X,Y=list(map(int,input().split())) x=max(list(map(int,input().split()))) y=min(list(map(int,input().split()))) P=0 for i in range(X+1,Y+1) : if X < i and i <=Y and x < i and i <= y : print("No War") break else: print("War")
N,M,X,Y=list(map(int,input().split())) x=max(list(map(int,input().split()))) y=min(list(map(int,input().split()))) P=0 for i in range(X+1,Y+1) : if x < i and i <= y : print("No War") break else: print("War")
p03251
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, produc...
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, produc...
p03251
n,m,x,y = list(map(int,input().split())) xl = list(map(int,input().split())) yl = list(map(int,input().split())) xl.sort(reverse = True) yl.sort() if xl[0] < yl[0]: p = yl[0] while p > x: if x < p and p <= y: print('No War') exit(0) print('War') else: print...
n,m,x,y = list(map(int,input().split())) xl = list(map(int,input().split())) yl = list(map(int,input().split())) xl.append(x) yl.append(y) xl.sort() yl.sort() if xl[-1] < yl[0]: print('No War') else: print('War')
p03251
n,m,X,Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) x.append(X) y.append(Y) x.sort() y.sort() if x[-1] < y[0]: print("No War") else: print("War")
n,m,X,Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) x.append(X) y.append(Y) if max(x) < min(y): print("No War") else: print("War")
p03251
n,m,x,y=list(map(int,input().split())) xl=list(map(int,input().split())) yl=list(map(int,input().split())) xl.append(x) yl.append(y) if max(xl) < min(yl) and x < y: print('No War') else: print('War')
n,m,x,y=list(map(int,input().split())) xl=list(map(int,input().split())) yl=list(map(int,input().split())) xl.append(x) yl.append(y) if max(xl) < min(yl): print('No War') else: print('War')
p03251
n,m,x,y = list(map(int,input().split())) xs = max(list(map(int,input().split()))) ys = min(list(map(int,input().split()))) ans = 'War' if xs+1 <= ys: for i in range(xs+1,ys+1): if x < i <= y: ans = 'No War' break print(ans)
n, m, x, y = list(map(int, input().split())) xs = list(map(int, input().split())) ys = list(map(int, input().split())) xs.append(x) ys.append(y) print(('No War' if max(xs) < min(ys) else 'War'))
p03251
N,M,X,Y = list(map(int, input().split())) Xx = [int(x) for x in input().split()] Yy = [int(x) for x in input().split()] mxx = max(Xx) mny = min(Yy) if mxx < mny and X < mny and mxx < Y: print("No War") else: print("War")
N,M,X,Y = list(map(int, input().split())) Xx = [int(x) for x in input().split()] Yy = [int(x) for x in input().split()] def f(): mxx = max(Xx) mny = min(Yy) for z in range(Y, X, -1): if mxx < z and z <= mny: return "No War" return "War" print((f()))
p03251
n,m,x,y= list(map(int,input().split())) lix=list(map(int,input().split())) liy=list(map(int,input().split())) lix.append(x) liy.append(y) if max(lix) < min(liy): print("No War") else: print("War")
n,m,x,y= list(map(int,input().split())) lix=list(map(int,input().split())) liy=list(map(int,input().split())) lix.append(x) liy.append(y) lix.sort() liy.sort() if lix[n] < liy[0]: print("No War") else: print("War")
p03251
N,M,X,Y=list(map(int,input().split())) x=list(map(int,input().split())) y=list(map(int,input().split())) can=False for Z in range(X+1,Y+1): if max(x)<Z<=min(y): can=True if can: print("No War") else: print("War")
N,M,X,Y=list(map(int,input().split())) x=list(map(int,input().split())) y=list(map(int,input().split())) xmin=max(x) ymin=min(y) for i in range(X+1,Y+1): if xmin<i<=ymin: print("No War") quit() print("War")
p03251
N, M, X, Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) ans = 1 if X >= Y: ans = 1 elif X < Y: z = list(range(X+1, Y+1)) for i in z: if max(x) < i and i <= min(y): ans = 0 if ans == 0: print('No ...
N, M, X, Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) zx = list(range(max(x)+1,101)) zy = list(range(-100, min(y)+1)) kanou = set(zx) & set(zy) if len(kanou) == 0: print('War') else: for i in kanou: if X < i <= Y: pr...
p03251
if __name__ == '__main__': n,m,X,Y = list(map(int,input().split())) x = list(map(int,input().split())) y = list(map(int,input().split())) x_max = max(x) y_min = min(y) flg = False for Z in range(X+1,Y+1): if x_max < Z <= y_min: flg = True break if flg: print("No War") else: pri...
if __name__ == '__main__': n,m,x,y = list(map(int,input().split())) X = list(map(int,input().split())) Y = list(map(int,input().split())) X.sort() Y.sort() flg = False #xの場所がYのFROM-に入っていないこと if (Y[0] <= x): flg = True #yの場所がXのFROM-に入っていないこと elif (y <= X[n-1]): flg = True #Xの右端とYの左端が交わらないこと...
p03251
def nl(): return list(map(int, input().split())) # print('Yes' if a else 'No') N, M, X, Y = nl() x = nl() y = nl() flg = False for i in range(X + 1, Y + 1): if max(x) < i and i <= min(y): flg = True break print(('No War' if flg else 'War'))
N, M, X, Y = list(map(int, input().split())) x = list(map(int, input().split())) + [X] y = list(map(int, input().split())) + [Y] x_max = max(x) y_min = min(y) if x_max >= y_min: war_happen = True else: war_happen = False print(('War' if war_happen else 'No War'))
p03251
n, m, xx, yy = list(map(int, input().split())) x = sorted(list(map(int, input().split()))) y = sorted(list(map(int, input().split()))) if x[-1] < y[0]: if xx < y[0] and yy > x[-1]: print("No War") else: print("War") else: print("War")
n, m, xx, yy = list(map(int, input().split())) x = sorted(list(map(int, input().split()))) y = sorted(list(map(int, input().split()))) for i in range(xx + 1, yy): if x[-1] < i <= y[0]: print("No War") break else: print("War")
p03251
A=list(map(int,input().split())) X=list(map(int,input().split())) Y=list(map(int,input().split())) x=max(X) y=min(Y) if x<y and A[2]<A[3] and A[2]<y and x<A[3]: print("No War") else: print("War")
N,M,X,Y=list(map(int,input().split())) x=list(map(int,input().split())) y=list(map(int,input().split())) x=x+[X] y=y+[Y] if max(x)<min(y): print("No War") else: print("War")
p03251
N,M,X,Y = [int(x) for x in input().split()] xl = [int(x) for x in input().split()] yl = [int(x) for x in input().split()] xl.sort() yl.sort() xmax = xl[-1] ymin = yl[0] war = 'War' nowar = 'No War' isOk = False if xmax < ymin: isOk = True else: print(war) exit() if X < ymin an...
N,M,X,Y = [int(x) for x in input().split()] xl = [int(x) for x in input().split()] yl = [int(x) for x in input().split()] xl.sort() yl.sort() xmax = xl[-1] ymin = yl[0] war = 'War' nowar = 'No War' kyokai = xmax + 1 isOk = False if xmax < ymin: isOk = True else: print(war) exit(...
p03251
def bogosort(l): import random while 1: random.shuffle(l) for i in range(1,len(l)): if l[i]<l[i-1]: break else: return l i=lambda:list(map(int,input().split())) n,m,x,y=i() if bogosort(i()+[x])[-1]<bogosort(i()+[y])[0]: print('No War') else: print('War')
(*z,X,Y),x,y=eval('map(int,input().split()),'*3);print(('No War'[3*(max(X,*x)>=min(Y,*y)):]))
p03251
def main(): import sys input = sys.stdin.readline n, m, x, y = list(map(int, input().rstrip('\n').split())) X = list(map(int, input().rstrip('\n').split())) Y = list(map(int, input().rstrip('\n').split())) mx = max(X) my = min(Y) for z in range(x + 1, y + 1): if mx < z <...
def slove(): import sys input = sys.stdin.readline n, m, x, y = list(map(int, input().rstrip('\n').split())) mx = max(list(map(int, input().rstrip('\n').split()))) my = min(list(map(int, input().rstrip('\n').split()))) for i in range(x + 1, y + 1): if mx < i <= my: pr...
p03251
n,m,x,y = list(map(int,input().split())) x1 = max([int(i) for i in input().split()]) + 1 y1 = min([int(i) for i in input().split()]) if x1 <= y1 and x1 <= y and y1 > x: print('No War') else: print('War')
n,m,x,y = list(map(int,input().split())) x1 = max(list(map(int,input().split()))) + 1 y1 = min(list(map(int,input().split()))) if x1 <= y1 and x1 <= y and y1 > x: print('No War') else: print('War')
p03251
def m_i(): return list(map(int, input().split())) N,M,X,Y = m_i() Z = max(m_i()) + 1 min_y = min(m_i()) print(("No War" if (X < Z) and (Z <= min_y) and (Z <= Y) else "War"))
def m_i(): return list(map(int, input().split())) N,M,X,Y = m_i() Z = max(m_i()) + 1 min_y = min(m_i()) print(("No War" if (X < Z) and (Z <= min(min_y,Y)) else "War"))
p03251
N, M, X, Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) ans = 'War' for z in range(X+1, Y+1): if len(list([x for x in x if x < z])) == N and len(list([x for x in y if x >= z])) == M: ans = 'No War' break print(ans)
N, M, X, Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) ans = 'War' for z in range(X+1, Y+1): if max(x) < z and min(y) >= z: ans = 'No War' break print(ans)
p03251
n, m, x, y = list(map(int, input().split())) xs = list(map(int, input().split())) ys = list(map(int, input().split())) print(("No War" if max([x] + list(xs)) < min([y] + list(ys)) else "War"))
n, m, x, y = list(map(int, input().split())) xs = list(map(int, input().split())) ys = list(map(int, input().split())) print(("No War" if max(x, *xs) < min(y, *ys) else "War"))
p03251
n,m,x,y = list(map(int,input().split())) X = list(map(int,input().split())) Y = list(map(int,input().split())) X = sorted(X) Y = sorted(Y) for i in range(x+1,y+1): if X[-1]<i and Y[0]>=i: print('No War') exit() print('War')
n,m,x,y = list(map(int,input().split())) a = list(map(int,input().split())) b = list(map(int,input().split())) a = max(a) b = min(b) for z in range(x+1,y+1): if a < z <= b: print('No War') exit() print('War')
p03251
N,M,X,Y = list(map(int,input().split())) x_list = list(map(int,input().split())) y_list = list(map(int,input().split())) for i in range(max(x_list)+1,min(y_list)+1): if i > X and i <= Y and max(x_list) < i and min(y_list) >= i: print('No War') break else: print('War')
n,m,X,Y = list(map(int,input().split())) x = sorted(map(int,input().split())) + [X] y = sorted(map(int,input().split())) + [Y] print(("No War" if max(x) < min(y) else "War"))
p03251
N, M, X, Y = list(map(int, input().split())) xlist = list(map(int, input().split())) ylist = list(map(int, input().split())) xmax = max(xlist) ymin = min(ylist) if xmax<ymin: for z in range(xmax+1, ymin+1): if X<z<=Y: print("No War") break else: print("War") e...
N, M, X, Y = list(map(int, input().split())) xs = list(map(int, input().split())) xs.append(X) ys = list(map(int, input().split())) ys.append(Y) xmax = max(xs) ymin= min(ys) if xmax<ymin: print("No War") else: print("War")
p03251
N, M, X, Y = list(map(int,input().split())) x = list(map(int,input().split())) y = list(map(int,input().split())) max_x = max(x) min_y = min(y) for i in range(X+1, Y+1): if(max_x < i <= min_y): print("No War") break else: print("War")
N, M, X, Y = list(map(int,input().split())) x = sorted(list(map(int,input().split()))) y = sorted(list(map(int,input().split()))) for i in range(X+1, Y+1): if(x[-1] < i <= y[0]): print("No War") break else: print("War")
p03251
n, m, X, Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) x.sort(reverse=True) xmax = max(x[0], X) y.sort() ymin = min(y[0], Y) if ymin - xmax > int(0): print("No War") else: print("War")
n, m, X, Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) x.sort(reverse=True) xmax = max(x[0], X) y.sort() ymin = min(y[0], Y) if ymin - xmax > 0: print("No War") else: print("War")
p03251
N,M,X,Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) if(max(x) < min(y) and X < min(y) and max(x) < Y ): print("No War") else: print("War")
N,M,X,Y = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) x.append(X) y.append(Y) if(max(x) < min(y)): print("No War") else: print("War")
p03251
n, m, x, y = list(map(int, input().split())) X = [int(i) for i in input().split()] Y = [int(i) for i in input().split()] X.append(x) Y.append(y) if max(X) < min(Y): print('No War') else: print('War')
n, m, x, y = list(map(int, input().split())) X = [int(i) for i in input().split()] Y = [int(i) for i in input().split()] X.append(x) Y.append(y) X.sort() Y.sort() print(('War' if max(X) >= min(Y) else 'No War'))
p03251
# https://beta.atcoder.jp/contests/abc110/tasks/abc110_b def solve(): _, _, x, y = list(map(int, input().split())) Xn = max(list(map(int, input().split()))) Ym = min(list(map(int, input().split()))) for z in range(x + 1, y + 1): if Xn < z <= Ym: print('No War') ...
# https://beta.atcoder.jp/contests/abc110/tasks/abc110_b def solve(): _, _, X, Y = list(map(int, input().split())) xn = max(list(map(int, input().split()))) ym = min(list(map(int, input().split()))) Z = xn + 1 if X < Z <= Y and xn < Z <= ym: print('No War') exit() ...
p03251
n,m,x,y=input().split() n,m,x,y=int(n),int(m),int(x),int(y) x1=input().split() x2=[] for i in range(n): x2.append(int(x1[i])) y1=input().split() y2=[] for i in range(m): y2.append(int(y1[i])) s="War" if y>x: for i in range(y-x): if x+i+1>max(x2) and min(y2)>=x+i+1: s="No ...
n,m,x,y=list(map(int,input().split())) X=max(list(map(int,input().split()))) Y=min(list(map(int,input().split()))) for z in range(x+1,y+1): if X<z<=Y: print("No War") break else: print("War")
p03251
while 1: n,a,b,c,x=list(map(int,input().split())) if n==0:break reel=list(map(int,input().split())) roop,i=-1,0 while i<n: roop+=1 if roop>10000: roop=-1 break if x==reel[i]: i+=1 x=(a*x+b)%c print(roop)
while True: N,A,B,C,X = list(map(int,input().split())) if N == A == B == C == X == 0:break sum = 0 Z = 0 Y = [int(x) for x in input().split()] if X == Y[0]: Y.pop(0) if len(Y) == 0: Z = 1 while Z == 0: if sum == 10000: sum = -2 Z = 1 sum ...
p01267
import copy from itertools import combinations N=int(eval(input())) S=list(input()[0] for _ in range(N)) cS=copy.deepcopy(S) ans=0 for i in cS: if i not in ['M', 'A', 'R', 'C', 'H']: S.remove(i) P=list(combinations(S,3)) for i in P: if len(set(i))==3: ans+=1 print(ans)
N=int(eval(input())) S=list(input()[0] for _ in range(N)) m=S.count('M') a=S.count('A') r=S.count('R') c=S.count('C') h=S.count('H') print((m*a*r+m*a*c+m*a*h +m*r*c+m*r*h +m*c*h +a*r*c+a*r*h +a*c*h +r*c*h))
p03425
# ABC089C - March from itertools import combinations def main(): n = int(eval(input())) lst = [input().rstrip() for _ in range(n)] cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0} for i in lst: if i[0] in "MARCH": cond[i[0]] += 1 ans = 0 for x, y, z in combinatio...
# ABC089C - March import sys input = sys.stdin.readline from itertools import combinations def main(): n = int(eval(input())) lst = [input().rstrip() for _ in range(n)] cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0} for i in lst: if i[0] in "MARCH": cond[i[0]] += 1 ...
p03425
from collections import * d=Counter() for _ in range(int(eval(input()))): d[input()[0]]+=1 import itertools as it print((sum(d[s]*d[t]*d[r] for s,t,r in it.combinations('MARCH',3))))
l=[input()[0] for _ in range(int(eval(input())))] import itertools as it print((sum(x*y*z for x,y,z in it.combinations([l.count(c) for c in 'MARCH'],3))))
p03425
from itertools import combinations n = int(eval(input())) march = ("M","A","R","C","H") d = [] for _ in range(n): pre = input()[0] if pre in march: d.append(pre) if len(d) < 3: print((0)) exit() ans = 0 for i in combinations(d,3): if len(set(i)) == 3: ans += 1 print(ans)
n = int(eval(input())) march = ("M","A","R","C","H") prefix = [] d = {} for _ in range(n): pre = input()[0] if pre in march: if pre not in prefix: prefix.append(pre) d[pre] = 1 else: d[pre] += 1 t = len(prefix) if t < 3: print((0)) exit() ans = 0 for i in r...
p03425
import sys from collections import Counter from itertools import combinations MARCH = set('MARCH') n = int(sys.stdin.readline().rstrip()) s = [x[0] for x in sys.stdin.read().split() if x[0] in MARCH] def main(): c = Counter(s) ways = 0 for comb in combinations('MARCH', 3): res = 1 ...
import sys from collections import Counter from itertools import combinations n, *s = [s[0] for s in sys.stdin.read().split()] def main(): c = Counter(s) res = 0 for i, j, k in combinations('MARCH', 3): res += c[i] * c[j] * c[k] print(res) if __name__ == '__main__': main()
p03425