[BZOJ1271] [BeiJingWc2008] Qin Teng and teaching evaluation (two points) _ two points

Source: Internet
Author: User

Transmission Door
Unexpectedly double 叒 叕 is the permission question ...

The topic is very long ah.
There are also a number of teaching assessment missions on the road, for each of the assessment missions from the beginning of each D station one person until E end, now to find a station of the number of odd points, this point may not, at most only one, ask this point where and how many people stand at this point.

If not Lyd Blue book tells me he is two points, I would like to go to the line tree.
To think about it, I overlooked one of the most important conditions: at most there is only one odd number of points.
Monotonicity. Monotonicity. There it is. Prefixes and.
So all we have to do is maintain a prefix and, because there is only one odd number, and the others are even numbered prefixes and certainly odd numbers. So we just need a second division to find the smallest prefix and the odd position is no good. The complexity of the prefix and is O (n) o (n) o (n) then the second point is O (logn) O (L o g N) O (logn), so the final complication is O (NLOGN) o (n l o g N) O (NLOGN)

#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <
Cmath> using namespace std;
typedef long Long LL;
const int maxn=200010; struct Node {ll s,d,e;}
A[MAXN];
int n;
    ll Getsum (ll limit) {ll ans=0;
        for (int i=1;i<=n;i++) {if (a[i].s>limit) continue;
        ll R=min (A[i].e,limit);
    ans+= (R-A[I].S)/a[i].d+1;
return ans;
    int main () {int t;scanf ("%d", &t);
    while (t--) {//computes the prefix and, because only one place is an odd number, as long as the binary prefix and the first odd prefix and point can be found (monotonicity is reflected in the prefix and) scanf ("%d", &n);
    ll limit=0;
        for (int i=1;i<=n;i++) {scanf ("%lld%lld%lld", &AMP;A[I].S,&AMP;A[I].E,&AMP;A[I].D);
    Limit=max (LIMIT,A[I].E);
    ll sum=getsum (limit); if (!) (
    sum&1)) {printf ("Poor QIN Teng: (\ n"); continue;}
    ll L=0,r=limit,ans=0;
        while (L<=r) {ll mid= (l+r)/2;
        if (Getsum (mid) &1) {ans=mid; r=mid-1;}
    else l=mid+1;
    ll cnt=0; for (int i=1;i<=n;i++) {if (A[i].s>ans) continue;
        if (A[i].e<ans) continue;
    if ((ANS-A[I].S)%a[i].d==0) cnt++;

    printf ("%lld%lld\n", ans,cnt);
return 0; }

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.