#676
Unrated
Splitting Haybales
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John wants to fairly split haybales between his two favorite cows Bessie and Elsie. He has NN ( 1N21051\le N\le 2\cdot 10^5) haybales sorted in non-increasing order, where the ii-th haybale has aia_i units of hay (2105a1a2aN12\cdot 10^5\ge a_1\ge a_2 \ge \dots \ge a_N \ge 1).

Farmer John is considering splitting a contiguous range of haybales al,,ara_l, \dots, a_r between Bessie and Elsie. He has decided to process the haybales in order from ll to rr, and when processing the ii-th haybale he will give it to the cow who currently has less hay (if it is a tie, he will give it to Bessie).

You are given QQ (1Q21051\le Q\le 2\cdot 10^5) queries, each with three integers l,r,xl,r,x (1lrN1\le l\le r\le N, x109|x|\le 10^9). For each query, output how many more units of hay Bessie will have than Elsie after processing haybales ll to rr, if Bessie starts with xx more units than Elsie. Note that this value is negative if Elsie ends up with more haybales than Bessie.

입력

First line contains NN.

Second line contains a1aNa_1\dots a_N.

Third line contains QQ.

Next QQ lines contain l,r,xl, r, x.

출력

Output QQ lines, containing the answer for each query.

예제 입력 1

2
3 1
15
1 1 -2
1 1 -1
1 1 0
1 1 1
1 1 2
1 2 -2
1 2 -1
1 2 0
1 2 1
1 2 2
2 2 -2
2 2 -1
2 2 0
2 2 1
2 2 2

예제 출력 1

1
2
3
-2
-1
0
1
2
-1
0
-1
0
1
0
1

예제 입력 2

5
4 4 3 1 1
7
1 1 20
1 2 20
1 5 20
1 1 0
1 5 0
1 4 0
3 5 2

예제 출력 2

16
12
7
4
1
2
1

점수

Input 3: Q100Q\le 100Inputs 4-6: At most 100100 distinct aia_iInputs 7-22: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.