Submission #20513

# Submission time Handle Problem Language Result Execution time Memory
20513 2017-02-12T07:23:14 Z CYI(#67, choyi0521) 초음속철도 (OJUZ11_rail) C++14
100 / 100
546 ms 12836 KB
#include<cstdio>
#include<algorithm>
#define mod 1000000007
using namespace std;
const int MXM = 2e5;
typedef long long ll;
int n, m, idx[MXM + 2], sz;
pair<int, int> p[MXM];
struct st {
    int s, a = 1, b;
}tree[MXM * 4];
void f(int h, int a, int b) {
    tree[h].a = (ll)tree[h].a*a%mod;
    tree[h].b = ((ll)tree[h].b*a + b) % mod;
    tree[h].s = ((ll)tree[h].s*a + b) % mod;
}
void update(int h, int l, int r, int gl, int gr, int a, int b) {
    if (r < gl || gr < l) return;
    if (gl <= l&&r <= gr) f(h, a, b);
    else {
        f(h * 2 + 1, tree[h].a, tree[h].b);
        f(h * 2 + 2, tree[h].a, tree[h].b);
        tree[h].a = 1;
        tree[h].b = 0;
        update(h * 2 + 1, l, (l + r) / 2, gl, gr, a, b);
        update(h * 2 + 2, (l + r) / 2 + 1, r, gl, gr, a, b);
        tree[h].s = (tree[h * 2 + 1].s + tree[h * 2 + 2].s) % mod;
    }
}
int query(int h, int l, int r, int gl, int gr) {
    if (r < gl || gr < l) return 0;
    if (gl <= l&&r <= gr) return tree[h].s;
    return (((ll)query(h * 2 + 1, l, (l + r) / 2, gl, gr) + query(h * 2 + 2, (l + r) / 2 + 1, r, gl, gr))*tree[h].a+tree[h].b) % mod;
}
int main() {
    scanf("%d%d", &n, &m);
    idx[sz++] = 1;
    idx[sz++] = n;
    for (int i = 0; i < m; i++) scanf("%d%d", &p[i].first, &p[i].second), idx[sz++] = p[i].second;
    sort(p, p + m);
    sort(idx, idx + sz);
    sz = unique(idx, idx + sz) - idx;
    update(0, 0, sz - 1, 0, 0, 1, 1);
    for (int i = 0; i < m; i++) {
        int l = lower_bound(idx, idx + sz, p[i].first) - idx,
            r = lower_bound(idx, idx + sz, p[i].second) - idx;
        int t = query(0, 0, sz - 1, l, r);
        update(0, 0, sz - 1, r, r, 1, t);
        update(0, 0, sz - 1, r + 1, sz - 1, 2, 0);
    }
    printf("%d", query(0, 0, sz - 1, sz - 1, sz - 1));
    return 0;
}

Compilation message

rail.cpp: In function 'int main()':
rail.cpp:36:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
                          ^
rail.cpp:39:98: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 0; i < m; i++) scanf("%d%d", &p[i].first, &p[i].second), idx[sz++] = p[i].second;
                                                                                                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 12836 KB Output is correct
