Bzoj 1635: [Usaco2007 jan]tallest Cow the highest cow

Source: Internet
Author: User

Topics 1635: [Usaco2007 jan]tallest Cow Highest cow time limit:5 Sec Memory limit:64 MB
Description

FJ ' s n (1 <= n <=) cows conveniently indexed 1..N is standing in a line. Each cow have a positive integer height (which is a bit of secret). You is told only the height H (1 <= H <= 1,000,000) of the tallest cow along with the index I of that cow. FJ has made a list of R (0 <= R <=) lines of the form "cow sees cow 34". This means, cow are at the least as tall as cow, and that every cow between and have a height that's Strictly s Maller than that's cow 17. For each cow from 1..N, determine its maximum possible height, and such that all of the information given is still correct. It's guaranteed that it's possible to satisfy all the constraints.

There are N (1 <= n <= 10000) cattle from 1 to n linear arrangement, height per cow is h[i] (1 <= i <= N), now tell you that the maximum height of the cow is maxh, and there is a R-group relationship, each set of relationships enter two numbers, assuming A and B, The first cow can see the cow B, can see the condition is a, b between the height of the other cattle is strictly less than min (H[a], h[b]), and H[b] >= H[a]

Input

* Line 1:four space-separated integers:n, I, H and R

* Lines 2..r+1:two distinct space-separated integers A and B (1 <= A, B <= N), indicating that cow a can see cow B.

Output

* Lines 1..n:line I contains the maximum possible height of cow I.

Sample Input9 3 5 5
1 3
5 3
4 3
3 7
9 8


INPUT DETAILS:

There is 9 cows, and the 3rd was the tallest with height 5.
Sample Output5
4
5
3
4
4
5
5
5
HINT Source

Silver

Solving

The difference sequence, in fact, is to calculate a little contribution after each point pair.

Code
1 /*Author:wnjxyk*/2#include <cstdio>3#include <algorithm>4 using namespacestd;5 6 structinput{7     intx, y;8 Input () {9         Ten     } OneInput (intAintb) { Ax=a;y=b; -     } - }; the  - Const intmaxq=10000; - Const intmaxn=10000; -Input inp[maxq+Ten]; + intheight; - intdelta[maxn+Ten]; + intn,r,h; A intindex; at  - BOOLCMP (Input a,input b) { -     if(a.x<b.x)return true; -     if(a.x==b.x && a.y<b.y)return true; -     return false;  - } in  - intMain () { toscanf"%d%d%d%d",&n,&index,&h,&R); +      for(intI=1; i<=r;i++){ -         intx, y; thescanf"%d%d",&x,&y); *         if(x>y) { $             inttmp=x;x=y;y=tmp;Panax Notoginseng         } -inp[i]=Input (x, y); the     } +Sort (inp+1, inp+r+1, CMP); A      for(intI=1; i<=r;i++){ the         if(inp[i].x==inp[i-1].x && inp[i].y==inp[i-1].Y)Continue; +delta[inp[i].y]++;d elta[inp[i].x+1]--; -     } $      for(intI=1; i<=n;i++){ $height+=Delta[i]; -printf"%d\n", H +height); -     } the     return 0; -}
View Code

Bzoj 1635: [Usaco2007 jan]tallest Cow the highest cow

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.