10-4 National Day Seventh simulation game

Source: Internet
Author: User

10-4 National Day Seventh simulation T1 Factory (Factory)

Water

#include<iostream>#include<cstdio>#define int long longusing namespace std;inline int read(){    int sum=0,f=1;    char ch=getchar();    while(ch<'0'||ch>'9'){        if(ch=='-')f=-1;        ch=getchar();    }    while(ch>='0'&&ch<='9'){        sum=(sum<<1)+(sum<<3)+ch-'0';        ch=getchar();    }    return sum*f;}const int wx=10017;int n,s,ans;int f[wx],a[wx],c[wx];signed main(){    freopen("factory.in","r",stdin);    freopen("factory.out","w",stdout);    n=read();s=read();    for(int i=1;i<=n;i++){        c[i]=read();a[i]=read();    }    f[1]=c[1];    ans+=(f[1]*a[1]);    for(int i=2;i<=n;i++){        f[i]=min(f[i-1]+s,c[i]);        ans+=(f[i]*a[i]);    }    printf("%lld\n",ans);    fclose(stdin);    fclose(stdout);    return 0;}
T2 Railway (Trainfair)

Description

In MS State-owned N cities, numbering from 1 to N, of which 1th cities are the capital of the state of Ms.

In MS country, there is only one railroad company, which operates a railway line connected to each city by M, each connecting two different cities in both directions. Through these lines, we can pass between any two cities.

Originally, it took only 1 cents to ride a line. However, due to poor business, the railway company proposed plans, in the next Q years, each year to a certain line price of 2 cents. Guarantee that a line will not be raised many times.

In addition, the railway company carries out a survey of residents ' satisfaction every year in every city. The residents of each city were very satisfied with the service of the railway company, but it was probably after the price of the line. Each year's satisfaction survey will be carried out after the year's price increase plan is implemented. If a city's residents spend the least amount of money they need to go to the capital by train in the same year, they will be unhappy with the railroad company, compared with the increase before the plan. The residents of the capital will never be dissatisfied with the railroad company.

Before the plan is implemented, you need to help the railway companies to count the number of urban residents who will be dissatisfied with the railway companies in each of the years ahead.

Input

The first line of the input file contains three positive integers N, M, Q, respectively, indicating the number of cities in MS country, the number of railway routes, and the length of time the plan will be implemented.

The next M line, where line I contains 22 integer ui,vi, indicates that Route II is connected to two cities numbered Ui and Vi.

Next Q line, where line J contains an integer RJ, indicating that the plan after the implementation of the J year will allow the first Rj line price increase.

Output

Output Q line, where line J represents the number of cities where the residents of the J year are dissatisfied with the railway company.

The shortest circuit has a property:

For an edge between x and Y to be set to Z, then if Dis[x]=dis[y]+edge[z].dis or Dis[y]=dis[x]+edge[z].dis, then we will select this side individually, then all the edges that meet this situation are a topological diagram.

For this nature to do things, analysis of the problem, the Benquan from a corner of the two angle is actually equivalent to delete this side. Because he is equivalent to the case of the shortest-circuiting change of the point 1 of the back points and the deletion.

Then we can take out all the edges that meet the above properties and build a topology diagram.

Why take these sides out?

For the red side, it is clear that he is not in line with the above-mentioned nature of the edge, that is not the shortest way side, then if this side changes, no point will have any effect.

In other words, every point and one of the shortest circuits will change only because of the change of the side of the path from one to the other, so it is clear.

Take out the edges of all the shortest paths to form a topological map, start typing each of the edges to be deleted, to find the edge of the two end of the distance 1 points farther from the point, then after judging this edge is the shortest way on the edge, we can reduce this point in the degree of one, while the edge of the mark cleared.

So if this point is reduced to 0, then it means there is no way to take the shortest route from the other path to 1, so the global increment ans can add one.

We can also think of, if delete this point, then certainly will affect the back point, so we have to start from this point backward extension, that is, the point of all the out side of all the deletion, in judging whether there will be a new point in the degree into 0, so that ans++, and then continue downward.

