Submission #376350

# Submission time Handle Problem Language Result Execution time Memory
376350 2021-03-11T10:00:54 Z ja_kingy trapezoid (balkan11_trapezoid) C++14
100 / 100
129 ms 10852 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

const int mxN = 1e5, MOD = 30013;
int n, x[mxN][4], pts[mxN*2];
pii st[4*mxN], dp[mxN];

pii comb(pii a, pii b) {
    if (a.first != b.first) return max(a,b);
    return {a.first, (a.second + b.second) % MOD};
}

void upd(int x, pii v) {
    for (x += 2*n; x; x /= 2) st[x] = comb(st[x], v);
}

pii qry(int l, int r) {
    pii res = {0,1};
    for (l += 2*n, r += 2*n; l < r; l /= 2, r /= 2) {
        if (l&1) res = comb(res, st[l++]);
        if (r&1) res = comb(res, st[--r]);
    }
    return res;
}

int compress(int x) {
    return lower_bound(pts, pts+2*n, x) - pts;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    vector<pii> tops;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 4; ++j) {
            cin >> x[i][j];
        }
        pts[2*i] = x[i][2];
        pts[2*i+1] = x[i][3];
        tops.push_back({i,0});
        tops.push_back({i,1});
    }
    sort(pts, pts+2*n);
    sort(tops.begin(), tops.end(), [&](pii a, pii b){ return x[a.first][a.second] < x[b.first][b.second];});
    for (pii t: tops) {
        if (t.second == 0) {
            dp[t.first] = qry(0, compress(x[t.first][2]));
            dp[t.first].first = (dp[t.first].first + 1) % MOD;
        } else {
            upd(compress(x[t.first][3]), dp[t.first]);
        }
    }
    cout << st[1].first << ' ' << st[1].second << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 3 ms 620 KB Output is correct
6 Correct 4 ms 748 KB Output is correct
7 Correct 4 ms 876 KB Output is correct
8 Correct 9 ms 1004 KB Output is correct
9 Correct 12 ms 1520 KB Output is correct
10 Correct 21 ms 2668 KB Output is correct
11 Correct 29 ms 3052 KB Output is correct
12 Correct 62 ms 5736 KB Output is correct
13 Correct 76 ms 6760 KB Output is correct
14 Correct 91 ms 7908 KB Output is correct
15 Correct 103 ms 8420 KB Output is correct
16 Correct 106 ms 8932 KB Output is correct
17 Correct 111 ms 9444 KB Output is correct
18 Correct 99 ms 10084 KB Output is correct
19 Correct 114 ms 10084 KB Output is correct
20 Correct 129 ms 10852 KB Output is correct