Sample Input 5 4 1 2 3 4 5 -5 -1 -3 -1 Sample Output 3 思路,首先发现a[i]的值的范围是在1~n之间,每次插入我们可以直接把cnt[a[i]]++ 删除的时候,要把所有在后面的数往前挪一位,那么其实也相当于所有在后面的数的前面 的cnt的前缀和减去1,于是利用树状数组动态维护前缀和,利用前缀和来找到删除的元素 时间复杂度O(nlogn) #include<bits/stdc++.h> using namespace std; #defin…
比赛链接:https://codeforces.com/contest/1354 A - Alarm Clock 题意 一个人要睡够 $a$ 分钟,一开始睡 $b$ 分钟后闹钟响铃,之后每次设置 $c$ 分钟后响铃,设置好后需要 $d$ 分钟入睡. 题解 首先判断能不能一开始就睡足 $a$ 分钟,如果不能判断能不能入睡,如果可以用需要补睡的时间对每次可以睡着的时间取上整. 代码 #include <bits/stdc++.h> using ll = long long; using names…
任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has got a robot which is situated on an infinite Cartesian plane, i…
题目:http://codeforces.com/contest/1156/problem/E 题意:给你1-n  n个数,然后求有多少个区间[l,r] 满足    a[l]+a[r]=max([l,r]) 思路:首先我们去枚举区间肯定不现实,我们只能取把能用的区间去用,我们可以想下每个数当最大值的时候所做的贡献 我们既然要保证这个数为区间里的最大值,我们就要从两边扩展,找到左右边界能扩展在哪里,这里你直接去枚举肯定不行 这里我们使用了线段树二分去枚举左右区间最远能走到哪里,然后很暴力的去枚举短…
题目链接:https://codeforces.com/contest/1359/problem/C 题意 热水温度为 $h$,冷水温度为 $c\ (c < h)$,依次轮流取等杯的热冷水,问二者在一容器中混合至最接近温度 $t$ 最少需要取多少杯. 题解 设取了 $x$ 杯热水,那么总的温度有两种情况: 取的冷水杯数与热水相同:$\frac{xh + xc}{2x}$ 取的冷水杯数比热水少一杯:$\frac{xh + (x - 1)c}{2x - 1}$ 第一种情况: $\frac{xh +…
题目哦 题意:给出一个序列,序列有四个字母组成,U:y+1,D:y-1 , L:x-1 , R:x+1;   这是规则 . 给出(x,y) 问可不可以经过最小的变化这个序列可以由(0,0) 变到(x,y) 注意!!!!是可以变任意序列的!不是只有y变y , x变x ,比赛看错题意导致没A , 分析:这需要借助前置和与后缀和 , 这样的话我就可以知道[L , R] 这个区间需要变化什么 , 没错你可以理解为题目的范围n变为[L , R] , x变为x-xl[L+1]-xr[R+1] ,y同理: 这…
题意:$m$个士兵,每个士兵都有一个灵敏度$a[i]$,起点为$0$,终点为$n + 1$,在路上有$k$个陷阱,每个陷阱有三个属性$l[i],r[i],d[i]$,$l[i]$表示陷阱的位置,如果你走到$r[i]$这个位置,则可以拆掉这个陷阱,$d[i]$与士兵的灵敏度对应,如果$d[i]>a[j]$,则这个士兵就会被困住,现在你可以挑选任意数量的士兵,你有两种方式移动方式: 带着士兵移动,但士兵不能被陷阱困住,每秒只能移动一格,从$x$到$x+1$或者$x-1$ 一个人去拆除陷阱$($你不会…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100005];int pos[(1<<20)+5];//pos[i]表示i=1<<j时的jint cnt[35][35];//cnt[i][j]表示s[i]=i,s[i+1]=j的移动数量int g[25][(1<<20)+5];//g[i][S],i不属于S表示s[i]=i,s[i+1]∈S的移动数量…
Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec Problem Description Input Output The only line should contain the minimal number of days required for the ship to reach the point (x2,y2)(x2,y2). If it…
Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec Problem Description Input The input contains a single line consisting of 2 integers N and M (1≤N≤10^18, 2≤M≤100). Output Print one integer, the total n…