답안 #66248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66248 2018-08-10T05:39:13 Z 윤교준(#1888) 초음속철도 (OJUZ11_rail) C++11
100 / 100
802 ms 13688 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MOD = 1000000007;
const int MAXN = 400005;

inline void add(int &a, int b) { a += b; if(MOD <= a) a -= MOD; }
inline void mul(int &a) { a += a; if(MOD <= a) a -= MOD; }
inline int addint(int a, int b) { add(a, b); return a; }

struct SEG {
	SEG() { init(); }
	int d[MAXN*4], pd[MAXN*4];

	void init() { fill(pd, pd+MAXN*4, 1); }
	void prop(int i, int s, int e) {
		if(1 == pd[i]) return;
		if(s != e) {
			pd[i<<1] = ll(pd[i<<1]) * pd[i] % MOD;
			pd[i<<1|1] = ll(pd[i<<1|1]) * pd[i] % MOD;
		}
		d[i] = ll(d[i]) * pd[i] % MOD;
		pd[i] = 1;
	}

	void upd(int i, int s, int e, int p, int q) {
		prop(i, s, e); if(q < p || e < p || q < s) return;
		if(p <= s && e <= q) {
			mul(pd[i]);
			prop(i, s, e);
			return;
		}
		int m = (s+e) >> 1;
		upd(i<<1, s, m, p, q); upd(i<<1|1, m+1, e, p, q);
		d[i] = addint(d[i<<1], d[i<<1|1]);
	}
	void updx(int i, int s, int e, int x, int r) {
		prop(i, s, e); if(x < s || e < x) return;
		if(s == e) {
			add(d[i], r);
			return;
		}
		int m = (s+e) >> 1;
		updx(i<<1, s, m, x, r); updx(i<<1|1, m+1, e, x, r);
		d[i] = addint(d[i<<1], d[i<<1|1]);
	}

	int get(int i, int s, int e, int p, int q) {
		prop(i, s, e); if(q < p || e < p || q < s) return 0;
		if(p <= s && e <= q) return d[i];
		int m = (s+e) >> 1;
		return addint(get(i<<1, s, m, p, q), get(i<<1|1, m+1, e, p, q));
	}
} seg;

int A[MAXN], B[MAXN], O[MAXN];

int N, M;

