Submission #243910

# Submission time Handle Problem Language Result Execution time Memory
243910 2020-07-02T06:26:41 Z abacaba trapezoid (balkan11_trapezoid) C++14
100 / 100
255 ms 62828 KB
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}
 
inline void setin(string s) {
    freopen(s.c_str(), "r", stdin);
}
 
inline void setout(string s) {
    freopen(s.c_str(), "w", stdout);
}
 
template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int mod = 30013;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 15;
int n;

struct pt {
    int l1, r1, l2, r2;
    bool operator < (const pt &rhs) const {
        return mp(r2, l2) < mp(rhs.r2, rhs.l2);
    }
} a[N];

pii dp[N];

inline bool lie(int l, int x, int r) {
    return l <= x && x <= r;
}

inline pii merge(pii a, pii b) {
    if(a.f == b.f)
        return mp(a.f, (a.se + b.se) % mod);
    return max(a, b);
}

pii empty_val(0, 0);

struct node {
    node *l, *r;
    pii val;
    node(node *_l = NULL, node *_r = NULL) {
        l = _l, r = _r;
        val = merge(l ? l->val : empty_val, r ? r->val : empty_val);
    }
};

typedef node* pnode;

vector <pnode> roots = {NULL};

pnode update(pnode t, int tl, int tr, int pos, pii val) {
    if(tl == tr) {
        pnode nw = new node(t);
        nw->val = merge(nw->val, val);
        return nw;
    }
    int mid = tl + tr >> 1;
    if(pos <= mid)
        return new node(update(t ? t->l : NULL, tl, mid, pos, val), t ? t->r : NULL);
    return new node(t ? t->l : NULL, update(t ? t->r : NULL, mid + 1, tr, pos, val));
}

pii get(pnode t, int tl, int tr, int l, int r) {
    if(tl > r || tr < l || !t)
        return empty_val;
    if(tl >= l && tr <= r)
        return t->val;
    int mid = tl + tr >> 1;
    return merge(get(t->l, tl, mid, l, r), get(t->r, mid + 1, tr, l, r));
}

vector <int> comp;

inline void compress_coordinates_l1_r1() {
    for(int i = 1; i <= n; ++i)
        comp.pb(a[i].l1), comp.pb(a[i].r1);
    sort(comp.begin(), comp.end());
    comp.erase(unique(comp.begin(), comp.end()), comp.end());
    auto gt = [&](int x) {
        return lower_bound(comp.begin(), comp.end(), x) - comp.begin();
    };
    for(int i = 1; i <= n; ++i)
        a[i].l1 = gt(a[i].l1), a[i].r1 = gt(a[i].r1);
}

inline int lower_bound(int r, int x) {
    int l = 1, res = 0;
    while(l <= r) {
        int mid = l + r >> 1;
        if(a[mid].r2 < x)
            l = mid + 1, res = mid;
        else
            r = mid - 1;
    }
    return res;
}

main() {
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    // setin("input.txt");
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i].l1 >> a[i].r1 >> a[i].l2 >> a[i].r2;
    sort(a + 1, a + 1 + n);
    compress_coordinates_l1_r1();
    for(int i = 1; i <= n; ++i) {
        dp[i] = {1, 1};
        int ind = lower_bound(i - 1, a[i].l2);
        if(ind != 0) {
            pii nw = get(roots[ind], 0, 2 * n, 0, a[i].l1 - 1);
            nw.f++;
            dp[i] = merge(dp[i], nw);
        }
        roots.pb(update(roots.back(), 0, 2 * n, a[i].r1, dp[i]));
    }
    pii ans(0, 0);
    for(int i = 1; i <= n; ++i)
        ans = merge(ans, dp[i]);
    cout << ans.f << ' ' << ans.se << endl;
    return 0;
}

Compilation message

trapezoid.cpp: In function 'node* update(pnode, int, int, int, std::pair<int, int>)':
trapezoid.cpp:106:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = tl + tr >> 1;
               ~~~^~~~
trapezoid.cpp: In function 'std::pair<int, int> get(pnode, int, int, int, int)':
trapezoid.cpp:117:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = tl + tr >> 1;
               ~~~^~~~
trapezoid.cpp: In function 'int lower_bound(int, int)':
trapezoid.cpp:138:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = l + r >> 1;
                   ~~^~~
trapezoid.cpp: At global scope:
trapezoid.cpp:147:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 8 ms 1280 KB Output is correct
6 Correct 10 ms 1792 KB Output is correct
7 Correct 11 ms 2304 KB Output is correct
8 Correct 13 ms 2816 KB Output is correct
9 Correct 24 ms 5624 KB Output is correct
10 Correct 44 ms 11380 KB Output is correct
11 Correct 56 ms 14452 KB Output is correct
12 Correct 116 ms 29944 KB Output is correct
13 Correct 145 ms 36336 KB Output is correct
14 Correct 165 ms 42860 KB Output is correct
15 Correct 195 ms 46192 KB Output is correct
16 Correct 227 ms 49516 KB Output is correct
17 Correct 217 ms 52844 KB Output is correct
18 Correct 190 ms 56172 KB Output is correct
19 Correct 205 ms 59504 KB Output is correct
20 Correct 255 ms 62828 KB Output is correct