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. Openssl与私有CA搭建

    转自:http://www.tuicool.com/articles/aURnim 随着网络技术的发展.internet的全球化,信息共享程度被进一步提高,各种基于互联网的应用如电子政务.电子商务日益 ...

  2. POJ 1305

    毕达哥斯三元组的模板题 练习练习 #include<iostream> #include<cstring> #include<cstdio> #include< ...

  3. 解决:angularjs radio默认选中失效问题

    添加ng-model后checked="checked"失效,可见angularjs也不好,会失效html标准属性   解决:添加ng-checked="1" ...

  4. [C]*和&

    一 .& c的&被称为“寻址运算符”,作用是指向某变量的指针: 请看以下代码: int main(void){ int int_1 = 16;        printf(" ...

  5. python基础--压缩文件

    1)怎么压缩备份多个文件 使用zipfile 创建压缩文件 查看信息 解压缩 # 创建 import zipfile # os.chdir('test') my_zip = zipfile.ZipFi ...

  6. Dnsmasq加速本地DNS请求

    文章目录 Dnsmasq安装 Dnsmasq配置 Dnsmasq启动 Dnsmasq使用 Dnsmasq小结   默认的情况下,我们平时上网用的本地DNS服务器都是使用电信或者联通的,但是这样也导致了 ...

  7. Gradle更小、更快构建APP的奇淫技巧

    本文已获得原作者授权同意,翻译以及转载原文链接:Build your Android app Faster and Smaller than ever作者:Jirawatee译文链接:Gradle更小 ...

  8. Modbus库开发笔记之七:Modbus其他辅助功能开发

    前面开发了各种应用,但是却一直没有提到一个问题,你就是对具体的数据进行读写操作.对于Modbus来说标准的数据有4种:线圈数据(地址:0000x).输入状态量数据(地址:1000x).保持寄存器数据( ...

  9. Confluence 6 Oracle 驱动输入你的数据库细节

    Confluence 的安装向导将会指导你一步一步的在 Confluence 中配置安装 Oracle 数据库. 使用 JDBC 连接(默认) JDBC 是推荐的连接你的 Confluence 到数据 ...

  10. Android 自动化测试框架

    Android常用的自动化测试工具框架: Monkey,MonkeyRunner,UIAutomator,Robotium,Appium,Monkey Talk...... 但这些工具框架都是什么呢有 ...