当前位置:首页|资讯

GFG 149 Beautiful cities - I

作者:您是打尖儿还是住店呢发布时间:2024-10-16

 There are n cities in a Geekland. 

Each city is given some beautifulness by the king. 

Cities with di erent beautifulness don't like to trade with each other. 

You are given with q queries each consisting of two integers u and v.

You need to tell if all the cities from u to v (both inclusive) can trade with every other city from u to v. 

Example 1:Input:n = 8 beautifulness = {2,2,2,2,1,1,1,3}q = 5queries = {{1,4},{2,5},{5,7},{1,8},{6,6}} 

Output:{1,0,1,0,1} 

Explanation:All the cities from 1 to 4 have a beautifulness of 2 therefore any city can trade with any other city.

So the answer for the  rst query is 1.City 5 does not trade with city 2,3 and 4. So the answer for the second query is 0. 

Similarly, for other queries. 

Example 2:Input:n = 6 beautifulness = {2,1,6,5,3,4}q = 4queries = {{1,2},{2,5},{5,6},{6,6}} Output:{0,0,0,1}

Explanation:

None of the queries except the last one has all cities which can trade with each other.

----

只要区间有2个元素的话,那么就肯定不能交易的,那么就用一个数组来维护当前的索引值即可。

知道怎么做了,瞬间就很简单了。



Copyright © 2024 aigcdaily.cn  北京智识时代科技有限公司  版权所有  京ICP备2023006237号-1