結果
| 問題 |
No.1209 XOR Into You
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-02 18:32:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 57 ms / 2,000 ms |
| コード長 | 881 bytes |
| コンパイル時間 | 2,210 ms |
| コンパイル使用メモリ | 197,848 KB |
| 最終ジャッジ日時 | 2025-02-24 14:31:39 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
main.cpp:34:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int p[N], n, bit[N];
std::pair<int, int> a[N], b[N];
void add(int x) {
while(x) {
++bit[x];
x -= x & -x;
}
}
int ask(int x) {
int ret = 0;
while(x <= n) {
ret += bit[x];
x += x & -x;
}
return ret;
}
int main() {
scanf("%d", &n);
for(int i = 0, pre = 0, x; i < n; ++i) {
scanf("%d", &x);
a[i] = {x ^ pre, i};
pre = x;
}
for(int i = 0, pre = 0, x; i < n; ++i) {
scanf("%d", &x);
b[i] = {x ^ pre, i};
pre = x;
}
std::sort(a + 1, a + n);
std::sort(b + 1, b + n);
for(int i = 0; i < n; ++i) {
if(a[i].first != b[i].first) {
puts("-1");
return 0;
}
p[a[i].second] = b[i].second;
}
long long ans = 0;
for(int i = 1; i < n; ++i) {
ans += ask(p[i]);
add(p[i]);
}
printf("%lld\n", ans);
return 0;
}