CF283E.Cow Tennis Tournament
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Farmer John is hosting a tennis tournament with his n cows. Each cow has a skill level s__i, and no two cows having the same skill level. Every cow plays every other cow exactly once in the tournament, and each cow beats every cow with skill level lower than its own.
However, Farmer John thinks the tournament will be demoralizing for the weakest cows who lose most or all of their matches, so he wants to flip some of the results. In particular, at k different instances, he will take two integers a__i, b__i (a__i < b__i) and flip all the results between cows with skill level between a__i and b__i inclusive. That is, for any pair x, y
he will change the result of the match on the final scoreboard (so if x won the match, the scoreboard will now display that y won the match, and vice versa). It is possible that Farmer John will change the result of a match multiple times. It is not guaranteed that a__i and b__i are equal to some cow's skill level.
Farmer John wants to determine how balanced he made the tournament results look. In particular, he wants to count the number of triples of cows (p, q, r) for which the final leaderboard shows that cow p beats cow q, cow q beats cow r, and cow r beats cow p. Help him determine this number.
Note that two triples are considered different if they do not contain the same set of cows (i.e. if there is a cow in one triple that is not in the other).
农夫约翰正在为他的 n 头奶牛举办一场网球锦标赛。每头奶牛有一个技能值 si,且任意两头奶牛的技能值互不相同。锦标赛中,每对奶牛恰好比赛一次;并且对于任意两头奶牛,技能值更高的那头总是获胜。
然而,农夫约翰认为,对于那些最弱的奶牛(它们会输掉大多数甚至全部比赛),这样的锦标赛结果可能会令它们士气低落,因此他希望翻转部分比赛结果。具体来说,他将在 k 个不同的时刻,每次给出两个整数 ai,bi(满足 ai<bi),并将所有技能值在区间 [ai,bi] 内的奶牛之间的比赛结果全部翻转。也就是说,对任意一对奶牛 x,y(满足 ai≤sx,sy≤bi),他将最终记分板上该场比赛的结果取反(即若原本是 x 获胜,则记分板上改为显示 y 获胜,反之亦然)。同一场比赛的结果可能被多次翻转。注意:ai 和 bi 不一定等于任何奶牛的技能值。
农夫约翰希望评估他所构造出的最终比赛结果的“平衡性”。具体而言,他希望统计满足如下条件的奶牛三元组 (p,q,r) 的数量:在最终记分板上,奶牛 p 击败了奶牛 q,奶牛 q 击败了奶牛 r,而奶牛 r 又击败了奶牛 p。请帮助他计算这一数量。
注意:只要两个三元组所包含的奶牛集合不同(即存在某头奶牛属于其中一个三元组但不属于另一个),就认为它们是不同的三元组。
输入格式
On the first line are two space-separated integers, n and k (3 ≤ n ≤ 105; 0 ≤ k ≤ 105). On the next line are n space-separated distinct integers, _s_1, _s_2, ..., s__n (1 ≤ s__i ≤ 109), denoting the skill levels of the cows. On the next k lines are two space separated integers, a__i and b__i (1 ≤ a__i < b__i ≤ 109) representing the changes Farmer John made to the scoreboard in the order he makes it.
第一行包含两个用空格分隔的整数 n 和 k(3≤n≤105;0≤k≤105)。
第二行包含 n 个用空格分隔的互不相同的整数 s1, s2, …, sn(1≤si≤109),表示奶牛的技能水平。
接下来的 k 行中,每行包含两个用空格分隔的整数 ai 和 bi(1≤ai<bi≤109),表示农夫约翰按顺序对计分板所做的修改。
输出格式
A single integer, containing the number of triples of cows (p, q, r) for which the final leaderboard shows that cow p beats cow q, cow q beats cow r, and cow r beats cow p.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
一个整数,表示满足以下条件的奶牛三元组 (p,q,r) 的数量:最终排行榜显示奶牛 p 击败奶牛 q,奶牛 q 击败奶牛 r,且奶牛 r 击败奶牛 p。
在 C++ 中,请勿使用 %lld 说明符读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 说明符。
输入输出样例
输入#1
3 2 1 2 3 1 2 2 3
输出#1
1
输入#2
5 3 5 9 4 1 7 1 7 2 8 3 9
输出#2
3
说明/提示
In the first sample, cow 3 > cow 1, cow 3 > cow 2, and cow 2 > cow 1. However, the results between cows 1 and 2 and cows 2 and 3 are flipped, so now FJ's results show that cow 1 > cow 2, cow 2 > cow 3, and cow 3 > cow 1, so cows 1, 2, and 3 form a balanced triple.
在第一个样例中,奶牛 3 > 奶牛 1,奶牛 3 > 奶牛 2,且奶牛 2 > 奶牛 1。然而,奶牛 1 与奶牛 2 之间、以及奶牛 2 与奶牛 3 之间的结果被翻转了,因此现在 FJ 的结果显示:奶牛 1 > 奶牛 2,奶牛 2 > 奶牛 3,且奶牛 3 > 奶牛 1,于是奶牛 1、2 和 3 构成一个平衡三元组。
输入解题思路,AI测评打分。不知道怎么写?