Soved:3

rank:133

A.Ternay String

欧拉降幂一下 但是反复求phi会超时 但mod是同一个就可以记忆化一下

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + ; char s[];
int len;
map<ll, ll> mp; ll getphi(ll o)
{
if(mp[o]) return mp[o];
ll res = o;
ll n = o;
for(ll i = ; i * i <= n; i++)
{
if(n % i == )
{
res -= res / i;
while(n % i == ) n /= i;
}
}
if(n > ) res -= res / n;
mp[o] = res;
return res;
} ll pow_mod(ll x, ll y, ll mo)
{
ll res = ;
while(y)
{
if(y & ) res = res * x % mo;
y >>= ;
x = x * x % mo;
}
return res;
} ll dfs(ll x, ll m)
{
if(x < ) return ;
if(m == ) return ;
if(s[x] == '')
{
ll p = getphi(m);
ll tmp = (dfs(x - , p) + p) % p;
tmp = pow_mod(, tmp, m);
return (6LL * tmp % m - 3LL + m) % m;
}
if(s[x] == '') return (dfs(x - , m) + 1LL) % m;
if(s[x] == '') return (dfs(x - , m) * 2LL + 2LL) % m;
return ;
} int main()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%s", s);
len = strlen(s);
ll ans = dfs(len - , mod);
printf("%lld\n", ans);
}
return ;
}

牛客多校Round 4的更多相关文章

  1. 牛客多校Round 10

    咕咕咕.... 去烽火台和兵马俑了

  2. 牛客多校Round 9

    Solved:1 rank:112 E. Music Game 题解说有个非简化的原题 bzoj4318 #include <bits/stdc++.h> using namespace ...

  3. 牛客多校Round 8

    Solved:2 rank:164 签了两个oeis,但这样真的开心嘛

  4. 牛客多校Round 6

    Solved:3 rank:156 J. Heritage of skywalker 学习一下nth_element 可以o (n)的找出前多少大的元素 #include <bits/stdc+ ...

  5. 牛客多校Round 5

    Solved:3 rank:195 F. take 官方题解:小 A 在打开第 i 个箱子后会交换手中的钻石和第 i 个箱子中的钻石 当且仅当第 i个箱子的钻石是前 i 个箱子打开后出现的所有钻石里最 ...

  6. 牛客多校Round 3

    Solved:2 rank:306 跑路场..... A.PACM team 简单背包记录路径都写挂 退役算了 #include <bits/stdc++.h> using namespa ...

  7. 牛客多校Round 2

    Solved:3 rank:187 H.travel 题意:给一颗带有点权的树 找三条不相交的链 使得点权最大 题解:使用树形DP dp[x][i][0/1] 表示x节点选择i条链 有没有经过x的链 ...

  8. 牛客多校Round 1

    Solved:1 rank:249 E. Removal dp i,j表示前i个数删除了j个且选择了第i个的答案 类似字符串的dp 预处理一下nex i_k即i后面k第一次出现的位置  就好转移了 # ...

  9. 2019牛客多校第一场 I Points Division(动态规划+线段树)

    2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...

随机推荐

  1. tensorflow,torch tips

    apply weightDecay,L2 REGULARIZATION_LOSSES weights = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIAB ...

  2. shell 爬虫 从日志分析到数据采集与分析

    [root@VM_61_158_centos ~]# curl http://ip.chinaz.com/220.112.233.179 |grep -e Whwtdhalf.*span.*span. ...

  3. go13---反射reflection

    package main /** 反射reflection 反射可大大提高程序的灵活性,使得 interface{} 有更大的发挥余地 反射使用 TypeOf 和 ValueOf 函数从接口中获取目标 ...

  4. sa分析

    onCheckedChanged用于监控开启和关闭,其实是Switch,也是Toggle Buttons http://www.google.com/design/spec/components/sw ...

  5. 4.7.6 Compaction of LR Parsing Tables

    4.7.6 Compaction of LR Parsing Tables A typical programming language grammar with 50 to 100 terminal ...

  6. ZOJ2107 Quoit Design 最近点对

    ZOJ2107 给定10^5个点,求距离最近的点对的距离. O(n^2)的算法是显而易见的. 可以通过分治优化到O(nlogn) 代码很简单 #include<iostream> #inc ...

  7. 将属性和方法添加到Date原型中

    <button onclick="myFunction()">点我</button> <script> Date.prototype.myMet ...

  8. 6章 Models

    传统的MVC结构中,有模型这么一个概念.Django中,Models又是怎么一回事呢? 刚才生成的这些乱七八糟的数据迁移就是Django自带的一些应用 INSTALLED_APPS = [ 'djan ...

  9. 使用AngularJS创建应用的5个框架(转)

    原文地址:http://www.php100.com/html/dujia/2015/0206/8580.html 本文由PHP100中文网编译,转载请看文末的转载要求,谢谢合作! 如果你计划使用An ...

  10. 百度上传组件 WebUploader

    WebUploader http://fex.baidu.com/webuploader/doc/index.html WebUploader API 文档详细解读 源码以及示例:https://gi ...