-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC305_D.py
More file actions
54 lines (44 loc) · 961 Bytes
/
ABC305_D.py
File metadata and controls
54 lines (44 loc) · 961 Bytes
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
#################################
#RE
import sys
input = sys.stdin.readline
import numpy as np
n=int(input())
A=list(map(int,input().split()))
T=np.zeros((A[-1]+10))
for i in range(n//2):
T[A[2*i+1]:A[2*i+2]]=1
q=int(input())
Q=[]
for i in range(q):
l,r=map(int,input().split())
print(int(T[l:r].sum()))
#################################
#titia
import sys
input = sys.stdin.readline
from bisect import bisect
N=int(input())
A=list(map(int,input().split()))
SUM=[0]*(N+1)
for i in range(N):
if i>0 and i%2==0:
SUM[i+1]=SUM[i]+(A[i]-A[i-1])
else:
SUM[i+1]=SUM[i]
SUM.append(SUM[-1])
Q=int(input())
for tests in range(Q):
x,y=map(int,input().split())
k=bisect(A,x)
if k>0 and k%2==0:
s1=SUM[k+1]-(A[k]-x)
else:
s1=SUM[k+1]
k=bisect(A,y)
if k>0 and k%2==0:
s2=SUM[k+1]-(A[k]-y)
else:
s2=SUM[k+1]
print(s2-s1)
#################################