답안 #20556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20556 2017-02-12T10:12:42 Z CodingAmolang(#71, sys7961) 초음속철도 (OJUZ11_rail) C++11
43 / 100
3000 ms 12748 KB
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<string.h>
using std::queue;
using std::vector;
const long long MOD = 1000000007;
using std::pair;
long long di[400100];
int sz = 500;
long long start[1000];
long long end[1000];
int cnt[1000];
long long sum[1000];
long long arr[400100];

long long poww(long long a, long long b) {
	if (b == 0)return 1;
	long long tmp = poww(a, b / 2);
	if (b % 2 == 1)return (((tmp*tmp) % MOD)*a) % MOD;
	return (tmp*tmp) % MOD;
}
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	vector<int> X = { 1,n };
	vector<pair<int, int>> seg;
	for (int i = 0; i < m; i++) {
		int s, e;
		scanf("%d%d", &s, &e);
		seg.push_back({ s,e });
		X.push_back(s);
		X.push_back(e);
	}
	std::sort(seg.begin(), seg.end());
	std::sort(X.begin(), X.end());
	X.erase(std::unique(X.begin(), X.end()), X.end());
	memset(start, 0xff, sizeof(start));
	for (int i = 0; i < X.size(); i++) {
		di[i] = i / sz;
		if (start[di[i]] == -1)start[di[i]] = i;
		end[di[i]] = i;
	}
	sum[di[0]]++;
	arr[0]++;
	for (auto segment : seg) {
		int s = std::lower_bound(X.begin(), X.end(), segment.first) - X.begin();
		int e = std::lower_bound(X.begin(), X.end(), segment.second) - X.begin();
		long long S = 0;
		for (int i = s; i <= e; i++) {
			if (start[di[i]] == i && end[di[i]]<=e) {
				S += sum[di[i]];
				S %= MOD;
				i = end[di[i]];
				continue;
			}
			S += arr[i];
			S %= MOD;

		}
		if (cnt[di[e]] != 0) {
			for (int i = start[di[e]]; i <= end[di[e]]; i++) {
				arr[i] *=poww(2,cnt[di[i]]);
				arr[i] %= MOD;
			}
			cnt[di[e]] = 0;
		}
		arr[e] += S;
		arr[e] %= MOD;
		sum[di[e]] += S;
		sum[di[e]] %= MOD;
		for (int i = e + 1; i <= X.size() - 1; i++) {
			if (start[di[i]] == i && end[di[i]] <= X.size()-1) {
				cnt[di[i]]++;
				sum[di[i]] *= 2;
				sum[di[i]] %= MOD;
				i = end[di[i]];
				continue;
			}
			sum[di[i]] += arr[i];
			sum[di[i]] %= MOD;
			arr[i] *= 2;
			arr[i] %= MOD;
		}
	}
	arr[X.size() - 1] *= poww(2,cnt[di[X.size()-1]]) % MOD;
	arr[X.size() - 1] %= MOD;
	printf("%lld", arr[X.size() - 1]);
}

Compilation message