2 Correct 0 ms 12836 KB Output is correct
3 Correct 3 ms 12836 KB Output is correct
4 Correct 6 ms 12836 KB Output is correct
5 Correct 3 ms 12836 KB Output is correct
6 Correct 3 ms 12836 KB Output is correct
7 Correct 3 ms 12836 KB Output is correct
8 Correct 0 ms 12836 KB Output is correct
9 Correct 0 ms 12836 KB Output is correct
10 Correct 0 ms 12836 KB Output is correct
11 Correct 0 ms 12836 KB Output is correct
12 Correct 3 ms 12836 KB Output is correct
13 Correct 0 ms 12836 KB Output is correct
14 Correct 0 ms 12836 KB Output is correct
15 Correct 0 ms 12836 KB Output is correct
16 Correct 0 ms 12836 KB Output is correct
17 Correct 0 ms 12836 KB Output is correct
18 Correct 0 ms 12836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 12836 KB Output is correct
2 Correct 0 ms 12836 KB Output is correct
3 Correct 3 ms 12836 KB Output is correct
4 Correct 6 ms 12836 KB Output is correct
5 Correct 3 ms 12836 KB Output is correct
6 Correct 3 ms 12836 KB Output is correct
7 Correct 3 ms 12836 KB Output is correct
8 Correct 0 ms 12836 KB Output is correct
9 Correct 0 ms 12836 KB Output is correct
10 Correct 0 ms 12836 KB Output is correct
11 Correct 0 ms 12836 KB Output is correct
12 Correct 3 ms 12836 KB Output is correct
13 Correct 0 ms 12836 KB Output is correct
14 Correct 0 ms 12836 KB Output is correct
15 Correct 0 ms 12836 KB Output is correct
16 Correct 0 ms 12836 KB Output is correct
17 Correct 0 ms 12836 KB Output is correct
18 Correct 0 ms 12836 KB Output is correct
19 Correct 0 ms 12836 KB Output is correct
20 Correct 0 ms 12836 KB Output is correct
21 Correct 0 ms 12836 KB Output is correct
22 Correct 3 ms 12836 KB Output is correct
23 Correct 0 ms 12836 KB Output is correct
24 Correct 0 ms 12836 KB Output is correct
25 Correct 0 ms 12836 KB Output is correct
26 Correct 0 ms 12836 KB Output is correct
27 Correct 3 ms 12836 KB Output is correct
28 Correct 3 ms 12836 KB Output is correct
29 Correct 0 ms 12836 KB Output is correct
30 Correct 0 ms 12836 KB Output is correct
31 Correct 3 ms 12836 KB Output is correct
32 Correct 0 ms 12836 KB Output is correct
33 Correct 0 ms 12836 KB Output is correct
34 Correct 0 ms 12836 KB Output is correct
35 Correct 0 ms 12836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 12836 KB Output is correct
2 Correct 0 ms 12836 KB Output is correct
3 Correct 0 ms 12836 KB Output is correct
4 Correct 6 ms 12836 KB Output is correct
5 Correct 223 ms 12836 KB Output is correct
6 Correct 386 ms 12836 KB Output is correct
7 Correct 356 ms 12836 KB Output is correct
8 Correct 0 ms 12836 KB Output is correct
9 Correct 333 ms 12836 KB Output is correct
10 Correct 359 ms 12836 KB Output is correct
11 Correct 163 ms 12836 KB Output is correct
12 Correct 376 ms 12836 KB Output is correct
13 Correct 369 ms 12836 KB Output is correct
14 Correct 83 ms 12836 KB Output is correct
15 Correct 396 ms 12836 KB Output is correct
16 Correct 83 ms 12836 KB Output is correct
17 Correct 403 ms 12836 KB Output is correct
18 Correct 383 ms 12836 KB Output is correct
19 Correct 383 ms 12836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 12836 KB Output is correct
2 Correct 0 ms 12836 KB Output is correct
3 Correct 3 ms 12836 KB Output is correct
4 Correct 6 ms 12836 KB Output is correct
5 Correct 3 ms 12836 KB Output is correct
6 Correct 3 ms 12836 KB Output is correct
7 Correct 3 ms 12836 KB Output is correct
8 Correct 0 ms 12836 KB Output is correct
9 Correct 0 ms 12836 KB Output is correct
10 Correct 0 ms 12836 KB Output is correct
11 Correct 0 ms 12836 KB Output is correct
12 Correct 3 ms 12836 KB Output is correct
13 Correct 0 ms 12836 KB Output is correct
14 Correct 0 ms 12836 KB Output is correct
15 Correct 0 ms 12836 KB Output is correct
16 Correct 0 ms 12836 KB Output is correct
17 Correct 0 ms 12836 KB Output is correct
18 Correct 0 ms 12836 KB Output is correct
19 Correct 0 ms 12836 KB Output is correct
20 Correct 0 ms 12836 KB Output is correct
21 Correct 0 ms 12836 KB Output is correct
22 Correct 3 ms 12836 KB Output is correct
23 Correct 0 ms 12836 KB Output is correct
24 Correct 0 ms 12836 KB Output is correct
25 Correct 0 ms 12836 KB Output is correct
26 Correct 0 ms 12836 KB Output is correct
27 Correct 3 ms 12836 KB Output is correct
28 Correct 3 ms 12836 KB Output is correct
29 Correct 0 ms 12836 KB Output is correct
30 Correct 0 ms 12836 KB Output is correct
31 Correct 3 ms 12836 KB Output is correct
32 Correct 0 ms 12836 KB Output is correct
33 Correct 0 ms 12836 KB Output is correct
34 Correct 0 ms 12836 KB Output is correct
35 Correct 0 ms 12836 KB Output is correct
36 Correct 6 ms 12836 KB Output is correct
37 Correct 6 ms 12836 KB Output is correct
38 Correct 3 ms 12836 KB Output is correct
39 Correct 3 ms 12836 KB Output is correct
40 Correct 6 ms 12836 KB Output is correct
41 Correct 9 ms 12836 KB Output is correct
42 Correct 6 ms 12836 KB Output is correct
43 Correct 0 ms 12836 KB Output is correct
44 Correct 6 ms 12836 KB Output is correct
45 Correct 3 ms 12836 KB Output is correct
46 Correct 3 ms 12836 KB Output is correct
47 Correct 9 ms 12836 KB Output is correct
48 Correct 9 ms 12836 KB Output is correct
49 Correct 0 ms 12836 KB Output is correct
50 Correct 3 ms 12836 KB Output is correct
51 Correct 0 ms 12836 KB Output is correct
52 Correct 3 ms 12836 KB Output is correct
53 Correct 6 ms 12836 KB Output is correct
54 Correct 3 ms 12836 KB Output is correct
55 Correct 9 ms 12836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 12836 KB Output is correct
2 Correct 0 ms 12836 KB Output is correct
3 Correct 3 ms 12836 KB Output is correct
4 Correct 6 ms 12836 KB Output is correct
5 Correct 3 ms 12836 KB Output is correct
6 Correct 3 ms 12836 KB Output is correct
7 Correct 3 ms 12836 KB Output is correct
8 Correct 0 ms 12836 KB Output is correct
9 Correct 0 ms 12836 KB Output is correct
10 Correct 0 ms 12836 KB Output is correct
11 Correct 0 ms 12836 KB Output is correct
12 Correct 3 ms 12836 KB Output is correct
13 Correct 0 ms 12836 KB Output is correct
14 Correct 0 ms 12836 KB Output is correct
15 Correct 0 ms 12836 KB Output is correct
16 Correct 0 ms 12836 KB Output is correct
17 Correct 0 ms 12836 KB Output is correct
18 Correct 0 ms 12836 KB Output is correct
19 Correct 0 ms 12836 KB Output is correct
20 Correct 0 ms 12836 KB Output is correct
21 Correct 0 ms 12836 KB Output is correct
22 Correct 3 ms 12836 KB Output is correct
23 Correct 0 ms 12836 KB Output is correct
24 Correct 0 ms 12836 KB Output is correct
25 Correct 0 ms 12836 KB Output is correct
26 Correct 0 ms 12836 KB Output is correct
27 Correct 3 ms 12836 KB Output is correct
28 Correct 3 ms 12836 KB Output is correct
29 Correct 0 ms 12836 KB Output is correct
30 Correct 0 ms 12836 KB Output is correct
31 Correct 3 ms 12836 KB Output is correct
32 Correct 0 ms 12836 KB Output is correct
33 Correct 0 ms 12836 KB Output is correct
34 Correct 0 ms 12836 KB Output is correct
35 Correct 0 ms 12836 KB Output is correct
36 Correct 0 ms 12836 KB Output is correct
37 Correct 0 ms 12836 KB Output is correct
38 Correct 0 ms 12836 KB Output is correct
39 Correct 6 ms 12836 KB Output is correct
40 Correct 223 ms 12836 KB Output is correct
41 Correct 386 ms 12836 KB Output is correct
42 Correct 356 ms 12836 KB Output is correct
43 Correct 0 ms 12836 KB Output is correct
44 Correct 333 ms 12836 KB Output is correct
45 Correct 359 ms 12836 KB Output is correct
46 Correct 163 ms 12836 KB Output is correct
47 Correct 376 ms 12836 KB Output is correct
48 Correct 369 ms 12836 KB Output is correct
49 Correct 83 ms 12836 KB Output is correct
50 Correct 396 ms 12836 KB Output is correct
51 Correct 83 ms 12836 KB Output is correct
52 Correct 403 ms 12836 KB Output is correct
53 Correct 383 ms 12836 KB Output is correct
54 Correct 383 ms 12836 KB Output is correct
55 Correct 6 ms 12836 KB Output is correct
56 Correct 6 ms 12836 KB Output is correct
57 Correct 3 ms 12836 KB Output is correct
58 Correct 3 ms 12836 KB Output is correct
59 Correct 6 ms 12836 KB Output is correct
60 Correct 9 ms 12836 KB Output is correct
61 Correct 6 ms 12836 KB Output is correct
62 Correct 0 ms 12836 KB Output is correct
63 Correct 6 ms 12836 KB Output is correct
64 Correct 3 ms 12836 KB Output is correct
65 Correct 3 ms 12836 KB Output is correct
66 Correct 9 ms 12836 KB Output is correct
67 Correct 9 ms 12836 KB Output is correct
68 Correct 0 ms 12836 KB Output is correct
69 Correct 3 ms 12836 KB Output is correct
70 Correct 0 ms 12836 KB Output is correct
71 Correct 3 ms 12836 KB Output is correct
72 Correct 6 ms 12836 KB Output is correct
73 Correct 3 ms 12836 KB Output is correct
74 Correct 9 ms 12836 KB Output is correct
75 Correct 539 ms 12836 KB Output is correct
76 Correct 333 ms 12836 KB Output is correct
77 Correct 276 ms 12836 KB Output is correct
78 Correct 69 ms 12836 KB Output is correct
79 Correct 416 ms 12836 KB Output is correct
80 Correct 519 ms 12836 KB Output is correct
81 Correct 9 ms 12836 KB Output is correct
82 Correct 476 ms 12836 KB Output is correct
83 Correct 49 ms 12836 KB Output is correct
84 Correct 406 ms 12836 KB Output is correct
85 Correct 426 ms 12836 KB Output is correct
86 Correct 433 ms 12836 KB Output is correct
87 Correct 129 ms 12836 KB Output is correct
88 Correct 146 ms 12836 KB Output is correct
89 Correct 519 ms 12836 KB Output is correct
90 Correct 543 ms 12836 KB Output is correct
91 Correct 529 ms 12836 KB Output is correct
92 Correct 476 ms 12836 KB Output is correct
93 Correct 433 ms 12836 KB Output is correct
94 Correct 546 ms 12836 KB Output is correct
95 Correct 533 ms 12836 KB Output is correct