【题目描述】
Give you an integer array (index from 0 to n-1, where n is the size of this array, data value from 0 to 10000) . For each element Ai in the array, count the number of element before this element Ai is smaller than it and return count number array.
Notice:We suggest you finish problem Segment Tree Build,Segment Tree Query II and Count of Smaller Number first.
给定一个整数数组(下标由 0 到 n-1, n 表示数组的规模,取值范围由 0 到10000)。对于数组中的每个ai元素,请计算ai前的数中比它小的元素的数量。
【注】:做此题前最好先完成 Segment Tree Build,Segment Tree Query II和Count of Smaller Number
【题目链接】
www.lintcode.com/en/problem/count-of-smaller-number-before-itself/
【题目解析】
此题可用线段树来做。
首先以0-10000为区间建树,并将所有区间count设为0。每一个最小区间(即叶节点)的count代表到目前为止遇到的该数的数量。
然后开始遍历数组,遇到A[i]时,去查0-A[i]-1区间的count,即为比A[i]小的数的数量
查完后将A[i]区间的count加1即可
【参考答案】
www.jiuzhang.com/solutions/count-of-smaller-number-before-itself/
转载于:https://my.oschina.net/u/3776581/blog/1621115
分享到:
相关推荐
python python_leetcode题解之1365_How_Many_Numbers_Are_Smaller
java lru leetcode LeetFlag Total Count #1715 Jan 9, 2021 Using vscode-leetcode logined via 3rd party ...Count of Smaller number 我一开始的想法是用模板把A[] build 成segment tree,然后valu
before it finally printed out the optimal solution. Taking various interruptions into account, the team estimated that the total CPU time spent was about 85 years! Consider a similar problem: You want...
read array and read number 1-print the element larger than number 2-print the element smaller than number
This file contains an example that show how to detect an object's distance and calculate the smallest distance.
The number of questions is increasing recently. Here is the classification of all `468` questions. For more questions and solutions, you can see my [LintCode](https://github.com/kamyu104/LintCode) ...
ApplicationofNatured-InspiredAlgorithmsfortheSolutionofComplexElectromagnetic Problems.............................................................................................
Keeping your clustered key value small increases the number of index rows that can be placed on an index page and decreases the number of levels that must be traversed. This minimizes I/O. As we’ll ...
number higher or lower 349: intersection of two arrays 350: intersection of two arrays ii medium 33: search in sorted array 81: search in rotated sorted array ii 153: find minimum in rotated sorted ...
The M.2 is a family of form factors that will enable expansion, contraction, and higher integration of functions onto a single form factor module solution. The key target for M.2 is to be ...
number of radio frequency (RF) chains is usually much smaller than that of antennas. To date, several channel estimation schemes have been proposed for mmWave massive MIMO over narrowband channels, ...
KGB Archiver console version ?...based on PAQ6 by Matt Mahoney PAQ6v2 - File archiver and compressor. (C) 2004, Matt Mahoney, ... For smaller values of MEM, some components are omitted and the number...
7 The key target for M.2 is to be significantly smaller in the XYZ and overall volume of the Half-Mini 8 Card used today in mobile Platforms in preparation for the very thin computing Platforms 9 (e.g...
java lru leetcode Java相关知识 基础知识 集合 多线程 JVM Spring 锁 ...LintCode相关必刷题目(转自面经) ...重点:快速排序、归并排序、堆排序(面试问排序基本就是这三个,理解并背熟) ...Smaller Numbers A
The features can be of any type and in any number of dimensions, and are defined by the user. The EMD is defined as the minimum amount of work needed to change one signature into the other. The ...
LintCode、LeetCode 等算法问题的 Java 解决方案。 一旦出现新问题或新测试用例,我将尝试修改解决方案。 顺序 问题 等级 语 0 [2 Sum II - 输入数组已排序.java]( Sum II - 输入数组已排序.java) Java 1 [2 Sum II....
LintCode、LeetCode 等算法问题的 Java 解决方案。 一旦出现新问题或新测试用例,我将尝试修改解决方案。 2016年年中,我意识到人们可能希望为此 repo 做出贡献,并通过提供修复程序、更好的解决方案等来使其更好。...
I was introduced to Microsoft Windows CE right before it was released in the fall of 1996. A Windows programmer for many years, I was intrigued by an operating system that applied the well-known ...
of holes in the"stone"lock.If the kev is smaller than the stonethen the key can be moved to any location relative to the stoneso ona as it doesn't extend bevond the edae of the stone in any ...