Submission #20505

# Submission time Handle Problem Language Result Execution time Memory
20505 2017-02-12T07:05:40 Z CYI(#67, choyi0521) 초음속철도 (OJUZ11_rail) C++14
0 / 100
579 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=1;
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 = ((ll)(tree[h * 2 + 1].s + tree[h * 2 + 2].s)*tree[h].a + tree[h].b) % 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 (query(h * 2 + 1, l, (l + r) / 2, gl, gr) + query(h * 2 + 2, (l + r) / 2 + 1, r, gl, gr)) % mod;
}
int main() {
    scanf("%d%d", &n, &m);
    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 - 1) - idx,
            r = lower_bound(idx, idx + sz, p[i].second) - idx;
        update(0, 0, sz - 1, r, r, 1, query(0, 0, sz - 1, l, r));
        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:38: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 3 ms 12836 KB Output is correct
2 Incorrect 0 ms 12836 KB Output isn't correct
3 Incorrect 0 ms 12836 KB Output isn't correct
4 Incorrect 0 ms 12836 KB Output isn't correct
5 Incorrect 3 ms 12836 KB Output isn't correct
6 Correct 0 ms 12836 KB Output is correct
7 Incorrect 0 ms 12836 KB Output isn't correct
8 Incorrect 0 ms 12836 KB Output isn't correct
9 Correct 0 ms 12836 KB Output is correct
10 Correct 0 ms 12836 KB Output is correct
11 Incorrect 0 ms 12836 KB Output isn't correct
12 Incorrect 0 ms 12836 KB Output isn't correct
13 Correct 0 ms 12836 KB Output is correct
14 Correct 0 ms 12836 KB Output is correct
15 Incorrect 0 ms 12836 KB Output isn't correct
16 Incorrect 3 ms 12836 KB Output isn't correct
17 Correct 0 ms 12836 KB Output is correct
18 Correct 3 ms 12836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12836 KB Output is correct
2 Incorrect 0 ms 12836 KB Output isn't correct
3 Incorrect 0 ms 12836 KB Output isn't correct
4 Incorrect 0 ms 12836 KB Output isn't correct
5 Incorrect 3 ms 12836 KB Output isn't correct
6 Correct 0 ms 12836 KB Output is correct
7 Incorrect 0 ms 12836 KB Output isn't correct
8 Incorrect 0 ms 12836 KB Output isn't correct
9 Correct 0 ms 12836 KB Output is correct
10 Correct 0 ms 12836 KB Output is correct
11 Incorrect 0 ms 12836 KB Output isn't correct
12 Incorrect 0 ms 12836 KB Output isn't correct
13 Correct 0 ms 12836 KB Output is correct
14 Correct 0 ms 12836 KB Output is correct
15 Incorrect 0 ms 12836 KB Output isn't correct
16 Incorrect 3 ms 12836 KB Output isn't correct
17 Correct 0 ms 12836 KB Output is correct
18 Correct 3 ms 12836 KB Output is correct
19 Correct 0 ms 12836 KB Output is correct
20 Incorrect 3 ms 12836 KB Output isn't correct
21 Correct 3 ms 12836 KB Output is correct
22 Incorrect 3 ms 12836 KB Output isn't correct
23 Incorrect 0 ms 12836 KB Output isn't correct
24 Correct 0 ms 12836 KB Output is correct
25 Incorrect 3 ms 12836 KB Output isn't correct
26 Incorrect 6 ms 12836 KB Output isn't correct
27 Correct 0 ms 12836 KB Output is correct
28 Correct 0 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 Incorrect 0 ms 12836 KB Output isn't 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 Incorrect 0 ms 12836 KB Output isn't correct
3 Correct 0 ms 12836 KB Output is correct
4 Incorrect 3 ms 12836 KB Output isn't correct
5 Correct 249 ms 12836 KB Output is correct
6 Correct 389 ms 12836 KB Output is correct
7 Correct 379 ms 12836 KB Output is correct
8 Correct 0 ms 12836 KB Output is correct
9 Correct 376 ms 12836 KB Output is correct
10 Correct 383 ms 12836 KB Output is correct
11 Correct 176 ms 12836 KB Output is correct
12 Correct 389 ms 12836 KB Output is correct
13 Correct 379 ms 12836 KB Output is correct
14 Correct 69 ms 12836 KB Output is correct
15 Incorrect 386 ms 12836 KB Output isn't correct
16 Correct 73 ms 12836 KB Output is correct
17 Correct 383 ms 12836 KB Output is correct
18 Correct 409 ms 12836 KB Output is correct
19 Correct 379 ms 12836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12836 KB Output is correct
2 Incorrect 0 ms 12836 KB Output isn't correct
3 Incorrect 0 ms 12836 KB Output isn't correct
4 Incorrect 0 ms 12836 KB Output isn't correct
5 Incorrect 3 ms 12836 KB Output isn't correct
6 Correct 0 ms 12836 KB Output is correct
7 Incorrect 0 ms 12836 KB Output isn't correct
8 Incorrect 0 ms 12836 KB Output isn't correct
9 Correct 0 ms 12836 KB Output is correct
10 Correct 0 ms 12836 KB Output is correct
11 Incorrect 0 ms 12836 KB Output isn't correct
12 Incorrect 0 ms 12836 KB Output isn't correct
13 Correct 0 ms 12836 KB Output is correct
14 Correct 0 ms 12836 KB Output is correct
15 Incorrect 0 ms 12836 KB Output isn't correct
16 Incorrect 3 ms 12836 KB Output isn't correct
17 Correct 0 ms 12836 KB Output is correct
18 Correct 3 ms 12836 KB Output is correct
19 Correct 0 ms 12836 KB Output is correct
20 Incorrect 3 ms 12836 KB Output isn't correct
21 Correct 3 ms 12836 KB Output is correct
22 Incorrect 3 ms 12836 KB Output isn't correct
23 Incorrect 0 ms 12836 KB Output isn't correct
24 Correct 0 ms 12836 KB Output is correct
25 Incorrect 3 ms 12836 KB Output isn't correct
26 Incorrect 6 ms 12836 KB Output isn't correct
27 Correct 0 ms 12836 KB Output is correct
28 Correct 0 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 Incorrect 0 ms 12836 KB Output isn't 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 Incorrect 6 ms 12836 KB Output isn't correct
37 Incorrect 6 ms 12836 KB Output isn't correct
38 Incorrect 9 ms 12836 KB Output isn't correct
39 Incorrect 0 ms 12836 KB Output isn't correct
40 Correct 9 ms 12836 KB Output is correct
41 Correct 9 ms 12836 KB Output is correct
42 Incorrect 6 ms 12836 KB Output isn't correct
43 Incorrect 0 ms 12836 KB Output isn't correct
44 Incorrect 6 ms 12836 KB Output isn't correct
45 Correct 0 ms 12836 KB Output is correct
46 Correct 6 ms 12836 KB Output is correct
47 Incorrect 6 ms 12836 KB Output isn't correct
48 Incorrect 6 ms 12836 KB Output isn't correct
49 Incorrect 0 ms 12836 KB Output isn't correct
50 Incorrect 3 ms 12836 KB Output isn't correct
51 Correct 3 ms 12836 KB Output is correct
52 Incorrect 3 ms 12836 KB Output isn't correct
53 Correct 13 ms 12836 KB Output is correct
54 Incorrect 6 ms 12836 KB Output isn't correct
55 Correct 9 ms 12836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12836 KB Output is correct
2 Incorrect 0 ms 12836 KB Output isn't correct
3 Incorrect 0 ms 12836 KB Output isn't correct
4 Incorrect 0 ms 12836 KB Output isn't correct
5 Incorrect 3 ms 12836 KB Output isn't correct
6 Correct 0 ms 12836 KB Output is correct
7 Incorrect 0 ms 12836 KB Output isn't correct
8 Incorrect 0 ms 12836 KB Output isn't correct
9 Correct 0 ms 12836 KB Output is correct
10 Correct 0 ms 12836 KB Output is correct
11 Incorrect 0 ms 12836 KB Output isn't correct
12 Incorrect 0 ms 12836 KB Output isn't correct
13 Correct 0 ms 12836 KB Output is correct
14 Correct 0 ms 12836 KB Output is correct
15 Incorrect 0 ms 12836 KB Output isn't correct
16 Incorrect 3 ms 12836 KB Output isn't correct
17 Correct 0 ms 12836 KB Output is correct
18 Correct 3 ms 12836 KB Output is correct
19 Correct 0 ms 12836 KB Output is correct
20 Incorrect 3 ms 12836 KB Output isn't correct
21 Correct 3 ms 12836 KB Output is correct
22 Incorrect 3 ms 12836 KB Output isn't correct
23 Incorrect 0 ms 12836 KB Output isn't correct
24 Correct 0 ms 12836 KB Output is correct
25 Incorrect 3 ms 12836 KB Output isn't correct
26 Incorrect 6 ms 12836 KB Output isn't correct
27 Correct 0 ms 12836 KB Output is correct
28 Correct 0 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 Incorrect 0 ms 12836 KB Output isn't 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 Incorrect 0 ms 12836 KB Output isn't correct
38 Correct 0 ms 12836 KB Output is correct
39 Incorrect 3 ms 12836 KB Output isn't correct
40 Correct 249 ms 12836 KB Output is correct
41 Correct 389 ms 12836 KB Output is correct
42 Correct 379 ms 12836 KB Output is correct
43 Correct 0 ms 12836 KB Output is correct
44 Correct 376 ms 12836 KB Output is correct
45 Correct 383 ms 12836 KB Output is correct
46 Correct 176 ms 12836 KB Output is correct
47 Correct 389 ms 12836 KB Output is correct
48 Correct 379 ms 12836 KB Output is correct
49 Correct 69 ms 12836 KB Output is correct
50 Incorrect 386 ms 12836 KB Output isn't correct
51 Correct 73 ms 12836 KB Output is correct
52 Correct 383 ms 12836 KB Output is correct
53 Correct 409 ms 12836 KB Output is correct
54 Correct 379 ms 12836 KB Output is correct
55 Incorrect 6 ms 12836 KB Output isn't correct
56 Incorrect 6 ms 12836 KB Output isn't correct
57 Incorrect 9 ms 12836 KB Output isn't correct
58 Incorrect 0 ms 12836 KB Output isn't correct
59 Correct 9 ms 12836 KB Output is correct
60 Correct 9 ms 12836 KB Output is correct
61 Incorrect 6 ms 12836 KB Output isn't correct
62 Incorrect 0 ms 12836 KB Output isn't correct
63 Incorrect 6 ms 12836 KB Output isn't correct
64 Correct 0 ms 12836 KB Output is correct
65 Correct 6 ms 12836 KB Output is correct
66 Incorrect 6 ms 12836 KB Output isn't correct
67 Incorrect 6 ms 12836 KB Output isn't correct
68 Incorrect 0 ms 12836 KB Output isn't correct
69 Incorrect 3 ms 12836 KB Output isn't correct
70 Correct 3 ms 12836 KB Output is correct
71 Incorrect 3 ms 12836 KB Output isn't correct
72 Correct 13 ms 12836 KB Output is correct
73 Incorrect 6 ms 12836 KB Output isn't correct
74 Correct 9 ms 12836 KB Output is correct
75 Incorrect 536 ms 12836 KB Output isn't correct
76 Incorrect 346 ms 12836 KB Output isn't correct
77 Incorrect 276 ms 12836 KB Output isn't correct
78 Incorrect 66 ms 12836 KB Output isn't correct
79 Correct 409 ms 12836 KB Output is correct
80 Incorrect 533 ms 12836 KB Output isn't correct
81 Incorrect 6 ms 12836 KB Output isn't correct
82 Incorrect 499 ms 12836 KB Output isn't correct
83 Correct 59 ms 12836 KB Output is correct
84 Incorrect 429 ms 12836 KB Output isn't correct
85 Incorrect 443 ms 12836 KB Output isn't correct
86 Incorrect 443 ms 12836 KB Output isn't correct
87 Correct 139 ms 12836 KB Output is correct
88 Incorrect 143 ms 12836 KB Output isn't correct
89 Incorrect 529 ms 12836 KB Output isn't correct
90 Incorrect 579 ms 12836 KB Output isn't correct
91 Incorrect 553 ms 12836 KB Output isn't correct
92 Correct 506 ms 12836 KB Output is correct
93 Incorrect 479 ms 12836 KB Output isn't correct
94 Incorrect 563 ms 12836 KB Output isn't correct
95 Incorrect 553 ms 12836 KB Output isn't correct