bzoj 1271

思路:因为被占奇数次的点只有一个, 那么我们可以将数轴分成两部分,奇数次点之前的前缀和为偶数,之后的前缀和为奇数,

然后就可以二分了。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define piii pair<int, pair<int,int> >

using namespace std;

const int N = 1e6 + 10;
const int M = 10 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;

LL s[N], t[N], d[N];
int n;

bool check(LL x) {
    LL ans = 0;
    for(int i = 1; i <= n; i++) {
        LL l = s[i], r = min(t[i], x);
        if(l > r) continue;
        ans += (r - l) / d[i] + 1;
    }
    return (ans & 1);
}
int main() {
    int T; scanf("%d", &T);
    while(T--) {
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) {
            scanf("%lld%lld%lld", &s[i], &t[i], &d[i]);
        }

        LL l = 0, r = 5e9, mid, ans = -1;

        while(l <= r) {
            mid = l + r >> 1;
            if(check(mid)) r = mid -1, ans = mid;
            else l = mid + 1;
        }
        if(ans != -1) {
            printf("%lld ", ans);
            LL cnt = 0;
            for(int i = 1; i <= n; i++) {
                if(s[i] <= ans && t[i] >= ans && (ans - s[i]) % d[i] == 0)
                    cnt++;
            }
            printf("%lld\n", cnt);
        } else {
            puts("Poor QIN Teng:(");
        }
    }
    return 0;
}
/*
*/

 

posted @ 2018-06-06 14:04  NotNight  阅读(133)  评论(0编辑  收藏  举报