File tree Expand file tree Collapse file tree 2 files changed +71
-0
lines changed
Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ import sys
2+
3+ input = sys .stdin .readline
4+
5+ n , m = map (int , input ().split ())
6+ a = list (map (int , input ().split ()))
7+
8+ remain = [0 ] * m # 나머지 개수
9+ prefix_sum = 0
10+ for i in range (n ):
11+ prefix_sum += a [i ]
12+ remain [prefix_sum % m ] += 1
13+
14+ res = remain [0 ]
15+ # 나머지가 같은 구간 2개를 뽑으면 나머지가 0이 됨
16+ for r in remain :
17+ # 조합; rC2 = r(r-1) / 2
18+ res += r * (r - 1 ) // 2
19+
20+ print (res )
21+
22+ """
23+ 5 3
24+ 1 2 3 1 2
25+ """
Original file line number Diff line number Diff line change 1+ import sys
2+
3+ input = sys .stdin .readline
4+
5+ n , m = map (int , input ().split ())
6+ dots = sorted (list (map (int , input ().split ())))
7+
8+ # 타겟을 찾는 최초 좌표 구하기
9+ def lower_bound (arr , target ):
10+ start , end = 0 , len (arr )
11+ while start < end :
12+ mid = (start + end ) // 2
13+ if arr [mid ] < target :
14+ start = mid + 1
15+ else :
16+ end = mid
17+ return start
18+
19+ # 타겟을 포함한 좌표 구하기 (놓친 부분 : 나눠서 해야 하는구나)
20+ def upper_bound (arr , target ):
21+ start , end = 0 , len (arr )
22+ while start < end :
23+ mid = (start + end ) // 2
24+ if arr [mid ] <= target :
25+ start = mid + 1
26+ else :
27+ end = mid
28+ return start
29+
30+
31+ for _ in range (m ):
32+ a , b = map (int , input ().split ())
33+
34+ left = lower_bound (dots , a )
35+ right = upper_bound (dots , b )
36+ print (right - left )
37+
38+ """
39+ 5 5
40+ 1 3 10 20 30
41+ 1 10
42+ 20 60
43+ 3 30
44+ 2 15
45+ 4 8
46+ """
You can’t perform that action at this time.
0 commit comments