Submission #889701

# Submission time Handle Problem Language Result Execution time Memory
889701 2023-12-20T05:46:16 Z chanhchuong123 trapezoid (balkan11_trapezoid) C++14
100 / 100
74 ms 9472 KB
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}

const int MAX = 100010;
const int MOD = 30013;
int nArr;
vector<int> tmp;
pair<int, int> ans[MAX];
pair<int, int> bit[MAX << 1];
vector<tuple<int, int, int>> events;

void add(int &x, const int &y) {
    x += y;
    if (x >= MOD) x -= MOD;
}

void update(int id, pair<int, int> value) {
    for (; id <= 2 * nArr; id += id & -id) {
        if (bit[id].fi <  value.fi) {
            bit[id] = value;
            continue;
        }
        if (bit[id].fi == value.fi)
            add(bit[id].se, value.se);
    }
}

pair<int, int> get(int id) {
    pair<int, int> res = make_pair(0, 1);
    for (; id > 0; id -= id & -id) {
        if (res.fi <  bit[id].fi) {
            res = bit[id];
            continue;
        }
        if (res.fi == bit[id].fi)
            add(res.se, bit[id].se);
    }
    return res;
}

void init(void) {
    cin >> nArr;
    for (int i = 1; i <= nArr; ++i) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        events.emplace_back(a, -i, c);
        events.emplace_back(b, +i, d);
        tmp.push_back(c);
        tmp.push_back(d);
    }
    sort(all(tmp)); tmp.resize(unique(all(tmp)) - tmp.begin());
}

#define POS(value) (upper_bound(all(tmp), value) - tmp.begin())
void process(void) {
    sort(all(events));
    for (tuple<int, int, int> &e: events) {
        int x, y, i; tie(x, i, y) = e;
        int id = abs(i);
        y = POS(y);

        if (i < 0) {
            ans[id] = get(y - 1);
            ans[id].fi += 1;
            continue;
        }

        update(y, ans[id]);
    }

    pair<int, int> res = get(2 * nArr);
    cout << res.fi << ' ' << res.se;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
//	freopen(".INP", "r",  stdin);
//	freopen(".OUT", "w", stdout);

    init();
    process();

	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 3 ms 2652 KB Output is correct
8 Correct 4 ms 2908 KB Output is correct
9 Correct 7 ms 3224 KB Output is correct
10 Correct 13 ms 4080 KB Output is correct
11 Correct 17 ms 4372 KB Output is correct
12 Correct 37 ms 5964 KB Output is correct
13 Correct 44 ms 6512 KB Output is correct
14 Correct 52 ms 8960 KB Output is correct
15 Correct 59 ms 8708 KB Output is correct
16 Correct 62 ms 8448 KB Output is correct
17 Correct 63 ms 9216 KB Output is correct
18 Correct 58 ms 8784 KB Output is correct
19 Correct 67 ms 9084 KB Output is correct
20 Correct 74 ms 9472 KB Output is correct