Submission #66229

# Submission time Handle Problem Language Result Execution time Memory
66229 2018-08-10T05:17:16 Z 강태규(#1885) 초음속철도 (OJUZ11_rail) C++11
100 / 100
729 ms 12144 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const int mod = 1e9 + 7;
int n, m, k;
pii se[200000];
vector<int> cp;

int find(int x) {
    return lower_bound(cp.begin(), cp.end(), x) - cp.begin() + 1;
}

int seg[1 << 20];
int mul[1 << 20];

void lazy(int i) {
    seg[i << 1] = (llong)seg[i << 1] * mul[i] % mod;
    mul[i << 1] = (llong)mul[i << 1] * mul[i] % mod;
    seg[i << 1 | 1] = (llong)seg[i << 1 | 1] * mul[i] % mod;
    mul[i << 1 | 1] = (llong)mul[i << 1 | 1] * mul[i] % mod;
    mul[i] = 1;
}

void update1(int i, int s, int e, int x, int v) {
    if (s == e) {
        seg[i] = (seg[i] + v) % mod;
        return;
    }
    lazy(i);
    int m = (s + e) / 2;
    if (x <= m) update1(i << 1, s, m, x, v);
    else update1(i << 1 | 1, m + 1, e, x, v);
    seg[i] = (seg[i << 1] + seg[i << 1 | 1]) % mod;
}

void update2(int i, int s, int e, int x, int y) {
    if (e < x || y < s) return;
    if (x <= s && e <= y) {
        seg[i] = (seg[i] << 1) % mod;
        mul[i] = (mul[i] << 1) % mod;
        return;
    }
    lazy(i);
    int m = (s + e) / 2;
    update2(i << 1, s, m, x, y);
    update2(i << 1 | 1, m + 1, e, x, y);
    seg[i] = (seg[i << 1] + seg[i << 1 | 1]) % mod;
}

int query(int i, int s, int e, int x, int y) {
    if (e < x || y < s) return 0;
    if (x <= s && e <= y) return seg[i];
    lazy(i);
    int m = (s + e) / 2;
    int ret = query(i << 1, s, m, x, y);
    ret += query(i << 1 | 1, m + 1, e, x, y);
    return ret % mod;
}

int main() {
    for (int i = 0; i < (1 << 20); ++i) seg[i] = 0, mul[i] = 1;
    
    scanf("%d%d", &n, &m);
    cp.push_back(1);
    cp.push_back(n);
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &se[i].first, &se[i].second);
        cp.push_back(se[i].first);
        cp.push_back(se[i].second);
    }
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());
    k = cp.size();
    
    sort(se, se + m);
    update1(1, 1, k, 1, 1);
    
    for (int i = 0; i < m; ++i) {
        int a, b;
        tie(a, b) = se[i];
        a = find(a); b = find(b);
        int ret = query(1, 1, k, a, b);
        update1(1, 1, k, b, ret);
        update2(1, 1, k, b + 1, k);
    }
    printf("%d\n", query(1, 1, k, k, k));
    
	return 0;
}

Compilation message

