A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6) 那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10) 思路:我们想一下如果题目说的是最长我们肯定是取最小x和最大的y连起来就完事. 但是要求长度最小又得覆盖,那么可以这样想,我们需要把最小的x不断右移到这条线段的y, 最大的左移到x,所以就是最大x-最小y完事 #include <bits/stdc++.h> using namespace std; #define ll long…
F2. Wrong Answer on test 233 (Hard Version) Your program fails again. This time it gets "Wrong answer on test 233" . This is the harder version of the problem. In this version, 1≤n≤2⋅105. You can hack this problem if you locked it. But you can h…
E. Arson In Berland Forest The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events. A destructive fire raged through the Forest, and several trees were damaged by it. Pr…
D2. Optimal Subsequences (Hard Version) This is the harder version of the problem. In this version, 1≤n,m≤2⋅105. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a seque…
C. Messy You are fed up with your messy room, so you decided to clean it up. Your room is a bracket sequence s=s1s2-sn of length n. Each character of this string is either an opening bracket '(' or a closing bracket ')'. In one operation you can choo…
B. Box Permutation p is a sequence of integers p=[p1,p2,-,pn], consisting of n distinct (unique) positive integers between 1 and n, inclusive. For example, the following sequences are permutations: [3,4,1,2], [1], [1,2]. The following sequences are n…
A. Math Problem Your math teacher gave you the following problem: There are n segments on the x-axis, [l1;r1],[l2;r2],-,[ln;rn]. The segment [l;r] includes the bounds, i.e. it is a set of such x that l≤x≤r. The length of the segment [l;r] is equal to…
//因为可以反转n次 所以可以得到任何可以构成的序列 #include<iostream> #include<string> #include<vector> using namespace std ; typedef pair<int,int>PII; int n,k; string s; string get_str(int n,int k) {//先构建前k-1个 string res=""; ; i<k-; i++) { r…
#include<bits/stdc++.h> using namespace std; ]; ]; int main() { int total; cin>>total; while(total--) { int n; bool flag=true; cin>>n; unordered_set<int>tree; set<int>num; ; i<=n; i++) num.insert(i);//插入每个数字 从小到大 ; i<=n…
//只要从所有区间右端点的最小值覆盖到所有区间左端点的最大值即可 #include<iostream> using namespace std ; int x,y; int n; int t; int main() { cin>>t; while(t--) { cin>>n; ) { cin>>x>>y; cout<<<<endl; } else { ,r=1e9+; ; i<=n; i++) { cin>&g…
题意:一共有$n$个数,$m$次询问,每次询问包括$k.pos$两个数,需要你从这$n$个数里面找出$k$个数,使得他们的总和最大,如果有多种情况,找出序号字典序最小的一组,然后输出这个序列中第$pos$个数的值. 思路:根据贪心的思想,把这$n$个数按大到小排个序$($相同大小按下标从小到大$)$,再按照每个元素的下标依次放入主席树中,对于每次询问,查找前$k$个数中第$pos$大的数,但这个查找到的值是下标,再把这个下标对应到数值即可,体现在代码中的$b[]$数组中. #include <i…
E. Arson In Berland Forest The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events. A destructive fire raged through the Forest, and several trees were damaged by it. Pr…
A - Forgetting Things 题意:给 \(a,b\) 两个数字的开头数字(1~9),求使得等式 \(a=b-1\) 成立的一组 \(a,b\) ,无解输出-1. 题解:很显然只有 \(a=b\) 和 \(a=b-1\) 的时候有解,再加上一个从 \(9\) 越到 \(10\) 的就可以了.被样例的 \(199,200\) 误导了. #include<bits/stdc++.h> using namespace std; typedef long long ll; int mai…
比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B:数学+排序 C:字符串搜索 A // https://codeforces.com/contest/1277/problem/A /* 题意: 给出一个数,求不大于该数的完美整数的个数(完美整数指全是一个数组成的数字,如:111, 333333, 444444, 9, 8888 ...) 分析:…
链接: https://codeforces.com/contest/1247/problem/D 题意: You are given n positive integers a1,-,an, and an integer k≥2. Count the number of pairs i,j such that 1≤i<j≤n, and there exists an integer x such that ai⋅aj=xk. 思路: 对每个数质数拆分,记录质数的指数modk的值,map记录ve…
链接: https://codeforces.com/contest/1247/problem/C 题意: Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). T…
链接: https://codeforces.com/contest/1247/problem/B2 题意: The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequen…
链接: https://codeforces.com/contest/1247/problem/A 题意: Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation a+1=b with positive integers a and b, but Kolya forgot the numbers a and b. He does, howev…
https://codeforces.com/contest/1241/problem/C You are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something! You have n tickets to sell. The price of the i-th ticket is pi.…
链接: https://codeforces.com/contest/1241/problem/D 题意: You are given a sequence a1,a2,-,an, consisting of integers. You can apply the following operation to this sequence: choose some integer x and move all elements equal to x either to the beginning,…
链接: https://codeforces.com/contest/1241/problem/B 题意: You are given two strings of equal length s and t consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings. During each operation you choose t…
链接: https://codeforces.com/contest/1241/problem/C 题意: You are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something! You have n tickets to sell. The price of the i-th ticket…
链接: https://codeforces.com/contest/1241/problem/A 题意: Let's denote correct match equation (we will denote it as CME) an equation \($a + b = c$\) there all integers \($a$\), \($b$\) and \($c$\) are greater than zero. For example, equations \($2 + 2 =…
概述 切了 ABCE,Room83 第一 还行吧 A - Happy Birthday, Polycarp! 题解 显然这样的数不会很多. 于是可以通过构造法,直接求出 \([1,10^9]\) 内所有符合要求的数. \(\mathrm{Code}\) #include<bits/stdc++.h> using namespace std; int a[]={1,2,3,4,5,6,7,8,9,11,22,33,44,55,66,77,88,99,111,222,333,444,555,666…
链接 签到题,求出位数,然后9*(位数-1)+ 从位数相同的全一开始加看能加几次的个数 #include<bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int t; int y; cin>>t; int ans = 0; while(t--) { cin>>y; ans = 0; int weishu = 0; int temp = y; while(temp&g…
F. Tree Factory Bytelandian Tree Factory produces trees for all kinds of industrial applications. You have been tasked with optimizing the production of a certain type of tree for an especially large and important order. The tree in question is a roo…
E. Rock Is Push You are at the top left cell (1,1) of an n×m labyrinth. Your goal is to get to the bottom right cell (n,m). You can only move right or down, one cell per step. Moving right from a cell (x,y) takes you to the cell (x,y+1), while moving…
B2. TV Subscriptions (Hard Version) The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the k TV shows. You know the schedule for the next n days: a sequence of integers a1,a…
A. Forgetting Things Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation…
D. Power Products You are given n positive integers a1,-,an, and an integer k≥2. Count the number of pairs i,j such that 1≤i<j≤n, and there exists an integer x such that ai⋅aj=xk. Input The first line contains two integers n and k (2≤n≤105, 2≤k≤100).…