内容目录
P2065 - 「Poetize10」封印一击From lydliyudong Normal (OI) |
||||||||
---|---|---|---|---|---|---|---|---|
区间选取 用Past和In_s维护经过的左右结点, 并由此算出 嵌套数(左-右) 左边的区间数=右 右边的区间数=总-(左-右)-右=总-左
PS:由于是闭区间,需要把-右的时间后延
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<cctype> #include<iostream> #include<functional> #include<algorithm> using namespace std; #define MAXN (200000+10) #define MAXAi (1000000000) #define NDEBUG struct segment_node { int l,type; friend bool operator<(const segment_node a,const segment_node b){return (a.l!=b.l)?a.l<b.l:a.type<b.type; } friend bool operator==(const segment_node a,const segment_node b){return (a.l==b.l&&a.type==b.type); } friend bool operator!=(const segment_node a,const segment_node b){return (!(a==b)); } }a[MAXN]; int n; long long next[MAXN]; int main() { #ifndef NDEBUG freopen("segmentbet.in","r",stdin); #endif memset(a,0,sizeof(a)); scanf("%d",&n);n<<=1; for (int i=1;i<=n;i+=2) { scanf("%d%d",&a[i].l,&a[i+1].l); a[i].type=-1;a[i+1].type=1; } sort(a+1,a+n+1); int in_s=0,minE=0; long long ans=0; memset(next,0,sizeof(next)); for (int i=n-1;i>=1;i--) { next[i]=next[i+1]; if (a[i+1].type==-1) next[i]+=a[i+1].l; } int j=1,past=0,pastE=0; for (int i=1;i<=n;i++) { if (a[i]!=a[i+1]) { int len=i-j+1; j=i+1; len*=-a[i].type; if (pastE!=a[i].l) {in_s+=past;past=0;} if (len>0) in_s+=len; else past+=len; long long cost=(long long)(long long)in_s*(long long)a[i].l+next[i]; if (ans<cost) { ans=cost; minE=a[i].l; } } } cout<<minE<<' '<<ans<<endl; return 0; }
|
写的不错
[reply]syzcch[/reply]
谢谢