답안 #20396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20396 2017-02-10T17:53:47 Z 윤지학(#34, gs13068) 초음속철도 (OJUZ11_rail) C++
100 / 100
589 ms 29244 KB
#include <cstdio>
#include <algorithm>

using namespace std;

const int P = 1000000007;

pair<int, int> a[200002];
int t[400004];

struct tree {
	tree *l, *r;
	int s, e, x, y;
} T[800008];
int Tn;

void Init(tree *p, int s, int e) {
	p->s = s;
	p->e = e;
	p->x = s == 1 && e == 1;
	p->y = 1;
	if (s != e) {
		p->l = T + ++Tn;
		Init(p->l, s, s + e >> 1);
		p->r = T + ++Tn;
		Init(p->r, (s + e >> 1) + 1, e);
	}
}

void Lazy(tree *p) {
	p->l->x = ((long long)p->l->x * p->y + p->x) % P;
	p->l->y = (long long)p->l->y * p->y % P;
	p->r->x = ((long long)p->r->x * p->y + p->x) % P;
	p->r->y = (long long)p->r->y * p->y % P;
	p->y = 1;
	p->x = 0;
}

void Mul(tree *p, int e) {
	if (p->s > e) return;
	if (p->e <= e) {
		p->x = (p->x << 1) % P;
		p->y = (p->y << 1) % P;
		return;
	}
	Lazy(p);
	Mul(p->l, e);
	Mul(p->r, e);
}

void Add(tree *p, int s, int e, int x) {
	if (p->s > e || p->e < s) return;
	if (s <= p->s && p->e <= e) {
		p->x = (p->x + x) % P;
		return;
	}
	Lazy(p);
	Add(p->l, s, e, x);
	Add(p->r, s, e, x);
}

int Get(tree *p, int x) {
	if (p->s == x && p->e == x) return p->x;
	Lazy(p);
	return p->r->s > x ? Get(p->l, x) : Get(p->r, x);
}

int main() {
	int i, j, k, n, m, r = 0;
	scanf("%d%d", &t[1], &n);
	t[0] = 1;
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &t[i << 1], &t[i << 1 | 1]);
		a[i].first = t[i << 1 | 1];
		a[i].second = -t[i << 1];
	}
	sort(a + 1, a + n + 1);
	sort(t, t + n + n + 2);
	m = unique(t, t + n + n + 2) - t;
	Init(T, 0, m);
	for (i = 1; i <= n; i++) {
		a[i].first = upper_bound(t, t + m, a[i].first) - t;
		a[i].second = upper_bound(t, t + m, -a[i].second) - t;
		k = Get(T, a[i].second);
		if (a[i].first == m) r = (r + k) % P;
		Mul(T, a[i].second - 1);
		Add(T, a[i].second, a[i].first, k);
	}
	printf("%d", r);
}

Compilation message

rail.cpp: In function 'void Init(tree*, int, int)':
rail.cpp:24:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   Init(p->l, s, s + e >> 1);
                   ^
rail.cpp:26:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   Init(p->r, (s + e >> 1) + 1, e);
                 ^
rail.cpp: In function 'int main()':
rail.cpp:69:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j, k, n, m, r = 0;
         ^
rail.cpp:70:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &t[1], &n);
                          ^
rail.cpp:73:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &t[i << 1], &t[i << 1 | 1]);
                                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 29244 KB Output is correct
