由于缺的题目比较多,竟然高达3题,所以再写一篇补题的博客

Lpl and Energy-saving Lamps

During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Lpl in the Castle? Dragon smiled enigmatically and answered that it is a big secret. After a pause, Dragon added:

— We have a contract. A rental agreement. He always works all day long. He likes silence. Besides that, there are many more advantages of living here in the Castle. Say, it is easy to justify a missed call: a phone ring can't reach the other side of the Castle from where the phone has been left. So, the imprisonment is just a tale. Actually, he thinks about everything. He is smart. For instance, he started replacing incandescent lamps with energy-saving lamps in the whole Castle...

Lpl chose a model of energy-saving lamps and started the replacement as described below. He numbered all rooms in the Castle and counted how many lamps in each room he needs to replace.

At the beginning of each month, Lpl buys mm energy-saving lamps and replaces lamps in rooms according to his list. He starts from the first room in his list. If the lamps in this room are not replaced yet and Lpl has enough energy-saving lamps to replace all lamps, then he replaces all ones and takes the room out from the list. Otherwise, he'll just skip it and check the next room in his list. This process repeats until he has no energy-saving lamps or he has checked all rooms in his list. If he still has some energy-saving lamps after he has checked all rooms in his list, he'll save the rest of energy-saving lamps for the next month.

As soon as all the work is done, he ceases buying new lamps. They are very high quality and have a very long-life cycle.

Your task is for a given number of month and descriptions of rooms to compute in how many rooms the old lamps will be replaced with energy-saving ones and how many energy-saving lamps will remain by the end of each month.

Input

Each input will consist of a single test case.

The first line contains integers nn and m (1 \le n \le 100000, 1 \le m \le 100)m(1≤n≤100000,1≤m≤100)— the number of rooms in the Castle and the number of energy-saving lamps, which Lpl buys monthly.

The second line contains nn integers k_1, k_2, ..., k_nk1​,k2​,...,kn​
(1 \le k_j \le 10000, j = 1, 2, ..., n)(1≤kj​≤10000,j=1,2,...,n) — the number of lamps in the rooms of the Castle. The number in position jj is the number of lamps in jj-th room. Room numbers are given in accordance with Lpl's list.

The third line contains one integer q (1 \le q \le 100000)q(1≤q≤100000) — the number of queries.

The fourth line contains qq integers d_1, d_2, ..., d_qd1​,d2​,...,dq​
(1 \le d_p \le 100000, p = 1, 2, ..., q)(1≤dp​≤100000,p=1,2,...,q)— numbers of months, in which queries are formed.

Months are numbered starting with 11; at the beginning of the first month Lpl buys the first m energy-saving lamps.

Output

Print qq lines.

Line pp contains two integers — the number of rooms, in which all old lamps are replaced already, and the number of remaining energy-saving lamps by the end of d_pdp​ month.

Hint

Explanation for the sample:

In the first month, he bought 44 energy-saving lamps and he replaced the first room in his list and remove it. And then he had 11 energy-saving lamps and skipped all rooms next. So, the answer for the first month is 1,1------11,1−−−−−−1 room's lamps were replaced already, 11 energy-saving lamp remain.

样例输入复制

5 4
3 10 5 2 7
10
5 1 4 8 7 2 3 6 4 7

样例输出复制

4 0
1 1
3 6
5 1
5 1
2 0
3 2
4 4
3 6
5 1

题目来源

ACM-ICPC 2018 南京赛区网络预赛

从队友扒到的题意

城堡里有n个房间每个房间里有ki盏旧灯,Lpl每天购买m盏灯,他会按顺序,如果他的新灯>=房间的旧灯,他会拿新灯替换所有旧灯,直到不能替换,q个询问,每个询问输出两个数字分别为当前月有几个房间已经替换过了,还剩下几盏灯

