CF1307E.Cow and Treats

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

After a successful year of milk production, Farmer John is rewarding his cows with their favorite treat: tasty grass!

On the field, there is a row of nn units of grass, each with a sweetness sis_i. Farmer John has mm cows, each with a favorite sweetness fif_i and a hunger value hih_i. He would like to pick two disjoint subsets of cows to line up on the left and right side of the grass row. There is no restriction on how many cows must be on either side. The cows will be treated in the following manner:

  • The cows from the left and right side will take turns feeding in an order decided by Farmer John.
  • When a cow feeds, it walks towards the other end without changing direction and eats grass of its favorite sweetness until it eats hih_i units.
  • The moment a cow eats hih_i units, it will fall asleep there, preventing further cows from passing it from both directions.
  • If it encounters another sleeping cow or reaches the end of the grass row, it will get upset. Farmer John absolutely does not want any cows to get upset.

Note that grass does not grow back. Also, to prevent cows from getting upset, not every cow has to feed since FJ can choose a subset of them.

Surprisingly, FJ has determined that sleeping cows are the most satisfied. If FJ orders optimally, what is the maximum number of sleeping cows that can result, and how many ways can FJ choose the subset of cows on the left and right side to achieve that maximum number of sleeping cows (modulo 109+710^9+7)? The order in which FJ sends the cows does not matter as long as no cows get upset.

在成功完成了一年牛奶生产后,农夫约翰正用奶牛们最爱的美食——美味的青草——来犒劳它们!

田地里有一排长度为 nn 的青草,每单位青草的甜度为 sis_i。农夫约翰有 mm 头奶牛,第 ii 头奶牛喜爱的甜度为 fif_i,饥饿值为 hih_i。他希望从中选出两个互不相交的子集,分别安排在青草排的左侧和右侧(左右两侧的奶牛数量均无限制)。奶牛将按如下方式被喂食:

  • 左侧和右侧的奶牛将轮流进食,轮次顺序由农夫约翰决定;
  • 当一头奶牛进食时,它会朝另一端直线行走(方向不变),沿途只吃甜度恰好等于其喜爱甜度 fif_i 的青草,直到总共吃下 hih_i 单位青草为止;
  • 一旦某头奶牛吃够了 hih_i 单位青草,它便立刻在当前位置睡着,从而阻挡后续所有从左或右方向经过该位置的奶牛;
  • 如果一头奶牛在行进途中遇到另一头已睡着的奶牛,或抵达青草排的尽头,它就会感到沮丧。农夫约翰绝对不允许任何奶牛感到沮丧。

注意:青草不会再生长。此外,为避免奶牛沮丧,农夫约翰可选择仅让部分奶牛进食(即不必让全部奶牛都参与喂食)。

令人惊讶的是,农夫约翰发现:睡着的奶牛最满足。若农夫约翰以最优策略安排喂食顺序,最多能有多少头奶牛睡着?以及,有多少种方式选择左侧与右侧的奶牛子集(模 109+710^9+7),使得最终睡着的奶牛数量达到该最大值?只要不引起任何奶牛沮丧,农夫约翰派遣奶牛的顺序无关紧要。

输入格式

The first line contains two integers nn and mm (1≤n≤50001 \le n \le 5000, 1≤m≤50001 \le m \le 5000) — the number of units of grass and the number of cows.

The second line contains nn integers s1,s2,…,sns_1, s_2, \ldots, s_n (1≤si≤n1 \le s_i \le n) — the sweetness values of the grass.

The ii-th of the following mm lines contains two integers fif_i and hih_i (1≤fi,hi≤n1 \le f_i, h_i \le n) — the favorite sweetness and hunger value of the ii-th cow. No two cows have the same hunger and favorite sweetness simultaneously.

第一行包含两个整数 nn 和 mm(1≤n≤50001 \le n \le 5000,1≤m≤50001 \le m \le 5000)—— 分别表示草的单位数量和奶牛的数量。

第二行包含 nn 个整数 s1,s2,…,sns_1, s_2, \ldots, s_n(1≤si≤n1 \le s_i \le n)—— 表示每单位草的甜度值。

接下来的 mm 行中,第 ii 行包含两个整数 fif_i 和 hih_i(1≤fi,hi≤n1 \le f_i, h_i \le n)—— 分别表示第 ii 头奶牛最喜爱的甜度值和饥饿值。任意两头奶牛不会同时具有相同的饥饿值和最喜爱的甜度值。

输出格式

Output two integers — the maximum number of sleeping cows that can result and the number of ways modulo 109+710^9+7.

输出两个整数——最多可以有多少头奶牛在睡觉,以及对应的方案数对 109+710^9+7 取模的结果。

输入输出样例

  • 输入#1

    5 2
    1 1 1 1 1
    1 2
    1 3

    输出#1

    2 2
  • 输入#2

    5 2
    1 1 1 1 1
    1 2
    1 4

    输出#2

    1 4
  • 输入#3

    3 2
    2 3 2
    3 1
    2 1

    输出#3

    2 4
  • 输入#4

    5 1
    1 1 1 1 1
    2 5

    输出#4

    0 1

说明/提示

In the first example, FJ can line up the cows as follows to achieve 22 sleeping cows:

  • Cow 11 is lined up on the left side and cow 22 is lined up on the right side.
  • Cow 22 is lined up on the left side and cow 11 is lined up on the right side.

In the second example, FJ can line up the cows as follows to achieve 11 sleeping cow:

  • Cow 11 is lined up on the left side.
  • Cow 22 is lined up on the left side.
  • Cow 11 is lined up on the right side.
  • Cow 22 is lined up on the right side.

In the third example, FJ can line up the cows as follows to achieve 22 sleeping cows:

  • Cow 11 and 22 are lined up on the left side.
  • Cow 11 and 22 are lined up on the right side.
  • Cow 11 is lined up on the left side and cow 22 is lined up on the right side.
  • Cow 11 is lined up on the right side and cow 22 is lined up on the left side.

In the fourth example, FJ cannot end up with any sleeping cows, so there will be no cows lined up on either side.

在第一个例子中,FJ 可以按以下方式排列奶牛,从而得到 22 头正在睡觉的奶牛:

  • 奶牛 11 排在左侧,奶牛 22 排在右侧。
  • 奶牛 22 排在左侧,奶牛 11 排在右侧。

在第二个例子中,FJ 可以按以下方式排列奶牛,从而得到 11 头正在睡觉的奶牛:

  • 奶牛 11 排在左侧。
  • 奶牛 22 排在左侧。
  • 奶牛 11 排在右侧。
  • 奶牛 22 排在右侧。

在第三个例子中,FJ 可以按以下方式排列奶牛,从而得到 22 头正在睡觉的奶牛:

  • 奶牛 11 和 22 都排在左侧。
  • 奶牛 11 和 22 都排在右侧。
  • 奶牛 11 排在左侧,奶牛 22 排在右侧。
  • 奶牛 11 排在右侧,奶牛 22 排在左侧。

在第四个例子中,FJ 无法使任何奶牛进入睡眠状态,因此两侧均不会排列任何奶牛。

输入解题思路,AI测评打分。不知道怎么写?

首页