D. Petya and Array 题目链接:https://codeforces.com/contest/1042/problem/D 题意: 给出n个数,问一共有多少个区间,满足区间和小于t. 题解: 假设目前区间右端点为r,左端点为l,那么由前缀和可得知:sumr-suml-1<t,然后我们再边个形:sumr<t+suml-1,根据这个我们可以发现这有点类似于逆序对. 然后我们就可以用求解逆序对问题的解法来解这个问题了,这里不同的就是每次前面的加上t大于当前这个数即为一对逆序对. 我用…
http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs(a[i])<=1e9) 思路 将公式转化以下,sum[r]-sum[l-1]<t 变成 sum[r]<sum[l-1]+t 可以考虑遍历每个r,先更新sum[r-1]+t,统计有多少满足条件的sum[l-1],反向树状数组维护即可 实现细节 对于每个r是更新他的sum[r-1] 因为要统计…
E. Garlands 题目连接: http://www.codeforces.com/contest/707/problem/E Description Like all children, Alesha loves New Year celebration. During the celebration he and his whole family dress up the fir-tree. Like all children, Alesha likes to play with gar…
题意:n个线段[Li, Ri], m次询问, 每次询问由cnt个点组成,输出包含cnt个点中任意一个点的线段的总数. 由于是无修改的,所以我们首先应该往离线上想, 不过我是没想出来. 首先反着做,先求不包含这个cnt个点的线段的总数, 那么不包含这些点的线段必然在cnt个点之间(这里需要再加两个点一个是0, 一个是MAX), 我们可以把所有线段按Ri 分类, 然后按右端点遍历,对于当前的线段可以在Li 处+1, 然后对于每一次询问中两个点(x, y)之间线段的个数, 只需要查询 左端点大于等于x…
F. A Heap of Heaps time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output Andrew skipped lessons on the subject 'Algorithms and Data Structures' for the entire term. When he came to the final tes…
题意: 给出一个数组,元素有正有负有0,问其区间和小于 t 的子区间的个数. sum[ r ]-sum[ l-1 ]<t,其中sum是a的前缀和. 实现的方法就是从前往后对于每一个sum[ i ],看在它前面有多少个大于等于sum[ i ] - t 的前缀和. 树状数组维护的是 i 前面有几个数小于等于它 #include <cstdio> #include <cstring> #include <queue> #include <cmath> #in…
Codeforces Round #510 (Div. 2) https://codeforces.com/contest/1042 A 二分 #include<iostream> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define sqr(x) ((x)*(x)) #define pb push_back #define eb emplace_back #…
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组 [Problem Description] ​ 给你一个长度为\(n\)的数组,第\(i\)个元素\(s_i\)表示一个排列中第\(i\)个元素之前,并且小于\(p_i\)的元素的和.求出满足此条件的排列. [Solution] ​ 假设\(n=5\),\(s[]=\{0,0,3,7,3\}\).从后往前看…
D. Factory Repairs 题目连接: http://www.codeforces.com/contest/635/problem/D Description A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce…
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text. Your editor consists of a line with infinite length and cursor, which point…
题意:给出一个数组,求其中和小于t的区间数. 先计算前缀和数组sum[i].对当前的sum[i],查询树状数组中有几个比(sum[i]-t)大的数,那么用sum[i]减它就是一个合法区间.再将当前的sum[i]加入树状数组. //#pragma comment(linker,"/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<string> #inc…
题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It's hard times now. Today Petya needs to score 100 points on Informatics…
地址:http://codeforces.com/contest/832/problem/B 题目: B. Petya and Exam time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output It's hard times now. Today Petya needs to score 100 points on Informati…
http://codeforces.com/contest/978/problem/G 感冒是真的受不了...敲代码都没力气... 题目大意: 期末复习周,一共持续n天,有m场考试 每场考试有如下信息: ①si表示知道第i门课的考试时间是在第si天的时候 ②di表示第i门课的考试时间 ③ci表示准备第i门课需要ci天的复习 在考试的那一天不能复习. 问n天中每一天都需要干啥? 三种情况,休息(输出0),复习(输出复习那一门科目的id),考试(输出m+1) 思路:按照di排序(即按照截止时间),然…
B. Vitamins 题目链接:https://codeforces.com/contest/1042/problem/B 题意: 给出几种药,没种可能包含一种或多种(最多三种)维生素,现在问要吃到这三种维生素买药最少花费是多少. 题解: 嗯...可以直接暴力: #include <bits/stdc++.h> using namespace std; typedef long long ll; ; int n; int c[N]; ]; ]; int main(){ scanf("…
A. Petya and Origami 题目链接:https://codeforc.es/contest/1080/problem/A 题意: 给出n,k,k表示每个礼品里面sheet的数量(礼品种类可以不同),现在给n位朋友送礼,每位朋友需要2个xx,5个xx,8个xx,问最少需要买多少礼品. 题解: 水过~ 代码如下: #include <cstring> #include <cstdio> #include <algorithm> #include <io…
第一次CF祭== 由于太菜了只做了前两题== 因为在第一题上耗费时间太多了,我还是太菜了==. A. Benches time limit per test 1 second memory limit per test 256 megabytes There are nn benches in the Berland Central park. It is known that aiai people are currently sitting on the ii-th bench. Anoth…
传送门:Problem C https://www.cnblogs.com/violet-acmer/p/9682082.html 题意: 给你n个数,定义有两种操作 ① 1 i j : (i != j) 将a[i]从数列中移除,且a[j] <- a[i]*a[j] ② 2 i : 将a[i]从数列中移除,此操作最多使用一次 注意:将数移除后剩余数的编号并未改变,依旧为初始时的输入顺序 在经过n-1次操作后使剩余的数最大 题解: 使用操作②的情况: (1) : 数列中含有0 (2) : 负数个数…
传送门:Problem B https://www.cnblogs.com/violet-acmer/p/9682082.html 题意: 如果可以通过喝果汁将维生素A,B,C全部摄取,求最小花费,如果不能,输出"-1". 题解: 我的思路:每个果汁含有的维生素最多有7种可能,分别为 A B C AB(BA) AC(CA) BC(CB) ABC(ACB)(BAC)(BCA)(CAB)(CBA) 将其分别对应为数字1-7 设变量price[i] price[1] : 只含维生素A的饮料的…
传送门:Problem A https://www.cnblogs.com/violet-acmer/p/9682082.html 题意: 公园里有n个沙滩,a[i]表示第i个沙滩初始人数,现有m个人可以到任意沙滩,在这m个人全部到达任意沙滩后,求沙滩最多人数的最大值和最小值 例如: 假设有n=5,m=3 a[i] = :1 2 3 4 5 沙滩人数最大化便是这m个人全到第5个沙滩上,a[5]=8,当前所有沙滩的最大值为8 使沙滩人数最大值尽量最小化,第一个人可以来到第一个沙滩,第二个人来到第二…
题意:给出一个数组,2种操作:.1:x*y然后x消失,2:除掉x(2操作最多只能进行一次).问最大的结果的一种操作方式.逻辑题,看能不能想全面. 1先数好0,正,负的数量,zero,pos,neg.如果0数量不为0,在所有0的内部用操作1减少到只剩1个0,zero置1:(删去0不影响结果,如果结果是0,那么剩1个0也能做到,如果结果不是0,那么删0是必须的) 2负数有奇数个时(这种情况下一定有非负解)(1)如果zero=0,用操作2删掉最大的负数(不删结果负,删了必为正)(2)zero=1,用0…
这场打的顺手到不敢相信.如果不是vp的话估计肯定打不到这个成绩. A:最大显然,最小的话每次暴力给最小的+1. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; int read() { ,f=;char c=getchar();…
题目 题意: 给你n个数,有两种操作,操作1是把第i个位置的数删去, 操作2 是把 a[ j ]= a[ i ]* a[ j ],把a[ i ]删去 .n-1个操作以后,只剩1个数,要使这个数最大 .要你输出这n-1个步骤. 思路: 结构体储存数和位置, 按值排序,然后分类讨论. 1. 负数个数是奇数,无0  .删除最大的一个负数,别的数正常搞定. 2. 负数个数是奇数,有0  .把最大的一个负数给堆积到最后一个0上,删除最后一个0 . 3. 负数个数是偶数,无0  . 不用删,正常处理. 4.…
题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你每天都在干什么,如果这一天你有考试,输出\(m+1\),如果你要准备第\(i\)场考试,输出\(i\),否则休息,输出\(0\). 题解:数据范围小,直接模拟,但我们需要先贪心,即每次都要先准备最早的考试,然后直接写两个\(for\)循环就行了. 代码: #include <iostream> #…
D. Happy Tree Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/D Description Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was w…
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/427/B Description The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c…
A. Greg and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/295/problem/A Description Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To apply operation …
B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/problem/B Description Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he…
D. Super M Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/D Description Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that…
题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把下降段的起始位置和结束位置记录下来然后进行推断,在进行推断时,有几种特殊情况:(s表示起始位置,e表示结束位置) 1.当e==n&&s!=1时,满足a[n]>a[s-1]输出yes: 2当s==1&&==n时,满足a[1]<a[e+1] 输出yes: 3当s==1&…