이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5;
struct Point
{
int x, y;
Point() {}
Point(int x, int y) : x(x), y(y) {}
bool operator < (const Point& p)
{
return x<p.x;
}
};
int n;
ll ans;
Point arr[MAXN+10];
vector<int> xpos, ypos;
int xcoord[MAXN+10];
vector<vector<Point>> tree;
void update(int node, int tl, int tr, int x, int y)
{
if(tl==tr) { tree[node]=vector<Point>(1, Point(x, y)); return; }
int mid=tl+tr>>1;
if(y<=mid) update(node*2, tl, mid, x, y);
else update(node*2+1, mid+1, tr, x, y);
while(!tree[node].empty() && tree[node].back().y<y) tree[node].pop_back();
tree[node].push_back({x, y});
}
int last=-1, ret=0;
void query(int node, int tl, int tr, int l, int r)
{
if(r<tl || tr<l) return;
if(l<=tl && tr<=r)
{
if(tree[node].empty()) return;
ret+=tree[node].end()-lower_bound(tree[node].begin(), tree[node].end(), Point(last, 0));
last=max(last, tree[node].back().x);
return;
}
int mid=tl+tr>>1;
query(node*2+1, mid+1, tr, l, r);
query(node*2, tl, mid, l, r);
}
int main()
{
int i, j;
scanf("%d", &n);
for(i=0; i<n; i++)
{
scanf("%d%d", &arr[i].x, &arr[i].y);
xpos.push_back(arr[i].x);
ypos.push_back(arr[i].y);
}
sort(xpos.begin(), xpos.end());
sort(ypos.begin(), ypos.end());
for(i=0; i<n; i++)
{
arr[i].x=lower_bound(xpos.begin(), xpos.end(), arr[i].x)-xpos.begin()+1;
arr[i].y=lower_bound(ypos.begin(), ypos.end(), arr[i].y)-ypos.begin()+1;
}
sort(arr, arr+n, [&](const Point& p, const Point& q)
{
return p.x<q.x;
});
tree.resize(n*4+10);
for(i=0; i<n; i++)
{
last=-1, ret=0;
query(1, 1, n, 1, arr[i].y);
ans+=ret;
update(1, 1, n, arr[i].x, arr[i].y);
}
printf("%lld", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
scarecrows.cpp: In function 'void update(int, int, int, int, int)':
scarecrows.cpp:32:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
scarecrows.cpp: In function 'void query(int, int, int, int, int)':
scarecrows.cpp:51:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
scarecrows.cpp: In function 'int main()':
scarecrows.cpp:58:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
scarecrows.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
scarecrows.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &arr[i].x, &arr[i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |