답안 #920504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920504 2024-02-02T16:11:57 Z ttamx 사다리꼴 (balkan11_trapezoid) C++14
100 / 100
99 ms 6484 KB
#include<bits/stdc++.h>

using namespace std;

const int N=1e5+5;
const int M=2e5+5;

int n;
int v1[M],v2[M],id1[N],id2[N];

struct Trapezoid{
    int a,b,c,d;
    Trapezoid(){};
}t[N];

struct Info{
    int val,freq;
    Info():val(0),freq(0){}
    Info(int _val,int _freq):val(_val),freq(_freq){}
    friend Info operator+(const Info &lhs,const Info &rhs){
        if(lhs.val>rhs.val)return lhs;
        if(lhs.val<rhs.val)return rhs;
        return Info(lhs.val,(lhs.freq+rhs.freq)%30013);
    }
    Info &operator+=(const Info &rhs){
        *this=*this+rhs;
        return *this;
    }
}dp[N];

struct fenwick{
    Info t[M];
    void update(int i,Info v){
        for(;i<M;i+=i&-i)t[i]+=v;
    }
    Info query(int i){
        Info res{};
        for(;i;i-=i&-i)res+=t[i];
        return res;
    }
}f;

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> t[i].a >> t[i].b >> t[i].c >> t[i].d;
        v1[i*2-1]=t[i].a;
        v1[i*2]=t[i].b;
        v2[i*2-1]=t[i].c;
        v2[i*2]=t[i].d;
    }
    sort(v1+1,v1+2*n+1);
    sort(v2+1,v2+2*n+1);
    for(int i=1;i<=n;i++){
        t[i].a=lower_bound(v1+1,v1+2*n+1,t[i].a)-v1;
        t[i].b=lower_bound(v1+1,v1+2*n+1,t[i].b)-v1;
        t[i].c=lower_bound(v2+1,v2+2*n+1,t[i].c)-v2;
        t[i].d=lower_bound(v2+1,v2+2*n+1,t[i].d)-v2;
    }
    iota(id1+1,id1+n+1,1);
    iota(id2+1,id2+n+1,1);
    sort(id1+1,id1+n+1,[&](int i,int j){return t[i].a<t[j].a;});
    sort(id2+1,id2+n+1,[&](int i,int j){return t[i].b<t[j].b;});
    Info ans{};
    for(int _i=1,p=1;_i<=n;_i++){
        int i=id1[_i];
        while(t[id2[p]].b<t[i].a){
            f.update(t[id2[p]].d,dp[id2[p]]);
            p++;
        }
        dp[i]=f.query(t[i].c-1);
        if(dp[i].val==0)dp[i].freq=1;
        dp[i].val++;
        ans+=dp[i];
    }
    cout << ans.val << " " << ans.freq;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 3 ms 4700 KB Output is correct
6 Correct 3 ms 4700 KB Output is correct
7 Correct 5 ms 4696 KB Output is correct
8 Correct 5 ms 4832 KB Output is correct
9 Correct 10 ms 4700 KB Output is correct
10 Correct 19 ms 4956 KB Output is correct
11 Correct 23 ms 5208 KB Output is correct
12 Correct 57 ms 5712 KB Output is correct
13 Correct 56 ms 5712 KB Output is correct
14 Correct 73 ms 6084 KB Output is correct
15 Correct 74 ms 5972 KB Output is correct
16 Correct 82 ms 6224 KB Output is correct
17 Correct 87 ms 6392 KB Output is correct
18 Correct 99 ms 6480 KB Output is correct
19 Correct 91 ms 6484 KB Output is correct
20 Correct 98 ms 6480 KB Output is correct