NOIP2015 Intelligent Quality Inspector [two-point | pretreatment]

Source: Internet
Author: User

backgroundNOIP2011 day2 Second questionDescriptionSmall T is a quality supervisor, recently responsible for testing the quality of a number of minerals. These minerals have n ores, numbered from 1 to N, each with its own weight of WI and Value VI. The process for testing minerals is:
1, given m interval [Li, Ri];
2, choose a parameter W;
3. For an interval [Li, Ri], calculate the ore's test value on this interval Yi:
the yi=σ1*σvj,σ loop variable is J, where J satisfies J∈[li,ri] and wj≥w, where J is the ore number.

The test results of this batch of minerals are the sum of the test values for each interval. The σyi,σ loop variable is i,1≤i≤m.

If the test results of this batch of minerals and the given standard value is too much difference, it is necessary to test another batch of minerals. Small t don't want to take time to test another batch of minerals, so he wants to adjust the value of the parameter w, so that the test results as close as possible to the standard value s, even if the absolute value of the s-y is minimal. Please help to find out the minimum value. Input FormatThe first line contains three integers n, m,s, which represent the number of ores, the number of intervals, and the standard values. The next n lines, 2 integers per line, are separated by a space, and the i+1 line represents the weight of the I ore, WI and Value VI.
the next M line, representing the interval, 2 integers per line, separated by a space, i+n+1 line represents the two endpoint Li and ri for the interval [Li, RI]. Note: Different intervals may overlap or coincide with each other. output FormatThe output has only one row and contains an integer that represents the minimum value you are seeking. Test Sample 1input
5 3
1 5
2 5
3 5
4 5
5 5
1 5
2 4
3 3
Output
10

An explanation of the sample
when W is selected 4, the test value of three interval is 20, 5, 0, the test result of this batch of minerals is 25, at this time the difference with the standard value S is the minimum of 10.
Notesfor 10% of the data, there are 1≤n, m≤10;
for 30% of the data, there are 1≤n, m≤500;
for 50% of the data, there are 1≤n, m≤5,000;
for 70% of the data, there are 1≤n, m≤10,000;
for 100% of data, there are 1≤n, m≤200,000,0 < WI, vi≤10^6,0 < s≤10^12,1≤li≤ri≤n. ----------------------------------------------------------------------------------------------------------- -------------------- two points W increases, y decreases, can be two points two minutes W, if Y>s, in L to W-1 two points; conversely w+1 to R, "The process keeps updating the answer" pretreatment fast calculation of y for a W, sweep the ore to calculate the number of valid ores prefixes and the WI prefix and, each interval one minus comes out "Note long long "
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;Const intn=200005;intn,m;intW[n],v[n],l[n],r[n];intlw=0, rw=-1;Long Longs,ans=1ll<< -;Long Longsw[200005];//S Wintsc[200005];//s CountLong LongCheckintww) {memset (SW,0,sizeof(SW)); Memset (SC,0,sizeof(SC));  for(intI=1; i<=n;i++) {//Pre        if(w[i]>=ww) {Sw[i]=sw[i-1]+V[i]; Sc[i]=sc[i-1]+1; }Else{Sw[i]=sw[i-1]; Sc[i]=sc[i-1]; }    }    Long Longy=0;  for(intI=0; i<m;i++) {y+ = (sc[r[i]]-sc[l[i]-1]) * (sw[r[i]]-sw[l[i]-1]); }    returny;}intMain () {scanf ("%d%d%lld",&n,&m,&s);  for(intI=1; i<=n;i++) {scanf ("%d%d",&w[i],&V[i]); RW=Max (rw,w[i]); }     for(intI=0; i<m;i++) scanf ("%d%d",&l[i],&R[i]); LW=0; rw++;  while(lw<=rw) {        intMid= (LW+RW) >>1; Long Longy=Check (mid); Ans=min (Ans,abs (y-s));//Update        if(y<s) rw=mid-1; ElseLw=mid+1; } cout<<ans; return 0;}

NOIP2015 Intelligent Quality Inspector [two-point | pretreatment]

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.