Bupt Summer Training #7 for Grade 14

Source: Internet
Author: User
Tags cmath

A. Codeforces 396C

Test instructions doesn't describe it.

for the first type of Operation 1 v x k , we can give v subtree all plus (x+depth[v]*k) the value.

for the second type of operation 2 v . After querying the values of each node, you only need to subtract depth[v]*k to get the answer. The k inside is the and of the k that has an effect on the V node.

By pushing formulas on paper, it's easy to know why it's right.

There are two tree-like arrays to maintain, of course, the operation of adding an entire subtrees tree is to pre-process the DFS sequence, convert the tree to linear, and then operate in the interval.

The interval operation can be either a line tree or a tree-like array. Of course, a tree-like array is relatively simple. I'm using a tree-like array.

There is another way to do this is to use the tree chain to split, if you learn the tree chain, you can try to do a bit ~


Code:
#include <iostream> #include <cstdio> #include <stack> #include <cstring> #include <queue > #include <algorithm> #include <cmath>//#include <unordered_map> #define N 500010//#define Lson x <<1//#define Rson x<<1|1//#define MID ((LT[X].L+LT[X].R)/2)//#define ID (x, y) ((x) *m+ (y))//#define CHECK (x , y) ((x) >=0 && (x) <n && (y) >=0 && (y) <m) using namespace Std;typedef Pair<long long        , long long> pii;const long long inf=0x3f3f3f3f;const long long mod = 1e9+7;void Open () {#ifndef Online_judge        Freopen ("D:/in.txt", "R", stdin);    Freopen ("D:/my.txt", "w", stdout); #endif//Online_judge}long long N, M, Tn;long long c1[n], c2[n], dep[n], st[n], Ed[n];vector<long long> g[n];void A DD (Long long c[], long long x, Long long Val) {for (long long i = x; I <= n+10; i + = ((i) & i)) c[i] = (C[i] + V AL)% MoD;}    Long Long getsum (long long c[], long long x) {long Long rnt = 0; For (LonG Long I=x;i>0;i-= ((-i) & i) Rnt = (rnt + c[i])%mod; return rnt;}    void Dfs (Long long u, Long long D) {dep[u] = D; st[u] = ++tn;    For (Long long i=0;i<g[u].size (); i++) Dfs (G[u][i], d+1); Ed[u] = Tn;}    int main () {Open ();    Tn = 0;    scanf ("%i64d", &n);        For (long long i=2;i<=n;i++) {long long x;        scanf ("%i64d", &x);    G[x].push_back (i);    } DFS (1, 0);    scanf ("%i64d", &m);        while (m--) {Long long op;        scanf ("%i64d", &op);            if (op = = 1) {Long long V, X, K;            scanf ("%i64d%i64d%i64d", &v, &x, &k);            Add (C1, St[v], x + k * Dep[v]% mod);            Add (c1, Ed[v]+1,-(x + k * Dep[v]% mod));            Add (c2, St[v], k);        Add (c2, ed[v]+1,-K);            }else {long long V;            scanf ("%i64d", &v);            Long Long TMP = Getsum (c1, st[v])-Getsum (C2, St[v]) * DEP[V];            TMP = (tmp%mod + mod)%mod; printf ("%i64d\n ", TMP); }} return 0;}



B. Codeforces 362CClick here to see the puzzle ~ ~

C. POJ 3468 A simple problem with integers point here to see the problem ~ ~ Here directly with the line tree can be, line segment tree interval to modify the basic skills do not say, I was doing this topic is to learn the tree array of interval modified interval query posture, So it's written in a tree-like array.

D. Codeforces 546DThis problem is easy to understand after test instructions, because the title needs to guarantee the maximum number of games, which is of courseNthe quality factor is taken out one by one, so this problem requires only5000000How many factorization are there in all the numbers within?(the repetition also needs to be calculated)you can, as for the later factorial form just let you ask for a range and only.

Code:
#include <iostream> #include <cstdio> #include <stack> #include <cstring> #include <queue > #include <algorithm> #include <cmath>//#include <unordered_map> #define N 5000010using namespace        Std;typedef pair<long long,long long> pii;const Long Long inf=0x3f3f3f3f;void Open () {#ifndef Online_judge        Freopen ("D:/in.txt", "R", stdin);    Freopen ("D:/my.txt", "w", stdout);    #endif//Online_judge}//long long Pn;long long vis[n];void get_prime () {memset (vis,0,sizeof (VIS));        For (long long i=2;i<n;i++) {if (vis[i]!=0) continue;        Vis[i]=1;            for (long j=i*2;j<n;j+=i) {long long tmp = j;            Long Long rnt=0;                while (tmp%i==0) {tmp/=i;            rnt++;        } vis[j]+=rnt;    }}}long Long A[n];int main () {//open ();    Get_prime ();    a[0]=0;    For (long long i=1;i<n;i++) a[i]=vis[i]+a[i-1]; Long Long T    scanf ("%i64d", &t);        while (t--) {Long Long A, a, b;        scanf ("%i64d%i64d", &a,&b);    printf ("%i64d\n", A[a]-a[b]); } return 0;}

E. POJ 2533 longest Ordered subsequence。。 The longest ascending sub-sequence, all kinds of books have, here do not say, and the amount of data only 1000, casual violence DP do the right here

If where not understand can direct Q me.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bupt Summer Training #7 for Grade 14

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.