Submission #163742

# Submission time Handle Problem Language Result Execution time Memory
163742 2019-11-15T04:43:11 Z jwvg0425 초음속철도 (OJUZ11_rail) C++17
100 / 100
1523 ms 55532 KB
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second
#define MOD ((i64)1e9 + 7)

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

class Mapping
{
public:
	void init(const vector<int>& raw, int base = 0)
	{
		start = base;
		arr = raw;
		sort(arr.begin(), arr.end());
		arr.erase(unique(arr.begin(), arr.end()), arr.end());
	}

	int get_idx(int k)
	{
		return start + (lower_bound(all(arr), k) - arr.begin());
	}

	int get_value(int idx)
	{
		return arr[idx - start];
	}

	int size()
	{
		return arr.size();
	}

private:
	int start;
	vector<int> arr;
};

i64 ipow(i64 x, i64 p)
{
	if (p == 0)
		return 1;

	i64 half = ipow(x, p / 2);
	half = (half * half) % MOD;

	if (p % 2 == 0)
		return half;
	else
		return (half * x) % MOD;
}

void updateLazy(vector<i64>& tree, vector<i64>& lazy, int start, int end, int node)
{
	if (lazy[node] == 0)
		return;

	i64 px = ipow(2, lazy[node]);
	tree[node] = (tree[node] * px) % MOD;

	if (start != end)
	{
		lazy[node * 2] += lazy[node];
		lazy[node * 2 + 1] += lazy[node];
	}

	lazy[node] = 0;
}

// * 2
void multRange(vector<i64>& tree, vector<i64>& lazy, int start, int end, int node, int left, int right)
{
	updateLazy(tree, lazy, start, end, node);

	if (left > end || right < start)
		return;

	if (left <= start && end <= right)
	{
		tree[node] = (tree[node] * 2) % MOD;

		if (start != end)
		{
			lazy[node * 2] += 1;
			lazy[node * 2 + 1] += 1;
		}

		return;
	}

	int mid = (start + end) / 2;
	multRange(tree, lazy, start, mid, node * 2, left, right);
	multRange(tree, lazy, mid + 1, end, node * 2 + 1, left, right);
	tree[node] = (tree[node * 2] + tree[node * 2 + 1]) % MOD;
}

void add(vector<i64>& tree, vector<i64>& lazy, int start, int end, int node, int pos, i64 diff)
{
	updateLazy(tree, lazy, start, end, node);

	if (pos > end || pos < start)
		return;

	if (start == end)
	{
		tree[node] = (tree[node] + diff) % MOD;
		return;
	}

	int mid = (start + end) / 2;
	add(tree, lazy, start, mid, node * 2, pos, diff);
	add(tree, lazy, mid + 1, end, node * 2 + 1, pos, diff);
	tree[node] = (tree[node * 2] + tree[node * 2 + 1]) % MOD;
}

i64 query(vector<i64>& tree, vector<i64>& lazy, int start, int end, int node, int left, int right)
{
	updateLazy(tree, lazy, start, end, node);

	if (left > end || right < start)
		return 0;

	if (left <= start && end <= right)
		return tree[node];

	int mid = (start + end) / 2;
	return query(tree, lazy, start, mid, node * 2, left, right) +
		query(tree, lazy, mid + 1, end, node * 2 + 1, left, right);
}


int main()
{
	int n, m;
	scanf("%d %d", &n, &m);

	vector<ii> train(m);
	vector<int> pos = { 1, n };

	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &train[i].xx, &train[i].yy);
		pos.push_back(train[i].xx);
		pos.push_back(train[i].yy);
	}

	Mapping mapping;
	mapping.init(pos);

	for (int i = 0; i < m; i++)
	{
		train[i].xx = mapping.get_idx(train[i].xx);
		train[i].yy = mapping.get_idx(train[i].yy);
	}

	sort(all(train));

	int k = mapping.size();
	vector<i64> tree(k * 8);
	vector<i64> lazy(k * 8);

	add(tree, lazy, 0, k, 1, 0, 1);

	for (int i = 0; i < m; i++)
	{
		// 모든 구간에 대해 경우의 수 유지하며 다음 단계로
		// train[i].yy 지점에서 train[i].xx ~ train[i].yy 까지 전부 더함
		i64 q = query(tree, lazy, 0, k, 1, train[i].xx, train[i].yy);
		add(tree, lazy, 0, k, 1, train[i].yy, q);

		// train[i].yy 지점 이후는 값이 2배씩 상승함(train[i] 고르거나 안 고르거나)
		multRange(tree, lazy, 0, k, 1, train[i].yy + 1, k);
	}

	printf("%lld\n", query(tree, lazy, 0, k, 1, k - 1, k - 1));

	return 0;
}

Compilation message