2 Correct 0 ms 29244 KB Output is correct
3 Correct 0 ms 29244 KB Output is correct
4 Correct 0 ms 29244 KB Output is correct
5 Correct 0 ms 29244 KB Output is correct
6 Correct 0 ms 29244 KB Output is correct
7 Correct 0 ms 29244 KB Output is correct
8 Correct 0 ms 29244 KB Output is correct
9 Correct 0 ms 29244 KB Output is correct
10 Correct 0 ms 29244 KB Output is correct
11 Correct 0 ms 29244 KB Output is correct
12 Correct 0 ms 29244 KB Output is correct
13 Correct 0 ms 29244 KB Output is correct
14 Correct 0 ms 29244 KB Output is correct
15 Correct 0 ms 29244 KB Output is correct
16 Correct 0 ms 29244 KB Output is correct
17 Correct 0 ms 29244 KB Output is correct
18 Correct 0 ms 29244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 29244 KB Output is correct
2 Correct 0 ms 29244 KB Output is correct
3 Correct 0 ms 29244 KB Output is correct
4 Correct 0 ms 29244 KB Output is correct
5 Correct 0 ms 29244 KB Output is correct
6 Correct 0 ms 29244 KB Output is correct
7 Correct 0 ms 29244 KB Output is correct
8 Correct 0 ms 29244 KB Output is correct
9 Correct 0 ms 29244 KB Output is correct
10 Correct 0 ms 29244 KB Output is correct
11 Correct 0 ms 29244 KB Output is correct
12 Correct 0 ms 29244 KB Output is correct
13 Correct 0 ms 29244 KB Output is correct
14 Correct 0 ms 29244 KB Output is correct
15 Correct 0 ms 29244 KB Output is correct
16 Correct 0 ms 29244 KB Output is correct
17 Correct 0 ms 29244 KB Output is correct
18 Correct 0 ms 29244 KB Output is correct
19 Correct 0 ms 29244 KB Output is correct
20 Correct 0 ms 29244 KB Output is correct
21 Correct 0 ms 29244 KB Output is correct
22 Correct 0 ms 29244 KB Output is correct
23 Correct 0 ms 29244 KB Output is correct
24 Correct 0 ms 29244 KB Output is correct
25 Correct 0 ms 29244 KB Output is correct
26 Correct 0 ms 29244 KB Output is correct
27 Correct 0 ms 29244 KB Output is correct
28 Correct 0 ms 29244 KB Output is correct
29 Correct 0 ms 29244 KB Output is correct
30 Correct 0 ms 29244 KB Output is correct
31 Correct 0 ms 29244 KB Output is correct
32 Correct 0 ms 29244 KB Output is correct
33 Correct 0 ms 29244 KB Output is correct
34 Correct 0 ms 29244 KB Output is correct
35 Correct 0 ms 29244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 29244 KB Output is correct
2 Correct 0 ms 29244 KB Output is correct
3 Correct 0 ms 29244 KB Output is correct
4 Correct 6 ms 29244 KB Output is correct
5 Correct 233 ms 29244 KB Output is correct
6 Correct 329 ms 29244 KB Output is correct
7 Correct 356 ms 29244 KB Output is correct
8 Correct 0 ms 29244 KB Output is correct
9 Correct 313 ms 29244 KB Output is correct
10 Correct 326 ms 29244 KB Output is correct
11 Correct 146 ms 29244 KB Output is correct
12 Correct 339 ms 29244 KB Output is correct
13 Correct 336 ms 29244 KB Output is correct
14 Correct 73 ms 29244 KB Output is correct
15 Correct 323 ms 29244 KB Output is correct
16 Correct 79 ms 29244 KB Output is correct
17 Correct 356 ms 29244 KB Output is correct
18 Correct 343 ms 29244 KB Output is correct
19 Correct 333 ms 29244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 29244 KB Output is correct
2 Correct 0 ms 29244 KB Output is correct
3 Correct 0 ms 29244 KB Output is correct
4 Correct 0 ms 29244 KB Output is correct
5 Correct 0 ms 29244 KB Output is correct
6 Correct 0 ms 29244 KB Output is correct
7 Correct 0 ms 29244 KB Output is correct
8 Correct 0 ms 29244 KB Output is correct
9 Correct 0 ms 29244 KB Output is correct
10 Correct 0 ms 29244 KB Output is correct
11 Correct 0 ms 29244 KB Output is correct
12 Correct 0 ms 29244 KB Output is correct
13 Correct 0 ms 29244 KB Output is correct
14 Correct 0 ms 29244 KB Output is correct
15 Correct 0 ms 29244 KB Output is correct
16 Correct 0 ms 29244 KB Output is correct
17 Correct 0 ms 29244 KB Output is correct
18 Correct 0 ms 29244 KB Output is correct
19 Correct 0 ms 29244 KB Output is correct
20 Correct 0 ms 29244 KB Output is correct
21 Correct 0 ms 29244 KB Output is correct
22 Correct 0 ms 29244 KB Output is correct
23 Correct 0 ms 29244 KB Output is correct
24 Correct 0 ms 29244 KB Output is correct
25 Correct 0 ms 29244 KB Output is correct
26 Correct 0 ms 29244 KB Output is correct
27 Correct 0 ms 29244 KB Output is correct
28 Correct 0 ms 29244 KB Output is correct
29 Correct 0 ms 29244 KB Output is correct
30 Correct 0 ms 29244 KB Output is correct
31 Correct 0 ms 29244 KB Output is correct
32 Correct 0 ms 29244 KB Output is correct
33 Correct 0 ms 29244 KB Output is correct
34 Correct 0 ms 29244 KB Output is correct
35 Correct 0 ms 29244 KB Output is correct
36 Correct 9 ms 29244 KB Output is correct
37 Correct 6 ms 29244 KB Output is correct
38 Correct 6 ms 29244 KB Output is correct
39 Correct 0 ms 29244 KB Output is correct
40 Correct 6 ms 29244 KB Output is correct
41 Correct 9 ms 29244 KB Output is correct
42 Correct 9 ms 29244 KB Output is correct
43 Correct 0 ms 29244 KB Output is correct
44 Correct 6 ms 29244 KB Output is correct
45 Correct 0 ms 29244 KB Output is correct
46 Correct 6 ms 29244 KB Output is correct
47 Correct 6 ms 29244 KB Output is correct
48 Correct 6 ms 29244 KB Output is correct
49 Correct 3 ms 29244 KB Output is correct
50 Correct 3 ms 29244 KB Output is correct
51 Correct 3 ms 29244 KB Output is correct
52 Correct 0 ms 29244 KB Output is correct
53 Correct 6 ms 29244 KB Output is correct
54 Correct 3 ms 29244 KB Output is correct
55 Correct 9 ms 29244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 29244 KB Output is correct
2 Correct 0 ms 29244 KB Output is correct
3 Correct 0 ms 29244 KB Output is correct
4 Correct 0 ms 29244 KB Output is correct
5 Correct 0 ms 29244 KB Output is correct
6 Correct 0 ms 29244 KB Output is correct
7 Correct 0 ms 29244 KB Output is correct
8 Correct 0 ms 29244 KB Output is correct
9 Correct 0 ms 29244 KB Output is correct
10 Correct 0 ms 29244 KB Output is correct
11 Correct 0 ms 29244 KB Output is correct
12 Correct 0 ms 29244 KB Output is correct
13 Correct 0 ms 29244 KB Output is correct
14 Correct 0 ms 29244 KB Output is correct
15 Correct 0 ms 29244 KB Output is correct
16 Correct 0 ms 29244 KB Output is correct
17 Correct 0 ms 29244 KB Output is correct
18 Correct 0 ms 29244 KB Output is correct
19 Correct 0 ms 29244 KB Output is correct
20 Correct 0 ms 29244 KB Output is correct
21 Correct 0 ms 29244 KB Output is correct
22 Correct 0 ms 29244 KB Output is correct
23 Correct 0 ms 29244 KB Output is correct
24 Correct 0 ms 29244 KB Output is correct
25 Correct 0 ms 29244 KB Output is correct
26 Correct 0 ms 29244 KB Output is correct
27 Correct 0 ms 29244 KB Output is correct
28 Correct 0 ms 29244 KB Output is correct
29 Correct 0 ms 29244 KB Output is correct
30 Correct 0 ms 29244 KB Output is correct
31 Correct 0 ms 29244 KB Output is correct
32 Correct 0 ms 29244 KB Output is correct
33 Correct 0 ms 29244 KB Output is correct
34 Correct 0 ms 29244 KB Output is correct
35 Correct 0 ms 29244 KB Output is correct
36 Correct 0 ms 29244 KB Output is correct
37 Correct 0 ms 29244 KB Output is correct
38 Correct 0 ms 29244 KB Output is correct
39 Correct 6 ms 29244 KB Output is correct
40 Correct 233 ms 29244 KB Output is correct
41 Correct 329 ms 29244 KB Output is correct
42 Correct 356 ms 29244 KB Output is correct
43 Correct 0 ms 29244 KB Output is correct
44 Correct 313 ms 29244 KB Output is correct
45 Correct 326 ms 29244 KB Output is correct
46 Correct 146 ms 29244 KB Output is correct
47 Correct 339 ms 29244 KB Output is correct
48 Correct 336 ms 29244 KB Output is correct
49 Correct 73 ms 29244 KB Output is correct
50 Correct 323 ms 29244 KB Output is correct
51 Correct 79 ms 29244 KB Output is correct
52 Correct 356 ms 29244 KB Output is correct
53 Correct 343 ms 29244 KB Output is correct
54 Correct 333 ms 29244 KB Output is correct
55 Correct 9 ms 29244 KB Output is correct
56 Correct 6 ms 29244 KB Output is correct
57 Correct 6 ms 29244 KB Output is correct
58 Correct 0 ms 29244 KB Output is correct
59 Correct 6 ms 29244 KB Output is correct
60 Correct 9 ms 29244 KB Output is correct
61 Correct 9 ms 29244 KB Output is correct
62 Correct 0 ms 29244 KB Output is correct
63 Correct 6 ms 29244 KB Output is correct
64 Correct 0 ms 29244 KB Output is correct
65 Correct 6 ms 29244 KB Output is correct
66 Correct 6 ms 29244 KB Output is correct
67 Correct 6 ms 29244 KB Output is correct
68 Correct 3 ms 29244 KB Output is correct
69 Correct 3 ms 29244 KB Output is correct
70 Correct 3 ms 29244 KB Output is correct
71 Correct 0 ms 29244 KB Output is correct
72 Correct 6 ms 29244 KB Output is correct
73 Correct 3 ms 29244 KB Output is correct
74 Correct 9 ms 29244 KB Output is correct
75 Correct 573 ms 29244 KB Output is correct
76 Correct 363 ms 29244 KB Output is correct
77 Correct 256 ms 29244 KB Output is correct
78 Correct 76 ms 29244 KB Output is correct
79 Correct 383 ms 29244 KB Output is correct
80 Correct 539 ms 29244 KB Output is correct
81 Correct 6 ms 29244 KB Output is correct
82 Correct 509 ms 29244 KB Output is correct
83 Correct 76 ms 29244 KB Output is correct
84 Correct 449 ms 29244 KB Output is correct
85 Correct 443 ms 29244 KB Output is correct
86 Correct 439 ms 29244 KB Output is correct
87 Correct 133 ms 29244 KB Output is correct
88 Correct 139 ms 29244 KB Output is correct
89 Correct 546 ms 29244 KB Output is correct
90 Correct 543 ms 29244 KB Output is correct
91 Correct 543 ms 29244 KB Output is correct
92 Correct 479 ms 29244 KB Output is correct
93 Correct 433 ms 29244 KB Output is correct
94 Correct 579 ms 29244 KB Output is correct
95 Correct 589 ms 29244 KB Output is correct