rail.cpp: In function 'int main()':
rail.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
rail.cpp:84:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &se[i].first, &se[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8440 KB Output is correct
2 Correct 10 ms 8676 KB Output is correct
3 Correct 11 ms 8676 KB Output is correct
4 Correct 10 ms 8676 KB Output is correct
5 Correct 11 ms 8676 KB Output is correct
6 Correct 11 ms 8740 KB Output is correct
7 Correct 9 ms 8740 KB Output is correct
8 Correct 9 ms 8768 KB Output is correct
9 Correct 9 ms 8768 KB Output is correct
10 Correct 9 ms 8768 KB Output is correct
11 Correct 9 ms 8768 KB Output is correct
12 Correct 9 ms 8768 KB Output is correct
13 Correct 8 ms 8768 KB Output is correct
14 Correct 9 ms 8768 KB Output is correct
15 Correct 9 ms 8892 KB Output is correct
16 Correct 9 ms 8892 KB Output is correct
17 Correct 9 ms 8892 KB Output is correct
18 Correct 10 ms 8892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8440 KB Output is correct
2 Correct 10 ms 8676 KB Output is correct
3 Correct 11 ms 8676 KB Output is correct
4 Correct 10 ms 8676 KB Output is correct
5 Correct 11 ms 8676 KB Output is correct
6 Correct 11 ms 8740 KB Output is correct
7 Correct 9 ms 8740 KB Output is correct
8 Correct 9 ms 8768 KB Output is correct
9 Correct 9 ms 8768 KB Output is correct
10 Correct 9 ms 8768 KB Output is correct
11 Correct 9 ms 8768 KB Output is correct
12 Correct 9 ms 8768 KB Output is correct
13 Correct 8 ms 8768 KB Output is correct
14 Correct 9 ms 8768 KB Output is correct
15 Correct 9 ms 8892 KB Output is correct
16 Correct 9 ms 8892 KB Output is correct
17 Correct 9 ms 8892 KB Output is correct
18 Correct 10 ms 8892 KB Output is correct
19 Correct 9 ms 8892 KB Output is correct
20 Correct 9 ms 8892 KB Output is correct
21 Correct 9 ms 8892 KB Output is correct
22 Correct 11 ms 8892 KB Output is correct
23 Correct 9 ms 8892 KB Output is correct
24 Correct 9 ms 8892 KB Output is correct
25 Correct 9 ms 8892 KB Output is correct
26 Correct 10 ms 8892 KB Output is correct
27 Correct 9 ms 8892 KB Output is correct
28 Correct 14 ms 8892 KB Output is correct
29 Correct 10 ms 8892 KB Output is correct
30 Correct 8 ms 8892 KB Output is correct
31 Correct 9 ms 8892 KB Output is correct
32 Correct 8 ms 8892 KB Output is correct
33 Correct 8 ms 8892 KB Output is correct
34 Correct 9 ms 8892 KB Output is correct
35 Correct 10 ms 8892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8892 KB Output is correct
2 Correct 11 ms 8892 KB Output is correct
3 Correct 9 ms 8892 KB Output is correct
4 Correct 16 ms 8956 KB Output is correct
5 Correct 277 ms 12032 KB Output is correct
6 Correct 443 ms 12032 KB Output is correct
7 Correct 402 ms 12032 KB Output is correct
8 Correct 8 ms 12032 KB Output is correct
9 Correct 386 ms 12044 KB Output is correct
10 Correct 412 ms 12044 KB Output is correct
11 Correct 169 ms 12044 KB Output is correct
12 Correct 426 ms 12044 KB Output is correct
13 Correct 415 ms 12044 KB Output is correct
14 Correct 105 ms 12084 KB Output is correct
15 Correct 440 ms 12084 KB Output is correct
16 Correct 95 ms 12084 KB Output is correct
17 Correct 433 ms 12084 KB Output is correct
18 Correct 417 ms 12084 KB Output is correct
19 Correct 495 ms 12084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8440 KB Output is correct
2 Correct 10 ms 8676 KB Output is correct
3 Correct 11 ms 8676 KB Output is correct
4 Correct 10 ms 8676 KB Output is correct
5 Correct 11 ms 8676 KB Output is correct
6 Correct 11 ms 8740 KB Output is correct
7 Correct 9 ms 8740 KB Output is correct
8 Correct 9 ms 8768 KB Output is correct
9 Correct 9 ms 8768 KB Output is correct
10 Correct 9 ms 8768 KB Output is correct
11 Correct 9 ms 8768 KB Output is correct
12 Correct 9 ms 8768 KB Output is correct
13 Correct 8 ms 8768 KB Output is correct
14 Correct 9 ms 8768 KB Output is correct
15 Correct 9 ms 8892 KB Output is correct
16 Correct 9 ms 8892 KB Output is correct
17 Correct 9 ms 8892 KB Output is correct
18 Correct 10 ms 8892 KB Output is correct
19 Correct 9 ms 8892 KB Output is correct
20 Correct 9 ms 8892 KB Output is correct
21 Correct 9 ms 8892 KB Output is correct
22 Correct 11 ms 8892 KB Output is correct
23 Correct 9 ms 8892 KB Output is correct
24 Correct 9 ms 8892 KB Output is correct
25 Correct 9 ms 8892 KB Output is correct
26 Correct 10 ms 8892 KB Output is correct
27 Correct 9 ms 8892 KB Output is correct
28 Correct 14 ms 8892 KB Output is correct
29 Correct 10 ms 8892 KB Output is correct
30 Correct 8 ms 8892 KB Output is correct
31 Correct 9 ms 8892 KB Output is correct
32 Correct 8 ms 8892 KB Output is correct
33 Correct 8 ms 8892 KB Output is correct
34 Correct 9 ms 8892 KB Output is correct
35 Correct 10 ms 8892 KB Output is correct
36 Correct 18 ms 12084 KB Output is correct
37 Correct 18 ms 12084 KB Output is correct
38 Correct 17 ms 12084 KB Output is correct
39 Correct 12 ms 12084 KB Output is correct
40 Correct 17 ms 12084 KB Output is correct
41 Correct 21 ms 12084 KB Output is correct
42 Correct 20 ms 12084 KB Output is correct
43 Correct 9 ms 12084 KB Output is correct
44 Correct 17 ms 12084 KB Output is correct
45 Correct 11 ms 12084 KB Output is correct
46 Correct 16 ms 12084 KB Output is correct
47 Correct 22 ms 12084 KB Output is correct
48 Correct 17 ms 12084 KB Output is correct
49 Correct 13 ms 12084 KB Output is correct
50 Correct 14 ms 12084 KB Output is correct
51 Correct 13 ms 12084 KB Output is correct
52 Correct 11 ms 12084 KB Output is correct
53 Correct 19 ms 12084 KB Output is correct
54 Correct 15 ms 12084 KB Output is correct
55 Correct 18 ms 12084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8440 KB Output is correct
2 Correct 10 ms 8676 KB Output is correct
3 Correct 11 ms 8676 KB Output is correct
4 Correct 10 ms 8676 KB Output is correct
5 Correct 11 ms 8676 KB Output is correct
6 Correct 11 ms 8740 KB Output is correct
7 Correct 9 ms 8740 KB Output is correct
8 Correct 9 ms 8768 KB Output is correct
9 Correct 9 ms 8768 KB Output is correct
10 Correct 9 ms 8768 KB Output is correct
11 Correct 9 ms 8768 KB Output is correct
12 Correct 9 ms 8768 KB Output is correct
13 Correct 8 ms 8768 KB Output is correct
14 Correct 9 ms 8768 KB Output is correct
15 Correct 9 ms 8892 KB Output is correct
16 Correct 9 ms 8892 KB Output is correct
17 Correct 9 ms 8892 KB Output is correct
18 Correct 10 ms 8892 KB Output is correct
19 Correct 9 ms 8892 KB Output is correct
20 Correct 9 ms 8892 KB Output is correct
21 Correct 9 ms 8892 KB Output is correct
22 Correct 11 ms 8892 KB Output is correct
23 Correct 9 ms 8892 KB Output is correct
24 Correct 9 ms 8892 KB Output is correct
25 Correct 9 ms 8892 KB Output is correct
26 Correct 10 ms 8892 KB Output is correct
27 Correct 9 ms 8892 KB Output is correct
28 Correct 14 ms 8892 KB Output is correct
29 Correct 10 ms 8892 KB Output is correct
30 Correct 8 ms 8892 KB Output is correct
31 Correct 9 ms 8892 KB Output is correct
32 Correct 8 ms 8892 KB Output is correct
33 Correct 8 ms 8892 KB Output is correct
34 Correct 9 ms 8892 KB Output is correct
35 Correct 10 ms 8892 KB Output is correct
36 Correct 11 ms 8892 KB Output is correct
37 Correct 11 ms 8892 KB Output is correct
38 Correct 9 ms 8892 KB Output is correct
39 Correct 16 ms 8956 KB Output is correct
40 Correct 277 ms 12032 KB Output is correct
41 Correct 443 ms 12032 KB Output is correct
42 Correct 402 ms 12032 KB Output is correct
43 Correct 8 ms 12032 KB Output is correct
44 Correct 386 ms 12044 KB Output is correct
45 Correct 412 ms 12044 KB Output is correct
46 Correct 169 ms 12044 KB Output is correct
47 Correct 426 ms 12044 KB Output is correct
48 Correct 415 ms 12044 KB Output is correct
49 Correct 105 ms 12084 KB Output is correct
50 Correct 440 ms 12084 KB Output is correct
51 Correct 95 ms 12084 KB Output is correct
52 Correct 433 ms 12084 KB Output is correct
53 Correct 417 ms 12084 KB Output is correct
54 Correct 495 ms 12084 KB Output is correct
55 Correct 18 ms 12084 KB Output is correct
56 Correct 18 ms 12084 KB Output is correct
57 Correct 17 ms 12084 KB Output is correct
58 Correct 12 ms 12084 KB Output is correct
59 Correct 17 ms 12084 KB Output is correct
60 Correct 21 ms 12084 KB Output is correct
61 Correct 20 ms 12084 KB Output is correct
62 Correct 9 ms 12084 KB Output is correct
63 Correct 17 ms 12084 KB Output is correct
64 Correct 11 ms 12084 KB Output is correct
65 Correct 16 ms 12084 KB Output is correct
66 Correct 22 ms 12084 KB Output is correct
67 Correct 17 ms 12084 KB Output is correct
68 Correct 13 ms 12084 KB Output is correct
69 Correct 14 ms 12084 KB Output is correct
70 Correct 13 ms 12084 KB Output is correct
71 Correct 11 ms 12084 KB Output is correct
72 Correct 19 ms 12084 KB Output is correct
73 Correct 15 ms 12084 KB Output is correct
74 Correct 18 ms 12084 KB Output is correct
75 Correct 729 ms 12084 KB Output is correct
76 Correct 458 ms 12084 KB Output is correct
77 Correct 333 ms 12084 KB Output is correct
78 Correct 109 ms 12084 KB Output is correct
79 Correct 476 ms 12084 KB Output is correct
80 Correct 656 ms 12084 KB Output is correct
81 Correct 19 ms 12084 KB Output is correct
82 Correct 585 ms 12084 KB Output is correct
83 Correct 77 ms 12084 KB Output is correct
84 Correct 528 ms 12084 KB Output is correct
85 Correct 563 ms 12084 KB Output is correct
86 Correct 681 ms 12144 KB Output is correct
87 Correct 198 ms 12144 KB Output is correct
88 Correct 174 ms 12144 KB Output is correct
89 Correct 614 ms 12144 KB Output is correct
90 Correct 656 ms 12144 KB Output is correct
91 Correct 631 ms 12144 KB Output is correct
92 Correct 549 ms 12144 KB Output is correct
93 Correct 494 ms 12144 KB Output is correct
94 Correct 596 ms 12144 KB Output is correct
95 Correct 598 ms 12144 KB Output is correct