Submission #2600970
Source Code Expand
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); } template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20); ll y, w; cin >> y >> w; VV<ll> li(2*w); int n, m; ll d; cin >> n >> m >> d; V<ll> base(n); for (int i = 0; i < n; i++) { cin >> base[i]; base[i]--; } for (int i = 0; i < m; i++) { ll b, c; cin >> b >> c; b--; c--; li[c].push_back(b*2*w+c); li[w+c].push_back(b*2*w+w+c); } ll ans = 0; map<ll, int> st; st[-TEN(18)] = 1; st[TEN(18)] = 1; auto di = [&](ll x, ll y) { assert(x != y); ll hx = x / (2*w), hy = y / (2*w); ll wx = x % (2*w), wy = y % (2*w); ll ans = (hy-hx) * w + (wy-wx) - 1; if (ans < 0) { cout << x << " " << y << " " << hx << " " << hy << " " << ans << endl; } assert(ans >= 0); return ans; }; auto add = [&](ll x) { // cout << "ADD " << x << endl; if (st.count(x)) { st[x]++; return; } ll bk, nx; { auto it = st.lower_bound(x); nx = it->first; it--; bk = it->first; } st[x] = 1; if (di(bk, nx) <= d) return; ans++; if (di(bk, x) <= d) { ans += di(bk, x); } if (di(x, nx) <= d) { ans += di(x, nx); } }; auto era = [&](ll x) { // cout << "ERA " << x << endl; if (st[x] > 1) { st[x]--; return; } assert(st[x] == 1); st.erase(x); ll bk, nx; { auto it = st.lower_bound(x); nx = it->first; it--; bk = it->first; } if (di(bk, nx) <= d) return; ans--; if (di(bk, x) <= d) { ans -= di(bk, x); } if (di(x, nx) <= d) { ans -= di(x, nx); } }; auto addl = [&](int x) { for (ll d: li[x]) add(d); }; auto eral = [&](int x) { for (ll d: li[x]) era(d); }; for (int i = 0; i < w-1; i++) { addl(i); } for (int i = 0; i < w; i++) { addl(i+(w-1)); for (ll d: base) { ll dy = d / w, dx = d % w; ll d2 = dy*(w*2) + (i + dx); add(d2); } // for (auto d: st) { // cout << "(" << d.first << ", " << d.second << "), "; // } // cout << endl; cout << ans << endl; for (ll d: base) { ll dy = d / w, dx = d % w; ll d2 = dy*(w*2) + i + dx; era(d2); } eral(i); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - 祝日 |
User | yosupo |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 3057 Byte |
Status | AC |
Exec Time | 4447 ms |
Memory | 19868 KB |
Judge Result
Set Name | Sample | Subtask1 | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 600 / 600 | 100 / 100 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Subtask1 | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, sample-01.txt, sample-02.txt |
All | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-20.txt, 02-21.txt, 02-22.txt, 02-23.txt, 02-24.txt, 02-25.txt, 02-26.txt, 02-27.txt, 02-28.txt, 02-29.txt, 02-30.txt, 02-31.txt, 02-32.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 393 ms | 16896 KB |
01-02.txt | AC | 320 ms | 13824 KB |
01-03.txt | AC | 321 ms | 10624 KB |
01-04.txt | AC | 76 ms | 3840 KB |
01-05.txt | AC | 226 ms | 9472 KB |
01-06.txt | AC | 206 ms | 8576 KB |
01-07.txt | AC | 162 ms | 8120 KB |
01-08.txt | AC | 82 ms | 4480 KB |
01-09.txt | AC | 335 ms | 13440 KB |
01-10.txt | AC | 56 ms | 3072 KB |
01-11.txt | AC | 271 ms | 13824 KB |
01-12.txt | AC | 210 ms | 12160 KB |
01-13.txt | AC | 299 ms | 15232 KB |
01-14.txt | AC | 87 ms | 5632 KB |
01-15.txt | AC | 244 ms | 10496 KB |
01-16.txt | AC | 58 ms | 2048 KB |
01-17.txt | AC | 39 ms | 2688 KB |
01-18.txt | AC | 228 ms | 8576 KB |
01-19.txt | AC | 389 ms | 16896 KB |
01-20.txt | AC | 339 ms | 14464 KB |
02-01.txt | AC | 3158 ms | 16896 KB |
02-02.txt | AC | 899 ms | 10752 KB |
02-03.txt | AC | 991 ms | 17408 KB |
02-04.txt | AC | 1502 ms | 16128 KB |
02-05.txt | AC | 3212 ms | 16640 KB |
02-06.txt | AC | 1656 ms | 12288 KB |
02-07.txt | AC | 157 ms | 8112 KB |
02-08.txt | AC | 289 ms | 2176 KB |
02-09.txt | AC | 1934 ms | 16640 KB |
02-10.txt | AC | 189 ms | 2688 KB |
02-11.txt | AC | 2526 ms | 15616 KB |
02-12.txt | AC | 560 ms | 11008 KB |
02-13.txt | AC | 805 ms | 10624 KB |
02-14.txt | AC | 140 ms | 1920 KB |
02-15.txt | AC | 685 ms | 10112 KB |
02-16.txt | AC | 42 ms | 512 KB |
02-17.txt | AC | 61 ms | 2688 KB |
02-18.txt | AC | 268 ms | 8576 KB |
02-19.txt | AC | 3202 ms | 16896 KB |
02-20.txt | AC | 128 ms | 8044 KB |
02-21.txt | AC | 613 ms | 3584 KB |
02-22.txt | AC | 2 ms | 256 KB |
02-23.txt | AC | 4447 ms | 19868 KB |
02-24.txt | AC | 1825 ms | 12416 KB |
02-25.txt | AC | 1365 ms | 11264 KB |
02-26.txt | AC | 3 ms | 256 KB |
02-27.txt | AC | 170 ms | 1024 KB |
02-28.txt | AC | 586 ms | 2688 KB |
02-29.txt | AC | 200 ms | 8192 KB |
02-30.txt | AC | 217 ms | 8320 KB |
02-31.txt | AC | 216 ms | 8320 KB |
02-32.txt | AC | 438 ms | 2048 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |
sample-03.txt | AC | 1 ms | 256 KB |
sample-04.txt | AC | 1 ms | 256 KB |