Submission #2671773


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define int long long
int read() {
    int x = 0, f = 1; char ch = getchar();
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}

const int Max = 200033;
const int mod = 1000000007;
const int inf = 1100000000;

int n, b[Max], dp[Max];
int ans, mn[Max], mx[Max];

struct man {
	int x, v;
    friend bool operator< (man a, man b) {
        return a.x < b.x;
    }
} p[Max];
struct line {
	int l, r;
    friend bool operator< (line a, line b) {
        return a.r == b.r ? a.l < b.l : a.r < b.r;
    }
} q[Max];

#define ls x << 1
#define rs x << 1 | 1
struct SegmentTree {
    int sum[Max * 8];
    void update(int x, int l, int r, int pos, int v) {
        if (l == r) {
            sum[x] = (sum[x] + v) % mod;
            return;
        }
        int mid = (l + r) >> 1;
        if (pos <= mid) update(ls, l, mid, pos, v);
        else update(rs, mid + 1, r, pos, v);
        sum[x] = (sum[ls] + sum[rs]) % mod;
    }
    int query(int x, int l, int r, int L, int R) {
        if (L <= l && r <= R) {
            return sum[x];
        }
        int re = 0, mid = (l + r) >> 1;
        if (L <= mid) re = (re + query(ls, l, mid, L, R)) % mod;
        if (R > mid) re = (re + query(rs, mid + 1, r, L, R)) % mod;
        return re;
    }
} sgt;

signed main() {
    n = read();
    for (int i = 1; i <= n; i++)
        p[i].x = read(), b[i] = p[i].v = read();
    sort(p + 1, p + n + 1);
    sort(b + 1, b + n + 1);
    for (int i = 1; i <= n; i++)
       p[i].v = lower_bound(b + 1, b + n + 1, p[i].v) - b;
    mn[n + 1] = inf;
    for (int i = n; i >= 1; i--)
        mn[i] = min(mn[i + 1], p[i].v);
    for (int i = 1; i <= n; i++)
        mx[i] = max(mx[i - 1], p[i].v);
    for (int i = 1; i <= n; i++) {
        q[i].l = mn[i], q[i].r = mx[i];
    }
    sort(q + 1, q + n + 1);
    dp[1] = 1;
    sgt.update(1, 1, n, q[1].r, dp[1]);
    for (int i = 2; i <= n; i++) {
        dp[i] = sgt.query(1, 1, n, max(1ll, q[i].l - 1), q[i].r);
        if (q[i].l == 1) dp[i]++;
        sgt.update(1, 1, n, q[i].r, dp[i]);
    }
    for (int i = n; i >= 1 && q[i].r == q[n].r; i--)
    	ans = (ans + dp[i]) % mod;
    printf("%lld\n", ans);
    return 0;
}

Submission Info

Submission Time
Task E - Mr.Aoki Incubator
User Fire_Storm
Language C++ (GCC 5.4.1)
Score 1200
Code Size 2384 Byte
Status AC
Exec Time 155 ms
Memory 19072 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1200 / 1200
Status
AC × 2
AC × 36
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 142 ms 17280 KB
02.txt AC 128 ms 17152 KB
03.txt AC 132 ms 17152 KB
04.txt AC 155 ms 17280 KB
05.txt AC 116 ms 17280 KB
06.txt AC 143 ms 17152 KB
07.txt AC 123 ms 17280 KB
08.txt AC 118 ms 15232 KB
09.txt AC 132 ms 19072 KB
10.txt AC 76 ms 15104 KB
11.txt AC 110 ms 19072 KB
12.txt AC 131 ms 19072 KB
13.txt AC 109 ms 19072 KB
14.txt AC 111 ms 19072 KB
15.txt AC 132 ms 19072 KB
16.txt AC 109 ms 19072 KB
17.txt AC 111 ms 19072 KB
18.txt AC 132 ms 19072 KB
19.txt AC 109 ms 19072 KB
20.txt AC 111 ms 19072 KB
21.txt AC 133 ms 19072 KB
22.txt AC 113 ms 19072 KB
23.txt AC 114 ms 19072 KB
24.txt AC 133 ms 19072 KB
25.txt AC 132 ms 17408 KB
26.txt AC 137 ms 17408 KB
27.txt AC 152 ms 17536 KB
28.txt AC 139 ms 17280 KB
29.txt AC 124 ms 18176 KB
30.txt AC 139 ms 18560 KB
31.txt AC 3 ms 10496 KB
32.txt AC 3 ms 10496 KB
33.txt AC 3 ms 10496 KB
34.txt AC 3 ms 10496 KB
s1.txt AC 3 ms 10496 KB
s2.txt AC 3 ms 10496 KB