C - pushpush

如果是按下标说的话

如果是偶数个

那么是

\(N,N - 2,N - 4...1,3,5...N - 1\)

如果是奇数个

\(N,N - 2,N - 4...2,4,6...N - 1\)

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int a[MAXN];
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) read(a[i]);
if(N & 1) {
for(int i = N ; i >= 1 ; i -= 2) {out(a[i]);space;}
for(int i = i = 2 ; i <= N ; i += 2) {out(a[i]);space;}
enter;
}
else {
for(int i = N ; i >= 1 ; i -= 2) {out(a[i]);space;}
for(int i = 1 ; i <= N ; i += 2) {out(a[i]);space;}
enter;
} }
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

D - 11

就相当于只有两个位置相同,那么即为

\(...1 .... 1....\)

算所有位置不同的子序列

如果这个序列只包括其中一个1,剩下的数不在两个1之间,那么这个序列就被重复计算了,很简单的计数

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,a[MAXN],fac[MAXN],invfac[MAXN];
int pos[MAXN],p;
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
int t = x,res = 1;
while(c) {
if(c & 1) res = mul(res,t);
t = mul(t,t);
c >>= 1;
}
return res;
}
int C(int n,int m) {
if(n < m) return 0;
return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
void Solve() {
read(N);
for(int i = 1 ; i <= N + 1; ++i) read(a[i]);
for(int i = 1 ; i <= N + 1; ++i) {
if(pos[a[i]]) p = i;
else pos[a[i]] = i;
}
fac[0] = 1;
for(int i = 1 ; i <= N + 1 ; ++i) {
fac[i] = mul(fac[i - 1],i);
}
invfac[N + 1] = fpow(fac[N + 1],MOD - 2);
for(int i = N ; i >= 0 ; --i) {
invfac[i] = mul(invfac[i + 1],i + 1);
}
for(int i = 1 ; i <= N + 1 ; ++i) {
int res = C(N + 1,i);
res = inc(res,MOD - C(pos[a[p]] - 1 + N + 1 - p,i - 1));
out(res);enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

E - guruguru

显然如果不按第二个按钮,只用第一种情况增加,增加的方式不能改变,把每次增加的段画在数轴上,会发现每次增加对于一段区间相当于如果选了x当喜爱按钮,那么费用会减少y,这个y在数轴上是个等差数列,用线段树维护一下就好

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,M;
int a[MAXN];
int64 ans,res;
struct node {
int L,R;
int64 a,d;
}tr[MAXN * 4];
void build(int u,int L,int R) {
tr[u].L = L;tr[u].R = R;
tr[u].a = tr[u].d = 0;
if(L == R) return;
int mid = (L + R) >> 1;
build(u << 1,L,mid);
build(u << 1 | 1,mid + 1,R);
}
void addlz(int u,int64 a,int64 d) {
tr[u].a += a;tr[u].d += d;
}
void pushdown(int u) {
int l = tr[u].L,m = (tr[u].L + tr[u].R) >> 1,r = tr[u].R;
addlz(u << 1,tr[u].a,tr[u].d);
addlz(u << 1 | 1,tr[u].a + (m + 1 - l) * tr[u].d,tr[u].d);
tr[u].a = tr[u].d = 0;
}
void Add(int u,int ql,int qr,int64 a,int64 d) {
if(ql > qr) return;
if(ql == tr[u].L && qr == tr[u].R) {addlz(u,a,d);return;}
int mid = (tr[u].L + tr[u].R) >> 1;
pushdown(u);
if(qr <= mid) Add(u << 1,ql,qr,a,d);
else if(ql > mid) Add(u << 1 | 1,ql,qr,a,d);
else {Add(u << 1,ql,mid,a,d),Add(u << 1 | 1,mid + 1,qr,a + (mid + 1 - ql) * d,d);}
}
void Getans(int u) {
if(tr[u].L == tr[u].R) {res = max(tr[u].a,res);return;}
pushdown(u);
Getans(u << 1);Getans(u << 1 | 1);
}
void Solve() {
read(N);read(M);
build(1,1,M);
for(int i = 1 ; i <= N ; ++i) {
read(a[i]);
}
for(int i = 2 ; i <= N ; ++i) {
if(a[i] > a[i - 1]) {
ans += a[i] - a[i - 1];
Add(1,a[i - 1] + 1,a[i],0,1);
}
else {
ans += M - a[i - 1] + a[i];
Add(1,a[i - 1] + 1,M,0,1);
Add(1,1,a[i],M - a[i - 1],1);
}
}
Getans(1);
out(ans - res);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

F - SS

先把原始的字符串变成两个相同的字符串的形式

设为\(SS\),如果\(S\)最后一位的next是\(k\),那么显然要在后边加\(S\)的后N-k和\(S\)的前N-k位

设\(S\)的后\(N - k\)位为\(T\),且\(k\)最大,那么

\(f(SS) = STST\)

设\(g(S) = ST\)

显然\(f(SS) = g(S) + g(S)\)

我们实际上只要求一个足够长的\(g(S)\)就行

\(g(S) = ST\)

当\(|T|\)是\(|S|\)的约数,可以得到\(g(ST) = STT\)

如果\(|T|\)不是\(|S|\)的约数,那么\(g(ST) = STS\)

然后第一种情况\(g^{\infty}(S) = STTTTTTT....\)

第二种情况\(g^{i + 2}(S) = g^{i + 1}(S) + g^{i}(S)\)

然后可以直接模拟,从第二种情况开始递推,如果出现第一种情况就可以记录退出,第二种情况增长速度是指数级的,递推100个左右就行

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
struct node {
int64 c[26],len;
node() {memset(c,0,sizeof(c));len = 0;}
friend node operator + (const node &a,const node &b) {
node r;
r.len = a.len + b.len;
for(int i = 0 ; i < 26 ; ++i) r.c[i] = a.c[i] + b.c[i];
return r;
}
friend node operator - (const node &a,const node &b) {
node r;
r.len = a.len - b.len;
for(int i = 0 ; i < 26 ; ++i) r.c[i] = a.c[i] - b.c[i];
return r;
}
friend node operator * (const node &a,const int64 &d) {
node r = a;
for(int i = 0 ; i < 26 ; ++i) {
r.c[i] = r.c[i] * d;
}
return r;
}
}g[MAXN];
char s[MAXN * 2],t[MAXN * 2];
int nxt[MAXN],N;
int st,all;
node Calc(int64 R) {
if(R > g[all].len && st) {
node res;
res = g[st];
int64 t = (R - g[st].len) / g[st - 1].len;
res = res + g[st - 1] * t;
return res + Calc(R - g[st].len - g[st - 1].len * t);
}
else if(R <= g[1].len){
node res;res.len = R;
for(int i = 1 ; i <= R ; ++i) {
res.c[s[i] - 'a']++;
}
return res;
}
else {
for(int i = all ; i >= 0 ; --i) {
if(g[i].len <= R) {
return g[i] + Calc(R - g[i].len);
}
}
}
}
void Solve() {
scanf("%s",s + 1);
int64 r,l;
read(l);read(r);
N = strlen(s + 1);
for(int i = 2 ; i <= N ; ++i) {
int p = nxt[i - 1];
while(p && s[i] != s[p + 1]) p = nxt[p];
if(s[i] == s[p + 1]) nxt[i] = p + 1;
else nxt[i] = 0;
}
int p = nxt[N];
while(p > (N - 1) / 2) p = nxt[p];
int L = N;
for(int i = p + 1 ; i <= N - p ; ++i) {
s[++L] = s[i];
}
for(int i = 1 ; i <= L / 2; ++i) {
g[1].c[s[i] - 'a']++;
}
g[1].len = L / 2;
p = nxt[L / 2];
g[0].len = L / 2 - p;
for(int i = 1 ; i <= L / 2 - p ; ++i) {
t[i] = s[i];
g[0].c[t[i] - 'a']++;
}
for(int i = 2 ; i <= 100 ; ++i) {
if(g[i - 1].len % (g[i - 1].len - g[i - 2].len) == 0) {all = i - 1;st = i - 1;break;}
if(g[i - 1].len + g[i - 2].len <= 1e18) g[i] = g[i - 1] + g[i - 2];
else {all = i - 1;break;}
}
if(!all) all = 100;
node ans = Calc(r) - Calc(l - 1);
for(int i = 0 ; i < 26 ; ++i) {
out(ans.c[i]);space;
}
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

【AtCoder】ARC077的更多相关文章

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. Win7系统分区提示会把选定的基本磁盘转化为动态磁盘

    其实是因为目前分区数量已经达到四个了,需要用分区工具先删除一个分区,可以解决问题了

  2. ROM、PROM、EPROM、EEPROM、FLASH ROM简介

    ROM指的是"只读存储器",即Read-Only Memory.这是一种线路最简单半导体电路,通过掩模工艺, 一次性制造,其中的代码与数据将永久保存(除非坏掉),不能进行修改.这玩 ...

  3. 【原创】测试基础之http_load(1)简介、安装、使用

    http_load-09Mar2016官方:https://acme.com/software/http_load/ 一 简介 http_load - multiprocessing http tes ...

  4. Pl/SQL 编程

    Pl/SQL 编程 一:前言 二:Pl/Sql 概述 二     ——  1: Pl/Sql块结构 [declare] --声明部分,可选 begin --执行部分,必须 [exception] -- ...

  5. Confluence 6 发送 Confluence 通知到其他 Confluence 服务器

    你可以配置 Confluence 服务器向其他的 Confluence 服务器发送消息.在这种情况下,Confluence 服务器将不会显示 workbox. 希望发送消息到其他 Confluence ...

  6. Confluence 6 使用 CSS 样式化 Confluence 的介绍

    这个页面对 Confluence 通过修改 CSS 来改变外观和感觉的情况进行了说明. 层叠样式表(Cascading Style Sheets (CSS))是对 Web 页面进行样式化的工业化标准. ...

  7. CSS在线字体库,外部字体的引用方法@font-face

    @font-face是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,随着@font-face模块的出现,我们在Web的开发中使用字体不怕只能使用Web安全字体,你们当中或许有许 ...

  8. Oracle基础

    一.Oracle数据库与实例区分 Oracle数据库是存在电脑磁盘中的文件 实例是存在内存中的进程 我们是通过操作实例间接操作数据库的 我们操作结果都存在内存缓存中,当我们提交事务时,才将修改数据记录 ...

  9. jquery_ajax 跨域

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  10. MySQL、MongoDB、Redis 数据库之间的区别

    NoSQL 的全称是 Not Only SQL,也可以理解非关系型的数据库,是一种新型的革命式的数据库设计方式,不过它不是为了取代传统的关系型数据库而被设计的,它们分别代表了不同的数据库设计思路. M ...