이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define ft first
#define sd second
#define pi pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(...) dbg_out(__VA_ARGS__)
using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;
//Constants
const ll INF = 5 * 1e18;
const int IINF = 2 * 1e9;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ld PI = 3.14159265359;
//Templates
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';}
void dbg_out() {cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); }
template<typename T> void mins(T& x, T y) {x = min(x, y);}
template<typename T> void maxs(T& x, T y) {x = max(x, y);}
template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct BIT {
vector<int> tre;
int sz;
BIT(int n) : sz(n + 5), tre(n + 5, 0) {}
void upd(int i, int k) {
while (i <= sz) {
tre[i] += k;
i += i & -i;
}
}
int get(int i) {
int res = 0;
while (i > 0) {
res += tre[i];
i -= i & -i;
}
return res;
}
int get(int l, int r) {
if (l > r) return 0;
return get(r) - get(l - 1);
}
};
int find_best(int n) {
int mx = 0;
for (int i = 0; i < min(n, 500); i++) {
vector<int> res = ask(i);
int cur = res[0] + res[1];
if (cur == 0) return i;
maxs(mx, cur);
}
BIT bit(n + 5);
vector<pi> al;
function<void(int, int)> solve = [&](int left, int right) {
if (left > right) return;
int mi = (left + right) / 2;
vector<int> res = ask(mi);
if (res[0] + res[1] == mx) {
if (res[1] - bit.get(mi + 1, n)) {
solve(mi + 1, right);
}
if (res[0] - bit.get(1, mi + 1)) {
solve(left, mi - 1);
}
} else {
int pleft = mi, pright = mi + 1;
while (pleft >= left) {
res = ask(pleft);
if (res[0] + res[1] == mx) break;
bit.upd(pleft + 1, 1);
al.pb({res[0] + res[1], pleft});
pleft--;
}
if (res[0] - bit.get(1, pleft + 1)) {
solve(left, pleft - 1);
}
while (pright <= right) {
res = ask(pright);
if (res[0] + res[1] == mx) break;
bit.upd(pright + 1, 1);
al.pb({res[0] + res[1], pright});
pright++;
}
if (res[1] - bit.get(pright + 1, n)) {
solve(pright + 1, right);
}
}
};
solve(0, n - 1);
sort(all(al));
return al[0].sd;
}
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In constructor 'BIT::BIT(int)':
prize.cpp:40:6: warning: 'BIT::sz' will be initialized after [-Wreorder]
40 | int sz;
| ^~
prize.cpp:39:14: warning: 'std::vector<int> BIT::tre' [-Wreorder]
39 | vector<int> tre;
| ^~~
prize.cpp:41:2: warning: when initialized here [-Wreorder]
41 | BIT(int n) : sz(n + 5), tre(n + 5, 0) {}
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |