题意:n个数1~n(n<=1e18)依次放在一个数组中,第i个数位置为2i-1,其它地方是空的.现在重复以下操作:将最右边的数放到离其左边最近的空的位置,直到所有数移到前一半的位置中.有q<=200000个询问,问你第i个数最终再哪个位置. 题解:这题被某人秒了,所以估计核心代码量不超过2行,于是XJB找规律,找了三四十分钟A了,不明觉厉. 找规律的方向是按照数据必定是个qlogn的算法,输入一个n,肯定要不断除2,又发现前n/2个数一直不动,又发现貌似后n/2的数有些神秘的间隔.最后XJB写…
题目链接: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 个数,然后从下标 1 开始将这 N 个数每隔一位放置一个,直到 N 个数被安排完,现在有一个操作就是每次将数列中最右边的数向离其左边最近的空缺处填上,一直这样子填,直到下标 1~N 被填满,然后现在给出 Q 个询问,每个询问给出一个 X ,你需要回答下标为 X 的位置填放了什么数? 分析 :   初始状态每个数都处于奇数位,且可以根据位置下标得到具体的数是什么,即 num = (pos>>1)  + 1 观察到当最后填充操作完成时,每个奇数位置的…
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…
题意: Dima是一名初级程序员. 在他的工作中,他经常不断地重复以下操作:从数组中删除每个第二个元素. 有一天,他对这个问题的解决方案感到厌倦,他提出了以下华丽的算法. 假设有一长度为2n的数组,最初的数组包含从1到n的n个数字,数字i位于序号为2i - 1的单元格中(序号从1开始编号),并且数组的其他单元格为空.每个步骤你需要选择一个最大序号的非空单元格,并将其中的数字移动到它左边最近的空单元格.一直循环该过程,直到所有n个数字出现在数组的前n个单元格中.例如,如果n = 4,则数组更改如下…
二次联通门 : Codeforces 221d D. Little Elephant and Array /* Codeforces 221d D. Little Elephant and Array 题意 : 询问一段区间中出现次数等于自身的数的个数 正解是dp 莫队水过, 作为我莫队的入门题 myj的思路 66 把所有需查询的区间排序 当前查询区间的答案为上一个区间的答案通过多次的区间移动得出 */ #include <algorithm> #include <cstdio>…
Codeforces 633C Spy Syndrome 2 | Trie树裸题 一个由许多空格隔开的单词组成的字符串,进行了以下操作:把所有字符变成小写,把每个单词颠倒过来,然后去掉单词间的空格.已知操作后的字符串以及可能出现的所有单词,请输出原字符串(多组解只输出一个). 我犯的错误:数组的trie树--如果根节点是1--则其余节点要从2开始啊啊啊 #include <cstdio> #include <cstring> #include <algorithm> u…
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:https://codeforces.com/contest/1080. A.Petya and Origami 题意:Petya要发出n张邀请函,每张请函需要2张红纸,5张绿纸,8张蓝纸.现在商店里有一些不同颜色的笔记本,每本中有k张颜色相同的纸,求最少要买几本笔记本. 这题就是一道模拟题,算出每种…
工业题 题解 抱歉,题解没时间写了 代码 #include<bits/stdc++.h> using namespace std; #define ll long long #define A 6666666 #define mod 998244353 ll jie[A],ni[A],acnt[A],bcnt[A]; ll fheng[A],fshu[A]; ll n,m,a,b; ll meng(ll x,ll k){ ll ans=1; for(;k;k>>=1,x=x*x%m…
T1:工业题 基本思路   这题有一个重要的小转化: 我们将原来的函数看作一个矩阵,\(f(i,j-1)*a\)相当于从\(j-1\)向右走一步并贡献a,\(f(i-1,j)*b\)相当于从\(i-1\)向下走一步并贡献b   那么问题就转化成了求从第\(0\)行与第\(0\)列的所有点走到点\((m,n)\)的所有方案数的总贡献   在一个点,对于他之前的点的所有走法,他都有可能向下或右走并带来贡献,所以是统计所有方案数.   易知从点\((i,j)\)到点\((m,n)\)的走的步数是\(m…
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…
B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/problem/B Description Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he…
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…
A. Co-prime Array 题目连接: http://www.codeforces.com/contest/660/problem/A Description You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want…
传送门: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…
题目链接: A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you…
题目链接: 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 d…
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…