Submission #1007688

# Submission time Handle Problem Language Result Execution time Memory
1007688 2024-06-25T10:24:16 Z doducanh trapezoid (balkan11_trapezoid) C++14
100 / 100
77 ms 7512 KB
#include <bits/stdc++.h>

using namespace std;
#define fi first
#define se second
const int maxn=1e5+7;
const int mod=30013;
const int maxx=2e9;
pair<int,int> cmax(pair<int,int>a,pair<int,int>b)
{
    if(a.fi<b.fi)a=b;
    else{
        if(a.fi==b.fi&&a.fi!=0)a.se=(a.se+b.se)%mod;
    }
    return a;
}
vector<pair<int,int>>top;
vector<pair<int,int>>bot;
int id(int x)
{
    return lower_bound(bot.begin(),bot.end(),make_pair(x,-maxx))-bot.begin()+1;
}
struct BIT
{
    int n;
    vector<pair<int,int>>t;
    BIT(){}
    BIT(int n):n(n),t(n+7){}
    void up(int x,pair<int,int> val){
        for(;x<n;x+=(x&(-x)))t[x]=cmax(t[x],val);
    }
    pair<int,int>get(int x)
    {
        if(x<=0)return {0,1};
        pair<int,int>res={0,1};
        for(;x;x-=(x&(-x)))res=cmax(res,t[x]);
        return res;
    }
};
int a[maxn],b[maxn],c[maxn],d[maxn];
int n;
pair<int,int>ans[maxn];

main()
{
//    freopen("trapezoid.in","r",stdin);
//    freopen("trapezoid.out","w",stdout);
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        top.push_back({a[i],i});
        top.push_back({b[i],i});
        bot.push_back({c[i],i});
        bot.push_back({d[i],i});
    }
    sort(top.begin(),top.end());
    sort(bot.begin(),bot.end());
    top.erase(unique(top.begin(),top.end()),top.end());
    bot.erase(unique(bot.begin(),bot.end()),bot.end());
    BIT t(bot.size()+7);
    for(pair<int,int>p:top){
        int x=p.fi;
        int i=p.se;
        if(x==a[i]){
            int pos=id(c[i])-1;
            pair<int,int>tmp=t.get(pos);
            ans[i]={tmp.fi+1,tmp.se};
        }
        else if(x==b[i]){
            int pos=id(d[i]);
            t.up(pos,ans[i]);
        }
    }
    pair<int,int>res={0,0};
    for(int i=1;i<=n;i++){
        res=cmax(res,ans[i]);
    }
    cout<<res.fi<<" "<<res.se;
    return 0;
}

Compilation message

trapezoid.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 2 ms 2708 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 3 ms 2652 KB Output is correct
9 Correct 6 ms 3032 KB Output is correct
10 Correct 12 ms 3792 KB Output is correct
11 Correct 16 ms 4044 KB Output is correct
12 Correct 34 ms 5084 KB Output is correct
13 Correct 36 ms 5656 KB Output is correct
14 Correct 50 ms 5956 KB Output is correct
15 Correct 57 ms 6320 KB Output is correct
16 Correct 62 ms 6616 KB Output is correct
17 Correct 65 ms 6836 KB Output is correct
18 Correct 59 ms 7136 KB Output is correct
19 Correct 64 ms 7352 KB Output is correct
20 Correct 77 ms 7512 KB Output is correct