Logo
(追記) (追記ここまで)

21909번 - Divisible by 3 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB118917879.592%

문제

For an array $[b_1, b_2, \dots , b_m]$ of integers, let’s define its weight as the sum of pairwise products of its elements, namely as the sum of $b_ib_j$ over 1ドル \le i < j \le m$.

You are given an array of $n$ integers $[a_1, a_2, \dots , a_n],ドル and are asked to find the number of pairs of integers $(l, r)$ with 1ドル \le l \le r \le n,ドル for which the weight of the subarray $[a_l, a_{l+1}, \dots , a_r]$ is divisible by 3ドル$.

입력

The first line of the input contains a single integer $n$ (1ドル \le n \le 5 \cdot 10^5$) — the length of the array.

The second line contains $n$ integers $a_1, a_2, \dots , a_n$ (0ドル \le a_i \le 10^9$) — the elements of the array.

출력

Output a single integer — the number of pairs of integers $(l, r)$ with 1ドル \le l \le r \le n,ドル for which the weight of the corresponding subarray is divisible by 3ドル$.

제한

예제 입력 1

3
5 23 2021

예제 출력 1

4

예제 입력 2

5
0 0 1 3 3

예제 출력 2

15

예제 입력 3

10
0 1 2 3 4 5 6 7 8 9

예제 출력 3

20

힌트

In the first sample, the weights of exactly 4ドル$ subarrays are divisible by 3ドル$:

  • weight($[5]$) = weight($[23]$) = weight($[2021]$) = 0ドル$
  • weight($[5, 23, 2021]$) = 56703ドル$ = 3ドル \cdot 41 \cdot 461$

출처

ICPC > Regionals > Europe > Southeastern European Regional Contest > SEERC 2020 E번

Contest > Open Cup > 2020/2021 Season > Stage 17: Grand Prix of Southern Europe E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /