CF 843 A. Sorting by Subsequences】的更多相关文章

A. Sorting by Subsequences You are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order,…
题面: 传送门 思路: 这道题乍一看有点难 但是实际上研究一番以后会发现,对于每一个位置只会有一个数要去那里,还有一个数要离开 那么只要把每个数和他将要去的那个位置连起来,构成了一个每个点只有一个入边一个出边的一张图 那么在这张图里的一个环,就代表着一个满足条件的子序列 所以只要把图建出来以后,统计图中的每一个环就可以了 Code: #include<iostream> #include<cstdio> #include<cstring> #include<alg…
题面: 传送门 思路: 真·动态最短路 但是因为每次只加1 所以可以每一次修改操作的时候使用距离分层的bfs,在O(n)的时间内解决修改 这里要用到一个小技巧: 把每条边(u,v)的边权表示为dis[u]+w(u,v)-dis[v],这样边权实际上变成了“这条边离作为最短路的一份子还差了多少” 然后在用这个边权的新图里面更新1到每个点的最短路,再用原来的dis加上这个值,就是当前的最短路了 实际上是把绝对数值转化为了“离最优解的距离”,以此解题 Code: #include<iostream>…
题面: 传送门 思路: 这是一道交互题 比赛的时候我看到了直接跳过了...... 后来后面的题目卡住了就回来看这道题,发现其实比较水 实际上,从整个序列里面随机选1000个数出来询问,然后从里面找出比x小的最大的那个,再往后面搜1000个数(顺序),这样的方法,不成功率是1.7e-9...... 所以随机化就可以了~ (要是这样还WA那真的是脸黑呢......) Code: #include<iostream> #include<cstdio> #include<cstrin…
[链接]http://codeforces.com/contest/844/problem/C [题意] 水题,没有记录意义 [题解] 排序之后,记录每个数字原来在哪里就好. 可以形成环的. 环的个数就是子列个数. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define…
A. Diversity time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters,…
A. Diversity time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters,…
·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意:       输入一个长度为n的无重复元素的序列{a1,a2……an}(1<=n<=105,|ai|<109,将其分成p个不重复的子序列,使得只对每个子序列升序排序,能够在各个子序列排完序后,整个序列也是升序排列好的.求p的最大值,将其输出后并按任意顺序每一行输出每个子序列长度和每个元素排序好的下标. ·分析:       对子序列排序,最终竟然可以使得整个序列都排好序,那…
689D - Friends and Subsequences 题意: 大致跟之前题目一样,用ST表维护a[]区间max,b[]区间min,找出多少对(l,r)使得maxa(l,r) == minb(l,r) 切题的感觉很爽唉 同样而二分查找,找最小和最大下标满足条件 cf中%I64d, 一般是%lld 代码: #include<bits/stdc++.h> #define ll long long const int maxn=200010; int sta[maxn][18]; int s…
Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are dist…