結果

問題 No.1895 Mod 2
ユーザー ぷらぷら
提出日時 2022-04-08 22:43:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,266 bytes
コンパイル時間 2,002 ms
コンパイル使用メモリ 200,556 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 08:19:46
合計ジャッジ時間 3,274 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 74 ms
5,376 KB
testcase_02 AC 84 ms
5,376 KB
testcase_03 AC 88 ms
5,376 KB
testcase_04 AC 68 ms
5,376 KB
testcase_05 AC 113 ms
5,376 KB
testcase_06 AC 113 ms
5,376 KB
testcase_07 AC 114 ms
5,376 KB
testcase_08 AC 66 ms
5,376 KB
testcase_09 AC 68 ms
5,376 KB
testcase_10 AC 36 ms
5,376 KB
testcase_11 AC 80 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        long long l,r;
        cin >> l >> r;
        int ans = 0;
        for(int i = 0; i < 50; i++) {
            long long now = (1ll << i);
            long long a = (l+now-1)/now,b = r/now;
            if(b == 0) {
                break;
            }
            long long L = 0,R = 1001001001;
            while (L+1 < R) {
                long long mid = (L+R)/2;
                if(mid*mid <= b) {
                    L = mid;
                }
                else {
                    R = mid;
                }
            }
            long long L2 = 0,R2 = 1001001001;
            while (L2+1 < R2) {
                long long mid = (L2+R2)/2;
                if (mid*mid >= a) {
                    R2 = mid;
                }
                else {
                    L2 = mid;
                }
            }
            if(L%2 == 0) {
                L--;
            }
            if(L2%2 == 0) {
                L2++;
            }
            else {
                L2 += 2;
            }
            if(L2 <= L) {
                ans ^= ((L-L2)/2)%2;
                ans ^= 1;
            }
        }
        cout << ans << endl;
    }
}
0