codeforces 536a//Tavas and Karafs// Codeforces Round #299(Div. 1)

题意:一个等差数列,首项为a,公差为b,无限长。操作cz是区间里选择最多m个不同的非0元素减1,最多操作t次,现给出区间左端ll,在t次操作能使区间全为0的情况下,问右端最大为多少。

这么一个简单题吞了我3小时的时间。主要是没考虑全。

首先,得出ll位置的值a1,如果a1>t那么不可行。

然后分2种情况。

1.区间长度<=m,那么只要右端<=t就行,否则不行。

2.区间长度>m,区间内元素总和<=m*t,且右端<=t就行,否则不行。这个我猜到了,不过忽略了右端<=t,因此wa了很久。

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000") 
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=1000010,INF=0x7FFFFFFF;
typedef long long lon;

int main()
{
    std::ios::sync_with_stdio(0);
    //freopen("d:\\1.txt","r",stdin); 
    lon a,b,n;
    cin>>a>>b>>n;
    for(lon i=0;i<n;++i)
    {
        lon ll,t,m;
        cin>>ll>>t>>m;
        lon lo=ll,hi=1e6+10;
        for(;lo<hi;)
        {
            lon mid=(lo+hi)/2;
            lon cur=0;
            lon a1=a+(ll-1)*b;
            lon len=(mid-ll+1);
            cur=a1*len+len*(len-1)*b/2;
            bool ok=0;
            if(len<=m)
            {
                ok=(a+(mid-1)*b)<=t;
            }
            else
            {
                ok=cur<=m*t&&(a+(mid-1)*b)<=t;
            }
            //cout<<"cur: "<<cur<<endl;
            //cout<<(m*t)<<" "<<ok<<" "<<lo<<" "<<hi<<" "<<"mid: "<<mid<<" "<<cur<<endl;
            if(!ok)hi=mid;
            else lo=mid+1;
        }
        cout<<(lo-1<ll?-1:lo-1)<<endl;
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/gaudar/p/9651881.html