Because each point can only be deleted once, so the complexity: O (N)

Code

#include <iostream> #include <cstdio> #include <queue>using namespace Std;const int Wx=200017;inline    int read () {int sum=0,f=1;    Char Ch=getchar (); while (ch< ' 0 ' | |        Ch> ' 9 ') {if (ch== '-') f=-1;    Ch=getchar ();        } while (ch>= ' 0 ' &&ch<= ' 9 ') {sum= (sum<<1) + (sum<<3) +ch-' 0 ';    Ch=getchar (); } return sum*f;} struct e{int nxt,to,dis,flag,he;} Edge[wx*2];int head[wx],dep[wx],in[wx],vis[wx];int num,n,m,q,ans,x,y,z;void Add (int from,int to,int dis) {Edge[++num]    . Nxt=head[from];    Edge[num].to=to;    Edge[num].he=from;    Edge[num].dis=dis; Head[from]=num;}    Queue<int > Qq;void dij (int u) {for (int i=1;i<=n;i++) dep[i]=2147483642,vis[i]=0;    Dep[1]=1;qq.push (1); vis[1]=1;        while (Qq.size ()) {int U=qq.front (); Qq.pop ();        vis[u]=0;            for (int i=head[u];i;i=edge[i].nxt) {int v=edge[i].to;     if (Dep[v]>dep[u]+edge[i].dis) {Dep[v]=dep[u]+edge[i].dis;           if (!vis[v]) {vis[v]=1;                Qq.push (v);            }}}}}void mark () {for (int. u=1;u<=n;u++) {for (int i=head[u];i;i=edge[i].nxt) {            int v=edge[i].to;            if (Dep[u]>dep[v]) continue;            if (dep[u]==dep[v]-1) {edge[i].flag=1;in[v]++;    }}}}int find (int now) {int re=0;        for (int i=head[now];i;i=edge[i].nxt) {if (!edge[i].flag) continue;        int v=edge[i].to;if (!in[v]) continue;        if (Dep[v]<dep[now]) continue;        in[v]--;edge[i].flag=0;    if (!in[v]) Re+=find (v) +1; } return re;}    int main () {freopen ("trainfair.in", "R", stdin);    Freopen ("Trainfair.out", "w", stdout);    N=read (); M=read (); Q=read ();    for (int i=1;i<=m;i++) {x=read (); Y=read (); Add (x,y,1); add (y,x,1);    } dij (1);    Mark ();        for (int i=1;i<=q;i++) {x=read (); if (Dep[edge[x*2].he]<=dep[edge[x*2].to]&&edge[x*2].flag) {            x*=2;            int now=edge[x].to;if (!in[now]) goto ZZ;            in[now]--;edge[x].flag=0;        if (!in[now]) Ans+=find (now) +1;            } else if (Dep[edge[x*2-1].he]<=dep[edge[x*2-1].to]&&edge[x*2-1].flag) {x=x*2-1;            int now=edge[x].to;if (!in[now]) goto ZZ;            in[now]--;edge[x].flag=0;        if (!in[now]) Ans+=find (now) +1;        } ZZ:;    printf ("%d\n", ans); } return 0;}
T3 math problem (math)

Description

Given a sequence of length n, please calculate this equation:

\ (\sum\limits_{i=1}^n\sum\limits_{j=i}^n (j-i+1) \min (A_i,a_{i+1},\dots,a_{j}) \max (a_i,a_{i+1},\dots,a_{j}) \ ).

Because the high-precision writing is too troublesome, please 10^9109 the answer to the output after modulo.

Input

  • The first line of the input file contains two number n, which indicates the length of sequence A.
  • The next line contains n numbers, which in turn represent the elements in the sequence a1,a2,..., an.

Output

Output the result of the value pair \ (10^9\) modulo.

For this problem: each time divides the interval into two small intervals of equal length. Each time you do not consider the answer to a cell that is included in the left or right interval of the current interval, consider only the inter-cell answers of L and r across the current large range of mid. Because this time is not asked, according to our solution strategy, the next time the interval will be separated, then a part of the answer is ignored.

