# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
51536 | Retro3014 | 허수아비 (JOI14_scarecrows) | C++17 | 181 ms | 12852 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 <iostream>
#include <vector>
#include <algorithm>
#define MAX_N 200003
#define INF 2000000000
using namespace std;
int seg[MAX_N*4+1];
struct S{
int x, y;
};
bool sf1(S a, S b){
return a.x<b.x;
}
bool sf2(S a, S b){
return a.y<b.y;
}
int N;
vector<S> v, v1;
vector<int> v2;
int idx[MAX_N+1];
void update(int x, int y)
{
while(x>0)
{
seg[x]+=y;
x/=2;
}
}
int sum(int x, int y)
{
int s=0;
while(x<=y)
{
if(x==y)
{
s+=seg[x];
return s;
}
if(x%2)
{
s+=seg[x];
x++;
}
if(!(y%2))
{
s+=seg[y];
y--;
}
x/=2;
y/=2;
}
return s;
}
long long ans;
int two=1;
int main()
{
scanf("%d", &N);
while(two<=(N+1)) two*=2;
for(int i=1; i<=N; i++)
{
S scan;
scanf("%d%d", &scan.x, &scan.y);
v1.push_back(scan);
}
sort(v1.begin(), v1.end(), sf2);
for(int i=0; i<N; i++)
{
v.push_back({v1[i].x, i});
}
v.push_back({-1, N});
sort(v.begin(), v.end(), sf1);
N++;
v1.clear();
for(int i=N-1; i>=0; i--)
{
while(!v2.empty() && v[v2.back()].y<v[i].y)
{
idx[v2.back()]=i;
v2.pop_back();
}
v2.push_back(i);
}
for(int i=1; i<N; i++)
{
int t=sum(two, two+v[i].y);
ans+=(long long)t;
update(two+v[i].y, 1-t);
update(two+v[idx[i]].y, t);
}
cout<<ans;
return 0;
}
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... |