codeforces 722F - Cyclic Cipher
题目链接:http://codeforces.com/problemset/problem/722/F
------------------------------------------------------------------------------
首先根据 $k <= 40$ 以及 $lcm(1...40)$ 在$long long$以内
可以意识到这题可以转化为求最大合法区间使得区间内的同余方程组合法
这个可以考虑用$exgcd$来做 并且也满足区间可合并的性质
对于一段连续区间 我们枚举左端点要找到最远的合法的右端点 可以先用$ST$表预处理后倍增查找
$($注意线段树/$ST$表要进行二分的时候不要真的进行二分 这样会多一个$log$ 要利用已经分割好的区间$)$
最后复杂度是$O(n * logn * exgcd$复杂度$)$
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + , E = 2e5 + ;
int len[N], firste[N], nexte[E], v[E], w[E];
int n, lim, e, ans, m;
void build(int x, int y, int z)
{
nexte[++e] = firste[x];
firste[x] = e;
v[e] = y;
w[e] = z;
}
void exgcd(long long a,long long b,long long &d, long long &x, long long &y)
{
if(!b)
{
x = ;
y = ;
d = a;
}
else
{
exgcd(b, a % b, d, y, x);
y -= x * (a / b);
}
}
long long a[][N], b[][N];
long long mul(long long aa, long long bb, long long mod)
{
return (aa * bb - (long long)(aa / (long double) mod * bb + 1e-) * mod + mod) % mod ;
}
void solve(long long m1, long long b1, long long m2, long long b2, long long &m0, long long &b0)
{
if(m1 == - || m2 == -)
{
m0 = b0 = -;
return;
}
long long d, x, y;
exgcd(m1, m2, d, x, y);
if((b2 - b1) % d != )
m0 = b0 = -;
else
{
long long t = m2 / d;
//x = (x % t * ((b2 - b1) / d % t) % t + t) % t;
x = (mul(x, (b2 - b1) / d, t) + t) % t;
m0 = m1 * (m2 / d);
b0 = m1 * x + b1;
}
}
int main()
{
scanf("%d%d", &n, &lim);
int x;
for(int i = ; i <= n; ++i)
{
scanf("%d", &len[i]);
for(int j = ; j < len[i]; ++j)
{
scanf("%d", &x);
build(x, i, j);
}
}
int last;
for(int u = ; u <= lim; ++u)
{
ans = m = last = ;
for(int p = firste[u]; ; p = nexte[p])
{
if(p && (!m || v[p] == last - ))
{
++m;
a[][m] = len[v[p]];
b[][m] = w[p];
last = v[p];
continue;
}
else
{
if(m > ans)
{
int top = ;
for(int i = ; ( << i) <= m; ++i)
{
top = i;
for(int j = ; j + ( << i) - <= m; ++j)
solve(a[i - ][j], b[i - ][j], a[i - ][j + ( << (i - ))],
b[i - ][j + ( << (i - ))], a[i][j], b[i][j]);
}
for(int j = ; m - j + > ans; ++j)
{
int k = j + ;
long long nowa = a[][j], nowb = b[][j], tmpa, tmpb;
for(int i = top; i >= ; --i)
if(k + ( << i) - <= m)
{
solve(nowa, nowb, a[i][k], b[i][k], tmpa, tmpb);
if(tmpa != -)
{
k += ( << i);
nowa = tmpa;
nowb = tmpb;
}
}
ans = max(ans, k - j);
}
}
if(!p)
break;
m = ;
a[][m] = len[v[p]];
b[][m] = w[p];
last = v[p];
}
}
printf("%d\n", ans);
}
return ;
}
codeforces 722F - Cyclic Cipher的更多相关文章
- [codeforces 901E] Cyclic Cipher 循环卷积-Bluestein's Algorithm
题目大意: 传送门 给两个数列${B_i}.{C_i}$,长度均为$n$,且${B_i}$循环移位线性无关,即不存在一组系数${X_i}$使得对于所有的$k$均有$\sum_{i=0}^{n-1} X ...
- CodeForces - 156C:Cipher (不错的DP)
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But t ...
- Codeforces - 102222C - Caesar Cipher
https://codeforc.es/gym/102222/my 好像在哪里见过这个东西?字符的左右移还是小心,注意在mod26范围内. #include<bits/stdc++.h> ...
- codeforces 708ALetter Cyclic Shift
2019-05-18 09:51:19 加油,加油,fightting !!! https://www.cnblogs.com/ECJTUACM-873284962/p/6375011.html 全为 ...
- Codeforces Round #453 (Div. 1)
Codeforces Round #453 (Div. 1) A. Hashing Trees 题目描述:给出一棵树的高度和每一层的节点数,问是否有两棵树都满足这个条件,若有,则输出这两棵树,否则输出 ...
- Codeforces Round #453
Visiting a Friend Solution Coloring a Tree 自顶向下 Solution Hashing Trees 连续2层节点数都超过1时能异构 Solution GCD ...
- Codeforces Round #385 (Div. 2) A. Hongcow Learns the Cyclic Shift 水题
A. Hongcow Learns the Cyclic Shift 题目连接: http://codeforces.com/contest/745/problem/A Description Hon ...
- Codeforces 708A Letters Cyclic Shift
A. Letters Cyclic Shift time limit per test:1 second memory limit per test:256 megabytes input:stand ...
- Cyclic Components CodeForces - 977E(DFS)
Cyclic Components CodeForces - 977E You are given an undirected graph consisting of nn vertices and ...
随机推荐
- 四、JVM — 类文件结构
类文件结构 一 概述 二 Class 文件结构总结 2.1 魔数 2.2 Class 文件版本 2.3 常量池 2.4 访问标志 2.5 当前类索引,父类索引与接口索引集合 2.6 字段表集合 2.7 ...
- Window Operations详解
window(windowLength, slideInterval):返回窗口长度为windowLength,每隔slideInterval滑动一次的window DStream countByWi ...
- 划水日记之大哥带我走渗透I
5/24/19 周五 access注入 先测试是否有漏洞 or nor and 1=1 and 1=2 2. Order by 猜字表端,发现一共有22个 3..然后使用 union select 1 ...
- Apache 配置内网站点
基于端口常用于内部网站,不对外开发的网站 [root@Nagios-Server extra]# vim ../httpd.conf Listen 80 Listen 8000 Listen 9000 ...
- 十一、Boostrap-X-editable
一.官网 http://vitalets.github.io/x-editable/index.html 二.实践 在jQuery中ajax配置项中的使用type与method的区别: type 和m ...
- Educational Codeforces Round 55 (Rated for Div. 2) D. Maximum Diameter Graph (构造图)
D. Maximum Diameter Graph time limit per test2 seconds memory limit per test256 megabytes inputstand ...
- tflite
1.编译libtensorflow-lite.a库: ubuntu下交叉环境编译: https://blog.csdn.net/computerme/article/details/80345065 ...
- hdu 3530 单调队列最值
/** HDU 3530 单调队列的应用 题意: 给定一段序列,求出最长的一段子序列使得该子序列中最大最小只差x满足m<=x<=k. 解题思路: 建立两个单调队列分别递增和递减维护(头尾删 ...
- centos 挂载windows 2003 smb
mount -t cifs //10.100.100.250/产品服务器/待测库/FI\ Cloud/CICD/BuildRoot_Dev/ /cicd --verbose -o vers=1.0,u ...
- spring security基本知识(三) 过滤详细说明
在我们前面的文章Spring Security 初识(一)中,我们看到了一个最简单的 Spring Security 配置,会要求所有的请求都要经过认证.但是,这并不是我们想要的,我们通常想自定义应用 ...