当前位置: 首页 > 编程日记 > 正文

Codeforces Round #FF 446 C. DZY Loves Fibonacci Numbers

參考:http://www.cnblogs.com/chanme/p/3843859.html

然后我看到在别人的AC的方法里还有这么一种神方法,他预先设定了一个阈值K,当当前的更新操作数j<K的时候,它就用一个类似于树状数组段更的方法,用一个 d数组去存内容,譬如它要在区间 [3,6]上加一段fibonacci

原来:

id 0 1 2 3 4 5 6 7 8 9 10

d  0 0 0 0 0 0 0 0 0 0 0

更新:

id 0 1 2 3 4 5 6  7  8  9 10

d  0 0 0 1 0 0 0 -5  -3 0 0

我们能够发现,当利用 d[i]=d[i]+d[i-1]+d[i-2] i由小到大更新后就会得到

id 0 1 2 3 4 5 6  7  8  9 10

d  0 0 0 1 1 2 3  0  0  0  0

所以对于[L,R]上加一段操作,我们能够d[L]+=1; d[R+1]-=f[R-L+2],d[R+2]=f[R-L+1];

所以假如我更新了m次,我每次更新的复杂度是O(1),我把全部数求出来一次的复杂度是O(n)

然后他的算法是这种,j<K的时候更新的时候依照上述方法更新,询问的话则是将询问区间和更新的区间求交,把交的和加上去。

当j==K的时候,利用d还原出新的a,把当前的区间清0.



C. DZY Loves Fibonacci Numbers
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation

F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2).

DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ..., an. Moreover, there are mqueries, each query has one of the two types:

  1. Format of the query "l r". In reply to the query, you need to add Fi - l + 1 to each element ai, where l ≤ i ≤ r.
  2. Format of the query "l r". In reply to the query you should output the value of  modulo 1000000009 (109 + 9).

Help DZY reply to all the queries.

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 300000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — initial array a.

Then, m lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1 ≤ l ≤ r ≤ n holds.

Output

For each query of the second type, print the value of the sum on a single line.

Sample test(s)
input
4 4
1 2 3 4
1 1 4
2 1 4
1 2 4
2 1 3
output
17
12
Note

After the first query, a = [2, 3, 5, 7].

For the second query, sum = 2 + 3 + 5 + 7 = 17.

After the third query, a = [2, 4, 6, 9].

For the fourth query, sum = 2 + 4 + 6 = 12.



#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>using namespace std;const int maxn=330000;
const long long int mod=1000000009LL;
typedef long long int LL;int n,m,k;
LL a[maxn],sum[maxn],fib[maxn],gib[maxn];
LL d[maxn]; int L[1100],R[1100];void init()
{fib[1]=1LL,fib[2]=1LL;gib[1]=1LL,gib[2]=2LL;for(int i=3;i<=n+50;i++){fib[i]=(fib[i-1]+fib[i-2])%mod;gib[i]=(gib[i-1]+fib[i])%mod;}
}int main()
{scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){scanf("%I64d",a+i);sum[i]=sum[i-1]+a[i];}init();while(m--){int c,l,r;scanf("%d%d%d",&c,&l,&r);if(c==1){L[k]=l,R[k]=r; k++;d[l]=(d[l]+1LL)%mod;d[r+1]=(d[r+1]-fib[r-l+2]+mod)%mod;d[r+2]=(d[r+2]-fib[r-l+1]+mod)%mod;if(k>=1000){for(int i=1;i<=n;i++){if(i>=2)d[i]=((d[i]+d[i-1])%mod+d[i-2])%mod;a[i]=(a[i]+d[i])%mod;sum[i]=sum[i-1]+a[i];}memset(d,0,sizeof(d));  k=0;}}else if(c==2){LL ret=0;for(int i=0;i<k;i++){int _left=max(l,L[i]);int _right=min(r,R[i]);if(_left>_right) continue;int s=_left-L[i]+1,e=_right-L[i]+1;ret=((ret+gib[e])%mod-gib[s-1]+mod)%mod;}ret=((ret+sum[r])%mod-sum[l-1]+mod)%mod;printf("%I64d\n",(ret+mod)%mod);}}return 0;
}



相关文章:

Java 基本概念

Java 基本概念 1. Java 语言的优点? 简单、高效 Java 语言与 C 类似&#xff0c;如果用户了解 C 和面向对象的概念&#xff0c;就可以很快编写出 Java 程序&#xff1b;此外&#xff0c;Java 又不同于诸如 C 语言提供的各种各样的方法&#xff0c;它只提供了基本的方法&#x…

list_for_each_safe

list_for_each_safeBidirect-list list_for_each_safe().https://biscuitos.github.io/blog/LIST_list_for_each_safe/

oracle恢复是怎么看进度,Oracle中查看慢查询进度的脚本分享

