Forcefield

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
set<int> s[2]{{0, INF}, {0, INF}};
int n, now, ans;
int main()
{
scanf("%d%d", &n, &now);
for (int i = 0, x, p; i < n; ++i)
scanf("%d%d", &x, &p), s[p & 1].insert(x);
for (int rev = 0;; rev ^= 1)
{
if (rev)
{
int pos = *s[1].upper_bound(now);
if (pos == INF)
{
if (s[0].size() != 2 || s[1].size() != 2)
ans = -1;
break;
}
s[1].erase(now = pos);
}
else
{
int pos = *--s[0].lower_bound(now);
if (pos)
s[0].erase(pos);
else
++ans;
now = pos;
}
}
printf("%d", ans);
}


Missing Part

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef double lf;
const int N = 65535;
const lf PI = acos(-1);
{
Rader(int n) : vector<int>(1 << int(ceil(log2(n))))
{
for (int i = at(0) = 0; i < size(); ++i)
if (at(i) = at(i >> 1) >> 1, i & 1)
at(i) += size() >> 1;
}
};
{
vector<complex<lf>> w;
FFT(int n) : Rader(n), w(size(), polar(1.0, 2 * PI / size()))
{
w[0] = 1;
for (int i = 1; i < size(); ++i)
w[i] *= w[i - 1];
}
vector<complex<lf>> fft(const vector<complex<lf>> &a)
{
vector<complex<lf>> x(size());
for (int i = 0; i < a.size(); ++i)
x[at(i)] = a[i];
for (int i = 1; i < size(); i <<= 1)
for (int j = 0; j < i; ++j)
for (int k = j; k < size(); k += i << 1)
{
complex<lf> &l = x[k], &r = x[k + i], t = w[size() / (i << 1) * j] * r;
r = l - t, l += t;
}
return x;
}
vector<ll> mul(vector<complex<lf>> xa, const vector<complex<lf>> &xb)
{
for (int i = 0; i < size(); ++i)
xa[i] *= xb[i];
vector<ll> ans(size());
xa = fft(xa), ans[0] = xa[0].real() / size() + 0.5;
for (int i = 1; i < size(); ++i)
ans[i] = xa[size() - i].real() / size() + 0.5;
return ans;
}
};
char a[N], b[N];
int main()
{
scanf("%s%s", a, b);
int n = strlen(a), ans = 0, p[5];
FFT f(n * 2);
vector<ll> sum[5][5];
vector<vector<complex<lf>>> xa(5, vector<complex<lf>>(n * 2)), xb(5, vector<complex<lf>>(n * 2));
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < n; ++j)
{
if (a[j] == 'A' + i)
xa[i][j] = xa[i][j + n] = 1;
if (b[j] == 'a' + i)
xb[i][n - j - 1] = 1;
}
xa[i] = f.fft(xa[i]), xb[i] = f.fft(xb[i]), p[i] = i;
}
for (int i = 0; i < 5; ++i)
for (int j = 0; j < 5; ++j)
sum[i][j] = f.mul(xa[i], xb[j]);
do
for (int j = 0, tmp; j < n * 2; ++j)
{
for (int i = tmp = 0; i < 5; ++i)
tmp += sum[i][p[i]][j];
ans = max(ans, tmp);
}
while (next_permutation(p, p + 5));
printf("%d", n - ans);
}


Cryptographic Argument

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e9 + 7;
{
Rader(int n) : vector<int>(1 << int(ceil(log2(n))))
{
for (int i = at(0) = 0; i < size(); ++i)
if (at(i) = at(i >> 1) >> 1, i & 1)
at(i) += size() >> 1;
}
} rev0(1), rev1(1);
ll h, k, m, l, r, a, b, c;
{
ll p = u >> (k >> 1) + 1, q = p << (k >> 1) ^ u >> 1;
p = rev1[p], q = rev0[q];
if (u & 1)
p ^= rev1.size() - 1, q ^= rev0.size() - 1;
return (q * rev1.size() | p) << 1 | u & 1;
}
int main()
{
scanf("%lld%lld%lld%lld%lld%lld%lld", &k, &m, &l, &r, &a, &b, &c);
rev0 = Rader(1 << (k >> 1)), rev1 = Rader(1 << k - (k >> 1) - 1);
for (ll i = 0, n = 1LL << k; i < m; ++i)
{
if (l & 1)
{
if (r & 1)
h ^= (r - l >> 1) * (n - 1) + ask(l);
else
h ^= (r - l - 1 >> 1) * (n - 1) + ask(l) + ask(r);
}
else
{
if (r & 1)
h ^= (r - l + 1 >> 1 & 1) * (n - 1);
else
h ^= (r - l >> 1 & 1) * (n - 1) ^ ask(r);
}
h = ((l ^ r ^ h) + c) % M;
l = (l ^ a ^ h) % (n + 1) % n;
r = (r ^ b ^ h) % (n - l) + l;
}
printf("%lld", h);
}


