結果
| 問題 |
No.387 ハンコ
|
| コンテスト | |
| ユーザー |
anta
|
| 提出日時 | 2016-06-23 03:17:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 717 ms / 5,000 ms |
| コード長 | 4,126 bytes |
| コンパイル時間 | 1,941 ms |
| コンパイル使用メモリ | 178,972 KB |
| 実行使用メモリ | 7,424 KB |
| 最終ジャッジ日時 | 2024-10-11 19:50:23 |
| 合計ジャッジ時間 | 8,413 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 |
ソースコード
//1個しか出現しないのをFFTでまとめてやる
#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<int MOD>
struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt() : x(0) {}
ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
int get() const { return (int)x; }
ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
ModInt inverse() const {
signed a = x, b = MOD, u = 1, v = 0;
while(b) {
signed t = a / b;
a -= t * b; std::swap(a, b);
u -= t * v; std::swap(u, v);
}
if(u < 0) u += Mod;
ModInt res; res.x = (unsigned)u;
return res;
}
};
typedef ModInt<998244353> fft_mint;
const int OmegaMax = 23;
fft_mint OmegaPrim = 31;
fft_mint Omega[OmegaMax + 1];
void fft_init() {
if(Omega[OmegaMax].get() != 0) return;
fft_mint x = OmegaPrim;
for(int i = OmegaMax; i >= 0; i --) {
Omega[i] = x;
x *= x;
}
}
//aを破壊する
void fft_main(int logn, const bool inv, fft_mint a[]) {
fft_init();
int n = 1 << logn;
fft_mint ww = Omega[logn];
if(inv) ww = ww.inverse();
for(int m = n, mi = 0; m >= 2; m >>= 1, mi ++) {
int mh = m >> 1;
fft_mint w = 1;
rep(i, mh) {
for(int j = i; j < n; j += m) {
int k = j + mh;
fft_mint x = a[j] - a[k];
a[j] += a[k];
a[k] = w * x;
}
w *= ww;
}
ww *= ww;
}
int i = 0;
reu(j, 1, n - 1) {
for(int k = n >> 1; k > (i ^= k); k >>= 1);
if(j < i) swap(a[i], a[j]);
}
}
void fft(int logn, fft_mint a[]) { fft_main(logn, false, a); }
void inverse_fft(int logn, fft_mint a[]) {
fft_main(logn, true, a);
int n = 1 << logn;
fft_mint invn = fft_mint(n).inverse();
rep(i, n) a[i] *= invn;
}
//v, wを破壊し、vに結果を返す
//v, wのサイズは 2^logn, lognはceil(log_2(size(v) + size(w)))必要
void convolution(fft_mint v[], fft_mint w[], int logn) {
fft(logn, v); fft(logn, w);
rep(i, 1 << logn) v[i] *= w[i];
inverse_fft(logn, v);
}
int main() {
int N;
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]);
typedef bitset<200000> Bitset;
Bitset B;
rep(i, N) if(b[i] == 1)
B.set(i);
vector<pair<int, int>> ais(N);
rep(i, N)
ais[i] = make_pair(a[i], i);
sort(ais.begin(), ais.end());
Bitset C;
vector<int> o(N);
for(int i = 0; i < N; ) {
int j = i;
if(i + 1 < N && ais[i + 1].first == ais[i].first) {
Bitset A;
for(; j < N && ais[j].first == ais[i].first; ++ j) {
int shift = ais[j].second;
A |= B << shift;
}
C ^= A;
i = j;
} else {
o[ais[i].second] = 1;
++ i;
}
}
{
int log2n = 0;
while((1 << log2n) < (N + N)) ++ log2n;
vector<fft_mint> bb(1 << log2n), oo(1 << log2n);
rep(i, N) bb[i].x = b[i];
rep(i, N) oo[i].x = o[i];
convolution(bb.data(), oo.data(), log2n);
rep(i, 2 * N - 1) if(bb[i].get() % 2)
C.flip(i);
}
rep(i, N * 2 - 1)
puts(C[i] ? "ODD" : "EVEN");
return 0;
}
anta