# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
115419 | gs18103 | 허수아비 (JOI14_scarecrows) | C++98 | 221 ms | 5940 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
pair <int, int> arr[202020];
long long ans = 0;
void dnc(int s, int e) {
if(s == e) return;
int m = (s + e) / 2;
stack <int> l, r;
for(int i = m; i >= s; i--) {
if(l.empty()) l.push(arr[i].y);
else if(l.top() < arr[i].y) l.push(arr[i].y);
}
int ty = 2000000000, re = 0;
for(int i = m + 1; i <= e; i++) {
if(arr[i].y < ty) ty = arr[i].y;
else continue;
while(!l.empty() && l.top() > ty) {
l.pop();
}
ans += l.size();
}
dnc(s, m);
dnc(m+1, e);
}
int main() {
int n;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> arr[i].x >> arr[i].y;
}
sort(arr+1, arr+n+1);
dnc(1, n);
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |