TLE求条

P1001 A+B Problem

imsbNR @ 2024-08-17 17:04:34

本人刚学 c++ 两天,现在 c++ 都这么难吗

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a, b;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> a >> b;
    ll l = -1e18, r = 1e18;
    while (l < r)
    {
        ll mid = (l + r) >> 1;
        if (mid - b > a)
            r = mid - 1;
        else
            l = mid;
    }
    cout << l << '\n';
    return 0;
}

by 123456789xiao @ 2024-08-17 17:08:36

天哪2天学这么多


by ywtank @ 2024-08-18 09:25:28

复杂度达O(a+b),不超时才怪


by Baizhanbo20130828 @ 2024-08-18 14:13:05

@123456789xiao 注意TA名字的颜色


by zhaoyikuan @ 2024-08-18 14:32:51

《刚学c++两天》


by sharkbee111111 @ 2024-08-18 17:25:02

《刚学两天》


by xbqlht21 @ 2024-08-22 10:44:09

@imsbNR 把1e18改成1e9,还有这不是Dijkstra板子题吗?(


by cxoi1712 @ 2024-08-22 11:43:51

两天学《二分》


by 123456789xiao @ 2024-08-24 07:47:38

you just need:

int a,b;

cin>>a>>b;

cout<<a+b;


by Hear_the_sound_of_AC @ 2024-08-24 17:11:03

是log2 1e18


by Feynman5210 @ 2024-08-31 10:26:33

把l+r>>1改成l+r+1>>1。


|