JZOJ 4214. 【NOIP2015模拟9.12】SERN的野望
题目
分析
https://blog.csdn.net/weixin_43993341/article/details/88913374
代码
1 #include <bits/stdc++.h> 2 using namespace std; 3 int f[100001],maxr[100001]; 4 struct A 5 { 6 int a,b,c; 7 }a[100001]; 8 bool cmp (A a,A b) 9 { 10 return a.a>b.a; 11 } 12 int main() 13 { 14 ios::sync_with_stdio(false); 15 int n; 16 cin>>n; 17 for (int i=1;i<=n;i++) 18 { 19 cin>>a[i].a>>a[i].b; 20 a[i].c=i; 21 } 22 sort (a+1,a+n+1,cmp); 23 maxr[1]=a[1].b; 24 f[a[1].c]=1; 25 for (int i=2;i<=n;i++) 26 { 27 int mid,t=a[i].b,l=1,r=i; 28 while (l<=r) 29 { 30 mid=(l+r)/2; 31 if (maxr[mid]<=t) r=mid-1; 32 if (maxr[mid]>t) l=mid+1; 33 } 34 maxr[l]=max(maxr[l],t); 35 f[a[i].c]=l; 36 } 37 for (int i=1;i<=n;i++) 38 printf("%d\n",f[i]); 39 }
为何要逼自己长大,去闯不该闯的荒唐