結果

問題 No.387 ハンコ
ユーザー antaanta
提出日時 2016-06-23 21:42:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,279 ms / 5,000 ms
コード長 2,804 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 177,840 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-04-19 23:58:29
合計ジャッジ時間 13,232 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,226 ms
8,832 KB
testcase_01 AC 2,279 ms
8,704 KB
testcase_02 AC 233 ms
5,724 KB
testcase_03 AC 236 ms
5,756 KB
testcase_04 AC 240 ms
5,376 KB
testcase_05 AC 892 ms
6,912 KB
testcase_06 AC 1,620 ms
8,192 KB
testcase_07 AC 248 ms
6,016 KB
testcase_08 AC 268 ms
6,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

template<typename Op>
void shiftOp(uint64_t *x, const uint64_t *y, int N, int shift, Op op) {
	if(N <= 0) return;
	x += shift / 64;
	shift %= 64;
	if(shift == 0) {
		for(int i = 0; i < N; ++ i)
			x[i] = op(x[i], y[i]);
	} else {
		x[0] = op(x[0], y[0] << shift);
		for(int i = 0; i < N - 1; ++ i)
			x[i + 1] = op(x[i + 1], op(y[i + 1] << shift, y[i] >> (64 - shift)));
		x[N] = op(x[N], y[N - 1] >> (64 - shift));
	}
}
void shiftOr(uint64_t *x, const uint64_t *y, int N, int shift) {
	shiftOp(x, y, N, shift, bit_or<uint64_t>());
}
void shiftXor(uint64_t *x, const uint64_t *y, int N, int shift) {
	shiftOp(x, y, N, shift, bit_xor<uint64_t>());
}
template<int LogH>
void verticalAddition(array<uint64_t, LogH> &x, uint64_t y) {
	uint64_t c = y;
	for(int i = 0; i < LogH - 1; ++ i) {
		uint64_t t = x[i] & c;
		x[i] ^= c;
		c = t;
	}
	x[LogH - 1] ^= c;
}
int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> a(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &a[i]);
		vector<int> b(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &b[i]);
		const int H = 64, LogH = 6;
		const int X = (N - 1) / 64 + 1;
		vector<uint64_t> B(X * 2 + 2);
		rep(i, N) if(b[i] == 1)
			B[i / 64] |= 1ULL << (i % 64);
		vector<int> values = a;
		sort(values.begin(), values.end());
		values.erase(unique(values.begin(), values.end()), values.end());
		int V = (int)values.size();
		vector<vi> shifts(V);
		rep(i, N) {
			int k = (int)(lower_bound(values.begin(), values.end(), a[i]) - values.begin());
			shifts[k].push_back(i);
		}
		vector<uint64_t> row(X * 2 + 2);
		vector<array<uint64_t, LogH>> sums(X * 2 + 2);
		vector<int> ans(X * 2 * 64, 0);
		for(int i = 0; i < V; ) {
			memset(sums.data(), 0, sizeof(uint64_t) * LogH * (X * 2));
			for(int y = 0; y < H && i < V; ++ y, ++ i) {
				memset(row.data(), 0, sizeof(uint64_t) * (X * 2));
				for(int shift : shifts[i])
					shiftOr(row.data(), B.data(), X, shift);
				rep(j, X * 2)
					verticalAddition<LogH>(sums[j], row[j]);
			}
			rep(j, X * 2) {
				rep(k, LogH) {
					uint64_t t = sums[j][k];
					rep(x, 64) {
						ans[j * 64 + x] += (int)((t & 1) << k);
						t >>= 1;
					}
				}
			}
		}
		rep(i, N * 2 - 1)
			puts(ans[i] % 2 ? "ODD" : "EVEN");
	}
	return 0;
}
0