Submission #163214

#TimeUsernameProblemLanguageResultExecution timeMemory
163214TadijaSebez허수아비 (JOI14_scarecrows)C++11
100 / 100
1875 ms9452 KiB
#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)

scarecrows.cpp: In function 'int main()':
scarecrows.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
scarecrows.cpp:32:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%i %i",&x[i],&y[i]),xs.pb(x[i]);
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...