QOJ.ac

QOJ

Time Limit: 6.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#16341. 模糊排序(交互版)

Statistics

这是一个交互式问题。请记得在每次输出后刷新输出缓冲区。你可以使用以下方法刷新输出:

  • C/C++ 中的 fflush(stdout)cout.flush()
  • Java 和 Kotlin 中的 System.out.flush()
  • Python 中的 sys.stdout.flush()

在 Pigeland,有 $n$ 所大学,编号为 $1$ 到 $n$。每年,一些排名机构会发布这些大学的排名。今年共有 $k$ 个排名榜单,每个榜单都是一个 $1$ 到 $n$ 的整数排列,代表这些大学。在每个排名中,大学在排列中的位置越靠前,说明它在该榜单中的排名越好。

2024年 ICPC 世界总决赛的真实故事。

Supigar 是一名想要申请 Pigeland 博士项目的五年级学生,他有一套自己的方法来综合评估这 $n$ 所大学。他认为大学 $x$ 优于另一所大学 $y$,当且仅当满足以下条件之一:

  • $x$ 在至少一个榜单中的排名比 $y$ 好,或者
  • $x$ 在至少一个榜单中的排名比 $z$($z \neq x, z \neq y$)好,且 $z$ 优于 $y$。

显然,在这种定义下,可能存在某些大学对 $x$ 和 $y$($x < y$),使得 $x$ 优于 $y$ 的同时 $y$ 也优于 $x$。Supigar 将这样的大学对称为模糊对(fuzzy)。

Supigar 有 $q$ 次询问,其中第 $i$ 次询问可以用三个整数 $id_i$、$l_i$ 和 $r_i$($l_i \le r_i$)表示。对于每次询问,他会考虑第 $id_i$ 个排名榜单,以及该榜单中第 $l_i$ 个位置到第 $r_i$ 个位置(均包含)之间的所有大学。他想知道,在这些大学中,有多少对大学是模糊对。请注意,模糊对的定义需要考虑所有 $k$ 个排名榜单中的优于关系。

交互

本题有多组测试数据。输入的第一行包含一个整数 $T$($1 \le T \le 2 \times 10^5$),表示测试数据的组数。对于每组测试数据:

第一行包含三个整数 $n, k$($1 \le n, k, n \times k \le 2 \times 10^5$)和 $q$($1 \le q \le 2 \times 10^5$),分别表示大学的数量、排名榜单的数量以及询问的数量。

接下来的 $k$ 行中,第 $i$ 行包含 $n$ 个互不相同的整数 $a_{i,1}, a_{i,2}, \dots, a_{i,n}$($1 \le a_{i,j} \le n$),表示第 $i$ 个排名榜单。

然后,你需要逐个处理这 $q$ 次询问。对于每次询问:

  • 读取一行,包含三个整数 $id_i$($1 \le id_i \le k$)、$l_i$ 和 $r_i$($1 \le l_i \le r_i \le n$)。
  • 输出一个整数,表示在第 $id_i$ 个排名榜单中,处于第 $l_i$ 到第 $r_i$ 个位置(包含两端)的大学之间的模糊对数量。

保证所有测试数据的 $n \times k$ 之和以及 $q$ 之和均不超过 $2 \times 10^5$。

提供了一个测试工具以帮助你开发和测试你的解决方案。

样例

样例输入 1

2
5 2 2
1 2 3 4 5
5 4 3 2 1
2 1 3
1 1 5
5 3 3
1 2 3 4 5
1 3 2 4 5
1 2 3 5 4
1 1 3
2 4 5
3 2 5

样例输出 1

3
10
1
1
2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.