/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 333 点
問題文
高橋君が経営するスポーツジムには N 人の会員がいます。このジムは毎日営業しており、会員はそれぞれ決まった曜日のパターンで毎週必ずジムに通います。
1週間は 7 日間で構成され、週の各日には 1 から 7 までの番号が付いています。番号 d の日を「第 d 日目」と呼びます。会員 i が毎週通う日は、整数の組 (L_i, R_i) によって以下のように定まります。
- L_i \leq R_i のとき:毎週、第 L_i 日目から第 R_i 日目まで(両端を含む)の連続する R_i - L_i + 1 日間に通います。例えば、L_i = 2, R_i = 4 なら毎週第 2, 3, 4 日目に通います。
- L_i > R_i のとき:毎週、第 L_i 日目から第 7 日目までと、第 1 日目から第 R_i 日目まで(それぞれ両端を含む)の合計 7 - L_i + 1 + R_i 日間に通います。これは1週間を巡回的に見たときの連続区間を表します。例えば、L_i = 6, R_i = 2 なら毎週第 6, 7, 1, 2 日目に通います。
高橋君は W 週間(通算 7 \times W 日間)にわたってジムを営業します。営業期間全体を通して日に 1 から 7W までの通し番号を付け、通し番号 k の日を「通算第 k 日目」と呼びます。通算第 1 日目は第 1 週の第 1 日目です。一般に、通算第 k 日目(1 \leq k \leq 7W)は、第 \lceil k/7 \rceil 週の第 ((k - 1) \bmod 7) + 1 日目に対応します。各会員はすべての週において、上記のパターンに従って必ずジムに通います(欠席はありません)。
この W 週間の営業期間中に、M 個のキャンペーンが予定されています。j 番目のキャンペーン(1 \leq j \leq M)では、通算第 S_j 日目から通算第 E_j 日目まで(両端を含む)がキャンペーン期間です。キャンペーン期間はすべて営業期間内に収まります。複数のキャンペーンの期間が重複することもあります。
通算第 k 日目にジムを訪れた会員が獲得するトレーニングポイントは、次のように定まります。通算第 k 日目をキャンペーン期間に含むキャンペーンの個数を c(c \geq 0)とすると、その日の来館で 1 + c ポイントを獲得します。すなわち、キャンペーンが行われていない日でも来館すれば 1 ポイントを獲得し、キャンペーン 1 つにつき追加で 1 ポイントを獲得します。
W 週間の営業が終わったとき、N 人の会員それぞれが獲得したトレーニングポイントの合計を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq W \leq 10^9
- 0 \leq M \leq 2 \times 10^5
- 1 \leq L_i \leq 7 (1 \leq i \leq N)
- 1 \leq R_i \leq 7 (1 \leq i \leq N)
- 1 \leq S_j \leq E_j \leq 7 \times W (1 \leq j \leq M)
- 入力はすべて整数である
- 各会員の獲得ポイントの合計はそれぞれ 64 ビット符号付き整数に収まる
入力
N W M L_1 R_1 L_2 R_2 \vdots L_N R_N S_1 E_1 S_2 E_2 \vdots S_M E_M
- 1行目には、会員の数 N、営業する週の数 W、キャンペーンの数 M がスペース区切りで与えられる。
- 続く N 行のうち i 行目(1 \leq i \leq N)には、会員 i の通う日のパターンを定める整数 L_i と R_i がスペース区切りで与えられる。
- 続く M 行のうち j 行目(1 \leq j \leq M)には、j 番目のキャンペーンの開始日 S_j と終了日 E_j が通算日の番号でスペース区切りで与えられる。M = 0 のときこの部分は存在しない。
出力
N 行出力せよ。i 行目(1 \leq i \leq N)には、会員 i が W 週間で獲得したトレーニングポイントの合計を出力せよ。
入力例 1
3 2 2 1 3 5 2 7 7 2 3 8 10
出力例 1
11 13 2
入力例 2
4 1 0 1 1 2 4 6 3 1 7
出力例 2
1 3 5 7
入力例 3
8 10 6 1 5 3 7 6 2 4 4 7 3 2 6 5 1 1 7 1 7 10 20 15 35 36 36 50 70 63 65
出力例 3
96 95 77 19 77 95 77 134
入力例 4
20 1000000000 15 1 1 2 2 3 3 4 4 5 5 6 6 7 7 1 3 2 5 3 7 5 2 6 1 7 4 1 7 4 2 2 1 6 6 3 5 7 1 5 5 1 1 2 100 50 1000 999999 1000005 7000000 7000100 123456789 123456999 999999999 1000000020 3500000000 3500000100 4999999999 5000000005 6000000000 6000001000 6999999990 7000000000 1 7000000000 2500000000 2500000000 3333333333 4444444444 123 456789
出力例 4
2158795759 2158795757 2158795754 2158795756 2158795756 2158795755 2158795755 6476387270 8635183023 10793978776 10793978782 6476387269 10793978781 15111570292 12952774538 15111570292 2158795755 6476387266 4317591514 2158795756
入力例 5
1 1000000000 2 1 7 1 7000000000 7000000000 7000000000
出力例 5
14000000001
Score : 333 pts
Problem Statement
Takahashi's sports gym has N members. The gym is open every day, and each member visits the gym every week according to a fixed weekly pattern of days.
A week consists of 7 days, and each day of the week is numbered from 1 to 7. We call day number d the "d-th day." The days member i visits every week are determined by a pair of integers (L_i, R_i) as follows:
- When L_i \leq R_i: Every week, they visit on consecutive days from the L_i-th day to the R_i-th day (both inclusive), for a total of R_i - L_i + 1 days. For example, if L_i = 2, R_i = 4, they visit on the 2nd, 3rd, and 4th days every week.
- When L_i > R_i: Every week, they visit from the L_i-th day to the 7th day, and from the 1st day to the R_i-th day (both inclusive), for a total of 7 - L_i + 1 + R_i days. This represents a contiguous interval when the week is viewed cyclically. For example, if L_i = 6, R_i = 2, they visit on the 6th, 7th, 1st, and 2nd days every week.
Takahashi operates the gym for W weeks (a total of 7 \times W days). We assign sequential numbers from 1 to 7W to the days over the entire operating period, and call sequential number k the "overall k-th day." The overall 1st day is the 1st day of week 1. In general, the overall k-th day (1 \leq k \leq 7W) corresponds to the ((k - 1) \bmod 7) + 1-th day of week \lceil k/7 \rceil. Each member visits the gym following the above pattern in every week without exception (no absences).
During this W-week operating period, M campaigns are scheduled. For the j-th campaign (1 \leq j \leq M), the campaign period runs from the overall S_j-th day to the overall E_j-th day (both inclusive). All campaign periods fall within the operating period. Campaign periods may overlap with each other.
The training points earned by a member who visits the gym on the overall k-th day are determined as follows: Let c (c \geq 0) be the number of campaigns whose campaign period includes the overall k-th day. Then the member earns 1 + c points for that visit. In other words, a visit earns 1 point even on days with no campaigns, and each active campaign grants an additional 1 point.
After the W weeks of operation are over, determine the total training points earned by each of the N members.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq W \leq 10^9
- 0 \leq M \leq 2 \times 10^5
- 1 \leq L_i \leq 7 (1 \leq i \leq N)
- 1 \leq R_i \leq 7 (1 \leq i \leq N)
- 1 \leq S_j \leq E_j \leq 7 \times W (1 \leq j \leq M)
- All input values are integers
- The total points earned by each member fits in a 64-bit signed integer
Input
N W M L_1 R_1 L_2 R_2 \vdots L_N R_N S_1 E_1 S_2 E_2 \vdots S_M E_M
- The first line contains the number of members N, the number of weeks W, and the number of campaigns M, separated by spaces.
- The following N lines, where the i-th line (1 \leq i \leq N) contains the integers L_i and R_i that define the visiting pattern of member i, separated by a space.
- The following M lines, where the j-th line (1 \leq j \leq M) contains the start day S_j and end day E_j of the j-th campaign as overall day numbers, separated by a space. This section does not exist when M = 0.
Output
Output N lines. The i-th line (1 \leq i \leq N) should contain the total training points earned by member i over the W weeks.
Sample Input 1
3 2 2 1 3 5 2 7 7 2 3 8 10
Sample Output 1
11 13 2
Sample Input 2
4 1 0 1 1 2 4 6 3 1 7
Sample Output 2
1 3 5 7
Sample Input 3
8 10 6 1 5 3 7 6 2 4 4 7 3 2 6 5 1 1 7 1 7 10 20 15 35 36 36 50 70 63 65
Sample Output 3
96 95 77 19 77 95 77 134
Sample Input 4
20 1000000000 15 1 1 2 2 3 3 4 4 5 5 6 6 7 7 1 3 2 5 3 7 5 2 6 1 7 4 1 7 4 2 2 1 6 6 3 5 7 1 5 5 1 1 2 100 50 1000 999999 1000005 7000000 7000100 123456789 123456999 999999999 1000000020 3500000000 3500000100 4999999999 5000000005 6000000000 6000001000 6999999990 7000000000 1 7000000000 2500000000 2500000000 3333333333 4444444444 123 456789
Sample Output 4
2158795759 2158795757 2158795754 2158795756 2158795756 2158795755 2158795755 6476387270 8635183023 10793978776 10793978782 6476387269 10793978781 15111570292 12952774538 15111570292 2158795755 6476387266 4317591514 2158795756
Sample Input 5
1 1000000000 2 1 7 1 7000000000 7000000000 7000000000
Sample Output 5
14000000001