要想到预处理这个题就解决一大半了,所以直接线段树啊,换完了就是变为inf就好

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pq priority_queue
const int N=1e5+,MD=1e9+,INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-,e=exp(),PI=acos(-.);
int a[N<<];
void build(int l,int r,int rt)
{
if(l==r)
{
scanf("%d",&a[rt]);
return;
}
int mid=(l+r)>>;
build(lson),build(rson);
a[rt]=min(a[rt<<],a[rt<<|]);
}
int query(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
return a[rt];
int mid=(l+r)>>,ans=1e9;
if(L<=mid)ans=min(ans,query(L,R,lson));
if(R>mid)ans=min(ans,query(L,R,rson));
return ans;
}
int f,La,Lb;
void update(int L,int R,int l,int r,int rt)
{
if(L>r||R<l)return;
if(L<=l&&r<=R&&a[rt]>La)return;
if(l==r)
{
++f,La-=a[rt],Lb=l,a[rt]=INF;
return;
}
int mid=(l+r)>>;
if(L<=mid)update(L,R,lson);
if(R>mid)update(L,R,rson);
a[rt]=min(a[rt<<],a[rt<<|]);
}
int n,m,q;
int ans1[N],ans2[N];
int main()
{
scanf("%d%d",&n,&m);
build(,n,);
for(int i=; i<=; i++)
{
if(f==n)
{
ans1[i]=f,ans2[i]=La;
continue;
}
La+=m,Lb=;
while(query(Lb,n,,n,)<=La)update(Lb,n,,n,);
ans1[i]=f,ans2[i]=La;
}
scanf("%d",&q);
for(int i=,x; i<q; i++)scanf("%d",&x),printf("%d %d\n",ans1[x],ans2[x]);
return ;
}
Skr
  • 256000K
 

A number is skr, if and only if it's unchanged after being reversed. For example, "12321", "11" and "1" are skr numbers, but "123", "221" are not. FYW has a string of numbers, each substring can present a number, he wants to know the sum of distinct skr number in the string. FYW are not good at math, so he asks you for help.

Input

The only line contains the string of numbers SS.

It is guaranteed that 1 \le S[i] \le 91≤S[i]≤9, the length of SS is less than 20000002000000.

Output

Print the answer modulo 10000000071000000007.

样例输入1复制

111111

样例输出1复制

123456

样例输入2复制

1121

样例输出2复制

135

题目来源

ACM-ICPC 2018 南京赛区网络预赛

比赛的时候特别想把这个题搞出来,奈何自己菜,回文树是第一次接触

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pq priority_queue
const int N=,MD=1e9+,INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-,e=exp(),PI=acos(-.);
char s[N];
ll fac[N],inv[N],slen;
ll ans=;
struct Palindrome_Automaton//回文自动机
{
int i,len[N],nxt[N][],fail[N],cnt[N],last,cur,S[N],p,n;
int newnode(int l)//新建节点
{
for(int i=; i<; i++)nxt[p][i]=; //新建的节点为p,先消除它的子节点
cnt[p]=;
len[p]=l;
return p++;//勿打成++p,因为此节点为p,我们应返回p
}
inline void init()//初始化
{
p=n=last=;
newnode();
newnode(-);
S[]=-;
fail[]=;
}
int get_fail(int x)
{
while(S[n-len[x]-]!=S[n])x=fail[x];
return x;
}
inline void add(int c,int pos)//插字符
{
c-='';
S[++n]=c;
int cur=get_fail(last);
if(!nxt[cur][c])
{
int now=newnode(len[cur]+);
fail[now]=nxt[get_fail(fail[cur])][c];
nxt[cur][c]=now;
ans=(ans+(fac[pos-len[now]+]-fac[pos+])*inv[slen-pos-]%MD+MD)%MD;
}
last=nxt[cur][c];
cnt[last]++;
}
void count()//统计本质相同的回文串的出现次数
{
//逆序累加,保证每个点都会比它的父亲节点先算完,于是父亲节点能加到所有子孙
for(int i=p-; i>=; i--)
cnt[fail[i]]+=cnt[i];
}
} run;
ll POW(ll x,ll y)
{
ll ans=;
for(; y; x=x*x%MD,y>>=)if(y&)ans=ans*x%MD;
return ans;
}
int main()
{
scanf("%s",&s);
slen=strlen(s);//千万要先把这个记录下来,因为求长度的时间复杂度是O(n)——直接扫一遍,碰到结束符才停止,我一开始把它直接塞进下方循环的nn里,就T了一遍
inv[]=,fac[slen]=;
ll t=POW(,MD-),now=;
for(int i=; i<=slen; i++)inv[i]=t*inv[i-]%MD;
for(int i=slen-; i>=; i--)fac[i]=(now*(s[i]-'')+fac[i+])%MD,now=now*%MD;
run.init(),ans=;
for(int i=; i<slen; i++)run.add(s[i],i);
cout<<ans<<"\n";
}

