湖南集训day4

难度:☆☆☆☆☆☆☆


题解: 有个定理,另sum(x)表示小于等于x的数中与x互质的数的和
sum(x)=φ(x)*x/2 最后可知f(x)=x (f(1)=2) 当然打表能知道。
然后就转化为了求Σi^k
然后就是拉格朗日插值法了,不在我理解范畴........
但这个博客介绍挺好哒 http://www.cnblogs.com/ECJTUACM-873284962/p/6833391.html
std:
#include <cstring>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm> using namespace std; const int Mod=998244353;
const int MAXK=1000000; int power(int x,int k)
{
int ret=1;
while (k)
{
if (k&1) ret=1LL*ret*x%Mod;
x=1LL*x*x%Mod;
k>>=1;
}
return ret;
} int k; int f[MAXK+10]; int pre[MAXK+10],suf[MAXK+10]; int jc[MAXK+10],K[MAXK+10]; int cnt(int n)
{
if (n==0) return 0;
int ans=0;
if (n<=k+10 || n<=MAXK)
{
for (int i=1; i<=n; i++) ans=(K[i]+ans)%Mod;
}
else
{
pre[0]=1;
for (int i=1; i<=k+2; i++) pre[i]=1LL*pre[i-1]*(n-i)%Mod; suf[k+3]=1;
for (int i=k+2; i>=1; i--) suf[i]=1LL*suf[i+1]*(n-i)%Mod; int l=k+1,r=0,flag=((k+1)&1)?(-1):(1);
for (int i=1; i<=k+2; i++)
{
int s=1LL*pre[i-1]*suf[i+1]%Mod,m=1LL*(flag*jc[l]+Mod)*jc[r]%Mod;
ans=(1LL*f[i]*s%Mod*power(m,Mod-2)%Mod+ans)%Mod;
l--;
r++;
flag*=-1;
}
}
ans=((ans+K[2])%Mod-1+Mod)%Mod;
return ans;
} int L,R; void init()
{
cin>>L>>R>>k;
for (int i=1; i<=MAXK+5; i++) K[i]=power(i,k); jc[0]=1;
for (int i=1; i<=k+2; i++) jc[i]=1LL*jc[i-1]*i%Mod;
for (int i=1; i<=k+2; i++) f[i]=(f[i-1]+K[i])%Mod; cout<<(cnt(R)-cnt(L-1)+Mod)%Mod;
return ;
} int main()
{
freopen("count.in","r",stdin);
freopen("count.out","w",stdout);
init();
fclose(stdin);
fclose(stdout);
//fprintf(stderr,"%.3lf\n",1.0*clock()/(1.0*CLOCKS_PER_SEC));
return 0;
}