So the main task is to give you a range:

? The range of the left point is L to mid, and the right endpoint range is mid+1 to R

? So the answer to the solution is:
\[\sum_{i=l}^{mid}\sum_{j=mid+1}^r (j-i+1) *max (A[i]......a[j]) *min (a[i]......a[j]) \]
Consider enumerating the left endpoint of the interval you are seeking.

Part of the idea of CDQ is that for the answer, we must seek out some useful information by means of a more violent approach. For convenience, divide this interval into the left and right two intervals, then we can find the valid information in the leave interval, then correspond to the correct interval to implement the updated answer, which is why only the interval of the mid-span is calculated in the current interval.

So for this problem, we enumerate the left end of the cell, then in the process of enumeration to determine the maximum from I to mid and the minimum value as MAXL and Minl, then for the left interval effective information to fully utilize the principle, we must consider the right endpoint J in what range can make these two quantities can be exploited.

Let's start with the analysis:

Now we have two quantities of maxl and minl, and they all have two states that can be used and not be used.

Then there are three kinds of situations: one is both can be used, two is only accesses than either can be used, and three is not available.

And we know the exact values of MAXL and minl, and when we enumerate forward from mid, the current MAXL and minl are the suffixes, so they are monotonic.

Similarly, we set a as a subscript to satisfy:\ (A[a]<=maxl &&a[a+1]>maxl\)

? Set B as a subscript satisfies:\ (a[b]>=minl&&a[b+1]<minl\)

Then A and B can be used to determine which range Maxl and Minl function.

So the task now is to find A and B.

Because the weight of a, B is the prefix extremum, and we look backward from the front, so is to meet the monotony, can be found in two points.

But here I stole a lazy direct violence to find a A, B, (OK, actually I will not ...) ), is also possible.

After finding a, A and B, we will find that the range of the mid to R is divided into three segments corresponding to the applicability of Maxl and MINL.

Here we assume that a<b;

So now the three paragraphs are analyzed.

