이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
const int MXN = 100005;
int n, k;
vector<pii> v;
ll sum;
struct SLOPE_TRICK {
int val, now;
multiset<int> L, R;
void init() {
val = 0;
now = INT_MAX;
L.clear();
R.clear();
L.insert(INT_MIN);
R.insert(INT_MAX);
}
void add(int x) {
val += abs(now - x);
if (L.lower_bound(x) == L.end()) {
if (x <= *R.begin()) {
L.insert(x);
R.insert(x);
val -= abs(now - x);
now = x;
} else {
R.insert(x);
R.insert(x);
L.insert(*R.begin());
R.erase(R.begin());
now = *R.begin();
}
} else {
L.insert(x);
L.insert(x);
R.insert(*L.rbegin());
L.erase(prev(L.end()));
int cur = *R.begin();
val -= (now - cur);
now = cur;
}
}
void COUT() {
debug(now, val);
for (auto i : L) cout << i << ' ';
cout << endl;
for (auto i : R) cout << i << ' ';
cout << endl;
}
} slt;
void miku() {
cin >> k >> n;
assert(k == 1);
FOR(i, 0, n) {
int a, b;
char c, d;
cin >> c >> a >> d >> b;
if (a > b) swap(a, b);
if (c == d) {
sum += b - a;
} else {
sum += 1;
v.push_back(mp(a, b));
}
}
slt.init();
for (auto &[a, b] : v) {
slt.add(a);
// slt.COUT();
slt.add(b);
// slt.COUT();
}
cout << sum + slt.val << '\n';
}
void test() {
slt.init();
slt.add(0);
slt.COUT();
slt.add(1);
slt.COUT();
slt.add(2);
slt.COUT();
slt.add(3);
slt.COUT();
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In member function 'void SLOPE_TRICK::COUT()':
bridge.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
bridge.cpp:63:9: note: in expansion of macro 'debug'
63 | debug(now, val);
| ^~~~~
# | 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... |