当前位置:网站首页>Codeforces 1634 F. Fibonacci additions - Fibonacci sequence addition, ideas
Codeforces 1634 F. Fibonacci additions - Fibonacci sequence addition, ideas
2022-06-12 13:32:00 【Tianyi City*】
The question :
I'll give you a length of n Array of a And an array b, There will be one operation at a time :
x l r
If x yes A Represents in the array a Operation on top , It is b
l r Indicates that the interval will be [l,r] Add the Fibonacci sequence to the one-to-one correspondence [1,r-l+1] Number of numbers .
Ask you the last a and b Whether it is equal or not .
Answer key :
It seems that Fibonacci sequence addition has been done before ?447E Well , That is to use the nature of Fibonacci , I forgot to go back and have a look .
The first thing that comes to mind in this problem is to put b Reduced to a On , Then just use it on an array , Each time you check whether it is all 0 That's all. .
And then what to do , I thought for a while about what to do with the line segment tree , So I changed my mind :
set up f[x] It is the th of Fibonacci series x position ,f[x]=f[x-1]+f[x-2].
Since the Fibonacci sequence is simply adding before and after , It can be expressed by difference .
If you use a[i] Express a[i]-a[i-1]-a[i-2] Well , That interval plus f[l:r] It turns into a[l]+1,a[r+1]-f[r-l+2]?
This is a normal difference , But here we are a[i] Minus the a[i-1] and a[i-2], therefore a[r] Changes in will affect a[r+2].
about a[r+3], It is maintained a[r+2] and a[r+1], Since these two have not changed , that a[r+3] It hasn't changed .
that a[r+2] How much has changed ? We can find out a[r] Combined with the f[r-l+1],a[r+1] unchanged , that a[r+2] Because the maintenance is a[r+2]-a[r+1]-a[r], So we should reduce f[r-l+1].
And then use num To maintain the current 0 The number of .
But it's easy here TLE ah , I can change it no matter how I change it T, Finally, put longlong It's not until you get rid of it
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3e5+5;
int f[N],a[N],b[N];
int n,q;
int mod;
void add(int &x,int y){
x+=y;
if(x>=mod)x-=mod;
if(x<0)x+=mod;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cin>>n>>q>>mod;
f[1]=f[2]=1;
int num=0;
for(int i=3;i<N;i++)add(f[i],f[i-1]+f[i-2]);
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++){
cin>>b[i],add(b[i],a[i]-2*b[i]);
add(a[i],-a[i]+b[i]-b[i-1]);
if(i>1)add(a[i],-b[i-2]);
num+=a[i]==0;
}
while(q--){
char s[5];
int l,r;
cin>>s>>l>>r;
if(s[0]=='A'){
if(a[l]==0)num--;
if(r+1<=n&&a[r+1]==0)num--;
if(r+2<=n&&a[r+2]==0)num--;
add(a[l],1),add(a[r+1],-f[r-l+2]),add(a[r+2],-f[r-l+1]);
if(a[l]==0)num++;
if(r+1<=n&&a[r+1]==0)num++;
if(r+2<=n&&a[r+2]==0)num++;
}
else{
if(a[l]==0)num--;
if(r+1<=n&&a[r+1]==0)num--;
if(r+2<=n&&a[r+2]==0)num--;
add(a[l],-1),add(a[r+1],f[r-l+2]),add(a[r+2],f[r-l+1]);
if(a[l]==0)num++;
if(r+1<=n&&a[r+1]==0)num++;
if(r+2<=n&&a[r+2]==0)num++;
}
if(num==n)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}
边栏推荐
- Paw 高级使用指南
- Overview of embedded system 2- composition and application of embedded system
- Innovation training (x) advanced interface beautification
- 在 Debian 10 上独立安装MySQL数据库
- C language implementation of string and memory library functions
- jupyternotebook有汉字数据库吗。在深度学习中可以识别手写中文吗
- [EDA] chip layout design: VLSI layout design using electric
- Application of bit operation in C language
- Rk3399 platform development series explanation (kernel debugging chapter) 2.50 use of systrace
- Qualcomm platform development series (Protocol) QMI brief introduction and usage
猜你喜欢

Actual combat | realizing monocular camera ranging by skillfully using pose solution

看完这一篇就够了,web中文开发
![[brush title] probability of winning a draw](/img/f5/7e8dac944876f920db10508ec38e92.png)
[brush title] probability of winning a draw

STM32F1与STM32CubeIDE编程实例-设备驱动-EEPROM-AT24C256驱动

C#DBHelper_FactoryDB_GetConn
颜色编码格式介绍

简历 NFT 平台 TrustRecruit 加入章鱼网络成为候选应用链

Script引入CDN链接提示net::ERR_FILE_NOT_FOUND问题

一种快速创建测试窗口的方法

Scyther工具形式化分析Woo-Lam协议
随机推荐
"New continent" of mobile application going to sea
It is enough to read this article. Web Chinese development
jupyternotebook有汉字数据库吗。在深度学习中可以识别手写中文吗
Resume NFT platform trustrecruit joined Octopus network as a candidate application chain
xcode 调试openGLES
【云原生 | Kubernetes篇】深入了解Deployment(八)
1002: output the second integer
Application of short circuit expression (||) in C language
[EDA] chip layout design: VLSI layout design using electric
基于华为云鲲鹏弹性云服务器ECS部署openGauss数据库【这次高斯不是数学家】
Will the next star of PPT for workplace speech be you [perfect summary] at the moment
import torch_ Geometric first graph network example
简历 NFT 平台 TrustRecruit 加入章鱼网络成为候选应用链
Realization of Joseph Ring with one-way ring linked list
Stm32f1 and stm32subeide programming example - device driver -dht11 temperature sensor driver
import torch_ Data view of geometric
Install MySQL database independently on Debian 10
1003: align output
D1 Nezha Development Board understands the basic startup and loading process
Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s