cf359D Pair of Numbers】的更多相关文章

Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, …
利用区间 gcd 个数不超过 log 种来做就可以了~ code: #include <bits/stdc++.h> #define N 300005 #define setIO(s) freopen(s".in","r",stdin) using namespace std; int n; set<int>s; struct solve { int A[N],pos[N],len[N],gc[N],b[N],top,tmp; void ge…
D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l…
D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l…
https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数,问一个区间内所有的数是否能被其其中一个数所全部整除,求出满足条件的区间的长度最大值,并输出这样的区间的个数与它们的左端点. 换句话将,求区间GCD=区间MIN的最大长度区间. 明显st表解决. 对于最大区间长度,二分判断即可. (因为在poj做过类似的题所以思路能很快……就是题看不懂有点难,所以特…
题意:给定一个正整数数组,求最长的区间,使得该区间内存在一个元素,它能整除该区间的每个元素. 析:暴力每一个可能的区间,从数组的第一个元素开始考虑,向两边延伸,设延伸到的最左边的点为l, 最右边的点为r.那么我们下一点考虑r+1即可, 因为[l, r]之间不会有更优解. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string>…
Codeforces Round #209 (Div. 2) D:http://codeforces.com/contest/359/problem/D 题意:给以一个n个数的序列,然后问你最大的区间l,r,在这个区间里面,存在一个数是这个区间所有数的约数,如果这个区间有多个,统计有多少个以及每个区间的左端点. 题解:这一题,别人用了一个很特殊的找发,让我叹为观止.哎,没有数学功底以及很强的推理能力,真的有点力不从心啊.说说别人是怎么找的吧.首先,从第一个数开始,往右边找,然后找到第一个不是a[…
http://codeforces.com/contest/359/problem/D 题意:给你n个数,然后找出在[l,r]中有一个数a[j],l<=j<=r,在[l,r]中的所有数都是a[j]的倍数.找出符合这样的r-l最长长度的个数,输出r-l最长长度的个数和长度,然后输出符合的l的序列. 枚举每一个数,然后向左找到l,向右找到r,r-l就是所求的符合一种,这样就可以找到最长的长度 #include <cstdio> #include <cstring> #inc…
原题 RMQ st表棵题 要想让一个区间里的所有数都可以整除其中一个数,那么他一定是这个区间内的最小值,并且同时是这个区间的gcd.然后这个问题就转化成了RMQ问题. 维护两个st表,分别是最小值和gcd,然后二分最长区间长度,用st表check即可. #include<cstdio> #include<algorithm> #include<cmath> #define N 300010 using namespace std; int n,a[N],mn[N][20…
题面: 给一个序列,求最长的合法区间,合法被定义为这个序列的gcd=区间最小值 输出最长合法区间个数,r-l长度 接下来输出每个合法区间的左端点 题解: 由于区间gcd满足单调性,所以我们可以二分区间长度,用st表维护区间最小值和gcd即可 #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #define N 300100 using namespace std; i…
任意门:http://poj.org/problem?id=1320 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3181   Accepted: 1776 Description A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the…
传送门 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2529   Accepted: 1406 Description A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the street. Every evening she walks…
Sorting is often useful as the first step in many different tasks. The most common task is to make finding things easier, but there are other uses also. Challenge Given a list of unsorted numbers, can you find the numbers that have the smallest absol…
A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the street. Every evening she walks her dog by leaving her house and randomly turning left or right and walking to the end of the street and back. On…
Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3078   Accepted: 1725 Description A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the street. Every evening she walks her…
#include<stdio.h> //we have defined the necessary header files here for this problem. //If additional header files are needed in your program, please import here. /* * 函数int deal(int n,int m):处理达到(n,m)转化为(1,1)时需要的次数 首先保证n<=m 当n==1时,deal(1,m)应该返回…
Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2753   Accepted: 1530 Description A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the street. Every evening she walks her…
Design and implement a TwoSum class. It should support the following operations:add and find. add - Add the number to an internal data structure.find - Find if there exists any pair of numbers which sum is equal to the value. For example,add(1); add(…
关于transition的几个基本点: 1. transition()是针对与每个DOM element的,每个DOM element的transition并不会影响其他DOM element的transition操作: 2. 对于每一个DOM element的transition每次只能执行一个,如果在一个DOM element上添加了许多transition操作,只有最后一个会起作用,前面的都会被覆盖掉.但是例外是,当这些transition是chaining的形式连接的时候,这些trans…
    Built-in Functions     abs() divmod() input() open() staticmethod() all() enumerate() int() ord() str() any() eval() isinstance() pow() sum() basestring() execfile() issubclass() print() super() bin() file() iter() property() tuple() bool() filte…
一.深浅拷贝 import copy #浅拷贝 n1={'k1':'wu','k2':123,'k3':['carl',852]} n2=n1 n3=copy.copy(n1) print(id(n1)) print(id(n2)) print(id(n3)) print(id(n1['k3'])) print(id(n3['k3'])) #深拷贝 n4=copy.deepcopy(n1) print(id(n4)) print(id(n1['k3'])) print(id(n4['k3']))…
Design and implement a TwoSum class. It should support the following operations: add and find. add - Add the number to an internal data structure.find - Find if there exists any pair of numbers which sum is equal to the value. For example, add(1); ad…
Monday, May 7, 2012 The Lambda Calculus for Absolute Dummies (like myself)   If there is one highly underrated concept in philosophy today, it is computation. Why is it so important? Because computationalism is the new mechanism. For millennia, philo…
学习总结 1.函数有利于我们可以省去重复的代码,函数可以使程序更加模块化,从而有利于程序的阅读.修改和完善.我们在系统设计或架构设计的时候,往往追求的是模块化.组件化.松耦合,而函数就是其代码的表现.许多程序员喜欢把函数看作“黑盒子”,即对应一定的输入产生特定的结果或返回某个数值,而黑盒子的内部行为并不需要考虑,然而有助于把精力投入到程序整体设计而不是其实现细节.按照C设计原则,我们不应为每个任务编写一个单独的函数,而应该尽量把函数的功能进行抽象设计到达通用目的. 2.函数的组成部分有函数类型.…
More is better Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others)Total Submission(s): 24825    Accepted Submission(s): 8911 Problem Description Mr Wang wants some boys to help him with a project. Because the project…
TELE Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4957   Accepted: 2726 Description A TV-network plans to broadcast an important football match. Their network of transmitters and users can be represented as a tree. The root of the tre…
2. Built-in Functions https://docs.python.org/3.4/library/functions.html?highlight=file The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order.     Built-in Funct…
[codeforces 339]E. Three Swaps 试题描述 Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row looks as foll…
A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number th…
原题链接在这里:https://leetcode.com/problems/two-sum-iii-data-structure-design/ 题目: Design and implement a TwoSum class. It should support the following operations: add and find. add - Add the number to an internal data structure.find - Find if there exists…