The Jedi Killer

28、29 行的EPS不能用sgn去掉，暂时不知道为啥…改了之后 WA4（猜测是浮点数做减法的时候的对齐操作丢了精度）。

#include <bits/stdc++.h>
#define X real()
#define Y imag()
using namespace std;
typedef double lf;
typedef complex<lf> Coord;
const lf EPS = 1e-9;
int sgn(lf d) { return (d > EPS) - (d < -EPS); }
lf Cross(const Coord &A, const Coord &B) { return A.X * B.Y - B.X * A.Y; }
int main()
{
int t, lm, lg, ans;
for (scanf("%d", &t); t--; printf(ans ? "YES\n" : "NO\n"))
{
scanf("%d%d", &lm, &lg);
vector<Coord> p;
for (int i = 0, x, y; i < 3; ++i)
scanf("%d%d", &x, &y), p.emplace_back(x, y);
if (!sgn(Cross(p[0] - p[1], p[1] - p[2])))
ans = sgn(max(max(abs(p[0] - p[1]), abs(p[1] - p[2])), abs(p[2] - p[0])) - max(lm, lg * 2)) <= 0;
else
for (int i = ans = 0; !ans && i < 3; ++i)
{
lf d0 = abs(p[(i + 1) % 3] - p[(i + 2) % 3]),
h = fabs(Cross(p[(i + 1) % 3] - p[i], p[(i + 2) % 3] - p[i]) / d0),
d1 = sqrt(norm(p[i] - p[(i + 1) % 3]) - h * h),
d2 = sqrt(norm(p[i] - p[(i + 2) % 3]) - h * h);
ans = sgn(h - lm) <= 0 && max(d1, d2) <= lg + EPS ||
sgn(h - lg) <= 0 && max(d1, d2) <= lm + EPS &&
sgn(h * h + d0 * d0 - max(norm(p[i] - p[(i + 1) % 3]), norm(p[i] - p[(i + 2) % 3]))) <= 0;
}
}
}


Youngling Tournament

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
struct BaseFenwick
{
vector<ll> v;
BaseFenwick(int n) : v(n, 0) {}
{
for (; x < v.size(); x += x & -x)
v[x] += w;
}
{
ll ans = 0;
for (; x; x -= x & -x)
ans += v[x];
return ans;
}
};
struct Ranker : vector<ll>
{
void init() { sort(begin(), end()), resize(unique(begin(), end()) - begin()); }
int ask(ll x) const { return lower_bound(begin(), end(), x) - begin(); }
} rk;
ll n, m, a[N], b[N], c[N];
int main()
{
scanf("%lld", &n);
for (int i = 1; i <= n; ++i)
scanf("%lld", &a[i]), rk.push_back(a[i]);
scanf("%lld", &m);
for (int i = 0; i < m; ++i)
scanf("%lld%lld", &b[i], &c[i]), rk.push_back(c[i]);
rk.init();
multiset<ll> s;
BaseFenwick t(rk.size() + 1);
for (int i = 1; i <= n; ++i)
for (int i = 0;; ++i)
{
int res = 1;
multiset<ll>::iterator p = s.begin(), q = p++;
if (*p == *q)
++res;
while (1)
{
if (p == s.begin())
++p;
if (p == s.end())
break;
q = p--;
++res;
}
printf("%d\n", res);
if (i == m)
break;
s.erase(s.find(a[b[i]]));
s.insert(a[b[i]] = c[i]);
}
}


Garland Checking

#include <bits/stdc++.h>
using namespace std;
struct UnionFindSet
{
vector<int> fa;
UnionFindSet(int n) : fa(n)
{
for (int i = 0; i < n; ++i)
fa[i] = i;
}
void splay(int u, int f)
{
if (fa[u] != u)
splay(fa[u], u);
fa[u] = f;
}
int ask(int u) { return fa[u] != u ? ask(fa[u]) : u; }
};
char s[9];
int n, a, b;
int main()
{
scanf("%d", &n);
for (UnionFindSet ufs(n + 1); ~scanf("%s", s) && s[0] != 'E';)
{
scanf("%d%d", &a, &b), ufs.splay(a, a), ufs.splay(b, b);
if (s[0] == 'T')
printf(ufs.ask(a) == b ? "YES\n" : "NO\n"), fflush(stdout);
else
ufs.fa[a] = s[0] == 'D' ? a : b;
}
}