biu哥这个hash很强大啊%%%留做模板

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pq priority_queue
const int N=,MD=1e9+,INF=0x3f3f3f3f,Mod=;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-,e=exp(),PI=acos(-.);
ull P=;
ull sqr[N],Hash_[N];
char str[N];
ull sumHash[N];
struct StringHash
{
int first[Mod+],num;
ull EdgeNum[N];
int nxt[N],close[N];
void init ()
{
num=,memset(first,,sizeof first);
}
int insert (unsigned long long val,int id)
{
int u=val%Mod;
for(int i=first[u],t;i;i=nxt[i])
{
if(val==EdgeNum[i])
{
t=close[i],close[i]=id;
return t;
}
}
++num;
EdgeNum[num]=val,close[num]=id,nxt[num]=first[u],first[u]=num;
return ;
}
} H;
int r[N];
ll sum[N],ans=,xp[N];
void init()
{
xp[]=;
for(int i=;i<N;i++)xp[i]=(xp[i-]*)%MD;
return ;
}
void make_hash(char str[])//处理出str的hash值
{ int len=strlen(str+);
sum[len+]=;
for(int i=len;i>=;i--)
{
sum[i]=(sum[i+]*+str[i]-'')%MD;
}
return ;
}
ll Get_hash(int i,int L)
{
return (sum[i]%MD-sum[i+L]*xp[L]%MD+MD)%MD;//注意这里要对被减的先取模
}
void insert_(int i,int j)
{
ull now=Hash_[j]-Hash_[i-]*sqr[j-i+];
if(!H.insert(now,))//先判重,再插入
ans=(ans+Get_hash(i,j-i+))%MD;
}
void solve(int n)
{
sqr[]=;
for(int i=;i<=n;++i)sqr[i]=sqr[i-]*P,Hash_[i]=Hash_[i-]*P+str[i];
}
void manacher(int n)
{
int x=,pos=;
for(int i=;i<=n;i++)
{
int j=;
insert_(i,i);
if(pos>i) j=min(r[*x-i],pos-i);
while(i+j+<=n&&str[i+j+]==str[i-j-])
{
insert_(i-j-,i+j+);
j++;
}
r[i]=j;
if(i+j>pos)
{
pos=i+j;
x=i;
}
}
x=,pos=;
for(int i=;i<=n;i++)
{
int j=;
if(pos>i)j=min(r[*x-i],pos-i+);
while(i+j<=n&&str[i+j]==str[i-j-])
{
insert_(i-j-,i+j);
++j;
}
r[i]=j;
if(i+j->pos)
{
pos=i+j-;
x=i;
}
}
}
int main()
{
scanf("%s",str+);
int n=strlen(str+);
init();//hash每一位的贡献预处理
make_hash(str);//hash贡献值预处理
solve(n);//hash表预处理
manacher(n);//manacher
printf("%lld\n",ans);
return ;
}

模拟甩锅给队友

