답안 #20558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20558 2017-02-12T10:18:59 Z CodingAmolang(#71, sys7961) 초음속철도 (OJUZ11_rail) C++11
70 / 100
3000 ms 12752 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 = 800;
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;
			}
			else if(cnt[di[i]]!=0){
				for (int k = start[di[i]]; k <= end[di[i]]; k++) {
					arr[k] *= poww(2, cnt[di[k]]);
					arr[k] %= MOD;
				}
				cnt[di[i]] = 0;
			}
			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:80:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = e + 1; i <= X.size() - 1; i++) {
                         ^
rail.cpp:81: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 7460 KB Output is correct
2 Correct 0 ms 7460 KB Output is correct
3 Correct 0 ms 7460 KB Output is correct
4 Correct 0 ms 7460 KB Output is correct
5 Correct 0 ms 7460 KB Output is correct
6 Correct 0 ms 7460 KB Output is correct
7 Correct 0 ms 7460 KB Output is correct
8 Correct 0 ms 7460 KB Output is correct
9 Correct 0 ms 7460 KB Output is correct
10 Correct 0 ms 7460 KB Output is correct
11 Correct 0 ms 7460 KB Output is correct
12 Correct 0 ms 7460 KB Output is correct
13 Correct 0 ms 7460 KB Output is correct
14 Correct 0 ms 7460 KB Output is correct
15 Correct 0 ms 7460 KB Output is correct
16 Correct 0 ms 7460 KB Output is correct
17 Correct 0 ms 7460 KB Output is correct
18 Correct 0 ms 7460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7460 KB Output is correct
2 Correct 0 ms 7460 KB Output is correct
3 Correct 0 ms 7460 KB Output is correct
4 Correct 0 ms 7460 KB Output is correct
5 Correct 0 ms 7460 KB Output is correct
6 Correct 0 ms 7460 KB Output is correct
7 Correct 0 ms 7460 KB Output is correct
8 Correct 0 ms 7460 KB Output is correct
9 Correct 0 ms 7460 KB Output is correct
10 Correct 0 ms 7460 KB Output is correct
11 Correct 0 ms 7460 KB Output is correct
12 Correct 0 ms 7460 KB Output is correct
13 Correct 0 ms 7460 KB Output is correct
14 Correct 0 ms 7460 KB Output is correct
15 Correct 0 ms 7460 KB Output is correct
16 Correct 0 ms 7460 KB Output is correct
17 Correct 0 ms 7460 KB Output is correct
18 Correct 0 ms 7460 KB Output is correct
19 Correct 0 ms 7460 KB Output is correct
20 Correct 0 ms 7460 KB Output is correct
21 Correct 0 ms 7460 KB Output is correct
22 Correct 0 ms 7460 KB Output is correct
23 Correct 0 ms 7460 KB Output is correct
24 Correct 0 ms 7460 KB Output is correct
25 Correct 0 ms 7460 KB Output is correct
26 Correct 0 ms 7460 KB Output is correct
27 Correct 0 ms 7460 KB Output is correct
28 Correct 0 ms 7460 KB Output is correct
29 Correct 0 ms 7460 KB Output is correct
30 Correct 0 ms 7460 KB Output is correct
31 Correct 0 ms 7460 KB Output is correct
32 Correct 0 ms 7460 KB Output is correct
33 Correct 0 ms 7460 KB Output is correct
34 Correct 0 ms 7460 KB Output is correct
35 Correct 0 ms 7460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7460 KB Output is correct
2 Correct 0 ms 7460 KB Output is correct
3 Correct 0 ms 7460 KB Output is correct
4 Correct 19 ms 7620 KB Output is correct
5 Correct 889 ms 12752 KB Output is correct
6 Correct 1443 ms 12752 KB Output is correct
7 Correct 1449 ms 12752 KB Output is correct
8 Correct 0 ms 7460 KB Output is correct
9 Correct 1256 ms 12752 KB Output is correct
10 Correct 1359 ms 12752 KB Output is correct
11 Correct 759 ms 10192 KB Output is correct
12 Correct 1403 ms 12752 KB Output is correct
13 Correct 1353 ms 12752 KB Output is correct
14 Correct 66 ms 12752 KB Output is correct
15 Correct 1119 ms 12752 KB Output is correct
16 Correct 76 ms 12752 KB Output is correct
17 Correct 1396 ms 12752 KB Output is correct
18 Correct 1403 ms 12752 KB Output is correct
19 Correct 1369 ms 12752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7460 KB Output is correct
2 Correct 0 ms 7460 KB Output is correct
3 Correct 0 ms 7460 KB Output is correct
4 Correct 0 ms 7460 KB Output is correct
5 Correct 0 ms 7460 KB Output is correct
6 Correct 0 ms 7460 KB Output is correct
7 Correct 0 ms 7460 KB Output is correct
8 Correct 0 ms 7460 KB Output is correct
9 Correct 0 ms 7460 KB Output is correct
10 Correct 0 ms 7460 KB Output is correct
11 Correct 0 ms 7460 KB Output is correct
12 Correct 0 ms 7460 KB Output is correct
13 Correct 0 ms 7460 KB Output is correct
14 Correct 0 ms 7460 KB Output is correct
15 Correct 0 ms 7460 KB Output is correct
16 Correct 0 ms 7460 KB Output is correct
17 Correct 0 ms 7460 KB Output is correct
18 Correct 0 ms 7460 KB Output is correct
19 Correct 0 ms 7460 KB Output is correct
20 Correct 0 ms 7460 KB Output is correct
21 Correct 0 ms 7460 KB Output is correct
22 Correct 0 ms 7460 KB Output is correct
23 Correct 0 ms 7460 KB Output is correct
24 Correct 0 ms 7460 KB Output is correct
25 Correct 0 ms 7460 KB Output is correct
26 Correct 0 ms 7460 KB Output is correct
27 Correct 0 ms 7460 KB Output is correct
28 Correct 0 ms 7460 KB Output is correct
29 Correct 0 ms 7460 KB Output is correct
30 Correct 0 ms 7460 KB Output is correct
31 Correct 0 ms 7460 KB Output is correct
32 Correct 0 ms 7460 KB Output is correct
33 Correct 0 ms 7460 KB Output is correct
34 Correct 0 ms 7460 KB Output is correct
35 Correct 0 ms 7460 KB Output is correct
36 Correct 103 ms 7620 KB Output is correct
37 Correct 79 ms 7620 KB Output is correct
38 Correct 46 ms 7620 KB Output is correct
39 Correct 0 ms 7620 KB Output is correct
40 Correct 19 ms 7620 KB Output is correct
41 Correct 86 ms 7620 KB Output is correct
42 Correct 99 ms 7620 KB Output is correct
43 Correct 0 ms 7460 KB Output is correct
44 Correct 53 ms 7620 KB Output is correct
45 Correct 0 ms 7620 KB Output is correct
46 Correct 26 ms 7620 KB Output is correct
47 Correct 66 ms 7620 KB Output is correct
48 Correct 66 ms 7620 KB Output is correct
49 Correct 3 ms 7620 KB Output is correct
50 Correct 3 ms 7620 KB Output is correct
51 Correct 3 ms 7620 KB Output is correct
52 Correct 9 ms 7460 KB Output is correct
53 Correct 89 ms 7620 KB Output is correct
54 Correct 36 ms 7620 KB Output is correct
55 Correct 109 ms 7620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 7460 KB Output is correct
2 Correct 0 ms 7460 KB Output is correct
3 Correct 0 ms 7460 KB Output is correct
4 Correct 0 ms 7460 KB Output is correct
5 Correct 0 ms 7460 KB Output is correct
6 Correct 0 ms 7460 KB Output is correct
7 Correct 0 ms 7460 KB Output is correct
8 Correct 0 ms 7460 KB Output is correct
9 Correct 0 ms 7460 KB Output is correct
10 Correct 0 ms 7460 KB Output is correct
11 Correct 0 ms 7460 KB Output is correct
12 Correct 0 ms 7460 KB Output is correct
13 Correct 0 ms 7460 KB Output is correct
14 Correct 0 ms 7460 KB Output is correct
15 Correct 0 ms 7460 KB Output is correct
16 Correct 0 ms 7460 KB Output is correct
17 Correct 0 ms 7460 KB Output is correct
18 Correct 0 ms 7460 KB Output is correct
19 Correct 0 ms 7460 KB Output is correct
20 Correct 0 ms 7460 KB Output is correct
21 Correct 0 ms 7460 KB Output is correct
22 Correct 0 ms 7460 KB Output is correct
23 Correct 0 ms 7460 KB Output is correct
24 Correct 0 ms 7460 KB Output is correct
25 Correct 0 ms 7460 KB Output is correct
26 Correct 0 ms 7460 KB Output is correct
27 Correct 0 ms 7460 KB Output is correct
28 Correct 0 ms 7460 KB Output is correct
29 Correct 0 ms 7460 KB Output is correct
30 Correct 0 ms 7460 KB Output is correct
31 Correct 0 ms 7460 KB Output is correct
32 Correct 0 ms 7460 KB Output is correct
33 Correct 0 ms 7460 KB Output is correct
34 Correct 0 ms 7460 KB Output is correct
35 Correct 0 ms 7460 KB Output is correct
36 Correct 0 ms 7460 KB Output is correct
37 Correct 0 ms 7460 KB Output is correct
38 Correct 0 ms 7460 KB Output is correct
39 Correct 19 ms 7620 KB Output is correct
40 Correct 889 ms 12752 KB Output is correct
41 Correct 1443 ms 12752 KB Output is correct
42 Correct 1449 ms 12752 KB Output is correct
43 Correct 0 ms 7460 KB Output is correct
44 Correct 1256 ms 12752 KB Output is correct
45 Correct 1359 ms 12752 KB Output is correct
46 Correct 759 ms 10192 KB Output is correct
47 Correct 1403 ms 12752 KB Output is correct
48 Correct 1353 ms 12752 KB Output is correct
49 Correct 66 ms 12752 KB Output is correct
50 Correct 1119 ms 12752 KB Output is correct
51 Correct 76 ms 12752 KB Output is correct
52 Correct 1396 ms 12752 KB Output is correct
53 Correct 1403 ms 12752 KB Output is correct
54 Correct 1369 ms 12752 KB Output is correct
55 Correct 103 ms 7620 KB Output is correct
56 Correct 79 ms 7620 KB Output is correct
57 Correct 46 ms 7620 KB Output is correct
58 Correct 0 ms 7620 KB Output is correct
59 Correct 19 ms 7620 KB Output is correct
60 Correct 86 ms 7620 KB Output is correct
61 Correct 99 ms 7620 KB Output is correct
62 Correct 0 ms 7460 KB Output is correct
63 Correct 53 ms 7620 KB Output is correct
64 Correct 0 ms 7620 KB Output is correct
65 Correct 26 ms 7620 KB Output is correct
66 Correct 66 ms 7620 KB Output is correct
67 Correct 66 ms 7620 KB Output is correct
68 Correct 3 ms 7620 KB Output is correct
69 Correct 3 ms 7620 KB Output is correct
70 Correct 3 ms 7620 KB Output is correct
71 Correct 9 ms 7460 KB Output is correct
72 Correct 89 ms 7620 KB Output is correct
73 Correct 36 ms 7620 KB Output is correct
74 Correct 109 ms 7620 KB Output is correct
75 Execution timed out 3000 ms 12752 KB Execution timed out
76 Execution timed out 3000 ms 11728 KB Execution timed out
77 Correct 1706 ms 12752 KB Output is correct
78 Correct 59 ms 12752 KB Output is correct
79 Execution timed out 3000 ms 12752 KB Execution timed out
80 Execution timed out 3000 ms 12752 KB Execution timed out
81 Correct 69 ms 7620 KB Output is correct
82 Execution timed out 3000 ms 12752 KB Execution timed out
83 Correct 59 ms 12752 KB Output is correct
84 Execution timed out 3000 ms 12752 KB Execution timed out
85 Execution timed out 3000 ms 12752 KB Execution timed out
86 Execution timed out 3000 ms 12752 KB Execution timed out
87 Correct 149 ms 12752 KB Output is correct
88 Correct 139 ms 12752 KB Output is correct
89 Execution timed out 3000 ms 12752 KB Execution timed out
90 Execution timed out 3000 ms 12752 KB Execution timed out
91 Execution timed out 3000 ms 12752 KB Execution timed out
92 Execution timed out 3000 ms 12752 KB Execution timed out
93 Execution timed out 3000 ms 12752 KB Execution timed out
94 Execution timed out 3000 ms 12752 KB Execution timed out
95 Execution timed out 3000 ms 12752 KB Execution timed out