Submission #987396

#TimeUsernameProblemLanguageResultExecution timeMemory
987396876polGarden (JOI23_garden)C++17
45 / 100
3088 ms16128 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; using pll = pair<ll, ll>; template <class T> using vec = vector<T>; template <class T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define FOR(i, s, e) for (ll i = (ll)s; i < (ll)e; i++) #define CFOR(i, s, e) for (ll i = (ll)s; i <= (ll)e; i++) #define TRAV(e, i) for (const auto &e : i) #define all(x) x.begin(), x.end() #define dbg(x) cerr << "ln" << __LINE__ << ": " << #x << " = " << x << endl; template <class T, class = decay_t<decltype(*begin(declval<T>()))>, class = enable_if_t<!is_same<string, T>::value>> ostream &operator<<(ostream &out, const T &obj) { out << "["; for (auto it = obj.begin(); it != obj.end(); it++) { out << &", "[2 * (it == obj.begin())] << *it; } return out << "]"; } template <class K, class V> ostream &operator<<(ostream &out, const pair<K, V> &obj) { return out << "(" << obj.first << ", " << obj.second << ")"; } int main() { ll n, m, d; cin >> n >> m >> d; deque<ll> xc, yc; deque<ll> ax; vec<bool> rx(d), ry(d); FOR(i, 0, n) { ll a, b; cin >> a >> b; xc.push_back(a); yc.push_back(b); ax.push_back(a); rx[a] = ry[b] = 1; } vec<deque<ll>> loc(d); FOR(i, 0, m) { ll a, b; cin >> a >> b; if (!rx[a] && !ry[b]) { ax.push_back(a); loc[b].push_back(a); } } sort(all(xc)); xc.erase(unique(all(xc)), xc.end()); sort(all(yc)); yc.erase(unique(all(yc)), yc.end()); sort(all(ax)); ax.erase(unique(all(ax)), ax.end()); FOR(i, 0, d) { sort(all(loc[i])); loc[i].erase(unique(all(loc[i])), loc[i].end()); } auto nm = [&](ll x) { return (x % d + d) % d; }; map<ll, ll> ss = {{yc[0], 1}}; map<ll, ll> gaps = {{d - 1, 1}}; auto insert = [&](ll x) { if (ss.count(x)) { ss[x]++; return; } auto it = ss.upper_bound(x); ll o1 = (it == ss.begin()) ? ss.rbegin()->first : prev(it)->first; ll o2 = (it == ss.end()) ? ss.begin()->first : it->first; if (--gaps[nm(o2 - o1 - 1)] == 0) gaps.erase(nm(o2 - o1 - 1)); ss[x]++; gaps[nm(x - o1 - 1)]++; gaps[nm(o2 - x - 1)]++; }; auto remove = [&](ll x) { if (--ss[x]) return; ss.erase(x); auto it = ss.upper_bound(x); ll o1 = (it == ss.begin()) ? ss.rbegin()->first : prev(it)->first; ll o2 = (it == ss.end()) ? ss.begin()->first : it->first; if (--gaps[nm(x - o1 - 1)] == 0) gaps.erase(nm(x - o1 - 1)); if (--gaps[nm(o2 - x - 1)] == 0) gaps.erase(nm(o2 - x - 1)); gaps[nm(o2 - o1 - 1)]++; }; FOR(i, 1, yc.size()) insert(yc[i]); ll ans = INT_MAX; FOR(_, 0, ax.size()) { while (xc.front() < ax.front()) { xc.push_back(xc.front() + d); xc.pop_front(); } ll mxx = xc.back(); vec<pll> oc; FOR(i, 0, d) { if (loc[i].empty()) continue; while (loc[i].front() < ax.front()) { loc[i].push_back(loc[i].front() + d); loc[i].pop_front(); } if (mxx <= loc[i].back()) oc.push_back({loc[i].back(), i}); } sort(all(oc)); ll co = max(mxx, oc.empty() ? 0 : oc.back().first); ans = min(ans, (d - gaps.rbegin()->first) * (co - ax.front() + 1)); ll ind; for (ind = oc.size() - 1; ind >= 0; ind--) { if (oc[ind].first <= mxx) break; co = max(mxx, (ind == 0) ? mxx : oc[ind - 1].first); insert(oc[ind].second); ans = min(ans, (d - gaps.rbegin()->first) * (co - ax.front() + 1)); } ind++; while (ind < oc.size()) remove(oc[ind++].second); ax.push_back(ax.front() + d); ax.pop_front(); } cout << ans << "\n"; }

Compilation message (stderr)

garden.cpp: In function 'int main()':
garden.cpp:126:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |         while (ind < oc.size()) remove(oc[ind++].second);
      |                ~~~~^~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...