牛客网J题在比赛时是通过率最高的一道题,但是这道题对于时间的复杂度要求比较高。在比赛的时候,很多队伍提交的程序都以”运行超时“而结束。那就让我们先来看看这道看似简单的题。
Different Integers
题目描述
Given a sequence of integers a1, a2, ..., an and q pairs of integers (l1, r1), (l2, r2), ..., (lq, rq), find count(l1, r1), count(l2, r2), ..., count(lq, rq) where count(i, j) is the number of different integers among a 1, a2, ..., ai, aj, aj + 1, ..., an.
输入描述:
The input consists of several test cases and is terminated by end-of-file. The first line of each test cases contains two integers n and q. The second line contains n integers a1, a2, ..., an. The i-th of the following q lines contains two integers li and ri.
输出描述:
For each test case, print q integers which denote the result.

博客详细解析了牛客网ACM多校训练营第一场J题,该题需要求解给定序列在特定区间内的不同整数数量。文中介绍了使用树状数组降低时间复杂度至的方法,包括题意理解、错误解法的反思和正确解法的阐述,适合学习数据结构优化的程序员参考。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



