mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 16:16:25 +00:00
Compare commits
4 Commits
e699498ba2
...
95ce0ec323
Author | SHA1 | Date | |
---|---|---|---|
95ce0ec323 | |||
904ab965c5 | |||
d55d3241c5 | |||
3654dfb19b |
112
LibreOJ/2880/2880.cpp
Normal file
112
LibreOJ/2880/2880.cpp
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 2e5 + 5;
|
||||||
|
|
||||||
|
int n, c[N], st[N];
|
||||||
|
long long ans;
|
||||||
|
std::vector<int> xs;
|
||||||
|
std::pair<int, int> p[N];
|
||||||
|
|
||||||
|
inline int lowbit(int x) {
|
||||||
|
return x & -x;
|
||||||
|
}
|
||||||
|
|
||||||
|
void insert(int x, int y) {
|
||||||
|
for (; x; x -= lowbit(x)) c[x] = std::min(c[x], y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int query(int x) {
|
||||||
|
int res = std::numeric_limits<int>::max();
|
||||||
|
|
||||||
|
for (; x <= n; x += lowbit(x)) res = std::min(res, c[x]);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear(int x) {
|
||||||
|
for (; x; x -= lowbit(x)) c[x] = std::numeric_limits<int>::max();
|
||||||
|
}
|
||||||
|
|
||||||
|
int search(int l, int r, int y) {
|
||||||
|
int res = r + 1;
|
||||||
|
|
||||||
|
while (l <= r) {
|
||||||
|
int mid = l + r >> 1;
|
||||||
|
|
||||||
|
if (p[st[mid]].second < y) {
|
||||||
|
res = mid;
|
||||||
|
r = mid - 1;
|
||||||
|
} else {
|
||||||
|
l = mid + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void solve(int l, int r) {
|
||||||
|
if (l >= r) return;
|
||||||
|
|
||||||
|
int mid = (l + r) >> 1;
|
||||||
|
solve(l, mid);
|
||||||
|
solve(mid + 1, r);
|
||||||
|
|
||||||
|
for (int i = l, j = mid + 1, top = 0; i <= mid; i++) {
|
||||||
|
while (j <= r && p[j].second > p[i].second) {
|
||||||
|
while (top && p[st[top]].first > p[j].first) top--;
|
||||||
|
|
||||||
|
st[++top] = j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ans += top - search(1, top, query(p[i].first)) + 1;
|
||||||
|
|
||||||
|
insert(p[i].first, p[i].second);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = l; i <= mid; i++) {
|
||||||
|
clear(p[i].first);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(p + l, p + r + 1, [](const std::pair<int, int> &a, const std::pair<int, int> &b) {
|
||||||
|
return a.second > b.second;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
std::fill_n(c, N, std::numeric_limits<int>::max());
|
||||||
|
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
cin >> p[i].first >> p[i].second;
|
||||||
|
|
||||||
|
xs.emplace_back(p[i].first);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(p + 1, p + 1 + n, [](const std::pair<int, int> &a, const std::pair<int, int> &b) {
|
||||||
|
return a.first < b.first;
|
||||||
|
});
|
||||||
|
std::sort(xs.begin(), xs.end());
|
||||||
|
xs.erase(std::unique(xs.begin(), xs.end()), xs.end());
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
p[i].first = std::lower_bound(xs.begin(), xs.end(), p[i].first) - xs.begin() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
solve(1, n);
|
||||||
|
|
||||||
|
cout << ans << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
LibreOJ/2880/data/01-01.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-01.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-01.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-01.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-02.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-02.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-02.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-02.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-03.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-03.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-03.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-03.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-04.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-04.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-04.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-04.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-05.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-05.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-05.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-05.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-06.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-06.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-06.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-06.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-07.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-07.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-07.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-07.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-08.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-08.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-08.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-08.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-09.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-09.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-09.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-09.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-10.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-10.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/01-10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/01-10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-01.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-01.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-01.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-01.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-02.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-02.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-02.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-02.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-03.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-03.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-03.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-03.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-04.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-04.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-04.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-04.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-05.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-05.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-05.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-05.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-06.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-06.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-06.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-06.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-07.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-07.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-07.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-07.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-08.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-08.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-08.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-08.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-09.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-09.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-09.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-09.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-10.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-10.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-11.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-11.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-11.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-12.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-12.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/02-12.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/02-12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-01.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-01.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-01.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-01.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-02.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-02.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-02.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-02.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-03.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-03.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-03.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-03.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-04.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-04.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-04.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-04.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-05.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-05.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-05.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-05.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-06.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-06.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-06.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-06.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-07.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-07.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-07.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-07.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-08.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-08.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-08.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-08.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-09.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-09.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-09.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-09.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-10.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-10.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-11.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-11.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-11.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-12.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-12.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-12.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-13.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-13.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-13.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-14.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-14.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-14.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-15.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-15.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-15.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-16.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-16.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-16.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-17.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-17.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-17.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-18.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-18.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-18.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-19.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-19.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-19.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-20.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-20.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/03-20.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/03-20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/sample-01.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/sample-01.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/sample-01.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/sample-01.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/sample-02.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/sample-02.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/2880/data/sample-02.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/2880/data/sample-02.in
(Stored with Git LFS)
Normal file
Binary file not shown.
44
Luogu/T275386/T275386.cpp
Normal file
44
Luogu/T275386/T275386.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 1e5 + 5;
|
||||||
|
|
||||||
|
int n, k, ans;
|
||||||
|
std::pair<int, int> a[N];
|
||||||
|
std::multiset<int> set;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> k;
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
cin >> a[i].first >> a[i].second;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(a + 1, a + 1 + n, [&](const std::pair<int, int> &a, const std::pair<int, int> &b) {
|
||||||
|
return a.second < b.second;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (int i = 1; i <= k; i++) set.insert(0);
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
auto it = set.upper_bound(a[i].first);
|
||||||
|
|
||||||
|
if (it != set.begin()) {
|
||||||
|
set.erase(--it);
|
||||||
|
set.insert(a[i].second);
|
||||||
|
ans++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << ans << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
88
Luogu/T275388/T275388.cpp
Normal file
88
Luogu/T275388/T275388.cpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <numeric>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 2e5 + 5;
|
||||||
|
|
||||||
|
int n, m;
|
||||||
|
bool vis[N];
|
||||||
|
std::vector<int> g[N], a, b;
|
||||||
|
|
||||||
|
void check() {
|
||||||
|
if (a.size() == n - a.size() - b.size()) {
|
||||||
|
std::fill_n(vis, N, false);
|
||||||
|
|
||||||
|
cout << b.size() << ' ' << a.size() << endl;
|
||||||
|
|
||||||
|
for (const int &x : b) {
|
||||||
|
cout << x << ' ';
|
||||||
|
|
||||||
|
vis[x] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
for (const int &x : a) {
|
||||||
|
cout << x << ' ';
|
||||||
|
|
||||||
|
vis[x] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
if (!vis[i]) {
|
||||||
|
cout << i << ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dfs(int u) {
|
||||||
|
vis[u] = true;
|
||||||
|
b.emplace_back(u);
|
||||||
|
check();
|
||||||
|
|
||||||
|
for (const int &v : g[u]) {
|
||||||
|
if (vis[v]) continue;
|
||||||
|
|
||||||
|
dfs(v);
|
||||||
|
check();
|
||||||
|
}
|
||||||
|
|
||||||
|
b.pop_back();
|
||||||
|
a.emplace_back(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> m;
|
||||||
|
|
||||||
|
for (int i = 1; i <= m; i++) {
|
||||||
|
int u, v;
|
||||||
|
|
||||||
|
cin >> u >> v;
|
||||||
|
|
||||||
|
g[u].emplace_back(v);
|
||||||
|
g[v].emplace_back(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
if (!vis[i]) dfs(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << -1 << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
Luogu/T275388/samples/checker.cpp
(Stored with Git LFS)
Normal file
BIN
Luogu/T275388/samples/checker.cpp
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/T275388/samples/ex_king4.in
(Stored with Git LFS)
Normal file
BIN
Luogu/T275388/samples/ex_king4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/T275388/samples/ex_king4.out
(Stored with Git LFS)
Normal file
BIN
Luogu/T275388/samples/ex_king4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
112
S2OJ/1008/1008.cpp
Normal file
112
S2OJ/1008/1008.cpp
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 2e5 + 5;
|
||||||
|
|
||||||
|
int n, c[N], st[N];
|
||||||
|
long long ans;
|
||||||
|
std::vector<int> xs;
|
||||||
|
std::pair<int, int> p[N];
|
||||||
|
|
||||||
|
inline int lowbit(int x) {
|
||||||
|
return x & -x;
|
||||||
|
}
|
||||||
|
|
||||||
|
void insert(int x, int y) {
|
||||||
|
for (; x; x -= lowbit(x)) c[x] = std::min(c[x], y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int query(int x) {
|
||||||
|
int res = std::numeric_limits<int>::max();
|
||||||
|
|
||||||
|
for (; x <= n; x += lowbit(x)) res = std::min(res, c[x]);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear(int x) {
|
||||||
|
for (; x; x -= lowbit(x)) c[x] = std::numeric_limits<int>::max();
|
||||||
|
}
|
||||||
|
|
||||||
|
int search(int l, int r, int y) {
|
||||||
|
int res = r + 1;
|
||||||
|
|
||||||
|
while (l <= r) {
|
||||||
|
int mid = l + r >> 1;
|
||||||
|
|
||||||
|
if (p[st[mid]].second < y) {
|
||||||
|
res = mid;
|
||||||
|
r = mid - 1;
|
||||||
|
} else {
|
||||||
|
l = mid + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void solve(int l, int r) {
|
||||||
|
if (l >= r) return;
|
||||||
|
|
||||||
|
int mid = (l + r) >> 1;
|
||||||
|
solve(l, mid);
|
||||||
|
solve(mid + 1, r);
|
||||||
|
|
||||||
|
for (int i = l, j = mid + 1, top = 0; i <= mid; i++) {
|
||||||
|
while (j <= r && p[j].second > p[i].second) {
|
||||||
|
while (top && p[st[top]].first > p[j].first) top--;
|
||||||
|
|
||||||
|
st[++top] = j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ans += top - search(1, top, query(p[i].first)) + 1;
|
||||||
|
|
||||||
|
insert(p[i].first, p[i].second);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = l; i <= mid; i++) {
|
||||||
|
clear(p[i].first);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(p + l, p + r + 1, [](const std::pair<int, int> &a, const std::pair<int, int> &b) {
|
||||||
|
return a.second > b.second;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
std::fill_n(c, N, std::numeric_limits<int>::max());
|
||||||
|
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
cin >> p[i].first >> p[i].second;
|
||||||
|
|
||||||
|
xs.emplace_back(p[i].first);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(p + 1, p + 1 + n, [](const std::pair<int, int> &a, const std::pair<int, int> &b) {
|
||||||
|
return a.first < b.first;
|
||||||
|
});
|
||||||
|
std::sort(xs.begin(), xs.end());
|
||||||
|
xs.erase(std::unique(xs.begin(), xs.end()), xs.end());
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
p[i].first = std::lower_bound(xs.begin(), xs.end(), p[i].first) - xs.begin() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
solve(1, n);
|
||||||
|
|
||||||
|
cout << ans << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
S2OJ/1008/data/ex_zxcv1.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/ex_zxcv1.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/ex_zxcv1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/ex_zxcv1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/ex_zxcv2.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/ex_zxcv2.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/ex_zxcv2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/ex_zxcv2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user