-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB.py
48 lines (43 loc) · 1.01 KB
/
B.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
from collections import deque
import sys
#==============To chaliye shuru krte he ====================#
n,q,k=map(int,input().split())
li=deque(map(int,input().split()))
if len(li)>1:
pre=[0]*n
pre[0]=li[1]-2
for i in range(1,n-1):
pre[i]=li[i+1]-li[i-1]-2
pre[-1]=li[-2]-1
for i in range(1,n):
pre[i]+=pre[i-1]
for i in range(q):
l,r=map(int,input().split())
ans=0
if l==r:
ans+=li[l-1]-1+k-li[l-1]
else:
ans=pre[r-2]-pre[l-1]
ans+=li[l]-2
ans+=k-li[r-2]-1
print(ans)
# for i in range(q):
# a,b=map(int,input().split())
# li1=deque()
# ans=0
# for i in range(a-1,b):
# li1.append(li[i])
# tr=False
# if a==b:
# ans+=li[a-1]-1
# ans+=k-li[a-1]
# tr=True
# else:
# ans+=li[a]-2
# #P(ans)
# for i in range(a,b-1):
# ans+=li[i+1]-li[i-1]-2
# #P(ans)
# #print(li[b-2])
# ans+=k-li[b-2]-1
# print(ans)