P3660 [USACO17FEB]Why Did the Cow Cross the Road III G

    • 145通过
    • 236提交
  • 题目提供者 FarmerJohn2
  • 评测方式 云端评测
  • 标签 前缀和 枚举,暴力 树状数组 USACO 2017
  • 难度 提高+/省选-
  • 时空限制 1000ms / 128MB

题解

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

    推荐的相关题目 显示

    题目背景

    给定长度为2N的序列,1~N各处现过2次,i第一次出现位置记为ai,第二次记为bi,求满足ai<aj<bi<bj的对数

    题目描述

    The layout of Farmer John's farm is quite peculiar, with a large circular road running around the perimeter of the main field on which his cows graze during the day. Every morning, the cows cross this road on their way towards the field, and every evening they all cross again as they leave the field and return to the barn.

    As we know, cows are creatures of habit, and they each cross the road the same way every day. Each cow crosses into the field at a different point from where she crosses out of the field, and all of these crossing points are distinct from each-other. Farmer John owns $N$ cows, conveniently identified with the integer IDs $1 \ldots N$ , so there are precisely $2N$ crossing points around the road. Farmer John records these crossing points concisely by scanning around the circle clockwise, writing down the ID of the cow for each crossing point, ultimately forming a sequence with $2N$ numbers in which each number appears exactly twice. He does not record which crossing points are entry points and which are exit points.

    Looking at his map of crossing points, Farmer John is curious how many times various pairs of cows might cross paths during the day. He calls a pair of cows $(a,b)$ a "crossing" pair if cow $a$ 's path from entry to exit must cross cow $b$ 's path from entry to exit. Please help Farmer John count the total number of crossing pairs.

    输入输出格式

    输入格式:

    The first line of input contains $N$ ( $1 \leq N \leq 50,000$ ), and the next $2N$ lines describe the cow IDs for the sequence of entry and exit points around the field.

    输出格式:

    Please print the total number of crossing pairs.

    输入输出样例

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