ICPC南京补题的更多相关文章

  1. 2018 ACM/ICPC 南京 I题 Magic Potion

    题解:最大流板题:增加两个源点,一个汇点.第一个源点到第二个源点连边,权为K,然后第一个源点再连其他点(英雄点)边权各为1,然后英雄和怪物之间按照所给连边(边权为1). 每个怪物连终点,边权为1: 参 ...

  2. hdu5017:补题系列之西安网络赛1011

    补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为m ...

  3. 2017河工大校赛补题CGH and 赛后小结

    网页设计课上实在无聊,便开始补题,发现比赛时候僵着的东西突然相通了不少 首先,"追妹"这题,两个队友讨论半天,分好多种情况最后放弃(可是我连题目都没看啊),今天看了之后试试是不是直 ...

  4. 网络流板子/费用流板子 2018南京I题+2016青岛G题

    2018南京I题: dinic,链式前向星,数组队列,当前弧优化,不memset全部数组,抛弃满流点,bfs只找一条增广路,每次多路增广 #include <bits/stdc++.h> ...

  5. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  6. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

  7. [数]补题ver.

    上次补题好像把两次训练混在一起了,总之先按时间顺序补完这一次|ू・ω・` ) HDU-6301 不会的东西不能逃避.jpg 红小豆非常讨厌构造题,因为非常不会,并且非常逃避学习这类题,因为总也搞不清楚 ...

  8. 4.30-5.1cf补题

    //yy:拒绝转载!!! 悄悄告诉你,做题累了,去打两把斗地主就能恢复了喔~~~ //yy:可是我不会斗地主吖("'▽'") ~~~那就听两遍小苹果嘛~~~ 五一假期除了花时间建模 ...

  9. 2018 CCPC 桂林站(upc复现赛)补题

    2018 CCPC 桂林站(upc复现赛)补题 G.Greatest Common Divisor(思维) 求相邻数的差值的gcd,对gcd分解素因子,对所有的素因子做一次遍历,找出最小答案. 几个样 ...

随机推荐

  1. 对fgets末尾'\0'的处理

    之所以要对fgets自动添加的字符进行处理的原因之一是:当你想比较输入的字符时,你会发现输入的字符和源码用来进行对比的字符一模一样,但是使用strcmp比较时就是不一样,原因就是fgets对输入字符添 ...

  2. Beginning Python Chapter 1 Notes

    James Payne(American)编写的<Beginning Python>中文译作<Python入门经典>,堪称是Python的经典著作. 当然安装Python是很简 ...

  3. CentOS7.3+MySQL5.7+Apache2.4+PHP7.1+phpMyAdmin4.7+JDK1.8+SVN1.6+Jenkins2.1环境搭建

    CentOS7.3+MySQL5.7+Apache2.4+PHP7.1+phpMyAdmin4.7+JDK1.8+SVN1.6+Jenkins2.1环境搭建 1.安装CentOS7.3虚拟机安装说明: ...

  4. LR中变量、参数的使用介绍

    Action(){ char * url = "www.baidu.com"; char arr_url[1024]; //将url变量的值复制给p_url1参数 lr_save_ ...

  5. HDU 5500 Reorder the Books (水题)

    题意: 有n本书,编号为1~n,现在书的顺序乱了,要求恢复成有序的样子,每次只能抽出其中一本并插到最前面,问最少需要多少抽几次? 思路: 如果pos[i]放的不是书i的话,则书i的右边所有的书都必须抽 ...

  6. 团队作业——项目Alpha版本发布

    ---恢复内容开始--- https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1   https://edu.cnblogs.com ...

  7. 超全面Java 面试题(2.1)

    这部分主要是开源JavaEE框架方面的内容,包括hibernate.MyBatis.spring.Spring MVC等,由于Struts2已经是明日黄花,在这里就不讨论Struts2的面试题,此外, ...

  8. javaweb基础(19)_jsp标签

    一.JSP标签介绍 JSP标签也称之为Jsp Action(JSP动作)元素,它用于在Jsp页面中提供业务逻辑功能,避免在JSP页面中直接编写java代码,造成jsp页面难以维护. 二.JSP常用标签 ...

  9. HTML5语义

    语义通俗化为意义,也就是语义化的元素等于意义化的元素,看到这个元素的名称,就知道这个元素的意义,是拿来做什么用的,这就是HTML5的一个新特性,一个具有语义化的元素能够清楚的把元素的意义告诉浏览器和开 ...

  10. mysql绿色版下载及应用

    一.mysql绿色版下载 第一歩:打开下载网址:https://www.oracle.com 点击Menu-->Database and Technologies-->Databases- ...