题意:
初始给出1-n的序列,有两个操作:
D l r,将[l,r]区间的每个数都复制一个;
Q l r,询问[l,r]区间内最多的相同数字的个数。
分析:
显然的线段树,但是这个序列的长度会因为D操作变化,即线段长度变化。通过观察发现这个序列永远是sort过的,那么我们只要维护每个数的数量,操作前找到l和r的位置,然后再单点更新、成段更新,成段询问,线段树的综合应用。...
分类:
其他好文 时间:
2014-08-24 12:59:22
阅读次数:
330
由于二维字符数组的第二维没有赋值运算符,即不能对整个一维数组进行赋值,因此是无法直接对二维数组用sort进行排序的,解决办法有二种:代码一: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 struct Data 7 {...
分类:
其他好文 时间:
2014-08-24 11:35:52
阅读次数:
125
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, ...
分类:
其他好文 时间:
2014-08-24 11:32:02
阅读次数:
164
import mathclass sort: def selectSort(self, L): size = len(L) for i in range(0, size): max = L[i] index = i ...
分类:
编程语言 时间:
2014-08-23 22:48:11
阅读次数:
205
using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace ListSort{ class Program { static void Main(s...
分类:
其他好文 时间:
2014-08-22 23:43:59
阅读次数:
233
package algorithm;
public class SortAll {
public static void main(String[] args) {
char buf[] = {'1','2','3','4','5'};
perm(buf,0,buf.length-1);
}
private static void perm(char[] buf, int sta...
分类:
编程语言 时间:
2014-08-22 17:56:39
阅读次数:
233
[root@web~]#netstat-anp|awk‘{print$6}‘|sort|uniq-c|sort-rn172ESTABLISHED59CONNECTED589SYN_RECV15STREAMSYN居然这么高,继续追查是那些ip发出的SYN:[root@tweb~]#netstat-an|grepSYN|awk‘{print$5}‘|awk-F:‘{print$1}‘|sort|uniq-c|sort-nr|more570x.x.x.x(ip就不写出了..
分类:
系统相关 时间:
2014-08-21 19:35:16
阅读次数:
305
这题前一阵子就看到了,一直没时间做,昨晚睡前想了想,要求n*log(n)以内的时间复杂度,第一时间想到的就是归并、快排和希尔排序(注:希尔排序时间为O(n^1.3),在数据量大于2的情况下小于n*log(n)),个人以为,链表的特性更适合归并,所以采用归并排序,实现的merge代码如下:publ.....
分类:
其他好文 时间:
2014-08-21 19:01:54
阅读次数:
226
冒泡排序(Bubble Sort,台湾译为:泡沫排序或气泡排序)是一种简单的排序算法。它的基本思想就是两两比较相邻记录的关键字,如果反序则交换,直到没有反序的记录为止。它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来。走访数列的工作是重复地进行直到没有再需要交换,也就是说该数列已经排序完成。 例如:初始序列3,6,4,2,11,10,5;从头开始,两两相比...
分类:
其他好文 时间:
2014-08-21 15:07:44
阅读次数:
188
Median of Two Sorted Arrays
Total Accepted: 17932 Total
Submissions: 103927My Submissions
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sort...
分类:
其他好文 时间:
2014-08-21 13:24:54
阅读次数:
206