이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
#include <utility>
using namespace std;
using ll = long long;
using pi = pair<ll,ll>;
using pl = pair<ll,ll>;
#define temp(T) template<class T>
temp(T) using V = vector<T>;
using vi = V<ll>;
using vl = V<ll>;
using vvi = V<vi>;
using vpi = V<pi>;
using vb = V<bool>;
using vvb = V<vb>;
vi dx = {0,1,-1,0};
vi dy = {1,0,0,-1};
#define sz(x) x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for (ll i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (ll i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
using str = string;
const ll MOD = 1e9 + 7;
const ll BIG = 1e18;
const ll INF = 1e9 + 2;
temp(T) bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; } // set a = min(a,b)
temp(T) bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0; } // set a = max(a,b)
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
// FILE I/O
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void setIO(str s = "") {
unsyncIO();
if (sz(s)) setIn(s+".in"), setOut(s+".out"); // for USACO
}
#define read(x) ll x; cin >> x
temp(T) void pr(T x) {
cout << to_string(x);
}
temp(T) void prln(T x) {
cout << to_string(x) << "\n";
}
vi readV(ll n) {
vi input(n);
F0R(i,n)
cin >> input[i];
return input;
}
ll rand(ll a, ll b) {
return a + rand() % (b - a + 1);
}
#define gen(x,a,b) ll x = rand(a,b)
temp(T) void moveAll(V<T> &a, V<T> &b) {
each(x,b) {
a.pb(x);
}
b.clear();
}
vi genArr(ll n, ll a, ll b) {
vi generated(n);
F0R(i,n) {
generated[i] = rand(a,b);
}
return generated;
}
vvi genTree(ll n) {
vvi g(n + 1);
F0R(i,n) {
gen(p,0,i);
g[p].pb(i + 1);
g[i + 1].pb(p);
}
return g;
}
vvb readGrid(ll a, ll b) {
vvb grid(a + 2, vb(b + 2, true));
F0R(i, a) {
F0R(j, b) {
bool k; cin >> k;
grid[i + 1][j + 1] = k;
}
}
return grid;
}
using tup = tuple<ll, ll, bool>; // x, y, changed
V<tup> pos;
ll d;
ll fix(ll t) {
if (t == 0) return d;
return (t + d) % d;
}
ll fix2(ll t) {
return (t + d) % d;
}
ll get(ll x, ll l, bool first) {
if (x == l && !first) return 0;
return (x - l + d - 1) % d;
}
struct circle {
multiset<ll> dataPolls;
set<ll> clone;
multiset<int> pq;
pl get(int p) {
auto it = dataPolls.lower_bound(p);
if (it == dataPolls.end()) it = dataPolls.begin();
int first = *it;
if (it == dataPolls.begin()) it = dataPolls.end();
it--;
int sec = *it;
return {first, sec};
}
void insert(ll x) {
if (!dataPolls.empty()) {
auto [a, b] = get(x);
pq.erase(pq.find(fix2(a - b)));
pq.emplace(fix2(a - x));
pq.emplace(fix2(x - b));
} else {
pq.emplace(0);
}
dataPolls.ins(x);
}
void erase(ll x) {
dataPolls.erase(dataPolls.find(x));
if (dataPolls.empty()) {
pq.clear();
return;
}
auto [a,b] = get(x);
pq.emplace(fix2(a - b));
pq.erase(pq.find(fix2(a - x)));
pq.erase(pq.find(fix2(x - b)));
}
ll query() {
if (dataPolls.empty()) return 1;
if (*dataPolls.begin() == *dataPolls.rbegin() == 1)
return 1;
return d - (*pq.rbegin() - 1);
}
void clear() {
dataPolls.clear();
pq.clear();
}
};
set<tup> elm;
queue<tup> reqRemoved;
ll imp = 0;
circle c;
void addCur(tup x) {
reqRemoved.emplace(x);
imp += get<2>(x);
c.insert(get<1>(x));
}
void remCur() {
c.erase(get<1>(reqRemoved.front()));
imp -= get<2>(reqRemoved.front());
elm.ins(reqRemoved.front());
reqRemoved.pop();
}
void removeFrom(ll l, ll r) {
auto a = elm.lower_bound({l,-1,0});
while (a != elm.end() && get<0>(*a) < r) {
addCur(*a);
elm.erase(a);
a = elm.lower_bound({l,-1,0});
}
}
void reset() {
c.clear();
elm.clear();
imp = 0;
reqRemoved = queue<tup>();
}
ll findOpt(ll w) {
reset();
ll best = INF;
each(v, pos) {
auto [x, y, changed] = v;
if (changed) c.insert(y);
elm.ins(v);
}
each(v, pos) {
auto [x, y, changed] = v;
ll l = x - w;
if (l < 0) {
l += d;
removeFrom(l, 1e9);
removeFrom(0, x);
} else {
removeFrom(l, x);
}
while (!reqRemoved.empty() && (fix(x - get<0>(reqRemoved.front()))) > w) {
remCur();
}
if (imp == 0) ckmin(best, c.query());
}
return best;
}
ll eval(int i) {
return ll(findOpt(i)) * ll(d - (i));
}
int main() {
setIO();
ll n, m; cin >> n >> m >> d;
F0R(i, n) {
ll x, y; cin >> x >> y;
pos.pb({x % d,y % d,true});
}
F0R(i, m) {
ll x, y; cin >> x >> y;
pos.pb({x % d,y % d,false});
}
int BSIZE = 40;
sort(all(pos));
ll ans = ll(INF) * ll(INF) ;
ll last = ans;
int combo = 0;
FOR(i,0, d) {
ll v =ll(findOpt(i)) * ll(d - (i));
if (v > d * d) break;
if (i < d - BSIZE && (eval(i + BSIZE) < eval(i + BSIZE / 2)) && (eval(i + BSIZE / 2) < eval(i)) && eval(i + BSIZE) <= d* d) i += BSIZE / 2;
if (v > last) combo++;
else combo = 0;
if (combo > 10) break;
ckmin(ans, v);
last = v;
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
garden.cpp: In member function 'll circle::query()':
garden.cpp:187:32: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
187 | if (*dataPolls.begin() == *dataPolls.rbegin() == 1)
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
garden.cpp: In function 'void setIn(str)':
garden.cpp:59:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | void setIn(str s) { freopen(s.c_str(),"r",stdin); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
garden.cpp: In function 'void setOut(str)':
garden.cpp:60:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | void setOut(str s) { freopen(s.c_str(),"w",stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |