답안 #580815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580815 2022-06-21T22:06:26 Z erto 사다리꼴 (balkan11_trapezoid) C++17
40 / 100
244 ms 38232 KB
#include <bits/stdc++.h>
typedef long long int ll;
#define INF ll(1e12 + 7)
#define INF2 998244353
#define N (ll)(2e5 + 5)
using namespace std;
#define int ll
#define lsb(x) (x & (-x))

int n, g, h,m,  q,z,t1,t2, ans, ans2; 
map<int, pair<int, int>> c;
pair<pair<int, int>, pair<int, int>> p[N];
vector<pair<pair<int, int>, pair<int, int>>> v;
vector<int> v2;

pair<int, int> comb(pair<int, int> x, pair<int, int> y){
    if(x.first > y.first){
        return x;
    }
    else if(x.first < y.first){
        return y;
    }
    else{
        return {x.first, x.second + y.second};
    }
}

struct SegTree{
    int n;
    vector<pair<int, int>> tree;
 
    SegTree(int _n){
        n = _n+1;
        while(lsb(n) != n)
            n += lsb(n);
        tree.resize(2*n, {0, 0});
    }
 
    void update(int i, pair<int, int> val){
        i += n;
        tree[i] = val;

        while(i >>= 1){
            tree[i] = comb(tree[i * 2] , tree[i * 2 + 1]);
        }
    }
 
    pair<int, int> query(int ql, int qr){ return query(1, 0, n-1, ql, qr); }
    pair<int, int> query(int i, int lb, int rb, int ql, int qr){
        if(ql <= lb && rb <= qr){
            return tree[i];
        }
        if(qr < lb || rb < ql)
            return {0, 0};
        int md = (lb+rb)/2;
        return comb(query(2*i, lb, md, ql, qr) , query(2*i+1, md+1, rb, ql, qr));
    }
};

void solve(){
    cin >> n;
    SegTree s(N * 2);
    
    for(int i=1; i<=n; i++){
        cin >> p[i].first.first >> p[i].first.second >> p[i].second.first >> p[i].second.second;
        v.push_back({{p[i].second.first, 0}, {p[i].first.first, p[i].first.second}});
        v.push_back({{p[i].second.second, 1}, {p[i].first.first, p[i].first.second}});
        v2.push_back(p[i].first.first);
        v2.push_back(p[i].first.second);
        v2.push_back(p[i].second.first);
        v2.push_back(p[i].second.second);
    }
    v2.push_back(0);
    v2.push_back(1);
    sort(v2.begin(), v2.end());

    unique(v2.begin(), v2.end());

    for(int i=0; i<v.size(); i++){
        v[i].first.first = 1 + (lower_bound(v2.begin(), v2.end(), v[i].first.first) - v2.begin());
        v[i].second.first = 1 + (lower_bound(v2.begin(), v2.end(), v[i].second.first) - v2.begin());
        v[i].second.second = 1 + (lower_bound(v2.begin(), v2.end(), v[i].second.second) - v2.begin());
    }    
    sort(v.begin(), v.end());

    for(int i=0; i<v.size(); i++){
        if(v[i].first.second){
            g = c[v[i].second.first].first, h = c[v[i].second.first].second;
            s.update(v[i].second.second, {g, h});
        }
        else{
            pair<int, int> p2 = s.query(0ll, v[i].second.first - 1);
            g = p2.first, h = p2.second;
            g++;
            if(g > ans){
                ans = g;
                ans2 = h;
            }
            if(h==0)h=1;
            c[v[i].second.first] = {g, h};
        }
    }
    ans2 %= 30013;

    cout << ans << " " << ans2;
}

signed main(){
    //freopen("trapezoid.in", "r", stdin);
    //freopen("trapezoid.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    //cin>>T;
    while (T--){
        solve();
    }
}

Compilation message

trapezoid.cpp: In function 'void solve()':
trapezoid.cpp:79:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i=0; i<v.size(); i++){
      |                  ~^~~~~~~~~
trapezoid.cpp:86:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for(int i=0; i<v.size(); i++){
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 8 ms 16724 KB Partially correct
2 Partially correct 8 ms 16724 KB Partially correct
3 Partially correct 11 ms 16852 KB Partially correct
4 Partially correct 10 ms 16852 KB Partially correct
5 Partially correct 13 ms 17128 KB Partially correct
6 Partially correct 13 ms 17364 KB Partially correct
7 Partially correct 15 ms 17512 KB Partially correct
8 Partially correct 17 ms 17872 KB Partially correct
9 Partially correct 27 ms 18788 KB Partially correct
10 Partially correct 46 ms 20960 KB Partially correct
11 Partially correct 56 ms 22052 KB Partially correct
12 Partially correct 110 ms 27504 KB Partially correct
13 Partially correct 146 ms 29556 KB Partially correct
14 Partially correct 188 ms 33020 KB Partially correct
15 Partially correct 179 ms 32960 KB Partially correct
16 Partially correct 199 ms 33928 KB Partially correct
17 Partially correct 227 ms 34988 KB Partially correct
18 Partially correct 210 ms 36076 KB Partially correct
19 Partially correct 207 ms 37096 KB Partially correct
20 Partially correct 244 ms 38232 KB Partially correct