mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
P2286 [HNOI2004]宠物收养场
R70587055
This commit is contained in:
parent
6027b94754
commit
c40a51310b
41
Luogu/P2286/P2286.cpp
Normal file
41
Luogu/P2286/P2286.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int mod = 1e6;
|
||||
|
||||
int n, op, x, ans;
|
||||
std::vector<int> a, b;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> op >> x;
|
||||
if (op == 0) {
|
||||
if (b.empty()) {
|
||||
a.insert(std::lower_bound(a.begin(), a.end(), -x), -x);
|
||||
} else {
|
||||
auto it = std::lower_bound(b.begin(), b.end(), -x);
|
||||
if (it == b.end() || it != b.begin() && std::abs(-*it - x) > std::abs(-*(it - 1) - x)) --it;
|
||||
ans = (ans + std::abs(-*it - x)) % mod;
|
||||
b.erase(it);
|
||||
}
|
||||
} else { // op == 1
|
||||
if (a.empty()) {
|
||||
b.insert(std::lower_bound(b.begin(), b.end(), -x), -x);
|
||||
} else {
|
||||
auto it = std::lower_bound(a.begin(), a.end(), -x);
|
||||
if (it == a.end() || it != a.begin() && std::abs(-*it - x) > std::abs(-*(it - 1) - x)) --it;
|
||||
ans = (ans + std::abs(-*it - x)) % mod;
|
||||
a.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << ans % mod << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user