难度:☆☆☆☆☆☆☆

题解: 有个定理,另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的更多相关文章

  1. Loj #6069. 「2017 山东一轮集训 Day4」塔

    Loj #6069. 「2017 山东一轮集训 Day4」塔 题目描述 现在有一条 $ [1, l] $ 的数轴,要在上面造 $ n $ 座塔,每座塔的坐标要两两不同,且为整点. 塔有编号,且每座塔都 ...

  2. Loj 6068. 「2017 山东一轮集训 Day4」棋盘

    Loj 6068. 「2017 山东一轮集训 Day4」棋盘 题目描述 给定一个 $ n \times n $ 的棋盘,棋盘上每个位置要么为空要么为障碍.定义棋盘上两个位置 $ (x, y),(u, ...

  3. 主席树 || 可持久化线段树 || BZOJ 3653: 谈笑风生 || Luogu P3899 [湖南集训]谈笑风生

    题面:P3899 [湖南集训]谈笑风生 题解: 我很喜欢这道题. 因为A是给定的,所以实质是求二元组的个数.我们以A(即给定的P)作为基点寻找答案,那么情况分两类.一种是B为A的父亲,另一种是A为B的 ...

  4. loj6068. 「2017 山东一轮集训 Day4」棋盘 二分图,网络流

    loj6068. 「2017 山东一轮集训 Day4」棋盘 链接 https://loj.ac/problem/6068 思路 上来没头绪,后来套算法,套了个网络流 经典二分图 左边横,右边列 先重新 ...

  5. P3900 [湖南集训]图样图森破

    P3900 [湖南集训]图样图森破 链接 分析: 感觉像个暴力. 可以枚举回文串的回文中心,即枚举一个串,枚举一个串的位置作为回文中心,然后求出这个串内的回文串的长度. 此时如果回文串两端都没有到这个 ...

  6. 集训Day4

    在bzoj刷了好几天杂题感觉手感不是很好 继续回来集训一下 好几天没更新了啊... bzoj1875 一个无向图,一个人要从起始点走$t$步走到终点,不能沿着刚走过来那条边回去,问有多少种走法 $m ...

  7. 佳木斯集训Day4

    Day4的出题人好毒瘤啊!!! T1我打表过的,正解现在也不会 #include <bits/stdc++.h> #define MAXN 10050 #define ll long lo ...

  8. 2022寒假集训day4

    day4(day5补完的) 继续刷搜索方面的题, 初步了解了序列. T1 迷宫问题 题目描述设有一个 n*n 方格的迷宫,入口和出口分别在左上角和右上角.迷宫格子中分别放 0 和 1 ,0 表示可通, ...

  9. FJ省队集训DAY4 T3

    #include<cstdio> #include<iostream> #include<cmath> #include<cstring> #inclu ...

随机推荐

  1. UVA - 11175 From D to E and Back(思路)

    题目: 思路: 如图E:图中a.b.c.d是有向图D中的顶点,如果ac.bc都指向cd,而ac又指向ce,那bc同样应该有一条指向ce的边不然就不能从图D转换来.所以直接枚举顶点就可以了. 代码: # ...

  2. UVA - 1618 Weak Key(RMQ算法)

    题目: 给出k个互不相同的证书组成的序列Ni,判断是否存在4个证书Np.Nq.Nr.Ns(1≤p<q<r<s≤k)使得Nq>Ns>Np>Nr或者Nq<Ns&l ...

  3. 39页第7题 计算2的i次方之和

    /*计算2的i次方之和*/ #include<stdio.h> #include<math.h>/*调用math.h文件中的函数*/ int main(void) { int ...

  4. Rsync远程同步工具使用

    rsync远程同步工具使用 Rsync(remote synchronize) 是一个远程数据同步工具,可以使用"Rsync算法"同步本地和远程主机之间的文件.Rsync的好处是只 ...

  5. 爬虫----Web_WeChat

    流程: 打开的web_wechat,就有出现二维码,在network中,name中login?loginicon中,status的状态是pending,pending的意思是前端发送了一个请求,但是还 ...

  6. 在vue项目中快速使用element UI

    推荐使用npm安装 1.安装:npm install element-ui -S 2.整体引入: 在你项目的main.js中写入: import ElementUI from 'element-ui' ...

  7. The Falling Leaves(建树方法)

    uva 699 紫书P159 Each year, fall in the North Central region is accompanied by the brilliant colors of ...

  8. c# 缓存!

    做项目的时候获取所有城市的时候,发现每次去获取都花费了很多时间,所以用缓存方法让效率更高! 这是我做的例子,如下: public class CacheGetCity { /// <summar ...

  9. 【Codeforces 1091D】New Year and the Permutation Concatenation

    [链接] 我是链接,点我呀:) [题意] 把1~n的n!种排列依次连接成一个长度为nn!的序列. 让你在这个序列当中找长度为n的连续段,使得连续段中的数字的和为n(n-1)/2 输出符合要求的连续段的 ...

  10. CodeForcesGym 100753F Divisions

    Divisions Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForcesGym. Or ...