Oracle一个大事务的sql往往不知道运行到了哪里,可以使用如下sql查看执行进度。代码如下:404_6set linesize 400;H_404_6set pagesize 400;H_404_6col sql_text format a100;H_404_6col opname format a15;H_404_6SELECT se.sid,H_404_6opname,H_404_6TRUNC (sofar / totalwork …

第三周 9.13-9.19

9.13 长春OL。 9.14-9.15 什么都没干。 9.16-9.17 补题。 9.18 什么都没干。 9.19 沈阳OL。 本周就是什么都没干。转载于:https://www.cnblogs.com/Aguin/p/4805509.html

vue-devTools插件安装流程

vue-devTools插件安装流程 本文主要介绍 vue的调试工具 vue-devtools 的安装和使用 工欲善其事, 必先利其器, 快快一起来用vue-devtools来调试开发你的vue项目吧 安装: 1.到github下载&#xff1a;&#xff08;下载一定要记得是master环境的代码&#xff0c;默认克隆后进入…

基于ipfire的open***功能--client to net (Roadwarrior)配置(一)

Client-to-Net configuration (Roadwarrior)全局配置第一步应该是生成服务证书来激活ipfire上的open***。完成这个后&#xff0c;全局配置就可以使用了。为了激活open***所需的接口&#xff0c;open***服务监听的地方&#xff0c;你需要勾选界面里的方框。如何勾选&#xff0c;…

oracle update from多表性能优化一例

这几天测试java内存数据库&#xff0c;和oracle比较时发下一个update from语句很慢&#xff0c;如下&#xff1a; update business_newset fare1_balance_ratio (select BALANCE_RATIO from bfare2where bfare2.exchange_type business_new.exchange_type andbfa…

Sorry, Sarah

Sorry, Sarah

C#中Winform程序中如何实现多维表头【不通过第三方报表程序】

问题&#xff1a;C#中Winform程序中如何实现多维表头。 在网上搜了很多方法&#xff0c;大多数方法对于我这种新手&#xff0c;看的都不是很懂。最后在新浪博客看到了一篇比较易懂的文章&#xff1a;【DataGridView二维表头与合并单元格】 大体的思路如下&#xff1a; 1.新建一…

斗地主发牌编程PHP,JAVA代码之斗地主发牌详解

package com.oracle.demo01;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.Map;public class Doudizhu {public static void main(String[] args) {//1.创建扑克牌MapMap pookernew HashMap();//创建所有key所在的容器A…

2022-2028年中国自动化设备市场研究及前瞻分析报告

【报告类型】产业研究 【报告价格】4500起 【出版时间】即时更新&#xff08;交付时间约3个工作日&#xff09; 【发布机构】智研瞻产业研究院 【报告格式】PDF版 本报告介绍了中国自动化设备行业市场行业相关概述、中国自动化设备行业市场行业运行环境、分析了中国自动化…

转发:某些函数需要将其一个或多个实参连同类型不变地转发给其他函数

16.47 编写你自己版本的翻转函数&#xff0c;通过调用接受左值和右值引用参数的函数来测试它。 #include<iostream> #include<string> #include<utility> using namespace std;template <typename T> int compare(const T &a ,const T &b) {if…

pycharm远程调试或运行代码

第一步&#xff1a;开始 第二步&#xff1a;设置远程服务器 第三步&#xff0c;查看 第四步&#xff0c;选择解释器&#xff0c;和指定文件映射路径&#xff08;相对上一步指定的相对路径&#xff09; 转载于:https://www.cnblogs.com/jeshy/p/11182359.html

LTE随机接入过程

随机接入的基本流程 Msg3和Msg4只有基于竞争的随机接入才存在&#xff0c;之所以叫Msg3/Msg4是因为不同的随机接入情况&#xff0c;Msg3/Msg4的消息不相同(本文稍后介绍)。 下图中的参数<ra-ResponseWindowSize>和<mac-ContentionResolutionTimer>来自SIB2中的rach…

workday与oracle,workingday与workday的区别 – 手机爱问

2005-04-11for的用法&#xff26;&#xff2f;&#xff32;到底应该怎么用&#xff1f;对于for的用法的确很多&#xff0c;可用作介词和连词&#xff0c;介词用法尤为丰富。以下详细列出了用法和句例&#xff0c;供你参考。for 1 preposition1used to say who is intended to g…

OGRE 2.1 Windows 编译

版权所有&#xff0c;转载请注明链接 OGRE 2.1 Windows 编译 环境&#xff1a;  Windows 7 64Bit  Visual Studio 2012  OGRE 2.1  CMake 2.8.12.1 OGRE&#xff1a;  OGRE官方推出了最新的OGRE2.1版本&#xff0c;链接地址&#xff1a;    https://bitbucket.or…

IDEA集成Docker插件实现一键自动打包部署微服务项目

一. 前言 大家在自己玩微服务项目的时候&#xff0c;动辄十几个服务&#xff0c;每次修改逐一部署繁琐不说也会浪费越来越多时间&#xff0c;所以本篇整理通过一次性配置实现一键部署微服务&#xff0c;实现真正所谓的一劳永逸。 二. 配置服务器 1. Docker安装 服务器需要安…

PHP的学习--PHP的引用

引用是什么 在 PHP 中引用意味着用不同的名字访问同一个变量内容。这并不像 C 的指针&#xff0c;替代的是&#xff0c;引用是符号表别名。注意在 PHP 中&#xff0c;变量名和变量内容是不一样的&#xff0c;因此同样的内容可以有不同的名字。最接近的比喻是 Unix 的文件名和文…

谈一谈浏览器解析CSS选择器的过程【前端每日一题-6】

谈一谈浏览器解析CSS选择器的过程&#xff1f; 这是一道发散题&#xff0c;可以根据自己的理解自行解答。 在开始前&#xff0c;我们必须了解一个真相&#xff1a;为什么排版引擎解析 CSS 选择器时一定要从右往左解析&#xff1f; 简单的来说&#xff1a;浏览器从右到左进行查找…

LTE: MIB和SIB,小区选择和重选规则

LTE 中MIB/SIB内容可以参考&#xff1a;https://blog.csdn.net/wowricky/article/details/51348613 MIB/SIB的详细内容参考下面两张图 MIB,SIB1,SIB2 可以关注下小区选择的参数&#xff0c;用特殊颜色表示 36.304 - 5.2.3.2 Cell Selection Criterion S准则&#xff0c;需要…

linux 生成dll文件,Linux和Windows平台 动态库.so和.dll文件的生成

Linux动态库的生成1、 纯cpp文件打包动态库将所有cpp文件和所需要的头文件放在同一文件夹&#xff0c;然后执行下面命令gcc -shared - fpic *.c -o xxx.so&#xff1b;g -stdc17 - fpic *.cpp -o xxx.so&#xff1b;[C17标准&#xff0c;需要高版本gcc&#xff0c;本人采用gcc …

Form表单提交前进行JS验证的3种方式

1. 提交按钮的onclick事件中验证 <script type"text/javascript"> function check(form) { return true; }</script> <form> <input type"submit" name"submit1" value"登陆" οnc…

2022-2028年中国椎间孔镜行业市场研究及前瞻分析报告

【报告类型】产业研究 【报告价格】4500起 【出版时间】即时更新&#xff08;交付时间约3个工作日&#xff09; 【发布机构】智研瞻产业研究院 【报告格式】PDF版 本报告介绍了中国椎间孔镜行业市场行业相关概述、中国椎间孔镜行业市场行业运行环境、分析了中国椎间孔镜行…

mysql 错误:1166 解决办法

原因&#xff1a;检查字段里面是不是有空格&#xff0c;去掉就可以了转载于:https://www.cnblogs.com/zhizhan/p/3950453.html

优先级队列(小顶堆)的dijkstra算法

php实现迪杰斯特拉算法&#xff0c;并由小顶堆优化 1 <?php2 3 class DEdge4 {5 public $nextIndex, $length;6 7 public function __construct($nextIndex, $length)8 {9 $this->nextIndex $nextIndex;10 $this->length $length;11 …

室内设计木地板材质合集包 Arroway – Design Craft Vol.4

室内设计木地板材质合集包 Arroway – Design Craft Vol.4 室内设计木地板材质合集包 Arroway – Design Craft Vol.4 阿洛维——设计工艺第四卷 大小&#xff1a;20G 信息: 云桥网络 平台获取素材&#xff01; 36种单板纹理 纹理包括漫反射、法线、凹凸、反射率、环境遮挡…

linux下有关phy的命令,linux – 如何为Debian安装b43-lpphy-installer?

b43-lpphy-installer是Ubuntu的包的名称,而不是Debian的包.你可以在jessie(Debian 8)中使用命令安装它&#xff1a;sudo apt-get install firmware-b43-installer通过内核版本,您似乎正在使用Debian 8.要了解有关debian软件包的详细信息,您可以按名称或文件搜索软件包&#xff…

Idea SpringBoot 基于 Docker容器环境进行远程调试

远程服务环境要求 对启动的jar服务命令进行修改&#xff0c;改成远程调试模式启动 eg: java -jar -agentlib:jdwptransportdt_socket,servery,suspendn,address18761 app.jar此命令特别之处是 关注监听端口&#xff1a;address18761&#xff0c;这端口号随性定义。 -agentl…

[转载]python optionparser1

原文地址&#xff1a;python optionparser1作者&#xff1a;afu7Python 有两个内建的模块用于处理命令行参数&#xff1a; 一个是 getopt&#xff0c;《Deep in python》一书中也有提到&#xff0c;只能简单处理 命令行参数&#xff1b; 另一个是 optparse&#xff0c;它功能强…

回溯法实现正则匹配判断

*&#xff1a;匹配任意个字符 &#xff1f;&#xff1a;匹配至多1个字符 <?phpclass MNode {public $strIndex;public $patIndex;public $leftMatch null; //精确匹配public $midMatch null; //模式匹配public $rightMatch null; //不能匹配public function __con…