提出 #72761591


ソースコード 拡げる

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int N = 5e6 + 5;
bool vis[N], a[N];
vector<vector<int>> adj;
vector<int> c[2];

void dfs(int v, int col)
{
    if(vis[v])
        return;
    c[col].push_back(v);
    vis[v] = 1;
    for(int x : adj[v])
        dfs(x, 1 - col);
}

int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tt;
    cin >> tt;
    while(tt--)
    {
        ll q, l, r;
        cin >> q >> l >> r;
        if(q == 0)
        {
            for(ll i = 60; i >= 0; i--)
            {
                ll bl = ((1ll << i) & l), br = ((1ll << i) & r);
                if(bl == br)
                {
                    if(bl > 0)
                    {
                        l -= bl;
                        r -= bl;
                    }
                }
                else
                    break;
            }
            if(l == r)
            {
                cout << 1 << '\n';
                continue;
            }
            ll x = 1;
            while(2 * x <= r)
                x *= 2;
            ll ans, l1 = (x - l), l2 = (r - x + 1), len = (r - l + 1);
            if(len <= x)
            {
                ans = (l1 + 1) / 2 + (l2 + 1) / 2;
            }
            else
            {
                ans = (len + 1) / 2;
            }
            cout << ans << '\n';
        }
        else
        {
            ll len = r - l + 1;
            for(int i = 0; i < len; i++)
                a[i] = vis[i] = 0;
            adj.assign(len, {});
            for(ll x = l; x <= r; x++)
            {
                for(ll bt = 0; bt < 60; bt++)
                {
                    if(((1ll << bt) & x) == 0)
                    {
                        ll y = x + (1ll << bt);
                        if(y <= r)
                        {
                            adj[x - l].push_back(y - l);
                            adj[y - l].push_back(x - l);
                        }
                    }
                }
            }
            for(int i = 0; i < len; i++)
            {
                if(vis[i])
                    continue;
                c[0].clear();
                c[1].clear();
                dfs(i, 0);
                if(c[0].size() > c[1].size())
                    for(int x : c[0])
                        a[x] = 1;
                else    
                    for(int x : c[1])
                        a[x] = 1;
            }
            for(int i = 0; i < len; i++)
                cout << a[i] ;
            cout << '\n';
        }
    }
    return 0;
}

提出情報

提出日時
問題 B - Hamming Distance is not 1
ユーザ aaa65654
言語 C++23 (GCC 15.2.0)
得点 0
コード長 2684 Byte
結果 WA
実行時間 2767 ms
メモリ > 1048576 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 800
結果
AC × 1
AC × 22
WA × 10
MLE × 21
セット名 テストケース
Sample sample.txt
All 1_1.txt, 1_10.txt, 1_2.txt, 1_3.txt, 1_4.txt, 1_5.txt, 1_6.txt, 1_7.txt, 1_8.txt, 1_9.txt, 2_1.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_2.txt, 2_3.txt, 2_4.txt, 2_5.txt, 2_6.txt, 2_7.txt, 2_8.txt, 2_9.txt, 3_1.txt, 3_10.txt, 3_11.txt, 3_12.txt, 3_13.txt, 3_14.txt, 3_15.txt, 3_16.txt, 3_17.txt, 3_18.txt, 3_19.txt, 3_2.txt, 3_20.txt, 3_21.txt, 3_22.txt, 3_23.txt, 3_24.txt, 3_25.txt, 3_26.txt, 3_27.txt, 3_28.txt, 3_3.txt, 3_4.txt, 3_5.txt, 3_6.txt, 3_7.txt, 3_8.txt, 3_9.txt, sample.txt
ケース名 結果 実行時間 メモリ
1_1.txt WA 2544 ms 710068 KiB
1_10.txt WA 2767 ms 812448 KiB
1_2.txt MLE 2314 ms > 1048576 KiB
1_3.txt WA 2332 ms 741652 KiB
1_4.txt WA 2351 ms 752376 KiB
1_5.txt WA 2220 ms 605056 KiB
1_6.txt WA 2118 ms 757068 KiB
1_7.txt WA 1916 ms 382028 KiB
1_8.txt WA 2430 ms 843248 KiB
1_9.txt MLE 2475 ms > 1048576 KiB
2_1.txt WA 4 ms 3656 KiB
2_10.txt MLE 2548 ms > 1048576 KiB
2_11.txt MLE 2537 ms > 1048576 KiB
2_12.txt MLE 2512 ms > 1048576 KiB
2_13.txt MLE 2443 ms > 1048576 KiB
2_14.txt AC 480 ms 69424 KiB
2_2.txt MLE 2401 ms > 1048576 KiB
2_3.txt MLE 2412 ms > 1048576 KiB
2_4.txt MLE 2527 ms > 1048576 KiB
2_5.txt MLE 2528 ms > 1048576 KiB
2_6.txt MLE 2514 ms > 1048576 KiB
2_7.txt MLE 2457 ms > 1048576 KiB
2_8.txt MLE 2442 ms > 1048576 KiB
2_9.txt MLE 2429 ms > 1048576 KiB
3_1.txt WA 55 ms 3644 KiB
3_10.txt MLE 2108 ms > 1048576 KiB
3_11.txt MLE 2473 ms > 1048576 KiB
3_12.txt AC 1566 ms 523436 KiB
3_13.txt AC 1622 ms 568852 KiB
3_14.txt AC 1692 ms 576932 KiB
3_15.txt AC 1632 ms 561120 KiB
3_16.txt AC 1659 ms 575844 KiB
3_17.txt AC 1220 ms 279652 KiB
3_18.txt AC 1182 ms 276056 KiB
3_19.txt AC 1175 ms 282060 KiB
3_2.txt MLE 2210 ms > 1048576 KiB
3_20.txt AC 1179 ms 290632 KiB
3_21.txt AC 1171 ms 272720 KiB
3_22.txt AC 1178 ms 286536 KiB
3_23.txt AC 1162 ms 252672 KiB
3_24.txt AC 977 ms 145872 KiB
3_25.txt AC 1020 ms 147496 KiB
3_26.txt AC 835 ms 77328 KiB
3_27.txt AC 814 ms 71052 KiB
3_28.txt AC 425 ms 17232 KiB
3_3.txt MLE 2086 ms > 1048576 KiB
3_4.txt MLE 2113 ms > 1048576 KiB
3_5.txt AC 2404 ms 961232 KiB
3_6.txt MLE 2206 ms > 1048576 KiB
3_7.txt AC 2436 ms 971492 KiB
3_8.txt AC 2426 ms 1005260 KiB
3_9.txt MLE 2195 ms > 1048576 KiB
sample.txt AC 1 ms 3452 KiB