Topic Links:
Fzu Problem 2236 14th target
Title Description:
Give a sequence of n numbers and ask how many of the strictly ascending sequences are in this sequence? does not require continuous
Problem Solving Ideas:
We also encountered the problem of optimizing DP with line-segment tree, and the number of programs within the expressed interval was saved in the segment tree node. First discretization sequence (in ascending order), build, and then in the order of no sort before the line to add points to the tree, each query less than the number of scenarios +1, is the current node insert can affect the number of scenarios. Add a new number to the corresponding position in the segment tree.
1#include <cstdio>2#include <queue>3#include <stack>4#include <cmath>5#include <cstring>6#include <iostream>7#include <algorithm>8 using namespacestd;9 Ten #defineLson 2*root One #defineRson 2*root+1 A typedef __int64 LL; - ConstLL mod =1000000007; - ConstLL inf= 1e14+7; the Const intMAXN =100010; - - structnode - { + intL, R; - LL num; + intMid () A { at return(L + R)/2; - } -} tree[maxn*4]; - LL A[MAXN], B[MAXN]; - - voidBuild (intRootintLintR) in { -TREE[ROOT].L =l; toTREE[ROOT].R =R; +Tree[root].num =0; - if(L = =R) the return ; * $ Build (Lson, L, Tree[root].mid ());Panax NotoginsengBuild (Rson, Tree[root].mid () +1, R); - } the voidInsert (intRoot, LL x,inty) + { A if(TREE[ROOT].L = = TREE[ROOT].R && TREE[ROOT].L = =y) the { +Tree[root].num = (tree[root].num + x)%MoD; - return ; $ } $ - if(Tree[root].mid () >=y) - Insert (Lson, x, y); the Else - Insert (Rson, x, y);WuyiTree[root].num = (tree[lson].num + tree[rson].num)%MoD; the } -LL Query (intRootintLintR) Wu { - if(TREE[ROOT].L = = L && TREE[ROOT].R = =R) About returnTree[root].num; $ - if(Tree[root].mid () >=R) - returnquery (Lson, L, R); - Else if(Tree[root].mid () <l) A returnquery (Rson, L, R); + Else the { -LL num =0; $num + =query (Lson, L, Tree[root].mid ()); thenum + = query (Rson, Tree[root].mid () +1, R); the returnNum%MoD; the } the } - in intMain () the { the intN; About the while(SCANF ("%d", &n)! =EOF) the { the for(intI=0; i<n; i++) + { -scanf ("%i64d", &a[i]); theB[i] =A[i];Bayi } the theSort (A, A +n); - intm = Unique (A, a+n)-A; - theLL ans =0; theBuild (1,0, m); the for(intI=0; i<n; i++) the { -LL nu, tmp = Lower_bound (A, a+m, B[i])-A; the if(TMP = =0) theNu =0; the Else94Nu = Query (1,0, tmp-1); the theInsert (1, nu+1, TMP); the }98 Aboutprintf ("%i64d\n", Query (1,0, M)); - }101 return 0;102 }103 ///4 1 2) 2 3
Fzu Problem 2236 14th target (segment tree + DP)