Lightoj 1085-all Possible Increasing subsequences tree array + discrete

Source: Internet
Author: User

http://www.lightoj.com/volume_showproblem.php?problem=1085

Test Instructions: the number of ascending subsequence sequences for a sequence.

idea: to find the law can be found that a number as the number of the end of the type of the number of all smaller than its case +1. Use a tree-like array to find it. C++11 Auto is not available on Lightoj/.\

/** @Date: 2016-12-01-21.58 * @Author: Lweleth ([email protected]) * @Link: https://github.com/* @Versi On: */#include <bits/stdc++.h> #define LL long long#define PII pair<int,int> #define MP (x, y) Make_pair ((x), (Y )) #define FI first#define se second#define PB (x) push_back ((x)) #define MMG (x) memset ((x), -1,sizeof (x)) #define MMF (x) mem  Set ((x), 0,sizeof (x)) #define MMI (x) memset ((x), INF, sizeof (x)) using namespace Std;const int INF = 0x3f3f3f3f;const int N =        1e5+20;const int mod = 1000000007;int C[n], a[n];void Add (int p, int v) {while (P < N) {C[p] + = V;        C[P]%= mod;    p + = (-P) & p;    }}int sum (int p) {int ans = 0;        while (p) {ans + = c[p];        Ans%= MoD;    P-= (-P) & p; } return ans;    int main () {int T;    int cnt = 0;    Cin >> T;        while (t--) {MMF (C);        int n;        scanf ("%d", &n);        Map<int, int>q;   for (int i = 1; I <= n; i++) {         scanf ("%d", &a[i]);        Q[a[i]] = 1;        } int c = 1;        for (Auto i = Q.begin (); I! = Q.end (); i++) I->se = c + +;        /*map<int, int>::iterator it; for (it = Q.begin (); It! = Q.end (); it++) It->se = c++;*/for (int i = 1; I <= n; i++)//Find the law to find a number            As the number of species of the end number for all cases smaller than its number +1 {int x = q[a[i]];        Add (x, sum (x-1) + 1);    } printf ("Case%d:%d\n", ++cnt, SUM (c-1)); } return 0;}

Lightoj 1085-all Possible increasing subsequences tree array + discrete

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.