mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 13:16:26 +00:00
parent
e699498ba2
commit
3654dfb19b
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.
BIN
S2OJ/1008/data/zxcv1.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv1.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv10.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv10.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv11.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv11.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv11.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv12.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv12.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv12.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv13.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv13.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv13.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv14.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv14.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv14.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv15.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv15.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv15.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv16.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv16.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv16.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv17.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv17.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv17.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv18.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv18.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv18.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv19.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv19.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv19.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv2.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv2.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv20.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv20.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv20.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv21.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv21.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv21.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv21.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv22.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv22.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv22.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv22.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv23.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv23.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv23.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv23.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv24.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv24.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv24.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv24.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv25.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv25.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv25.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv25.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv26.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv26.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv26.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv26.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv27.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv27.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv27.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv27.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv28.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv28.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv28.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv28.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv29.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv29.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv29.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv29.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv3.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv3.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv30.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv30.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv30.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv30.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv31.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv31.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv31.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv31.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv32.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv32.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv32.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv32.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv33.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv33.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv33.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv33.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv34.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv34.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv34.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv34.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv35.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv35.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv35.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv35.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv36.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv36.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv36.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv36.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv37.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv37.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv37.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv37.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv38.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv38.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv38.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv38.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv39.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv39.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv39.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv39.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv4.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv4.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv40.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv40.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv40.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv40.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv41.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv41.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv41.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv41.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv42.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv42.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv42.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv42.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv5.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv5.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv6.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv6.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv7.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv7.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv8.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv8.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv9.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv9.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1008/data/zxcv9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1008/data/zxcv9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user