CF993E:Nikita and Order Statistics(FFT)】的更多相关文章

Description 给你一个数组 $a_{1 \sim n}$,对于 $k = 0 \sim n$,求出有多少个数组上的区间满足:区间内恰好有 $k$ 个数比 $x$ 小.$x$ 为一个给定的数. Input 第一行$n,x$. 第二行给出$n$个数 Output 一行答案. Sample Input1 5 31 2 3 4 5 Sample Output1 6 5 4 0 0 0 Sample Input2 2 6-5 9 Sample Output2 1 2 0 Sample Input…
题目链接 CF993E 题解 我们记小于\(x\)的位置为\(1\),否则为\(0\) 区间由端点决定,转为两点前缀和相减 我们统计出每一种前缀和个数,记为\(A[i]\)表示值为\(i\)的位置出现的次数 那么对于\(k > 0\)有 \[ans_k = \sum\limits_{x - y = k} A[x]A[y]\] 令 \[B[x] = A[n - x]\] 那么有 \[ans_k = \sum\limits_{x + y = n + k} A[x]B[y]\] 就成了卷积的形式 第\…
洛谷 Codeforces 思路 一开始想偏想到了DP,后来发现我SB了-- 考虑每个\(a_i<x\)的\(i\),记录它前一个和后一个到它的距离为\(L_i,R_i\),那么就有 \[ ans_k=\sum_{i=1}^n L_iR_{i+k-1} \] 显然把\(L\)数组翻转一下就是一个FFT了. 最后特判\(k=0\). 代码 #include<bits/stdc++.h> clock_t t=clock(); namespace my_std{ using namespace…
小于x的赋值为1,否则为0 区间等于k的个数 求0~n连续的n+1个k? N<=1e5? FFT! 考虑卷积建模:用下标相加实现转移到位,数值相乘类比乘法原理! 法一: 分治,然后FFT没了 法二: 不分治也可以!区间查询->前缀相减 ans[j-i]=f[j]*f[i],f[i]表示数值为i的前缀和个数 减法怎么办?reverse变成加法! i->n-i ans[j-i]=f[j]*f[i]=f[j]*f'[n-i] FFT一下,n+j-i位置的值就是ans辣 #include<…
题意: 给你一个数组a1~an,对于k=0~n,求出有多少个数组上的区间满足:区间内恰好有k个数比x小.x为一个给定的数.n<=10^5.值域没有意义. 分析: 大神们都说这道题是一个套路题,真是长见识%%%. 首先我们可以将题面转化,因为x是预先给出的,所以我们可以对其进行预处理,将数列中小于x的数都设为1,其他都为0,然后求一个前缀和,另前缀和数组为s[i]我们开一个数组v[i],记录在前缀和数组中数值i出现的次数. 然后我们可以得到这样一个式子 (据说看到这个式子就是套路了) 然后我们对这…
Description 题库链接 给你一个长度为 \(n\) 的序列 \(A\) ,和一个数 \(x\) ,对于每个 \(i= 0\sim n\) ,求有多少个非空子区间满足恰好有 \(i\) 个数 \(<x\) . \(1 \leq n \leq 2 \cdot 10^5\) Solution 我们用 \([A_i<x]\) 做一个前缀和,显然这是单调递增的.记前缀和为 \(i\) 的个数为 \(f_i\) . 显然对于 \(i=k,k\neq 0\) 答案就是 \[\sum_{i=0}^{…
//maximum and minimum     暴力遍历 O(n) //i-th element dicide and conquer random_selected_partition     k(all the element samller than value[k] put left of value[k],all tht elenment larger than value[k] put right) recurrence test if(i=k)return value[k] i…
http://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/ #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <string> #include <fstream…
题意: N个数,找出第二大的数.如果没有输出-1. 思路: UNIQUE的使用. 代码: int a[105]; int n; int main(){ cin>>n; rep(i,0,n-1) cin>>a[i]; sort(a,a+n); int t=unique(a,a+n)-a; //unique只是把重复的数放到了数组的后部分 if(t<2) puts("NO"); else print("%d\n",a[1]); return…
众所周知,tzc 在 2019 年(12 月 31 日)就第一次开始接触多项式相关算法,可到 2021 年(1 月 1 日)才开始写这篇 blog. 感觉自己开了个大坑( 多项式 多项式乘法 好吧这个应该是多项式各种运算中的基础了. 首先,在学习多项式乘法之前,你需要学会: 复数 我们定义虚数单位 \(i\) 为满足 \(x^2=-1\) 的 \(x\). 那么所有的复数都可以表示为 \(z=a+bi\) 的形式,其中 \(a,b\) 均为实数. 复数的加减直接对实部虚部相加减就行了. 复数的乘…
RT 2018.12.27 i207M:BZOJ 4695 最假女选手 以维护最大值为例,记录最大值和严格次大值和最大值的出现次数,然后取min的时候递归到小于最大值但大于次大值修改,这个就是最重要的地方,剩下的就是码码码调调调 #include<cstdio> #include<cctype> #include<cstring> #include<algorithm> using namespace std; ,M=,inf=1e9; int maxx[M…
菜鸡 wxw 的计划(肯定会咕咕咕 12.27 luogu P4244 [SHOI2008]仙人掌图 II(咕咕咕 luogu P4246 [SHOI2008]堵塞的交通 (没有咕! luogu P1848 [USACO12OPEN]书架Bookshelf(不咕! 12.28 一场 cf 虚拟比赛(div.2 rk 18) 一场 cf div.2,用的是小号(i_am_sooke)(rk 20) 题解在这里 sooke 看到我小号的用户名貌似不太开心 qaq 我好菜啊 qaq 12.29 luo…
Selection: selection is a trivial problem if the input numbers are sorted. If we use a sorting algorithm having O(nlgn) worst case running time, then the selection problem can be solved in O(nlgn) time. But using a sorting is more like using a cannon…
题目 Source http://poj.org/problem?id=2104 Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return q…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 51440   Accepted: 17594 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse…
Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quickly k-th order statistics in the array…
D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output In one well-known algorithm of finding the k-th order statistics we should divide all elements into groups of five consecu…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 51732   Accepted: 17722 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse…
SURF算子,参考这篇文章的解释http://www.ipol.im/pub/art/2015/69/ SURF 是   Speeded Up Robust Features 加速鲁棒特征的含义. The source code and the online demo are accessible at the IPOL web page of this article1. Theproposed implementation of the SURF algorithm is written i…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 34048   Accepted: 10810 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 47066   Accepted: 15743 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 35653   Accepted: 11382 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse…
Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quickly k-th order statistics in the array…
Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quickly k-th order statistics in the array…
传送门 D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output In one well-known algorithm of finding the k-th order statistics we should divide all elements into groups of five con…
http://poj.org/problem?id=2104 裸题不说.主席树水过. #include <cstdio> #include <iostream> #include <algorithm> using namespace std; #define dbg(x) cout << #x << "=" << x << endl #define read(x) x=getint() #define…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 50247   Accepted: 17101 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse…
K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 44537   Accepted: 14781 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse…
主席树 Description You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quickly k-th order statistics in the a…
题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of finding the k-th order statistics we should divide all elements into groups of five consecutive elements and find the median of each five. A median is cal…