先对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…
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…
Discription As you know, the most intelligent beings on the Earth are, of course, cows. This conclusion was reached long ago by the Martian aliens, as well as a number of other intelligent civilizations from outer space. Sometimes cows gather into co…
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…
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…
D - Conveyor Belts 思路:分块dp, 对于修改将对应的块再dp一次. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define y1 skldjfskldjg #define y2 skldfjsklejg using namespace std; ;…
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…
题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include…
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\)个…