RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0625

Splitting Haybales

Diamond II 다이아몬드 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Farmer John wants to fairly split haybales between his two favorite cows Bessie
and Elsie. He has \(N\) ( \(1\le N\le 2\cdot 10^5\)) haybales sorted in
non-increasing order, where the \(i\)-th haybale has \(a_i\) units of hay
(\(2\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
\(a_l, \dots, a_r\) between Bessie and Elsie. He has decided to process the
haybales in order from \(l\) to \(r\), and when processing the \(i\)-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 \(Q\) (\(1\le Q\le 2\cdot 10^5\)) queries, each with three integers
\(l,r,x\) (\(1\le l\le r\le N\), \(|x|\le 10^9\)). For each query, output how many
more units of hay Bessie will have than Elsie after processing haybales \(l\) to
\(r\), if Bessie starts with \(x\) more units than Elsie. Note that this value is
negative if Elsie ends up with more haybales than Bessie.

Problem credits: Benjamin Qi

제약

SCORING

  • Input 3: \(Q\le 100\)
  • Inputs 4-6: At most \(100\) distinct \(a_i\)
  • Inputs 7-22: No additional constraints.

Problem credits: Benjamin Qi

입력 형식

First line contains \(N\).

Second line contains \(a_1\dots a_N\).

Third line contains \(Q\).

Next \(Q\) lines contain \(l, r, x\).

출력 형식

Output \(Q\) 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
2
3
-2
-1
0
1
2
-1
0
-1
0
1
0
1
설명

For the 1st query, Elsie starts with \(2\) more hay than Bessie. Then, after
processing haybale \(1\), Bessie will receive \(3\) hay, and Bessie will have \(1\)
more hay than Elsie.

For the 3rd query, Elsie and Bessie start with the same number of hay. After
processing haybale \(1\), Bessie will receive \(3\) hay, and Bessie will have \(3\)
more hay than Elsie.

For the 9th query, Bessie starts with \(1\) more hay than Elsie, then after
processing the 1st haybale, has \(2\) less hay than Elsie, and after processing
the 2nd haybale, has \(1\) less hay than Elsie.

예제 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
출력
16
12
7
4
1
2
1
설명

In the 5th query, there are \(5\) haybales to process. Bessie receives \(4\) hay, then Elsie
receives \(4\) hay, then Bessie receives \(3\) hay, then Elsie receives \(1\) hay,
then Elsie receives \(1\) hay.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2023-2024 > US Open > Platinum

태그

평가 및 의견

Splitting Haybales

개요
출제자 난이도 Diamond II 다이아몬드 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Splitting Haybales

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8