Submission #55090914


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
using ui = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,l,r) for(int i=(l);i>=(r);--i)
#define repn(i,n) for(int i=0;i<(n);++i)
#define sizc(x) ((int)x.size())
#define allc(x) x.begin(),x.end()
#define fir first
#define sec second
namespace KnownError_{
constexpr int N = 4e5+5;
int n,l[N],r[N];
int a[N],tot;
int epc[N];
vector<int> vc[N];
int get(int x){return lower_bound(a+1,a+tot+1,x)-a;}
pair<int,int> t[N<<1];
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
using ui = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,l,r) for(int i=(l);i>=(r);--i)
#define repn(i,n)  for(int i=0;i<(n);++i)
#define sizc(x) ((int)x.size())
#define allc(x) x.begin(),x.end()
#define fir first
#define sec second
namespace KnownError_{
    constexpr int N = 4e5+5;
    int n,l[N],r[N];
    int a[N],tot;
    int epc[N];
    vector<int> vc[N];
    int get(int x){return lower_bound(a+1,a+tot+1,x)-a;}
    pair<int,int> t[N<<1];
    int tg[N<<1];
    pair<int,int> mg(pair<int,int> x,pair<int,int> y){
        if(x.fir!=y.fir)return max(x,y);
        return min(x,y);
    }
    pair<int,int> operator+(pair<int,int> x,int y){return {x.fir+y,x.sec};}
    void bd(int u,int L,int R){
        if(L==R){t[u]={epc[L-1],L};return;}
        int M=L+R>>1,ls=M<<1,rs=M<<1|1;
        bd(ls,L,M),bd(rs,M+1,R);
        t[u]=mg(t[ls],t[rs]);
    }
    void add(int u,int L,int R,int l,int r,int x){
        if(r<L||R<l||r<l)return;
        if(l<=L&&R<=r){t[u]=t[u]+x;tg[u]+=x;return;}
        int M=L+R>>1,ls=M<<1,rs=M<<1|1;
        add(ls,L,M,l,r,x),add(rs,M+1,R,l,r,x);
        t[u]=mg(t[ls],t[rs])+tg[u];
    }
    pair<int,int> qry(int u,int L,int R,int l,int r){
        if(r<L||R<l||r<l)return {(int)-1e9,0};
        if(l<=L&&R<=r)return t[u];
        int M=L+R>>1,ls=M<<1,rs=M<<1|1;
        return mg(qry(ls,L,M,l,r),qry(rs,M+1,R,l,r))+tg[u];
    }
    pair<int,int> ans={0,1};int mx=0;
    void main(){
    	cin>>n;
        a[tot=1]=0;
        rep(i,1,n)cin>>l[i]>>r[i],a[++tot]=l[i],a[++tot]=r[i],a[++tot]=l[i]+1,a[++tot]=r[i]+1;
        sort(a+1,a+tot+1),tot=unique(a+1,a+tot+1)-a-1;
        while(a[tot]>1e9)--tot;
        rep(i,1,n){
            int L=get(l[i]),R=get(r[i]);
            ++epc[L],++epc[R],vc[L].push_back(R);
        }
        rep(i,1,tot)epc[i]+=epc[i-1];
        bd(1,1,tot);
        per(i,tot,1){
            for(auto j:vc[i])add(1,1,tot,j+1,tot,-1);
            auto res=qry(1,1,tot,i+1,tot)+-epc[i];
            for(auto j:vc[i])add(1,1,tot,j+1,tot,1);
            if(res.fir>mx)mx=res.fir,ans={a[i],a[res.sec]};
            else if(res.fir==mx)ans=min(ans,pair<int,int>{a[i],a[res.sec]});
            for(auto j:vc[i])add(1,1,tot,j,j,-1),add(1,1,tot,j+1,tot,-2);
        }
        cout<<ans.fir<<' '<<ans.sec<<'\n';
    }
}
signed main(){
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    KnownError_::main();
}

Submission Info

Submission Time
Task F - InterSections
User KnownError_
Language C++ 20 (gcc 12.2)
Score 550
Code Size 2650 Byte
Status AC
Exec Time 278 ms
Memory 29392 KB

Compile Error

Main.cpp: In function ‘void KnownError_::bd(int, int, int)’:
Main.cpp:30:16: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   30 |         int M=L+R>>1,ls=M<<1,rs=M<<1|1;
      |               ~^~
Main.cpp: In function ‘void KnownError_::add(int, int, int, int, int, int)’:
Main.cpp:37:16: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   37 |         int M=L+R>>1,ls=M<<1,rs=M<<1|1;
      |               ~^~
Main.cpp: In function ‘std::pair<int, int> KnownError_::qry(int, int, int, int, int)’:
Main.cpp:44:16: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   44 |         int M=L+R>>1,ls=M<<1,rs=M<<1|1;
      |               ~^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 550 / 550
Status
AC × 2
AC × 44
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 3 ms 3492 KB
00_sample_01.txt AC 3 ms 3628 KB
01_random_00.txt AC 278 ms 29192 KB
01_random_01.txt AC 168 ms 19784 KB
01_random_02.txt AC 274 ms 29148 KB
01_random_03.txt AC 208 ms 23580 KB
01_random_04.txt AC 275 ms 29140 KB
01_random_05.txt AC 203 ms 23204 KB
01_random_06.txt AC 275 ms 29208 KB
01_random_07.txt AC 112 ms 14872 KB
01_random_08.txt AC 273 ms 29148 KB
01_random_09.txt AC 235 ms 25636 KB
01_random_10.txt AC 275 ms 29260 KB
01_random_11.txt AC 267 ms 28544 KB
01_random_12.txt AC 276 ms 29084 KB
01_random_13.txt AC 120 ms 15576 KB
01_random_14.txt AC 276 ms 29160 KB
01_random_15.txt AC 237 ms 25860 KB
01_random_16.txt AC 274 ms 29128 KB
01_random_17.txt AC 205 ms 23084 KB
01_random_18.txt AC 274 ms 29072 KB
01_random_19.txt AC 207 ms 23300 KB
01_random_20.txt AC 216 ms 19036 KB
01_random_21.txt AC 214 ms 18996 KB
01_random_22.txt AC 213 ms 19104 KB
01_random_23.txt AC 267 ms 23024 KB
01_random_24.txt AC 264 ms 22904 KB
01_random_25.txt AC 269 ms 22952 KB
01_random_26.txt AC 198 ms 29184 KB
01_random_27.txt AC 199 ms 29236 KB
01_random_28.txt AC 196 ms 29120 KB
01_random_29.txt AC 197 ms 29116 KB
01_random_30.txt AC 199 ms 29252 KB
01_random_31.txt AC 197 ms 29388 KB
01_random_32.txt AC 196 ms 29316 KB
01_random_33.txt AC 199 ms 29392 KB
01_random_34.txt AC 166 ms 17552 KB
01_random_35.txt AC 184 ms 11544 KB
01_random_36.txt AC 168 ms 17568 KB
01_random_37.txt AC 190 ms 11552 KB
01_random_38.txt AC 162 ms 17512 KB
01_random_39.txt AC 156 ms 17500 KB
01_random_40.txt AC 152 ms 17420 KB
01_random_41.txt AC 19 ms 6120 KB


2025-03-18 (Tue)
16:33:55 +00:00