# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163214 | TadijaSebez | 허수아비 (JOI14_scarecrows) | C++11 | 1875 ms | 9452 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 ll long long
#define pb push_back
const int N=200050;
const int S=447;
const int H=N/S+1;
int SEQ[H][S],a[N],ptr[H];
bool use[N+S];
void Build(int B)
{
int l=B*S,r=(B+1)*S-1;
ptr[B]=0;
for(int i=r;i>=l;i--) if(use[i])
{
while(ptr[B] && SEQ[B][ptr[B]-1]>a[i]) ptr[B]--;
SEQ[B][ptr[B]++]=a[i];
}
}
void Add(int pos)
{
use[pos]=1;
int B=pos/S;
Build(B);
}
int x[N],y[N],id[N],stk[N],top;
vector<int> xs;
int main()
{
int n;
scanf("%i",&n);
for(int i=1;i<=n;i++) scanf("%i %i",&x[i],&y[i]),xs.pb(x[i]);
sort(xs.begin(),xs.end());
for(int i=1;i<=n;i++) a[x[i]=lower_bound(xs.begin(),xs.end(),x[i])-xs.begin()+1]=y[i],id[i]=i;
sort(id+1,id+1+n,[&](int i, int j){ return y[i]>y[j];});
ll sol=0;
for(int j=1,i;i=id[j],j<=n;j++)
{
int pos=x[i];
int B=pos/S;
int r=(B+1)*S-1;
top=0;
for(int k=r;k>pos;k--) if(use[k])
{
while(top && stk[top]>a[k]) top--;
stk[++top]=a[k];
}
int mn=top?stk[1]:1e9+7;
int ans=0;
ans+=top;
for(int k=B+1;k*S<=n;k++)
{
if(ptr[k])
{
ans+=upper_bound(SEQ[k],SEQ[k]+ptr[k],mn)-SEQ[k];
mn=min(mn,SEQ[k][0]);
}
}
sol+=ans;
Add(x[i]);
}
printf("%lld\n",sol);
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... |