rail.cpp: In function 'int main()':
rail.cpp:155:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
rail.cpp:162:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &train[i].xx, &train[i].yy);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 420 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 420 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 252 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 9 ms 632 KB Output is correct
5 Correct 405 ms 12128 KB Output is correct
6 Correct 682 ms 51316 KB Output is correct
7 Correct 668 ms 50536 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 626 ms 47348 KB Output is correct
10 Correct 657 ms 49896 KB Output is correct
11 Correct 216 ms 7788 KB Output is correct
12 Correct 676 ms 51020 KB Output is correct
13 Correct 669 ms 50296 KB Output is correct
14 Correct 106 ms 5224 KB Output is correct
15 Correct 598 ms 30248 KB Output is correct
16 Correct 113 ms 5224 KB Output is correct
17 Correct 711 ms 51200 KB Output is correct
18 Correct 707 ms 51048 KB Output is correct
19 Correct 686 ms 44520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 420 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 252 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 27 ms 1772 KB Output is correct
37 Correct 20 ms 1528 KB Output is correct
38 Correct 14 ms 760 KB Output is correct
39 Correct 5 ms 504 KB Output is correct
40 Correct 13 ms 1144 KB Output is correct
41 Correct 22 ms 1656 KB Output is correct
42 Correct 22 ms 1784 KB Output is correct
43 Correct 2 ms 256 KB Output is correct
44 Correct 16 ms 1272 KB Output is correct
45 Correct 4 ms 508 KB Output is correct
46 Correct 11 ms 1144 KB Output is correct
47 Correct 17 ms 1192 KB Output is correct
48 Correct 18 ms 1144 KB Output is correct
49 Correct 7 ms 508 KB Output is correct
50 Correct 6 ms 504 KB Output is correct
51 Correct 7 ms 504 KB Output is correct
52 Correct 7 ms 632 KB Output is correct
53 Correct 21 ms 1656 KB Output is correct
54 Correct 10 ms 760 KB Output is correct
55 Correct 23 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 420 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 252 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 256 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 9 ms 632 KB Output is correct
40 Correct 405 ms 12128 KB Output is correct
41 Correct 682 ms 51316 KB Output is correct
42 Correct 668 ms 50536 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 626 ms 47348 KB Output is correct
45 Correct 657 ms 49896 KB Output is correct
46 Correct 216 ms 7788 KB Output is correct
47 Correct 676 ms 51020 KB Output is correct
48 Correct 669 ms 50296 KB Output is correct
49 Correct 106 ms 5224 KB Output is correct
50 Correct 598 ms 30248 KB Output is correct
51 Correct 113 ms 5224 KB Output is correct
52 Correct 711 ms 51200 KB Output is correct
53 Correct 707 ms 51048 KB Output is correct
54 Correct 686 ms 44520 KB Output is correct
55 Correct 27 ms 1772 KB Output is correct
56 Correct 20 ms 1528 KB Output is correct
57 Correct 14 ms 760 KB Output is correct
58 Correct 5 ms 504 KB Output is correct
59 Correct 13 ms 1144 KB Output is correct
60 Correct 22 ms 1656 KB Output is correct
61 Correct 22 ms 1784 KB Output is correct
62 Correct 2 ms 256 KB Output is correct
63 Correct 16 ms 1272 KB Output is correct
64 Correct 4 ms 508 KB Output is correct
65 Correct 11 ms 1144 KB Output is correct
66 Correct 17 ms 1192 KB Output is correct
67 Correct 18 ms 1144 KB Output is correct
68 Correct 7 ms 508 KB Output is correct
69 Correct 6 ms 504 KB Output is correct
70 Correct 7 ms 504 KB Output is correct
71 Correct 7 ms 632 KB Output is correct
72 Correct 21 ms 1656 KB Output is correct
73 Correct 10 ms 760 KB Output is correct
74 Correct 23 ms 1656 KB Output is correct
75 Correct 1501 ms 55392 KB Output is correct
76 Correct 916 ms 36200 KB Output is correct
77 Correct 474 ms 5224 KB Output is correct
78 Correct 106 ms 5224 KB Output is correct
79 Correct 913 ms 14812 KB Output is correct
80 Correct 1502 ms 55532 KB Output is correct
81 Correct 18 ms 1016 KB Output is correct
82 Correct 1322 ms 49708 KB Output is correct
83 Correct 86 ms 5096 KB Output is correct
84 Correct 1259 ms 42780 KB Output is correct
85 Correct 984 ms 30232 KB Output is correct
86 Correct 1008 ms 30288 KB Output is correct
87 Correct 203 ms 5204 KB Output is correct
88 Correct 184 ms 5228 KB Output is correct
89 Correct 1499 ms 55324 KB Output is correct
90 Correct 1484 ms 55276 KB Output is correct
91 Correct 1499 ms 55528 KB Output is correct
92 Correct 1320 ms 53736 KB Output is correct
93 Correct 978 ms 30292 KB Output is correct
94 Correct 1523 ms 55272 KB Output is correct
95 Correct 1490 ms 55372 KB Output is correct