#include "rainbow.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
random_device(rd);
mt19937 rng(rd());
const long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
struct custom_hash
{
template<class T>
unsigned long long operator()(T v) const
{
unsigned long long x = v;
x += FIXED_RANDOM; x += 11400714819323198485ull;
x = (x ^ (x >> 30)) * 13787848793156543929ull;
x = (x ^ (x >> 27)) * 10723151780598845931ull;
return x ^ (x >> 31);
}
};
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class U> using hash_table = gp_hash_table<T, U, custom_hash>;
template<class T>
void ckmin(T &a, T b)
{
a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
a = max(a, b);
}
long long expo(long long a, long long e, long long mod)
{
return ((e == 0) ? 1 : ((expo(a * a % mod, e >> 1, mod)) * ((e & 1) ? a : 1) % mod));
}
template<class T, class U>
T nmod(T &x, U mod)
{
if (x >= mod) x -= mod;
}
template<class T>
T gcd(T a, T b)
{
return (b ? gcd(b, a % b) : a);
}
template<class T>
T randomize(T mod)
{
return (uniform_int_distribution<T>(0, mod - 1))(rng);
}
#define y0 ___y0
#define y1 ___y1
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define debug(x) cerr << #x << " = " << x << endl;
#define sz(x) ((int) (x.size()))
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-9;
#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 400013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
int N;
struct pseg
{
struct node
{
node *ch[2];
ll stor;
node()
{
ch[0] = ch[1] = nullptr;
stor = 0;
}
};
int T;
node *root[MAXN];
int ft[MAXN];
vector<pair<ll, int> > updates[MAXN];
ll DNE = 0;
ll comb(ll a, ll b)
{
return a + b;
}
node* build(int L, int R)
{
node* t = new node();
if (L == R) return t;
int mid = (L + R) >> 1;
t -> ch[0] = build(L, mid);
t -> ch[1] = build(mid + 1, R);
return t;
}
node *update(node *w, int L, int R, int a, ll v)
{
if (a < L || R < a)
{
return w;
}
node *t = new node();
if (L == R)
{
t -> stor = w -> stor + v;
return t;
}
int mid = (L + R) >> 1;
t -> ch[0] = update(w -> ch[0], L, mid, a, v);
t -> ch[1] = update(w -> ch[1], mid + 1, R, a, v);
t -> stor = comb(t -> ch[0] -> stor, t -> ch[1] -> stor);
return t;
}
ll query(node *w, int L, int R, int a, int b)
{
if (b < L || R < a)
{
return DNE;
}
if (a <= L && R <= b)
{
return w -> stor;
}
int mid = (L + R) >> 1;
return query(w -> ch[0], L, mid, a, b) + query(w -> ch[1], mid + 1, R, a, b);
}
void process()
{
root[0] = build(0, N);
ft[0] = 0;
for (int i = 1; i <= N; i++)
{
for (auto p : updates[i])
{
ll v = p.fi; int idx = p.se;
T++; root[T] = update(root[T - 1], 0, N, idx, v);
}
ft[i] = T;
}
}
ll sum(int t, int L, int R)
{
return query(root[ft[t]], 0, N, L, R);
}
ll rect(int x0, int x1, int y0, int y1)
{
return query(root[ft[x1]], 0, N, y0, y1) - query(root[ft[x0 - 1]], 0, N, y0, y1);
}
};
pseg vseg, hseg, tseg, bvseg, bhseg, btseg;
set<pii> s;
vector<pii> hor, vert, vtx, bhor, bvert, bvtx;
void workset()
{
for (pii p : s)
{
int x = p.fi, y = p.se;
bool go[3][3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
go[i][j] = true;
if (s.find({x + i - 1, y + j - 1}) == s.end()) go[i][j] = false;
}
}
if (!go[1][2]) vert.PB({x, y + 1});
else bvert.PB({x, y + 1});
if (!go[2][1]) hor.PB({x + 1, y});
else bhor.PB({x + 1, y});
if (!go[1][0]) vert.PB({x, y});
else bvert.PB({x, y});
if (!go[0][1]) hor.PB({x, y});
else bhor.PB({x, y});
if (!go[0][0] || !go[0][1] || !go[1][0] || !go[1][1]) vtx.PB({x, y});
else bvtx.PB({x, y});
if (!go[1][0] || !go[1][1] || !go[2][0] || !go[2][1]) vtx.PB({x + 1, y});
else bvtx.PB({x + 1, y});
if (!go[0][1] || !go[0][2] || !go[1][1] || !go[1][2]) vtx.PB({x, y + 1});
else bvtx.PB({x, y + 1});
if (!go[1][1] || !go[1][2] || !go[2][1] || !go[2][2]) vtx.PB({x + 1, y + 1});
else bvtx.PB({x + 1, y + 1});
}
}
void init(int R, int C, int x, int y, int K, char *S)
{
N = max(R, C) + 2;
s.insert({x, y});
for (int i = 0; i < K; i++)
{
if (S[i] == 'N') x--;
if (S[i] == 'S') x++;
if (S[i] == 'E') y++;
if (S[i] == 'W') y--;
s.insert({x, y});
}
workset();
sort(hor.begin(), hor.end());
hor.erase(unique(hor.begin(), hor.end()), hor.end());
sort(vert.begin(), vert.end());
vert.erase(unique(vert.begin(), vert.end()), vert.end());
sort(vtx.begin(), vtx.end());
vtx.erase(unique(vtx.begin(), vtx.end()), vtx.end());
sort(bhor.begin(), bhor.end());
bhor.erase(unique(bhor.begin(), bhor.end()), bhor.end());
sort(bvert.begin(), bvert.end());
bvert.erase(unique(bvert.begin(), bvert.end()), bvert.end());
sort(bvtx.begin(), bvtx.end());
bvtx.erase(unique(bvtx.begin(), bvtx.end()), bvtx.end());
for (pii p : hor)
{
// cerr << "hor " << p.fi << ' ' << p.se << endl;
hseg.updates[p.fi].PB({1, p.se});
}
for (pii p : vert)
{
// cerr << "vert " << p.fi << ' ' << p.se << endl;
vseg.updates[p.fi].PB({1, p.se});
}
for (pii p : vtx)
{
// cerr << "vtx " << p.fi << ' ' << p.se << endl;
tseg.updates[p.fi].PB({1, p.se});
}
for (pii p : bhor)
{
bhseg.updates[p.fi].PB({1, p.se});
}
for (pii p : bvert)
{
// cerr << "bvh " << p.fi << ' ' << p.se << endl;
bvseg.updates[p.fi].PB({1, p.se});
}
for (pii p : bvtx)
{
btseg.updates[p.fi].PB({1, p.se});
}
hseg.process();
vseg.process();
tseg.process();
bhseg.process();
bvseg.process();
btseg.process();
}
ll x0, x1, y0, y1;
ll edges()
{
// cerr << vseg.rect(x0, x1, y0 + 1, y1) << ' ' << hseg.rect(x0 + 1, x1, y0, y1) << endl;
return 2 * (x1 - x0 + 1) + 2 * (y1 - y0 + 1) + vseg.rect(x0, x1, y0 + 1, y1) + hseg.rect(x0 + 1, x1, y0, y1);
}
ll vertices()
{
return 2 * (x1 - x0 + 1) + 2 * (y1 - y0 + 1) + tseg.rect(x0 + 1, x1, y0 + 1, y1);
}
ll bedges()
{
// cerr << "edges " << vseg.rect(x0, x1, y0, y1 + 1) << ' ' << hseg.rect(x0, x1 + 1, y0, y1) << ' ' << bvseg.rect(x0, x1, y1 + 1, y1 + 1) << endl;
return vseg.rect(x0, x1, y0, y1 + 1) + hseg.rect(x0, x1 + 1, y0, y1)
+ bvseg.rect(x0, x1, y0, y0) + bvseg.rect(x0, x1, y1 + 1, y1 + 1)
+ bhseg.rect(x0, x0, y0, y1) + bhseg.rect(x1 + 1, x1 + 1, y0, y1);
}
ll bvertices()
{
return tseg.rect(x0, x1 + 1, y0, y1 + 1)
+ btseg.rect(x0, x1 + 1, y0, y0) + btseg.rect(x0, x1 + 1, y1 + 1, y1 + 1)
+ btseg.rect(x0, x0, y0, y1 + 1) + btseg.rect(x1 + 1, x1 + 1, y0, y1 + 1);
}
ll total()
{
return edges() - vertices() + 1;
}
ll bads()
{
// debug(bedges());
// cerr << bedges() << ' ' << bvertices() << endl;
return bedges() - bvertices() + 1;
}
int colour(int _x0, int _y0, int _x1, int _y1)
{
x0 = _x0; x1 = _x1; y0 = _y0; y1 = _y1;
ll ans = 0;
// cerr << total() << ' ' << bads() << endl;
// cerr << total() << ' ' << bads() << endl;
ans = total() - bads();
//F + V = E + 2 => F = E - V + 2 => ans = E - V + 1 - (# of bad cc's)
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
56956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
56956 KB |
Output is correct |
2 |
Correct |
52 ms |
56988 KB |
Output is correct |
3 |
Incorrect |
2482 ms |
329012 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
329012 KB |
Output is correct |
2 |
Correct |
978 ms |
453220 KB |
Output is correct |
3 |
Correct |
913 ms |
456280 KB |
Output is correct |
4 |
Correct |
927 ms |
457140 KB |
Output is correct |
5 |
Correct |
732 ms |
457140 KB |
Output is correct |
6 |
Incorrect |
334 ms |
457140 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
56956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
56956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |