Description 有一个长度为n的序列a1,a2,...,an.其中ai要么是1("W"),要么是2("T"). 现在有m个询问,每个询问是询问有没有一个连续的子序列,满足其和为q. Input 第一行n,m (1<=n,m<=1000000) 第二行这个序列,起始编号为1,终止编号为n 下面每行一个询问q,询问有没有一个连续的子序列,满足其和为q (1<=q<=2000000) Output 对于每个询问,输出一行,如果有,输出这个序…
题目链接 BZOJ2217 题解 如果只判定存不存在方案的话,我倒是想到可以将\(2\)拆成两个\(1\),其中一个不能作为区间开头,线段树优化计算补集方案数 但是一看这道题要输出方案啊,,, 怎么办? 考虑如果凑不出\(x\),那一定可以凑出\(x + 1\) 我们就找到前缀和为\(x\)的位置,如果没有,就找\(x + 1\) 前缀和为\(x\)当然就得到答案啦 前缀和为\(x + 1\),我们考虑将区间整体右移,如果左端点出去和右端点进来的数相同,区间值不变,如果不同,那我们就可以通过调整…
若能得到一个和为t的区间,那么至少去掉两端点中任意一个后必定能得到和为t-2的区间. 所以只需要分别找到和最大的和为奇数和偶数的区间,然后$O(n)$完成构造即可. #include<cstdio> #define N 1000010 int n,m,i,s[N],b,c,d,t,l,r,f[N<<1][2];char a[N]; inline void read(int&a){char c;while(!(((c=getchar())>='0')&&…
[BZOJ2217][Poi2011]Lollipop Description 有一个长度为n的序列a1,a2,...,an.其中ai要么是1("W"),要么是2("T").现在有m个询问,每个询问是询问有没有一个连续的子序列,满足其和为q. Input 第一行n,m (1<=n,m<=1000000)第二行这个序列,起始编号为1,终止编号为n下面每行一个询问q,询问有没有一个连续的子序列,满足其和为q (1<=q<=2000000) Out…
2217: [Poi2011]Lollipop Time Limit: 15 Sec  Memory Limit: 64 MBSec  Special JudgeSubmit: 383  Solved: 159[Submit][Status][Discuss] Description 有一个长度为n的序列a1,a2,...,an.其中ai要么是1("W"),要么是2("T"). 现在有m个询问,每个询问是询问有没有一个连续的子序列,满足其和为q. Input 第一行…
Description 有一个长度为n的序列a1,a2,...,an.其中ai要么是1("W"),要么是2("T").现在有m个询问,每个询问是询问有没有一个连续的子序列,满足其和为q. Input 第一行n,m (1<=n,m<=1000000)第二行这个序列,起始编号为1,终止编号为n下面每行一个询问q,询问有没有一个连续的子序列,满足其和为q (1<=q<=2000000) Output 对于每个询问,输出一行,如果有,输出这个序列的起…
ACM思维题训练集合 A new Berland businessman Vitaly is going to open a household appliances' store. All he's got to do now is to hire the staff. The store will work seven days a week, but not around the clock. Every day at least k people must work in the sto…
Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are true silver dollars; one coin is counterfeit even though its color and size make it indistinguishable from the real silver dollars. The counterfeit coin has a diff…
C. Okabe and Boxes 这个题目是一个有点思维的模拟,当时没有想到, 思维就是这个栈的排序这里,因为每次直接排序肯定会t的,所以不可以这么写,那怎么表示排序呢? 就是直接把栈清空,如果栈顶就是我们需要的这个值,那就把这个值直接pop, 但是如果不是呢,就可以直接清空这个栈表示排序,如果栈已经是空的了,说明之前排过序了. 如果不是那就清空(排序),这个有点难想. #include <cstdio> #include <cstring> #include <cstd…
传送门 https://codeforces.com/contest/1496/problem/B 题目 Example input 5 4 1 0 1 3 4 3 1 0 1 4 3 0 0 1 4 3 2 0 1 2 3 2 1 2 3 output 4 4 3 5 3 Note In the first test case, S={0,1,3,4}S={0,1,3,4}, a=mex(S)=2a=mex⁡(S)=2, b=max(S)=4b=max(S)=4, ⌈a+b2⌉=3⌈a+b2⌉…