/*
题意转化为求最大的区间长度使得这段区间和减k>=0
首先做前缀和,可知若当前到了k,i<j<k && sum[i]<sum[j]则j一定不可能比i更优
用单调栈维护这个过程。然后倒序更新答案即可。
*/ #include<iostream>
#include<cstdio>
#include<cstring> #define N 1000007 using namespace std;
long long sum[N];
int a[N],st[N],top,n,m,cnt; inline int read()
{
int x=,f=;char c=getchar();
while(c>''||c<''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} void solve(int k)
{
top=;int res=;
for(int i=;i<=n;i++)
{
sum[i]=sum[i-]+a[i]-k;
if(!top || sum[st[top]]>sum[i]) st[++top]=i;
}
for(int i=n;i>=;i--)
{
while(top && sum[i]>=sum[st[top]]) top--;
res=max(res,i-st[top+]);
}
printf("%d ",res);
} int main()
{
freopen("blocks.in","r",stdin);
freopen("blocks.out","w",stdout);
n=read();m=read();
for(int i=;i<=n;i++) a[i]=read();
while(m--) solve(read());
return ;
}



/*
将字符串倒序插入trie树,问题就转换成了若干字符串结束的LCA深度
倍增维护LCA,每插入一个字符串,处理一次fa数组就可以了
当然这题也可以哈希+二分
*/
#include<iostream>
#include<cstdio>
#include<cstring> #define N 100007
#define M 1000007 using namespace std;
int Log[N],pos[N];
int n,m,len,cnt,sum;
char last[N],str[N];
struct Trie
{
int s[],f[];
int dep;
}tr[M]; inline int read()
{
int x=,f=;char c=getchar();
while(c>''||c<''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} void insert(int x)
{
last[x]=str[len-];
int now=;
for(int i=len-;i>=;i--)
{
int id=str[i]-'a';
if(!tr[now].s[id])
{
tr[now].s[id]=++cnt;
tr[cnt].f[]=now;
tr[cnt].dep=tr[now].dep+;
for(int i=;i<=;i++)
{
tr[cnt].f[i]=tr[tr[cnt].f[i-]].f[i-];
if (tr[cnt].f[i]==) break;//再往后跳也不可能有f值.
}
}now=tr[now].s[id];
}pos[x]=now;
} inline void init()
{
for(int i=,now=-,next=;i<=N;i++)
{
if(i==next) now++,next<<=;
Log[i]=now;
}
} int up(int x,int step)
{
while (step)
{
int up=Log[step];
x=tr[x].f[up];
step-=(<<up);
}
return x;
} int LCA(int x,int y)
{
if(tr[x].dep>tr[y].dep) x=up(x,tr[x].dep-tr[y].dep);
else y=up(y,tr[y].dep-tr[x].dep);
if(x== || y==) puts("myjdsb"); int k=Log[tr[x].dep];
while(x!=y)
{
while(k>= && tr[x].f[k]==tr[y].f[k]) k--;
if(k==-) return tr[x].f[];
x=tr[x].f[k];y=tr[y].f[k];
}return x;
} int main()
{
freopen("biology.in","r",stdin);
freopen("biology.out","w",stdout);
init();
n=read();m=read();cnt=;sum=;
for(int i=;i<=n;i++)
{
scanf("%s",str);
len=strlen(str);
sum+=len;insert(i);
}
while(m--)
{
int ty=read();
if(ty==)
{
scanf("%s",str);
len=strlen(str);
insert(++n);
}
else
{
int T=read(),ans=;
while(T--)
{
int x=read();
if(!ans) ans=pos[x];
else ans=LCA(ans,pos[x]);
}
printf("%d\n",tr[ans].dep);
}
}
return ;
}
湖南集训day4的更多相关文章
- Loj #6069. 「2017 山东一轮集训 Day4」塔
Loj #6069. 「2017 山东一轮集训 Day4」塔 题目描述 现在有一条 $ [1, l] $ 的数轴,要在上面造 $ n $ 座塔,每座塔的坐标要两两不同,且为整点. 塔有编号,且每座塔都 ...
- Loj 6068. 「2017 山东一轮集训 Day4」棋盘
Loj 6068. 「2017 山东一轮集训 Day4」棋盘 题目描述 给定一个 $ n \times n $ 的棋盘,棋盘上每个位置要么为空要么为障碍.定义棋盘上两个位置 $ (x, y),(u, ...
- 主席树 || 可持久化线段树 || BZOJ 3653: 谈笑风生 || Luogu P3899 [湖南集训]谈笑风生
题面:P3899 [湖南集训]谈笑风生 题解: 我很喜欢这道题. 因为A是给定的,所以实质是求二元组的个数.我们以A(即给定的P)作为基点寻找答案,那么情况分两类.一种是B为A的父亲,另一种是A为B的 ...
- loj6068. 「2017 山东一轮集训 Day4」棋盘 二分图,网络流
loj6068. 「2017 山东一轮集训 Day4」棋盘 链接 https://loj.ac/problem/6068 思路 上来没头绪,后来套算法,套了个网络流 经典二分图 左边横,右边列 先重新 ...
- P3900 [湖南集训]图样图森破
P3900 [湖南集训]图样图森破 链接 分析: 感觉像个暴力. 可以枚举回文串的回文中心,即枚举一个串,枚举一个串的位置作为回文中心,然后求出这个串内的回文串的长度. 此时如果回文串两端都没有到这个 ...
- 集训Day4
在bzoj刷了好几天杂题感觉手感不是很好 继续回来集训一下 好几天没更新了啊... bzoj1875 一个无向图,一个人要从起始点走$t$步走到终点,不能沿着刚走过来那条边回去,问有多少种走法 $m ...
- 佳木斯集训Day4
Day4的出题人好毒瘤啊!!! T1我打表过的,正解现在也不会 #include <bits/stdc++.h> #define MAXN 10050 #define ll long lo ...
- 2022寒假集训day4
day4(day5补完的) 继续刷搜索方面的题, 初步了解了序列. T1 迷宫问题 题目描述设有一个 n*n 方格的迷宫,入口和出口分别在左上角和右上角.迷宫格子中分别放 0 和 1 ,0 表示可通, ...
- FJ省队集训DAY4 T3
#include<cstdio> #include<iostream> #include<cmath> #include<cstring> #inclu ...
随机推荐
- ExtJs如何判断form表单是否被修改过详解
1.Extjs表单提交主要有三种方式: 1, EXT的form表单ajax提交(默认提交方式) 相对单独的ajax提交来说优点在于能省略写参数数组 ,form.getForm().submi ...
- ZOJ - 3987 - Numbers (大数 + 贪心)
参考自:https://blog.csdn.net/u013534123/article/details/78484494 题意: 给出两个数字n,m,把n分成m份,使得以下最小 思路: 或运算只有0 ...
- Shell脚本中非交互式修改密码的方法(转)
这篇文章主要介绍了Shell脚本中非交互式修改密码的两种方法,本文讲解了使用chpasswd和使用passwd和--stdin组合两种方法,需要的朋友可以参考下. 对系统定期修改密码是一个很重要的安全 ...
- 搭建Nginx服务
Nginx 是一个高性能的 http 和反向代理服务器,也是一个 IMAP/POP3/SMPT 服务器. Nginx 是由 logor Sysoev 为俄罗斯访问第二的 Ranbler.ru 站点开发 ...
- 第九节:web爬虫之urllib(五)
第四个模块 robotparser: 主要是用来识别网站的 robots.txt 文件,然后判断哪些网站可以爬,哪些网站不可以爬的,其实用的比较少.
- BZOJ 1666 USACO 2006 Oct. 奶牛的数字游戏
直接模拟2333 #include<cstdio> #include<algorithm> using namespace std; int n,ans; void read( ...
- Git——跟踪或取消跟踪文件
在Git是用过程中,可能遇到以下情况: 1.被跟踪文件里面有不想跟踪的文件. 2.每次用git status查看状态时总是列出未被跟踪的文件. 解决方法: 1.当被跟踪的文件里面有不想跟踪的文件时,使 ...
- 【Codeforces 1102E】Monotonic Renumeration
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 会发现如果a[i]=a[j] 那么b[i]~b[j]都是相同的,等于b[i] 而b[i]等于b[i-1]+1或者b[i] 有两种可能 所以对于 ...
- noip模拟赛 whzzt-Confidence
分析:做着感觉像脑筋急转弯一样......因为空间的限制,存不下每一个数,所以用数学方法来解. 设t1=Σai - Σbi = aj - bj,t2=Σi*ai - Σi*bi = j*(aj - b ...
- J - Invitation Cards 最短路
In the age of television, not many people attend theater performances. Antique Comedians of Malidine ...