mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 14:36:27 +00:00
parent
3654dfb19b
commit
d55d3241c5
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.
Loading…
Reference in New Issue
Block a user