The first time today to participate in BC, although due to the movement will delay time, but still began to do the topic.
The first question happens to be a recently done tree array type, NLOGN complexity. The rule calculation is simple. The middle part is eliminated during the interval accumulation of a length, and the change in interval length causes the partial change to be subtracted. Minus is the front k-1, plus the back n-k+1 a
The second question has not been very well understood test instructions, although thought is not difficult.
At first did not overflow two times with a long long, O (︶^︶) o ay later see the mold and the like directly ll
#include <cstdio> #include <string> #include <string.h> #include <iostream> #include < algorithm> #include <map> #include <iterator>using namespace std;typedef __int64 ll; #define N 10+447000# Define MAX (a) > (b)? ( A):(B)) #define LOWBIT (x) (-X) &x#define MOD 1000000007int n,m;ll a[n];void Update (int l,int n) {while (l<n) { a[l]= (a[l]+n)%mod; L+=lowbit (l); }}ll sum (int l) {ll ans=0; while (l>0) {ans= (A[l]+ans)%mod; L-=lowbit (l); } return ans; int main () {int i,k; int T; Freopen ("In.txt", "R", stdin); while (~SCANF ("%d", &t)) while (t--) {memset (a,0,sizeof (a)); scanf ("%d", &n); for (i=1;i<=n;i++) {scanf ("%d", &k); Update (I,K); } ll Ans=0; ll Sub=0; ll Add=0; for (k=1;k<=n;k++) {sub= (sum (k-1) +sub)%mod; add= (SUM (n-k+1) +add)%mod; Ans= (add-sub+ans+mod)%mod; } printf ("%i64d\n", ans); } return 0;}
Bestcoder Round #16 Revenge of Segment trees (tree-like array)