当前位置:网站首页>St Table + two points
St Table + two points
2022-06-24 21:58:00 【Weng Weiqiang】
subject :https://codeforces.ml/contest/1549/problem/D
ST surface :
1. Online modification is not supported Preprocessing event complexity 0(nlogn), Query events o(1)
2. For example, find the maximum value of a certain section st[i][j] From i To i+2^j
Then its maximum value is determined by the first half and the second half
The first half : by i+2^(j-1), The second half is (i+2^(j-1)+1)+2^(j-1)
that st[i][j]=max(st[i][j-1],st[i][i+2^(j-1)+1][j-1])
for(int j=1;(1<<j)<=n;j++)
{
for(int i=1;i+(1<<j)<=n+1;i++)
{
st[i][j]=max[st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
}Topic analysis :
Carelessness : Find the longest subsequence in an interval , The values of this sequence are congruent m,m>=2
analysis :
Congruence property :
If x ≡ y ( m o d p )
that ( x − y ) %p==0
So construct a difference array , Then, if the difference fraction group satisfying the interval is not coprime
AC Code :
#define _CRT_SECURE_NO_WARNINGS
#include<vector>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[212100];
ll st[212100][30];
ll lg2[212100];// representative k The scope of the
ll n;
// Verify whether it is mutual prime
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll query(ll l, ll r) { return gcd(st[l][lg2[r - l + 1]], st[r - (1 << lg2[r - l + 1]) + 1][lg2[r - l + 1]]); }
ll bsearch(ll l, ll r, ll p)
{
ll mid;
ll k = 1;
while (l < r)// Find the optimal interval Meet the requirements of mutual prime
{
mid = l + r + 1 >> 1;
if (abs(query(p, mid)) < 2)// Be careful abs Where to put it
{
r = mid - 1;// Try to make the interval smaller
}
else
{
l = mid;
}
}
if (abs(query(p, l)) < 2) { return 1; }
return l;
}
int main()
{
int T;
cin >> T;
lg2[0] = -1;
for (int i = 2; i <= 210000; i++) { lg2[i] = lg2[i>>1] + 1; } // After a k The value is always greater than the previous one
while (T--)
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
// Initialize the rest
for (int i = n + 1; i <= 2 * n && i <= 200000; i++) { st[i][0] = 0; }
for (int i = 1; i <= n; i++)
{
st[i][0] = a[i] - a[i - 1];// Build a differential array
}
for (int i = 1; (1 << i) <= n; i++)//i It's state
{
for (int j = 1; j + (1 << i) - 1 <= n; j++)//j Is the position
{
st[j][i] = gcd(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
}
}
ll p = 1;
for (ll i = 1; i <= n; i++)
{
ll u = bsearch(i + 1, n, i + 1);// Third i+1 Save this location
if (u == 1)continue;// Mutual prime continues to extend
p = max(p, u - i + 1);
}
cout << p << endl;
}
}
边栏推荐
- 架构实战营 第 6 期 毕业设计
- [camera Foundation (II)] camera driving principle and Development & v4l2 subsystem driving architecture
- [featured] how do you design unified login with multiple accounts?
- Vscode netless environment rapid migration development environment (VIP collection version)
- Opengauss kernel: simple query execution
- (待补充)GAMES101作业7提高-实现微表面模型你需要了解的知识
- Structured interview of state-owned enterprises and central enterprises employment of state-owned enterprises Modou Interactive Employment Service steward
- 专科出身,2年进苏宁,5年跳阿里,论我是怎么快速晋升的?
- 旅行商问题(TSP)的相关论文总结
- [untitled]
猜你喜欢

【OpenCV 例程200篇】209. HSV 颜色空间的彩色图像分割

Multithreaded finalization

将二维数组方阵顺时针旋转90°

Application practice | massive data, second level analysis! Flink+doris build a real-time data warehouse scheme

数据链路层 && 一些其他的协议or技术

VSCode无网环境快速迁移开发环境(VIP典藏版)

刷题笔记(十八)--二叉树:公共祖先问题

专科出身,2年进苏宁,5年跳阿里,论我是怎么快速晋升的?

壹沓科技签约七匹狼,助力「中国男装领导者」数字化转型

Introduce the overall process of bootloader, PM, kernel and system startup
随机推荐
虚拟机CentOS7中无图形界面安装Oracle(保姆级安装)
How to resolve the 35 year old crisis? Sharing of 20 years' technical experience of chief architect of Huawei cloud database
手动事务的几个类
Excel layout
Multithreaded finalization
How to achieve energy conservation and environmental protection of full-color outdoor LED display
[notes of Wu Enda] multivariable linear regression
leetcode1863_ 2021-10-14
A deep learning model for urban traffic flow prediction with traffic events mined from twitter
【无标题】
Blender FAQs
[notes of Wu Enda] convolutional neural network
Object. Defineproperty and reflect Fault tolerance of defineproperty
(to be added) games101 job 7 improvement - knowledge you need to know to realize micro surface model
leetcode_1470_2021.10.12
[theory] deep learning in the covid-19 epic: a deep model for urban traffic revitalization index
ST表+二分
壹沓科技签约七匹狼,助力「中国男装领导者」数字化转型
SAP接口debug设置外部断点
EasyBypass