http://acm.nyist.net/JudgeOnline/problem.php?pid=600 只附代码好了 #include<bits/stdc++.h> using namespace std; ; struct node { int num,id; } s[N]; int s1[N],a[N]; bool cmp(node x,node y) { return x.num<y.num; } int lowbit(int x) { return x&-x; } vo…
http://acm.nyist.net/JudgeOnline/problem.php?pid=600 只附代码好了 #include<bits/stdc++.h> using namespace std; ; struct node { int num,id; } s[N]; int s1[N],a[N]; bool cmp(node x,node y) { return x.num<y.num; } int lowbit(int x) { return x&-x; } vo…
题目链接:1337: Car race game 参考资料:⑴ Car race game 树状数组 棋煜,⑵ 树状数组,⑶ 离散化 补充资料:⑴ qsort,⑵ 二分查找 Description Bob is a game programming specialist. In his new car race game, there are some racers(n means the amount of racers (1<=n<=100000)) racers star from so…
牛客2019多校联盟Day7 Fine the median 题意:  每次给数组插入区间[Li,Ri] 内的所有数,每操作一次查询中位数. 遇到这题真的算是巧合,然而就是这种冥冥之中的缘分,给了我线段树的一个全新的思想. 这题与以往的线段树做法有所不同,常规的线段树题目,可能就是一个点区间代表一个数据,然后找个区间最大值什么的. 这种很显而易见的,对吧?因为点区间代表了一个点,仅仅是一个点,所以做起来比较容易. 而今天这题十分有趣.它的点区间代表的是一个区间. 比如这题,我们去怎么解决呢? 对…
HDU 3333:http://acm.hdu.edu.cn/showproblem.php?pid=3333 这两个题是类似的,都是离线处理查询,对每次查询的区间的右端点进行排序.这里我们需要离散化处理一下,标记一下前面是否出现过这个值,然后不断更新last数组(该数组保存的是每个数最后一次出现的位置).最后用树状数组维护. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ; struct node{…
Problem 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 ascending order. For the inp…
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…
https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/G [题意] 给定一个数组a,问这个数组有多少个子序列,满足子序列中任意两个相邻数的差(绝对值)都不大于d. [思路] 首先,朴素的dp思想: dp[i]为以a[i]结尾的子问题的答案,则dp[i]=sum(dp[k]),k<i&&|a[k]-a[i]|<=d 但是时间复杂度为O(n^2),会超时. 我们可以这样想: 如果数组a排好序后,dp[i]就是区间(a[…
题目链接 参考博客 题意: 给n个线段,对于每个线段问它覆盖了多少个线段. 思路: 由于线段端点是在2e9范围内,所以要先离散化到2e5内(左右端点都离散化了,而且实际上离散化的范围是4e5),然后对右端点升序排序: 例如 2 3  5 6  4 7  1 8 这样的话,如果对i<j,a[ i ].l >= a[ j ].l ,那么第 j 组一定包含了第 i 组,算完第一组sum(3)-sum(2-1),把a[1].l加入到树状数组中,再算第二组,以此类推算到第三组时,sum(7)=2(1~7…
#include <iostream> #include <algorithm> #include <cstring> using namespace std ; ; struct node{ int val,pos ; }tmp[N]; int a[N] ;//离散化后的原始数组 int c[N] ;//树状数组 bool cmp(node st1,node st2){ return st1.val < st2.val ; } int lowbit(int x)…