牛客网暑期ACM多校训练营(第一场) J题详解

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

牛客网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.

备注

* 1 ≤ n, q ≤ 105

* 1 ≤ ai ≤ n

* 1 ≤ li, ri ≤ n

* The number of test cases does not exceed 10.

示例1:

输入

3 2

1 2 1

1 2

1 3

4 1

1 2 3 4

1 3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值