int main() {
	ios::sync_with_stdio(false);

	cin >> M >> N;
	for(int i = 1; i <= N; i++) cin >> A[i] >> B[i];

	{
		vector<int> V;
		V.eb(1); V.eb(M);
		for(int i = 1; i <= N; i++) {
			V.eb(A[i]);
			V.eb(B[i]);
		}
		sorv(V); univ(V);
		M = sz(V);
		for(int i = 1; i <= N; i++) {
			A[i] = int(lower_bound(allv(V), A[i]) - V.begin()) + 1;
			B[i] = int(lower_bound(allv(V), B[i]) - V.begin()) + 1;
		}
	}
	iota(O, O+N+1, 0);
	sort(O+1, O+N+1, [&](int a, int b) { return B[a] < B[b]; });

	seg.updx(1, 1, M, 1, 1);
	for(int oi = 1, i; oi <= N; oi++) {
		i = O[oi];
		int s = A[i], e = B[i], ret = 0;
		ret = seg.get(1, 1, M, s, e-1);
		seg.upd(1, 1, M, 1, s-1);
		seg.upd(1, 1, M, e, M);
		seg.updx(1, 1, M, e, ret);
	}
	
	cout << seg.get(1, 1, M, M, M) << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 9 ms 6704 KB Output is correct
4 Correct 7 ms 6704 KB Output is correct
5 Correct 7 ms 6908 KB Output is correct
6 Correct 8 ms 6908 KB Output is correct
7 Correct 8 ms 6908 KB Output is correct
8 Correct 9 ms 6908 KB Output is correct
9 Correct 10 ms 6908 KB Output is correct
10 Correct 7 ms 6908 KB Output is correct
11 Correct 8 ms 6908 KB Output is correct
12 Correct 8 ms 6908 KB Output is correct
13 Correct 7 ms 6908 KB Output is correct
14 Correct 8 ms 6908 KB Output is correct
15 Correct 8 ms 6908 KB Output is correct
16 Correct 8 ms 6908 KB Output is correct
17 Correct 7 ms 6908 KB Output is correct
18 Correct 7 ms 6908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 9 ms 6704 KB Output is correct
4 Correct 7 ms 6704 KB Output is correct
5 Correct 7 ms 6908 KB Output is correct
6 Correct 8 ms 6908 KB Output is correct
7 Correct 8 ms 6908 KB Output is correct
8 Correct 9 ms 6908 KB Output is correct
9 Correct 10 ms 6908 KB Output is correct
10 Correct 7 ms 6908 KB Output is correct
11 Correct 8 ms 6908 KB Output is correct
12 Correct 8 ms 6908 KB Output is correct
13 Correct 7 ms 6908 KB Output is correct
14 Correct 8 ms 6908 KB Output is correct
15 Correct 8 ms 6908 KB Output is correct
16 Correct 8 ms 6908 KB Output is correct
17 Correct 7 ms 6908 KB Output is correct
18 Correct 7 ms 6908 KB Output is correct
19 Correct 8 ms 6908 KB Output is correct
20 Correct 9 ms 6908 KB Output is correct
21 Correct 7 ms 6908 KB Output is correct
22 Correct 7 ms 6908 KB Output is correct
23 Correct 7 ms 6908 KB Output is correct
24 Correct 9 ms 6908 KB Output is correct
25 Correct 7 ms 6984 KB Output is correct
26 Correct 8 ms 6984 KB Output is correct
27 Correct 7 ms 6984 KB Output is correct
28 Correct 9 ms 6984 KB Output is correct
29 Correct 8 ms 6984 KB Output is correct
30 Correct 7 ms 6984 KB Output is correct
31 Correct 9 ms 6984 KB Output is correct
32 Correct 8 ms 6984 KB Output is correct
33 Correct 9 ms 6984 KB Output is correct
34 Correct 8 ms 6984 KB Output is correct
35 Correct 9 ms 6984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6984 KB Output is correct
2 Correct 9 ms 6984 KB Output is correct
3 Correct 8 ms 6984 KB Output is correct
4 Correct 13 ms 7012 KB Output is correct
5 Correct 323 ms 10588 KB Output is correct
6 Correct 470 ms 13496 KB Output is correct
7 Correct 435 ms 13496 KB Output is correct
8 Correct 8 ms 13496 KB Output is correct
9 Correct 432 ms 13496 KB Output is correct
10 Correct 426 ms 13496 KB Output is correct
11 Correct 165 ms 13496 KB Output is correct
12 Correct 475 ms 13556 KB Output is correct
13 Correct 449 ms 13556 KB Output is correct
14 Correct 103 ms 13556 KB Output is correct
15 Correct 448 ms 13556 KB Output is correct
16 Correct 113 ms 13556 KB Output is correct
17 Correct 480 ms 13688 KB Output is correct
18 Correct 463 ms 13688 KB Output is correct
19 Correct 482 ms 13688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 9 ms 6704 KB Output is correct
4 Correct 7 ms 6704 KB Output is correct
5 Correct 7 ms 6908 KB Output is correct
6 Correct 8 ms 6908 KB Output is correct
7 Correct 8 ms 6908 KB Output is correct
8 Correct 9 ms 6908 KB Output is correct
9 Correct 10 ms 6908 KB Output is correct
10 Correct 7 ms 6908 KB Output is correct
11 Correct 8 ms 6908 KB Output is correct
12 Correct 8 ms 6908 KB Output is correct
13 Correct 7 ms 6908 KB Output is correct
14 Correct 8 ms 6908 KB Output is correct
15 Correct 8 ms 6908 KB Output is correct
16 Correct 8 ms 6908 KB Output is correct
17 Correct 7 ms 6908 KB Output is correct
18 Correct 7 ms 6908 KB Output is correct
19 Correct 8 ms 6908 KB Output is correct
20 Correct 9 ms 6908 KB Output is correct
21 Correct 7 ms 6908 KB Output is correct
22 Correct 7 ms 6908 KB Output is correct
23 Correct 7 ms 6908 KB Output is correct
24 Correct 9 ms 6908 KB Output is correct
25 Correct 7 ms 6984 KB Output is correct
26 Correct 8 ms 6984 KB Output is correct
27 Correct 7 ms 6984 KB Output is correct
28 Correct 9 ms 6984 KB Output is correct
29 Correct 8 ms 6984 KB Output is correct
30 Correct 7 ms 6984 KB Output is correct
31 Correct 9 ms 6984 KB Output is correct
32 Correct 8 ms 6984 KB Output is correct
33 Correct 9 ms 6984 KB Output is correct
34 Correct 8 ms 6984 KB Output is correct
35 Correct 9 ms 6984 KB Output is correct
36 Correct 20 ms 13688 KB Output is correct
37 Correct 16 ms 13688 KB Output is correct
38 Correct 16 ms 13688 KB Output is correct
39 Correct 10 ms 13688 KB Output is correct
40 Correct 20 ms 13688 KB Output is correct
41 Correct 19 ms 13688 KB Output is correct
42 Correct 18 ms 13688 KB Output is correct
43 Correct 9 ms 13688 KB Output is correct
44 Correct 17 ms 13688 KB Output is correct
45 Correct 9 ms 13688 KB Output is correct
46 Correct 15 ms 13688 KB Output is correct
47 Correct 18 ms 13688 KB Output is correct
48 Correct 17 ms 13688 KB Output is correct
49 Correct 11 ms 13688 KB Output is correct
50 Correct 12 ms 13688 KB Output is correct
51 Correct 11 ms 13688 KB Output is correct
52 Correct 9 ms 13688 KB Output is correct
53 Correct 17 ms 13688 KB Output is correct
54 Correct 17 ms 13688 KB Output is correct
55 Correct 16 ms 13688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 8 ms 6648 KB Output is correct
3 Correct 9 ms 6704 KB Output is correct
4 Correct 7 ms 6704 KB Output is correct
5 Correct 7 ms 6908 KB Output is correct
6 Correct 8 ms 6908 KB Output is correct
7 Correct 8 ms 6908 KB Output is correct
8 Correct 9 ms 6908 KB Output is correct
9 Correct 10 ms 6908 KB Output is correct
10 Correct 7 ms 6908 KB Output is correct
11 Correct 8 ms 6908 KB Output is correct
12 Correct 8 ms 6908 KB Output is correct
13 Correct 7 ms 6908 KB Output is correct
14 Correct 8 ms 6908 KB Output is correct
15 Correct 8 ms 6908 KB Output is correct
16 Correct 8 ms 6908 KB Output is correct
17 Correct 7 ms 6908 KB Output is correct
18 Correct 7 ms 6908 KB Output is correct
19 Correct 8 ms 6908 KB Output is correct
20 Correct 9 ms 6908 KB Output is correct
21 Correct 7 ms 6908 KB Output is correct
22 Correct 7 ms 6908 KB Output is correct
23 Correct 7 ms 6908 KB Output is correct
24 Correct 9 ms 6908 KB Output is correct
25 Correct 7 ms 6984 KB Output is correct
26 Correct 8 ms 6984 KB Output is correct
27 Correct 7 ms 6984 KB Output is correct
28 Correct 9 ms 6984 KB Output is correct
29 Correct 8 ms 6984 KB Output is correct
30 Correct 7 ms 6984 KB Output is correct
31 Correct 9 ms 6984 KB Output is correct
32 Correct 8 ms 6984 KB Output is correct
33 Correct 9 ms 6984 KB Output is correct
34 Correct 8 ms 6984 KB Output is correct
35 Correct 9 ms 6984 KB Output is correct
36 Correct 9 ms 6984 KB Output is correct
37 Correct 9 ms 6984 KB Output is correct
38 Correct 8 ms 6984 KB Output is correct
39 Correct 13 ms 7012 KB Output is correct
40 Correct 323 ms 10588 KB Output is correct
41 Correct 470 ms 13496 KB Output is correct
42 Correct 435 ms 13496 KB Output is correct
43 Correct 8 ms 13496 KB Output is correct
44 Correct 432 ms 13496 KB Output is correct
45 Correct 426 ms 13496 KB Output is correct
46 Correct 165 ms 13496 KB Output is correct
47 Correct 475 ms 13556 KB Output is correct
48 Correct 449 ms 13556 KB Output is correct
49 Correct 103 ms 13556 KB Output is correct
50 Correct 448 ms 13556 KB Output is correct
51 Correct 113 ms 13556 KB Output is correct
52 Correct 480 ms 13688 KB Output is correct
53 Correct 463 ms 13688 KB Output is correct
54 Correct 482 ms 13688 KB Output is correct
55 Correct 20 ms 13688 KB Output is correct
56 Correct 16 ms 13688 KB Output is correct
57 Correct 16 ms 13688 KB Output is correct
58 Correct 10 ms 13688 KB Output is correct
59 Correct 20 ms 13688 KB Output is correct
60 Correct 19 ms 13688 KB Output is correct
61 Correct 18 ms 13688 KB Output is correct
62 Correct 9 ms 13688 KB Output is correct
63 Correct 17 ms 13688 KB Output is correct
64 Correct 9 ms 13688 KB Output is correct
65 Correct 15 ms 13688 KB Output is correct
66 Correct 18 ms 13688 KB Output is correct
67 Correct 17 ms 13688 KB Output is correct
68 Correct 11 ms 13688 KB Output is correct
69 Correct 12 ms 13688 KB Output is correct
70 Correct 11 ms 13688 KB Output is correct
71 Correct 9 ms 13688 KB Output is correct
72 Correct 17 ms 13688 KB Output is correct
73 Correct 17 ms 13688 KB Output is correct
74 Correct 16 ms 13688 KB Output is correct
75 Correct 721 ms 13688 KB Output is correct
76 Correct 426 ms 13688 KB Output is correct
77 Correct 394 ms 13688 KB Output is correct
78 Correct 94 ms 13688 KB Output is correct
79 Correct 456 ms 13688 KB Output is correct
80 Correct 709 ms 13688 KB Output is correct
81 Correct 21 ms 13688 KB Output is correct
82 Correct 579 ms 13688 KB Output is correct
83 Correct 83 ms 13688 KB Output is correct
84 Correct 566 ms 13688 KB Output is correct
85 Correct 607 ms 13688 KB Output is correct
86 Correct 546 ms 13688 KB Output is correct
87 Correct 174 ms 13688 KB Output is correct
88 Correct 187 ms 13688 KB Output is correct
89 Correct 662 ms 13688 KB Output is correct
90 Correct 802 ms 13688 KB Output is correct
91 Correct 677 ms 13688 KB Output is correct
92 Correct 615 ms 13688 KB Output is correct
93 Correct 516 ms 13688 KB Output is correct
94 Correct 591 ms 13688 KB Output is correct
95 Correct 644 ms 13688 KB Output is correct