World is Exploding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 727    Accepted Submission(s): 348 Problem Description Given a sequence A with length n,count how many quadruple (a,b,c,d) sati…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 World is Exploding Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others) 问题描述 输入 The input consists of multiple test cases. Each test case begin with an integer n in a sin…
World is Exploding 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 Description Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: a≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab,Ac>Ad. Input The input consists of multiple test c…
hdu 5792 要找的无非就是一个上升的仅有两个的序列和一个下降的仅有两个的序列,按照容斥的思想,肯定就是所有的上升的乘以所有的下降的,然后再减去重复的情况. 先用树状数组求出lx[i](在第 i 个数左边的数中比它小的数的个数),ld[i](在第 i 个数左边的数中比它大的数的个数),rx[i](在第 i 个数右边的数中比它小的数的个数) ,rd[i](在第 i 个数右边的数中比它大的数的个数).然后重复的情况无非就是题目中a与c重合(rx[i]*rd[i]),a与d重合(rd[i]*ld[…
Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数.请输出最少需要修改多少个元素.   Input 第一行输入一个T(1≤T≤10),表示有多少组数据 每一组数据: 第一行输入一个N(1≤N≤105),表示数列的长度 第二行输入N个数A1,A2,...,An. 每一个数列中的元素都是正整数而且不超过106.   Output 对于每组数据,先输出一行 Case #i: 然…
Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: a≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab,Ac>Ada≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab,Ac>Ad. InputThe input consists of multiple test cases. Each test case begin with an int…
传送门 设$f_i$表示$i$排列的数量,其中$x$表示不确定 那么$$ans=f_{1324}-f_{1432}-f_{1243}=(f_{1x2x}-f_{1423})-(f_{14xx}-f_{1423})-(f_{12xx}-f_{1234})$$ $$=f_{1x2x}-(f_{14xx}+f_{12xx})+f_{1234}$$ $$=f_{1x2x}-f_{1xxx}+f_{13xx}+f_{1234}$$ ①$f_{1xxx}$用树状数组求正序对 ②$f_{1234}$四个树状数…
题目 题意:  给你一串数字,然后给你最多进行k次交换(只能交换相邻的)问交换后的最小逆序对个数是多少. 给你一个序列,每次只能交换相邻的位置,把他交换成一个递增序列所需要的最少步数 等于 整个序列的逆序对数. 对于这个题目,我们只要求出个逆序对个数,然后输出逆序数 - k就行了,如果是负数输出0. 之前做的这道题也是和逆序对有关,但是通过这道的代码改编一下,总是Runtime Error (ACCESS_VIOLATION),原因在于这里 The first line contains 2 i…
Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 388    Accepted Submission(s): 148 Problem Description Given the finite multi-set A of n pairs of integers, an another finite multi-set B …
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2189    Accepted Submission(s): 634 Problem Description When the magic ball game turns up, Kimi immediately falls in it. The int…
BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然,他能为长者所续的时间,为这三个维度上能量的乘积, 但目前的宇宙很不乐观,胡乱偷取可能造成维度的崩溃, 所以,他必须按逆序偷取这些维度,且在偷取中, 每次偷取的维度的能量必须严格小于他上次偷取的能量, 由于膜法师生活在多元宇宙,所以他可以让所有可能的偷取方案全部发生 题目描述 但他数学不好,所以找到…
题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascend…
http://acm.split.hdu.edu.cn/showproblem.php?pid=5792 题意: 思路: lmin[i]:表示左边比第i个数小的个数. lmax[i]:表示左边比第i个数大的个数. rmin[i]:表示右边比第i个数小的个数. rmax[i]:表示右边比第i个数大的个数. 这些都是可以用树状数组计算出来的,把所有的lmin加起来就是所有(a,b)对的个数,所有lmax加起来就是所有(c,d)对的个数,两者相乘就是所有情况之和了.但是需要注意的是,在这些情况中还存在…
题目,要求找出有多少对这样的东西,四个数,并且满足num[a]<num[b] &&num[c]>num[d] 要做这题,首先要懂得用树状数组,我设,下面的小于和大于都是严格的小于和大于 dpL_min[i]:表示在第i个数往左,(不包括第i个),有多少个数是少于num[i]的 dpL_max[i]:表示在第i个数往左,(不包括第i个),有多少个数是大于num[i]的 dpR_min[i]:表示在第i个数往右,(不包括第i个),有多少个数是小于num[i]的 dpR_max[i]…
题目大意: Given a sequence A with length n,count how many quadruple (a,b,c,d) satisfies: a≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab,Ac>Ada≠b≠c≠d,1≤a<b≤n,1≤c<d≤n,Aa<Ab,Ac>Ad. A1,A2⋯AnA1,A2⋯An.  1≤n≤500001≤n≤50000  0≤Ai≤1e9 基本思路: 最朴素的思想就是算出所有顺序对所有逆序对…
http://acm.hdu.edu.cn/showproblem.php?pid=5792 1012 World is Exploding 题意:选四个数,满足a<b and A[a]<A[b]   c<d and A[c]>A[d] 问有几个这样的集合 思路: 树状数组+离线化 先处理出每个数左边比它小 大,右边比它大 小的数目,用cnt[][i]表示.最后统计一下减去重复的就可以 #include <iostream> #include <cstdio>…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences                                  Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)                                             …
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number                        Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)                                            Total Submission(s): 10…
Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection. The input data guarantee that no two se…
ZYB's Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5592 Description ZYB has a premutation P,but he only remeber the reverse log of each prefix of the premutation,now he ask you to restore the premutation…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题目让你求一个数组,这个数组可以不断把最前面的元素移到最后,让你求其中某个数组中的逆序对最小是多少. 一开始就求原来初始数组的逆序对,树状数组求或者归并方法求(可以看<挑战程序设计>P178),然后根据最前面的元素大小递推一下每次移到最后得到的逆序数,取最小值. #include <iostream> #include <cstdio> #include <cs…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5877 [题目大意] 给出一棵带权有根树,询问有几对存在祖先关系的点对满足权值相乘小于等于k. [题解] 我们沿根节点开始将点权加入权值树状数组,每次处理完子树就回溯,保证每个节点的答案统计是在只包括祖先节点的树状数组中进行. [代码] #include <cstdio> #include <algorithm> #include <vector> #include &l…
Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4672    Accepted Submission(s): 3244 Problem Description You want to processe a sequence of n distinct integers by swapping two adjacent s…
题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite multi-set B of m triples of integers, we define the product of A and B as a multi-set C=A∗B={⟨a,c,d⟩∣⟨a,b⟩∈A, ⟨c,d,e⟩∈B and b=e} For each ⟨a,b,c⟩∈C, its B…
http://acm.hdu.edu.cn/showproblem.php?pid=4325 题意:给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x. 思路: 因为数据量比较多,所以需要离散化.区间的离散化需要注意一下,如果端点不连续的话,需要额外插点. 区间情况就用树状数组来维护. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 Problem DescriptionYJJ is a salesman who has traveled through western country. YJJ is always on journey. Either is he at the destination, or on the way to destination.One day, he is going to travel…
http://acm.hdu.edu.cn/showproblem.php?pid=5877 题意: 给出一棵树,每个顶点都有权值,现在要你找出满足要求的点对(u,v)数,u是v的祖先并且a[u]*a[v]<=k. 思路: 转化一下,a[v]<=k/a[u],k/a[u]的最大值也就是k/a[v],也就是寻找<=k/a[v]的个数,到这儿,是不是很像树状数组? 我们只需要从根开始dfs,插入到树状数组中,并且查询即可.注意这道题目需要离散化一下. #include <iostrea…
题目链接:[http://acm.split.hdu.edu.cn/showproblem.php?pid=5517] 题意:定义multi_set A<a , d>,B<c , d , e>,C<x , y , z>,给出 A , B ,定义 C = A * B = ={⟨a,c,d⟩∣⟨a,b⟩∈A, ⟨c,d,e⟩∈B and b=e} .求出C之后,求C中一个元素t[i]<a , b , c>是否存在一个元素tmp<x , y , z>使…
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Counting Intersections Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 Given some segments which are paralleled to the coordinate axis. You need to coun…
http://acm.hdu.edu.cn/listproblem.php?vol=49 给定一颗树,然后对于每一个节点,找到它的任何一个祖先u,如果num[u] * num[v] <= k.则贡献加1 思路:主要的麻烦就是动态修改前缀和了.因为对于每个数字val.则找它祖先的话, <= k / val的数字,都是合法的.所以问题转化成求你现在dfs中保存的数字,有多少个是  <= k / val的,树状数组即可. 问题就是,数字太大了,这不适合树状数组,那么我们把每个数字离散成他们的下…