One, when \ (Mid+1\leq j&&j \leq a\), this time interval I to J of the maximum and the minimum value is MAXL and minl, so you can write the answer formula:
\[ans+=\sum_{j=mid+1}^a (j-i+1) *maxl*minl\\=maxl*minl*\sum_{j=mid+1}^a (j-i+1) \\=maxl*minl* ((A-mid+1) * (mid-i) + ( Mid-i) * (mid-i-1)/2)//Arithmetic progression O (1)
Two, when \ (a+1 \leq j&&j\leq b\), this time interval I to J maximum value will not be MAXL, because this is the definition of a. However, MINL can still be used as the minimum interval.

So when we find a corresponding J, we need a maximum value of the prefix to J. Formula:
\[ans+=\sum_{j=a+1}^b (J-i+1) *minl*f (j) \\=minl*\sum_{j=a+1}^b (j-i+1) *f[j]\\=minl* (\sum_{j=a+1}^bj*f (j)-(i-1) *\ SUM_{J=A+1}^BF (j)) \]
It is clear to see that we just need to maintain a good prefix and we can get the answer to this part O (1).

In addition, we are currently discussing the a<b, then for the b<a situation is to be considered, to judge the good, the same ideas.

Third, when \ (b+1 \leq J &&j\leq r\) , this time interval i,j the maximum and minimum values are not MAXL and minl, then the idea of two, it is easy to think of formulas.
\[ans+=\sum_{j=b+1}^r (J-i+1) *g (j) *f (J) \\=\sum_{j=b+1}^rj*g (J) *f (j)-(I-1) *\sum_{j=b+1}^rg (j) *f (j) \]
In the separate maintenance prefix and just fine.

Pay attention to the boundary, attention to initialization, attention to modulus, this problem is really good, but really disgusting.

Code

#include <iostream> #include <cstdio> #define INT long longusing namespace Std;const int Mod=1e9;inline int    Read () {int sum=0,f=1;    Char Ch=getchar (); while (ch< ' 0 ' | |        Ch> ' 9 ') {if (ch== '-') f=-1;    Ch=getchar ();        } while (ch>= ' 0 ' &&ch<= ' 9 ') {sum= (sum<<1) + (sum<<3) +ch-' 0 ';    Ch=getchar (); } return sum*f;} const int Wx=1000017;int a[wx];int S[wx],smx[wx],smn[wx],ss[wx],ssl[wx],smxl[wx],smnl[wx],mx[wx],mn[wx];int N,ans;    void work (int l,int R) {if (l==r) {ans= (ans+ (A[l]*a[r])%mod)%mod;return;    } int mid=l+r>>1;    Work (L,mid), work (MID+1,R);    mn[mid]=0x3f3f3f3f;    s[mid]=smx[mid]=smn[mid]=mx[mid]=ss[mid]=ssl[mid]=smxl[mid]=smnl[mid]=0;         for (int i=mid+1;i<=r;i++) {Mx[i]=max (mx[i-1],a[i]);//f[i] Save prefix minimum mn[i]=min (mn[i-1],a[i]);//g[i] Save prefix maximum        s[i]= (S[i-1]+i-mid)%mod;        Ss[i]= (Ss[i-1]+mn[i]*mx[i])%mod;        Smx[i]= (Smx[i-1]+mx[i])%mod; Smn[i]= (Smn[i-1]+mn[i])%mod;        Ssl[i]= (ssl[i-1]+mx[i]*mn[i]%mod* (i-mid))%mod;        Smxl[i]= (smxl[i-1]+mx[i]* (i-mid))%mod;    Smnl[i]= (smnl[i-1]+mn[i]* (i-mid))%mod;    } int a=mid,b=mid;    int maxl=0,minl=0x3f3f3f3f;        for (int i=mid;i>=l;i--) {Maxl=max (maxl,a[i]);        Minl=min (Minl,a[i]);        while (B&LT;R&AMP;&AMP;MX[B+1]&LT;MAXL) b++;//b maintains the last position less than or equal to Max; while (A&LT;R&AMP;&AMP;MN[A+1]&GT;MINL) a++;//a maintains the last position greater than or equal to min,//if (A&LT;=B) {//Ans= (ans+maxl*minl%mod* (mid -i) * (a-mid+1) + (mid-i) * (mid-i-1)/2)%mod)%mod;//ans= (ans+maxl* (sumff[b]-(i-1) *sumf[b])%mod-maxl* (sumff[a-1]-(i-1           ) *sumf[a-1]%mod)%mod;//ans= (ans+ (sum[b]-) i-1])-(*sum[b (sum[a-1]-) i-1])) *sum[a-1}//else {// Ans= (ans+maxl*minl%mod* ((mid-i) * (b-mid+1) + (mid-i) * (mid-i-1)/2))%mod;//ans= (ans+minl* (sumgg[a]-) i-1 Mg[a])%mod-minl* (sumgg[b-1]-(i-1) *sumg[b-1])%mod)%mod;//ans= (ans+ (sum[a]-(i-1) *sum[a])-(sum[b-1]-(i-1) *SUm[B-1 ]))%mod;//} iNT X=min (A, B), Y=max (A, b);        int ii=mid-i+1;        Ans= (ans+ (s[x]+ii* (x-mid)) *maxl%mod*minl)%mod;        if (b<=a) ans= (ans+ (smxl[y]-smxl[x]+ii* (smx[y]-smx[x))%mod*minl)%mod;        Else ans= (ans+ (smnl[y]-smnl[x]+ii* (smn[y]-smn[x))%MOD*MAXL)%mod;    Ans= (ans+ (ssl[r]-ssl[y]+ii* (ss[r]-ss[y)))%mod;    }}signed Main () {freopen ("math.in", "R", stdin);    Freopen ("Math.out", "w", stdout);    N=read ();    for (int i=1;i<=n;i++) a[i]=read ();    Work (1,n);    printf ("%lld\n", (ans+mod)%mod); return 0;}

10-4 National Day seventh simulation game Puzzle

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.