题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1271
题解:
这种题真是太神了!
只需要考虑被覆盖的次数的奇偶性,并且保证满足题意的点至多只有一个,所以考虑前缀和
该点以前前缀和都是偶数,该点及以后都是奇数! 然后就可以二分这个位置了。。。orz
给想出这道题的人跪了!
代码:
#include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<map> #include<set> #include<queue> #include<string> #define inf 2147483647 #define maxn 250000 #define maxm 500+100 #define eps 1e-10 #define ll long long #define pa pair<int,int> #define for0(i,n) for(int i=0;i<=(n);i++) #define for1(i,n) for(int i=1;i<=(n);i++) #define for2(i,x,y) for(int i=(x);i<=(y);i++) #define for3(i,x,y) for(int i=(x);i>=(y);i--) #define mod 1000000007 using namespace std; inline int read() { int x=,f=;char ch=getchar(); while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();} while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();} return x*f; }
int n,s[maxn],t[maxn],d[maxn];
int calc(int x)
{
int ret=;
for1(i,n)if(s[i]<=x)ret+=(min(x,t[i])-s[i])/d[i]+;
return ret;
} int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); int cs=read();
while(cs--)
{
n=read();
for1(i,n)s[i]=read(),t[i]=read(),d[i]=read();
ll l=,r=inf,mid;
while(l<=r)
{
mid=(l+r)>>;
if(calc(mid)&)r=mid-;else l=mid+;
//cout<<l<<' '<<r<<' '<<mid<<endl;
//cout<<( calc(mid)&1 )<<endl;
}
if(r==inf)printf("Poor QIN Teng:(\n");else printf("%lld %d\n",l,calc(l)-calc(l-));
} return ; }