QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#499917#6730. CoolbitsAu_GoldWA 474ms5152kbC++202.1kb2024-07-31 20:11:012024-07-31 20:11:07

Judging History

你现在查看的是最新测评结果

  • [2024-07-31 20:11:07]
  • 评测
  • 测评结果:WA
  • 用时:474ms
  • 内存:5152kb
  • [2024-07-31 20:11:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const int N = 1e5 + 5, M = 1e4 + 5, mod = 7;

ll n, l[N], r[N], par;

void solve()
{
    cin >> n;
    ll minr = LONG_LONG_MAX;
    for (ll i = 1; i <= n; i++)
    {
        cin >> l[i] >> r[i];
        minr = min(minr, r[i]);
    }

    ll wei = minr & -minr, ans = minr;
    for (ll i = 1; i <= n; i++)
    {
        if (r[i] == minr)
            continue;

        if (l[i] >= (1 << wei + 1)) // 如果 l大于等于2^(wei+1)
        {
            ll lb = l[i], res = 0;
            for (ll i = 0; i <= wei; i++) // 取出l的二进制低wei位
            {
                if (l[i] >> i & 1)
                    res = res + (1 << i);
            }

            if (r[i] - l[i] >= (1 << wei + 1) - res) // 当r与l的差 大于等于 (1 << wei + 1)与l的二进制低wei位的差 时才有
                ans = ans & ((1 << wei + 1) - 1);
            else
                ans = ans & r[i];
        }
        else if (l[i] < (1 << wei + 1)) // 如果l在[ 2^wei,2^(wei+1) )内
        {
            if (r[i] < (1 << wei + 1)) // 如果r在(2^wei,2^(wei+1))
                ans = ans & r[i];
            else if (r[i] >= (1 << wei + 1)) // 如果r大于等于2^(wei+1)
                ans = ans & ((1 << wei + 1) - 1);
        }
    }
    cout << ans << endl;
}
/*
2
3
0 8
2 6
3 9
1
1 100

3
10 17
2 6
3 9
*/

int main()
{
    int t = 1;
   cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

/*
 // 将l变为其二进制的低三位
            ll lb = l[i], res = 0;
            for (ll i = 0; i <= wei; i++)
            {
                if (l[i] >> i & 1)
                    res = res + (1 << i);
            }
            l[i] = res;
            // 将r变为其 1 + 二进制低三位
            ll rb = r[i];
            res = 0;
            for (ll i = 0; i <= wei; i++)
            {
                if (r[i] >> i & 1)
                    res = res + (1 << i);
            }
            r[i] = res + (1 << wei + 1);
            */

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

input:

2
3
0 8
2 6
3 9
1
1 100

output:

6
100

result:

ok 2 number(s): "6 100"

Test #2:

score: -100
Wrong Answer
time: 474ms
memory: 5152kb

input:

1117
74
234256176 451122435
614716780 701954053
31102604 284818525
528763990 809400397
40637446 612671528
329403504 936190213
112402633 729525189
248142852 481053286
30877745 700834811
529884578 749041634
146522084 758550567
934650972 996096650
538751855 856147351
170918541 975066425
253153230 35361...

output:

3
3
0
2
1
3
6
3
3
296
1
1
3
3
28
3
3
88
2
2
6
1
6
1
12
1
2
6
2
2
2
1
1
20
56
1
3
1
1
2
6
4
56
2
6
3
1
73200
1
1
2
2
72
3
3
3
6
2
28
3
2
20
6
3
392
3
3
3
1
376
3
3
3
850937702
3
504
6
2
0
12
3
3
1
2
3
264
0
3
2
3
2
1
28
1
12
0
0
2
106832
6
2
360
2
6
101200
3
3
12
3
4
3
1
1
936819481
3
6
2
3
3
1
1
6
3...

result:

wrong answer 1st numbers differ - expected: '29882460', found: '3'