rail.cpp: In function 'int main()':
rail.cpp:40:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < X.size(); i++) {
                    ^
rail.cpp:73:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = e + 1; i <= X.size() - 1; i++) {
                         ^
rail.cpp:74:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (start[di[i]] == i && end[di[i]] <= X.size()-1) {
                                        ^
rail.cpp:26:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
rail.cpp:31:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &s, &e);
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7456 KB Output is correct
2 Correct 0 ms 7456 KB Output is correct
3 Correct 0 ms 7456 KB Output is correct
4 Correct 0 ms 7456 KB Output is correct
5 Correct 0 ms 7456 KB Output is correct
6 Correct 0 ms 7456 KB Output is correct
7 Correct 0 ms 7456 KB Output is correct
8 Correct 0 ms 7456 KB Output is correct
9 Correct 0 ms 7456 KB Output is correct
10 Correct 0 ms 7456 KB Output is correct
11 Correct 0 ms 7456 KB Output is correct
12 Correct 0 ms 7456 KB Output is correct
13 Correct 0 ms 7456 KB Output is correct
14 Correct 0 ms 7456 KB Output is correct
15 Correct 0 ms 7456 KB Output is correct
16 Correct 0 ms 7456 KB Output is correct
17 Correct 0 ms 7456 KB Output is correct
18 Correct 0 ms 7456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7456 KB Output is correct
2 Correct 0 ms 7456 KB Output is correct
3 Correct 0 ms 7456 KB Output is correct
4 Correct 0 ms 7456 KB Output is correct
5 Correct 0 ms 7456 KB Output is correct
6 Correct 0 ms 7456 KB Output is correct
7 Correct 0 ms 7456 KB Output is correct
8 Correct 0 ms 7456 KB Output is correct
9 Correct 0 ms 7456 KB Output is correct
10 Correct 0 ms 7456 KB Output is correct
11 Correct 0 ms 7456 KB Output is correct
12 Correct 0 ms 7456 KB Output is correct
13 Correct 0 ms 7456 KB Output is correct
14 Correct 0 ms 7456 KB Output is correct
15 Correct 0 ms 7456 KB Output is correct
16 Correct 0 ms 7456 KB Output is correct
17 Correct 0 ms 7456 KB Output is correct
18 Correct 0 ms 7456 KB Output is correct
19 Correct 0 ms 7456 KB Output is correct
20 Correct 0 ms 7456 KB Output is correct
21 Correct 0 ms 7456 KB Output is correct
22 Correct 0 ms 7456 KB Output is correct
23 Correct 0 ms 7456 KB Output is correct
24 Correct 0 ms 7456 KB Output is correct
25 Correct 0 ms 7456 KB Output is correct
26 Correct 0 ms 7456 KB Output is correct
27 Correct 0 ms 7456 KB Output is correct
28 Correct 0 ms 7456 KB Output is correct
29 Correct 0 ms 7456 KB Output is correct
30 Correct 0 ms 7456 KB Output is correct
31 Correct 0 ms 7456 KB Output is correct
32 Correct 0 ms 7456 KB Output is correct
33 Correct 0 ms 7456 KB Output is correct
34 Correct 0 ms 7456 KB Output is correct
35 Correct 0 ms 7456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7456 KB Output is correct
2 Correct 0 ms 7456 KB Output is correct
3 Correct 0 ms 7456 KB Output is correct
4 Correct 13 ms 7616 KB Output is correct
5 Correct 413 ms 12748 KB Output is correct
6 Correct 1493 ms 12748 KB Output is correct
7 Correct 1489 ms 12748 KB Output is correct
8 Correct 0 ms 7456 KB Output is correct
9 Correct 1296 ms 12748 KB Output is correct
10 Correct 1383 ms 12748 KB Output is correct
11 Correct 513 ms 10188 KB Output is correct
12 Correct 1483 ms 12748 KB Output is correct
13 Correct 1416 ms 12748 KB Output is correct
14 Correct 63 ms 12748 KB Output is correct
15 Correct 963 ms 12748 KB Output is correct
16 Correct 69 ms 12748 KB Output is correct
17 Correct 1466 ms 12748 KB Output is correct
18 Correct 1473 ms 12748 KB Output is correct
19 Correct 1369 ms 12748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7456 KB Output is correct
2 Correct 0 ms 7456 KB Output is correct
3 Correct 0 ms 7456 KB Output is correct
4 Correct 0 ms 7456 KB Output is correct
5 Correct 0 ms 7456 KB Output is correct
6 Correct 0 ms 7456 KB Output is correct
7 Correct 0 ms 7456 KB Output is correct
8 Correct 0 ms 7456 KB Output is correct
9 Correct 0 ms 7456 KB Output is correct
10 Correct 0 ms 7456 KB Output is correct
11 Correct 0 ms 7456 KB Output is correct
12 Correct 0 ms 7456 KB Output is correct
13 Correct 0 ms 7456 KB Output is correct
14 Correct 0 ms 7456 KB Output is correct
15 Correct 0 ms 7456 KB Output is correct
16 Correct 0 ms 7456 KB Output is correct
17 Correct 0 ms 7456 KB Output is correct
18 Correct 0 ms 7456 KB Output is correct
19 Correct 0 ms 7456 KB Output is correct
20 Correct 0 ms 7456 KB Output is correct
21 Correct 0 ms 7456 KB Output is correct
22 Correct 0 ms 7456 KB Output is correct
23 Correct 0 ms 7456 KB Output is correct
24 Correct 0 ms 7456 KB Output is correct
25 Correct 0 ms 7456 KB Output is correct
26 Correct 0 ms 7456 KB Output is correct
27 Correct 0 ms 7456 KB Output is correct
28 Correct 0 ms 7456 KB Output is correct
29 Correct 0 ms 7456 KB Output is correct
30 Correct 0 ms 7456 KB Output is correct
31 Correct 0 ms 7456 KB Output is correct
32 Correct 0 ms 7456 KB Output is correct
33 Correct 0 ms 7456 KB Output is correct
34 Correct 0 ms 7456 KB Output is correct
35 Correct 0 ms 7456 KB Output is correct
36 Incorrect 76 ms 7616 KB Output isn't correct
37 Incorrect 56 ms 7616 KB Output isn't correct
38 Incorrect 33 ms 7616 KB Output isn't correct
39 Correct 0 ms 7616 KB Output is correct
40 Correct 13 ms 7616 KB Output is correct
41 Correct 63 ms 7616 KB Output is correct
42 Incorrect 76 ms 7616 KB Output isn't correct
43 Correct 0 ms 7456 KB Output is correct
44 Incorrect 33 ms 7616 KB Output isn't correct
45 Correct 0 ms 7616 KB Output is correct
46 Correct 13 ms 7616 KB Output is correct
47 Incorrect 43 ms 7616 KB Output isn't correct
48 Incorrect 46 ms 7616 KB Output isn't correct
49 Correct 3 ms 7616 KB Output is correct
50 Correct 3 ms 7616 KB Output is correct
51 Correct 3 ms 7616 KB Output is correct
52 Incorrect 6 ms 7456 KB Output isn't correct
53 Correct 59 ms 7616 KB Output is correct
54 Incorrect 23 ms 7616 KB Output isn't correct
55 Correct 73 ms 7616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7456 KB Output is correct
2 Correct 0 ms 7456 KB Output is correct
3 Correct 0 ms 7456 KB Output is correct
4 Correct 0 ms 7456 KB Output is correct
5 Correct 0 ms 7456 KB Output is correct
6 Correct 0 ms 7456 KB Output is correct
7 Correct 0 ms 7456 KB Output is correct
8 Correct 0 ms 7456 KB Output is correct
9 Correct 0 ms 7456 KB Output is correct
10 Correct 0 ms 7456 KB Output is correct
11 Correct 0 ms 7456 KB Output is correct
12 Correct 0 ms 7456 KB Output is correct
13 Correct 0 ms 7456 KB Output is correct
14 Correct 0 ms 7456 KB Output is correct
15 Correct 0 ms 7456 KB Output is correct
16 Correct 0 ms 7456 KB Output is correct
17 Correct 0 ms 7456 KB Output is correct
18 Correct 0 ms 7456 KB Output is correct
19 Correct 0 ms 7456 KB Output is correct
20 Correct 0 ms 7456 KB Output is correct
21 Correct 0 ms 7456 KB Output is correct
22 Correct 0 ms 7456 KB Output is correct
23 Correct 0 ms 7456 KB Output is correct
24 Correct 0 ms 7456 KB Output is correct
25 Correct 0 ms 7456 KB Output is correct
26 Correct 0 ms 7456 KB Output is correct
27 Correct 0 ms 7456 KB Output is correct
28 Correct 0 ms 7456 KB Output is correct
29 Correct 0 ms 7456 KB Output is correct
30 Correct 0 ms 7456 KB Output is correct
31 Correct 0 ms 7456 KB Output is correct
32 Correct 0 ms 7456 KB Output is correct
33 Correct 0 ms 7456 KB Output is correct
34 Correct 0 ms 7456 KB Output is correct
35 Correct 0 ms 7456 KB Output is correct
36 Correct 0 ms 7456 KB Output is correct
37 Correct 0 ms 7456 KB Output is correct
38 Correct 0 ms 7456 KB Output is correct
39 Correct 13 ms 7616 KB Output is correct
40 Correct 413 ms 12748 KB Output is correct
41 Correct 1493 ms 12748 KB Output is correct
42 Correct 1489 ms 12748 KB Output is correct
43 Correct 0 ms 7456 KB Output is correct
44 Correct 1296 ms 12748 KB Output is correct
45 Correct 1383 ms 12748 KB Output is correct
46 Correct 513 ms 10188 KB Output is correct
47 Correct 1483 ms 12748 KB Output is correct
48 Correct 1416 ms 12748 KB Output is correct
49 Correct 63 ms 12748 KB Output is correct
50 Correct 963 ms 12748 KB Output is correct
51 Correct 69 ms 12748 KB Output is correct
52 Correct 1466 ms 12748 KB Output is correct
53 Correct 1473 ms 12748 KB Output is correct
54 Correct 1369 ms 12748 KB Output is correct
55 Incorrect 76 ms 7616 KB Output isn't correct
56 Incorrect 56 ms 7616 KB Output isn't correct
57 Incorrect 33 ms 7616 KB Output isn't correct
58 Correct 0 ms 7616 KB Output is correct
59 Correct 13 ms 7616 KB Output is correct
60 Correct 63 ms 7616 KB Output is correct
61 Incorrect 76 ms 7616 KB Output isn't correct
62 Correct 0 ms 7456 KB Output is correct
63 Incorrect 33 ms 7616 KB Output isn't correct
64 Correct 0 ms 7616 KB Output is correct
65 Correct 13 ms 7616 KB Output is correct
66 Incorrect 43 ms 7616 KB Output isn't correct
67 Incorrect 46 ms 7616 KB Output isn't correct
68 Correct 3 ms 7616 KB Output is correct
69 Correct 3 ms 7616 KB Output is correct
70 Correct 3 ms 7616 KB Output is correct
71 Incorrect 6 ms 7456 KB Output isn't correct
72 Correct 59 ms 7616 KB Output is correct
73 Incorrect 23 ms 7616 KB Output isn't correct
74 Correct 73 ms 7616 KB Output is correct
75 Execution timed out 3000 ms 12748 KB Execution timed out
76 Execution timed out 3000 ms 11724 KB Execution timed out
77 Incorrect 1103 ms 12748 KB Output isn't correct
78 Correct 63 ms 12748 KB Output is correct
79 Execution timed out 3000 ms 12748 KB Execution timed out
80 Execution timed out 3000 ms 12748 KB Execution timed out
81 Incorrect 49 ms 7616 KB Output isn't correct
82 Execution timed out 3000 ms 12748 KB Execution timed out
83 Correct 56 ms 12748 KB Output is correct
84 Execution timed out 3000 ms 12748 KB Execution timed out
85 Execution timed out 3000 ms 12748 KB Execution timed out
86 Execution timed out 3000 ms 12748 KB Execution timed out
87 Correct 136 ms 12748 KB Output is correct
88 Correct 126 ms 12748 KB Output is correct
89 Execution timed out 3000 ms 12748 KB Execution timed out
90 Execution timed out 3000 ms 12748 KB Execution timed out
91 Execution timed out 3000 ms 12748 KB Execution timed out
92 Execution timed out 3000 ms 12748 KB Execution timed out
93 Execution timed out 3000 ms 12748 KB Execution timed out
94 Execution timed out 3000 ms 12748 KB Execution timed out
95 Execution timed out 3000 ms 12748 KB Execution timed out