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

17462번 - MST and Rectangles 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 1024 MB32121035.714%

문제

You have a 2D array A of size $N \times N$. Each cell initially contains 0.

You are also given Q queries of the form X1 X2 Y1 Y2 W, which means you should perform the following operation on A:

  • For each pair of integers (i, j) where X1 ≤ X2 < Y1 ≤ Y2 and X1 ≤ i ≤ X2 and Y1 ≤ j ≤ Y2 , add W to the value of cell A[i][j] and A[j][i].

Consider an undirected graph G with N vertices. For each 1 ≤ i, j ≤ N, there is an edge connecting vertices i and j with cost A[i][j]. Calculate the cost of Minimum Spanning Tree of G.

입력

The first line contains a single integer N, Q.

The next Q lines contain five integers X1 X2 Y1 Y2 W, describing a query.

출력

Print the cost of Minimum Spanning Tree of G.

제한

  • 1ドル \le N, Q \le 10^5$
  • 1ドル \le X_1 \le X_2 < Y_1 \le Y_2 \le N$
  • $|W| \le 10^6$

예제 입력 1

5 3
1 1 2 4 10
2 2 3 4 10
3 3 4 4 10

예제 출력 1

0

예제 입력 2

5 5
3 3 4 5 -10
1 2 3 4 20
4 4 5 5 -10
2 2 4 4 -20
1 1 2 4 0

예제 출력 2

-20

예제 입력 3

6 8
1 3 6 6 3
4 4 6 6 10
3 3 5 6 -8
1 2 5 5 -7
1 2 6 6 -1
1 3 4 5 6
3 5 6 6 7
2 3 6 6 3

예제 출력 3

-2

힌트

출처

  • 문제를 만든 사람: koosaga
  • 문제의 오타를 찾은 사람: bjwj5505
(追記) (追記ここまで)

출처

대학교 대회

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

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