P3658 [USACO17FEB]Why Did the Cow Cross the Road III P

    • 44通过
    • 189提交
  • 题目提供者 FarmerJohn2
  • 评测方式 云端评测
  • 标签 USACO 2017 高性能
  • 难度 省选/NOI-
  • 时空限制 1000ms / 128MB

题解

  • 提示:收藏到任务计划后,可在首页查看。
  • 最新讨论 显示

    推荐的相关题目 显示

    题目描述

    Farmer John is continuing to ponder the issue of cows crossing the road through his farm, introduced in the preceding two problems. He realizes now that the threshold for friendliness is a bit more subtle than he previously considered -- breeds $a$ and $b$ are now friendly if $|a - b| \leq K$ , and unfriendly otherwise. Given the orderings of fields on either side of the road through FJ's farm, please count the number of unfriendly crossing pairs of breeds, where a crossing pair of breeds is defined as in the preceding problems.

    思考过前两个问题后,农民约翰正在继续思考如何对付穿过农场的牛的问题。 他现在意识到,友好的品种的标准比他以前想的稍微微妙一些 -对于品种 $a,b$ 如果 $|a - b| \leq K$ ,现在是友好的。 否则是不友好的。给定这条路两边的田地的顺序,请计算有多少交叉的不良品种对,其中一对品种在前问题被定义。

    输入输出格式

    输入格式:

    The first line of input contains $N$ ( $1 \leq N \leq 100,000$ ) and $K$ ( $0 \leq K < N$ ). The next $N$ lines describe the order, by breed ID, of fields on one side of the road; each breed ID is an integer in the range $1 \ldots N$ . The last $N$ lines describe the order, by breed ID, of the fields on the other side of the road. Each breed ID appears exactly once in each ordering.

    一行包含 $N$ ( $1 \leq N \leq 100,000$ )与 $K$ ( $0 \leq K < N$ ),接下来 $N$ 行按顺序描述了小路一旁田地的品种的ID号,每一个ID号是一个在 $1...N$ 之间的整数。倒数 $N$ 行描述了小路另一旁田地的品种的ID号。每个ID只在一个顺序中出现一次

    输出格式:

    Please output the number of unfriendly crossing pairs of breeds.

    请输出不友好的品种对的数量。

    输入输出样例

    输入样例#1: 复制
    4 1
    4
    3
    2
    1
    1
    4
    2
    3
    输出样例#1: 复制
    2

    说明

    In this example, breeds 1 and 4 are unfriendly and crossing, as are breeds 1 and 3.

    感谢@Adscn提供翻译

    提示
    标程仅供做题后或实在无思路时参考。
    请自觉、自律地使用该功能并请对自己的学习负责。
    如果发现恶意抄袭标程,将按照I类违反进行处理。