codeforces 949B A Leapfrog in the Array】的更多相关文章

B. A Leapfrog in the Array time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation aga…
题意: 现在给你一个n,表示有2*n-1个方格,第奇数方格上会有一个数字 1-n按顺序放.第偶数个方格上是没有数字的.变动规则是排在最后一个位置的数字,移动到它前边最近的空位 . 直到数字之间没有空位.之后有q次询问.每次问你这个位置上的数是多少 题解: 1:  1 2:  1 2 3:  1 3 2 4:  1 3 2 4 5:  1 5 2 4 3 6:  1 4 2 6 3 5 7:  1 6 2 5 3 7 4 8:  1 5 2 7 3 6 4 8 9:  1 9 2 6 3 8 4…
题目链接:A Leapfrog in the Array 题意:给出1-n的n个数,从小到大每隔一个位置放一个数.现在从大到小把数往前移动,每次把最右边的数移动最靠右边的空格处直到n个数都在前n个位置. 题解:从数据的大小就可以看出这题一定是推公式的题,那么假设现在一个数刚刚移动到了x位置,那么这个数之前一定有x/2个数没有移动过,所有这个数后面就有n-x/2个数(这里包括x本身).所以x在移动之前的位置就是x+(n-x/2).所以一直将所要求的x 按 x =  x+(n-x/2)这个公式一直向…
题意:n个数1~n(n<=1e18)依次放在一个数组中,第i个数位置为2i-1,其它地方是空的.现在重复以下操作:将最右边的数放到离其左边最近的空的位置,直到所有数移到前一半的位置中.有q<=200000个询问,问你第i个数最终再哪个位置. 题解:这题被某人秒了,所以估计核心代码量不超过2行,于是XJB找规律,找了三四十分钟A了,不明觉厉. 找规律的方向是按照数据必定是个qlogn的算法,输入一个n,肯定要不断除2,又发现前n/2个数一直不动,又发现貌似后n/2的数有些神秘的间隔.最后XJB写…
题意 : 给出 N 表示有标号 1~N 的 N 个数,然后从下标 1 开始将这 N 个数每隔一位放置一个,直到 N 个数被安排完,现在有一个操作就是每次将数列中最右边的数向离其左边最近的空缺处填上,一直这样子填,直到下标 1~N 被填满,然后现在给出 Q 个询问,每个询问给出一个 X ,你需要回答下标为 X 的位置填放了什么数? 分析 :   初始状态每个数都处于奇数位,且可以根据位置下标得到具体的数是什么,即 num = (pos>>1)  + 1 观察到当最后填充操作完成时,每个奇数位置的…
二次联通门 : Codeforces 221d D. Little Elephant and Array /* Codeforces 221d D. Little Elephant and Array 题意 : 询问一段区间中出现次数等于自身的数的个数 正解是dp 莫队水过, 作为我莫队的入门题 myj的思路 66 把所有需查询的区间排序 当前查询区间的答案为上一个区间的答案通过多次的区间移动得出 */ #include <algorithm> #include <cstdio>…
http://codeforces.com/contest/950/problem/D 前n/2个格子的奇数下标的数没有参与移动 候n/2个格子的奇数下标的数一定是一路移向偶数下标移 所以还原数的初始位置时,让数沿原来的路线向右移动,到达的第一个奇数下标就是这个数的初始位置 在初始位置a的数是(a+1)/2 现在就剩下了如何还原数向左移的过程 假设数a最后移到了位置x, 在位置x之前有 x/2 个奇数位有数 a移到了x,说明除了前面的数,剩下的数都在x之后 所以位置x之后有n-x/2-1 个数,…
A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the…
http://codeforces.com/problemset/problem/949/B Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored wit…
题目链接: http://codeforces.com/problemset/problem/498/C C. Array and Operations time limit per test1 secondmemory limit per test256 megabytes 问题描述 You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pair…
传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions i…
题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比较,因此问题最关键的是,记录每个数第一次出现的位置,即左值.因为要保证次数是出现最多,因此需要一个cnt[]数组来记录出现次数.然后当最多出现次数与当前cnt[x]次数相同时,要选择区间较短的,再更新左右区间值. 赛中短路竟然想不出来~~~泪啊~~泪啊- >_< #include <iost…
题目链接:http://codeforces.com/problemset/problem/295/A 我的做法,两次线段树 #include <cstdio> #include <cstring> const int N = 100005; long long sumv[N * 3]; long long add[N * 3]; long long a[N]; struct opera { int l, r; long long d; } op[N]; void pushdown…
time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output Ayoub had an array aaa of integers of size nnn and this array had two interesting properties: All the integers in the array were between…
Codeforces 洛谷:咕咕咕 CF少有的大数据结构题. 思路 考虑一些欧拉函数的性质: \[ \varphi(p)=p-1\\ \varphi(p^k)=p^{k-1}\times (p-1)=p^k \times \frac{p-1}{p},k>0\\ \varphi(ab)=\varphi(a)\varphi(b),gcd(a,b)=1\\ \dots \] 有上面三个就够了. 要求 \[ \varphi(\prod a_i) \] 可以考虑把\(\prod a_i\)拆成 \[ \p…
Please, another Queries on Array? 利用欧拉函数的计算方法, 用线段树搞一搞就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, i…
D. Little Elephant and Array time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from…
http://codeforces.com/contest/220/problem/B 题意:给出一个数组,给出m组询问,问区间中出现a[i] 次的有多少个. sl: 很显然的离线问题了. 大视野菜花的加强版. 可以这么搞,假设当前走到了a 看看之前是不是有a个a有的话就在a-k处 减1 同时补上上次的操作就行.具体键代码. http://codeforces.com/contest/220/submission/6948720…
B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. Amr doesn't c…
t题目链接:http://codeforces.com/contest/1291/problem/B 思路: 用极端的情况去考虑问题,会变得很简单. 无论是单调递增,单调递减,或者中间高两边低的情况都可以变为三种模型. (1)0,1,2,3,4........n-3,n-2,n-1 (2)n-1,n-2,n-3.....3,2,1,0 (3)0,1,2,3,4,.....n.......4,3,2,1,0 那么,我们只需要查看当前位置是否大于等于极端模型(3)在这个位置的数值,如果当前位置不满足…
一个人只要存在债务关系,那么他的债务可以和这整个债务关系网中任何人连边,和他当初借出或欠下的人没有关系.只需要记录他的债务值即可. #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; vector<array<> >v; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); lon…
You are given an array aa consisting of nn integers. In one move, you can choose two indices 1≤i,j≤n1≤i,j≤n such that i≠ji≠j and set ai:=ajai:=aj . You can perform such moves any number of times (possibly, zero). You can choose different indices in d…
Codeforces 题目传送门 & 洛谷题目传送门 *2800 的 DS,不过还是被我自己想出来了 u1s1 这个 D1C 比某些 D1D 不知道难到什么地方去了 首先碰到这类问题我们肯定考虑枚举什么东西,然后在枚举过程中用个什么东西维护答案,求出其对答案的贡献.此题一个很直观的想法是枚举左端点,但很遗憾此题涉及 gcd,不太好直接维护.故我们换个想法,枚举答案. 我们先预处理出每个数的所有因子--这个显然可以在 \(n\ln n\) 的时间内求出.然后从大到小动态地枚举一个指针 \(i\).…
题解上说的很清楚了,我照着写的,表示膜拜题解 然后时间复杂度我觉得应该是O(nlogn),虽然常数略大,预处理和倒着扫,都是O(nlogn) #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <vector> using namespace std; typedef long long LL; ; ],a[N<<…
线段树的区间更新与区间求和...一颗这样的线段树用两次... 先扫描1~k...用线段树统计出每个操作执行的次数... 那么每个操作就变成了 op. l  , op.r , op.c= times* op.c 清空线段树..将初始的a1,a2~~an放入..用每个操作来更新值~~ Program: #include<iostream> #include<stdio.h> #include<string.h> #include<set> #include &l…
题意: 给以一个定义, F(l, r) 的值表示序列 A[1:n]的子序列 A[1....(l-1),(r+1)...n] 之中 任意两个数的最大公约数的最大值. 求 Sum=∑i=1N∑j=1N(F(i,j)),(i≠j) 思路: 英文题解 大致解释一下: H[i] 表示 F(l, r) <= i 区间 (l,r) 的个数. V[A[i]] = { b1, b2, .... bk }, 其中 A[i] % bx == 0 还有一个next 数组 设 next[j] = k, 表示 F(l, k…
因为只有奇偶之间有操作, 可以看出是二分图, 然后拆质因子, 二分图最大匹配求答案就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #defin…
看见$a_i\leq 200000$和gcd,就大概知道是要枚举gcd也就是答案了... 因为答案是max,可以发现我们很容易算出<=i的答案,但是很难求出单个i的答案,所以我们可以运用差分的思想. $H[i]$表示$f(l,r)<=i$的$(l,r)$对数,显然这个是随i增大而单调不降的,考虑怎么计算出这个. $next[l]$表示满足$f(l,r)<=i$的最小的$r$,则有$H[i]=\sum_{l=1}^{n}n-next[l]+1$.显然$next[l]$也会随着$i$变小而单…
题意: 给出1<=n<=10^18和1<=q<=200000,有一个长度为2*n-1的数组,初始时单数位置存(i+1)/2,双数位置是空的.每次找出最右边的一个数将它跳到离它最近的左边的空格,反复操作直到前n个数被充满 .q个询问,每个询问给出一个数x<=n,输出最终的序列x位置的数是什么. 分析: 一看数据规模和这个题就大概想到是数学题,然后试着找规律推式子.按照蒟蒻我的惯例这种题先写暴力找规律.然后发现,每次跳,第一次跳跳一个,再一次跳两个,一直到跳到n-1个. 那么从左…
考虑在位置 \(p\) 的青蛙. 如果 \(p\) 是奇数,答案显然是 \((p+1)/2\). 否则,由于未跳时 \(p\) 左边有 \(p/2\) 只,则 \(p\) 右边有 \(n-p/2\) 只,则这青蛙是从 \(p+n-p/2\) 处跳过来的. #include <iostream> #include <cstdio> using namespace std; typedef long long ll; int q; ll n, uu; ll f(ll x){ if(x&…