[Solution] National Day joy title race brief explanations Comet OJ

[Solution] National Day joy title race brief explanations Comet OJ

A

Direct do

B

Done directly Conclusion:
\ [ANS = \ max ([Max \ GE \ mathrm {SUM}] Max, S [n-] / 2) \]

C

Consider this approach:

For a left-house \ ((L, R & lt) \) , all legal right on the house \ (LR \) coordinate system, the point is legitimate \ ((l ', r' ) \) satisfies \ (l ' \ le r \ and r '\ ge l \) in all points. Sort by guarantee \ (l '\ le r \ ) legitimate, then all queries Fenwick tree \ (r' \ ge l \ ) number. Complexity \ (O (n-\ log M) \) , to discretization

//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>

using namespace std;  typedef long long ll;
inline int qr(){
      register int ret=0,f=0;
      register char c=getchar();
      while(c<48||c>57)f|=c==45,c=getchar();
      while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
      return f?-ret:ret;
}
const int maxn=2e5+5;
int sav[maxn<<2];
int n,m,cnt,len;
#define l first
#define r second
pair<int,int> data[maxn],data2[maxn];
inline int arc(int x){return lower_bound(sav+1,sav+len+1,x)-sav;}
int seg[maxn<<2];
inline void add(const int&pos,const int&tag){
      for(int t=pos;t<=len+1;t+=t&-t) seg[t]+=tag;
}

inline ll que(const int&pos){
      int ret=0;
      for(int t=pos;t>0;t-=t&-t) ret+=seg[t];
      return ret;
}

int main(){
      n=qr(); m=qr();
      for(int t=1;t<=n;++t){
        int t1=qr(),t2=qr(); 
        data[t]={t1,t2};
        sav[++*sav]=t1; sav[++*sav]=t2;
      }
      for(int t=1;t<=m;++t){
        int t1=qr(),t2=qr();
        data2[t]={t1,t2};
        sav[++*sav]=t1; sav[++*sav]=t2;
      }
      sort(sav+1,sav+*sav+1);
      len=unique(sav+1,sav+*sav+1)-sav-1;
      for(int t=1;t<=n;++t) data[t].l=arc(data[t].l),data[t].r=arc(data[t].r);
      for(int t=1;t<=m;++t) data2[t].l=arc(data2[t].l),data2[t].r=arc(data2[t].r);
      sort(data+1,data+n+1);
      sort(data2+1,data2+m+1);
      ll ans=0;
      for(int t=1,pos=0;t<=n;++t){
        while(pos<m&&data2[pos+1].l<=data[t].r) add(data2[++pos].r,1);
        ans+=pos-que(data[t].l-1);
      }
      printf("%lld\n",ans);
      return 0;
}

Guess you like

Origin www.cnblogs.com/winlere/p/11616357.html