Submission #290604

#TimeUsernameProblemLanguageResultExecution timeMemory
290604AM1648Land of the Rainbow Gold (APIO17_rainbow)C++17
100 / 100
1132 ms153592 KiB
/* be name khoda */ // #define long_enable #include <iostream> #include <algorithm> #include <cstring> #include <numeric> #include <vector> #include <fstream> #include <set> #include <map> using namespace std; #ifdef long_enable typedef long long int ll; #else typedef int ll; #endif typedef pair<ll, ll> pii; typedef pair<pii, ll> ppi; typedef pair<ll, pii> pip; typedef vector<ll> vi; typedef vector<pii> vpii; #define forifrom(i, s, n) for (ll i = s; i < n; ++i) #define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i) #define fori(i, n) forifrom (i, 0, n) #define forir(i, n) forirto (i, n, 0) #define F first #define S second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define smin(a, b) a = min(a, (b)) #define smax(a, b) a = max(a, (b)) #define debug(x) cout << #x << " -> " << (x) << endl #define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl #define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl #define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl #define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl #define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl const ll MOD = 1000000007; const ll INF = 2000000000; const long long BIG = 1446803456761533460LL; #define XL (x << 1) #define XR (XL | 1) #define MD ((l + r) >> 1) #define Add(a, b) a = ((a) + (b)) % MOD #define Mul(a, b) a = (1LL * (a) * (b)) % MOD // ----------------------------------------------------------------------- const ll maxn = 400000 + 10; ll n, m, rmn = maxn, rmx = 0, cmn = maxn, cmx = 0; pii d[256]; struct Segment { ll m = 0; pii pts[maxn]; vi seg[maxn * 2]; void add(ll r, ll c) { pts[m++] = {r, c}; } void build() { sort(pts, pts + m); m = unique(pts, pts + m) - pts; fori (i, m) seg[pts[i].F + n].eb(pts[i].S); forirto (i, n, 1) { ll lsz = seg[i << 1].size(), rsz = seg[i << 1 ^ 1].size(); seg[i].resize(lsz + rsz); merge(all(seg[i << 1]), all(seg[i << 1 ^ 1]), seg[i].begin()); } } inline ll count(vi &ar, ll l, ll r) { return lower_bound(all(ar), r) - lower_bound(all(ar), l); } ll get(ll l1, ll r1, ll l2, ll r2) { ll s = 0; for (l1 += n, r1 += n; l1 < r1; l1 >>= 1, r1 >>= 1) { if (l1 & 1) s += count(seg[l1], l2, r2), ++l1; if (r1 & 1) --r1, s += count(seg[r1], l2, r2); } return s; } } verts, edgesV, edgesH, faces; void move(ll r, ll c) { smin(rmn, r), smax(rmx, r); smin(cmn, c), smax(cmx, c); faces.add(r, c); fori (i, 4) verts.add(r + (i & 1), c + (i >> 1)); fori (i, 2) edgesV.add(r, c + i), edgesH.add(r + i, c); } void init(ll Ri, ll Ci, ll sr, ll sc, ll M, char *P) { d['N'] = {-1, 0}; d['S'] = {1, 0}; d['W'] = {0, -1}; d['E'] = {0, 1}; n = Ri, m = Ci; --sr, --sc; move(sr, sc); fori (i, M) { sr += d[(ll) P[i]].F, sc += d[(ll) P[i]].S; move(sr, sc); } verts.build(); edgesV.build(); edgesH.build(); faces.build(); } ll colour(ll ar, ll ac, ll br, ll bc) { --ar, --ac; ll v = verts.get(ar + 1, br, ac + 1, bc); ll e = edgesV.get(ar, br, ac + 1, bc) + edgesH.get(ar + 1, br, ac, bc); ll river = faces.get(ar, br, ac, bc); bool inside = (ar < rmn && rmx < br - 1 && ac < cmn && cmx < bc - 1); ll c = 1 + inside; ll f = c - v + e + 1 - 1; // c = v - e + (f - 1) (-1 was for big face) ll ans = f - river; return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...