結果

問題 No.1930 XOR of Two Range
ユーザー SSRSSSRS
提出日時 2022-05-06 21:40:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,318 bytes
コンパイル時間 1,803 ms
コンパイル使用メモリ 172,940 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-20 02:33:17
合計ジャッジ時間 8,521 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,624 KB
testcase_01 TLE -
testcase_02 TLE -
testcase_03 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
long long solve(long long N, int p){
  if (N == -1){
    return 0;
  }
  long long ans = 0;
  for (int i = p; i <= p + 1; i++){
    vector<vector<int>> dpcnt(52, vector<int>(2, 0));
    vector<vector<long long>> dpxor(52, vector<long long>(2, 0));
    dpcnt[51][0] = 1;
    for (int j = 50; j >= 0 ; j--){
      for (int k = 0; k < 2; k++){
        for (int l = 0; l < 2; l++){
          bool ok = true;
          if (j == 0 && l != i % 2){
            ok = false;
          }
          if (j == 1 && l != i / 2 % 2){
            ok = false;
          }
          if (k == 0 && (N >> j & 1) == 0 && l == 1){
            ok = false;
          }
          if (ok){
            int k2 = k;
            if ((N >> j & 1) == 1 && l == 0){
              k2 = 1;
            }
            dpcnt[j][k2] += dpcnt[j + 1][k];
            dpcnt[j][k2] %= 2;
            dpxor[j][k2] ^= dpxor[j + 1][k];
            if (dpcnt[j + 1][k] == 1 && l == 1){
              dpxor[j][k2] ^= (long long) 1 << j;
            }
          }
        }
      }
    }
    ans ^= dpxor[0][1];
  }
  return ans;
}
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    long long L, R;
    cin >> L >> R;
    cout << (solve(L + R + 1, L * 2 % 4) ^ solve(L * 2 - 1, L * 2 % 4)) << endl;
  }
}
0