D. Turtles Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/103/problem/D Description As you know, the most intelligent beings on the Earth are, of course, cows. This conclusion was reached long ago by the Martian aliens, a…
Description 给一个序列 \(a\) ,\(m\) 次询问,每次询问给出 \(t, k\) .求 \(a_t + a_{t+k}+a_{t+2k}+\cdots+a_{t+pk}\) 其中 \(t+pk \leq n\) 且 \(t+(p+1)k > n\) \(n,m \leq 300000,a_i \leq 10^9\) Solution 对 \(k\) 即公差分块.设定一个 \(T\) . 当 \(k > T\) 时,直接暴力算.复杂度 \(O(\frac{n}{T})\):…
题意: 给定序列 $a,m$ 次询问,每次询问给出 $t,k$. 求 $a_{t}+a_{t+k}+a_{t+2k}+.....a_{t+pk}$ 其中 $t+(p+1)k>n$ 题解: 这种跳步数问题可以用根号分治来解决: 对于 $k$ 比较大的询问直接暴力跳,而对于 $k$ 较小的部分就通过预处理的手段来做. 我们现在只考虑 $k<\sqrt n$ 的情况,即需要我们预处理的部分. 如果直接维护 $f[i][j]$ 表示从 $i$ 开始以 $j$ 的步伐跳到 $n$ 所能得到的点权和的话空…
先对b从小到大sort,判断b是不是比sqrt(n)大,是的话就直接暴力,不是的话就用dp维护一下 dp[i]表示以nb为等差,i为起点的答案,可以节省nb相同的情况 #include<bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define pii pair<int,int> #define C 0.5772156649 #define p…
http://codeforces.com/contest/103/problem/D 对于b大于 sqrt(n)的,暴力处理的话,那么算出每个的复杂度是sqrt(n),就是把n分成了sqrt(n)段, 其他的,b小于sqrt(n)的,那么不同 b值最多只有sqrt(n)个,但是询问可能达到q个.考虑到,如果b相同的话,放在一起,能不能记录一个结果呢?如果能,那么就最多是sqrt(n)个不同的询问. 用dp[pos]表示从pos这个位置开始,间隔为b的答案值. 那么需要从后面往前dp,每次转移d…
题目链接: http://codeforces.com/contest/103/problem/D D. Time to Raid Cowavans time limit per test:4 secondsmemory limit per test:70 megabytes 问题描述 As you know, the most intelligent beings on the Earth are, of course, cows. This conclusion was reached lo…
Time to Raid Cowavans 题意: 询问 下标满足 a + b * k 的和是多少. 题解: 将询问分块. 将b >= blo直接算出答案. 否则存下来. 存下来之后,对于每个b扫一遍数组,然后同时处理相同b的询问. 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt","r",stdin); freopen("_o…
Portal Description 给出长度为\(n(n\leq3\times10^5)\)的序列\(\{a_n\}\),进行\(q(q\leq3\times10^5)\)次询问:给出\(x,y\),求\(\sum_{i=x,i+=y}^n a_i\). Solution 将询问离线,按\(y\)排序. 对于\(y<\sqrt n\),对于每个\(y\)计算sum[i]表示\(x=i\)时的答案.计算sum[i]复杂度为\(O(n)\),每次询问为\(O(1)\),对于\(\sqrt n\)个…
Time to Raid Cowavans 题意:一共有n头牛, 每头牛有一个重量,m次询问, 每次询问有a,b 求出 a,a+b,a+2b的牛的重量和. 题解:对于m次询问,b>sqrt(n)的时候我们直接把结果跑出来,当b<sqrt(n)的时候我们离线询问,算出所有一个b的任意一起点的值. 复杂度为 q*sqrt(n); 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_i…
题意: 思路:院赛防AK题,然而还没来得及做就被数据出锅的题坑了…… #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<iostream> #include<algorithm> #include<map> #include<set> #include<queue> #include<vec…