Submission #163741

# Submission time Handle Problem Language Result Execution time Memory
163741 2019-11-15T04:37:46 Z jwvg0425 초음속철도 (OJUZ11_rail) C++17
0 / 100
2106 ms 59392 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);
	}

	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 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 2 ms 380 KB Output isn't correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Incorrect 2 ms 256 KB Output isn't correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 3 ms 376 KB Output isn't correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Incorrect 2 ms 504 KB Output isn't correct
16 Incorrect 2 ms 376 KB Output isn't correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 2 ms 380 KB Output isn't correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Incorrect 2 ms 256 KB Output isn't correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 3 ms 376 KB Output isn't correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Incorrect 2 ms 504 KB Output isn't correct
16 Incorrect 2 ms 376 KB Output isn't correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Incorrect 2 ms 396 KB Output isn't correct
20 Incorrect 2 ms 256 KB Output isn't correct
21 Incorrect 2 ms 256 KB Output isn't correct
22 Incorrect 2 ms 256 KB Output isn't correct
23 Incorrect 2 ms 256 KB Output isn't correct
24 Incorrect 2 ms 256 KB Output isn't correct
25 Incorrect 2 ms 256 KB Output isn't correct
26 Incorrect 2 ms 256 KB Output isn't correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Incorrect 3 ms 380 KB Output isn't correct
30 Incorrect 3 ms 376 KB Output isn't correct
31 Incorrect 2 ms 256 KB Output isn't correct
32 Incorrect 2 ms 376 KB Output isn't correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 256 KB Output is correct
35 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 11 ms 760 KB Output isn't correct
5 Incorrect 590 ms 16136 KB Output isn't correct
6 Incorrect 1453 ms 55048 KB Output isn't correct
7 Incorrect 1450 ms 53216 KB Output isn't correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Incorrect 1301 ms 50796 KB Output isn't correct
10 Incorrect 1451 ms 53608 KB Output isn't correct
11 Incorrect 320 ms 9068 KB Output isn't correct
12 Incorrect 1529 ms 54984 KB Output isn't correct
13 Incorrect 1437 ms 53992 KB Output isn't correct
14 Incorrect 169 ms 7784 KB Output isn't correct
15 Incorrect 1382 ms 34256 KB Output isn't correct
16 Incorrect 108 ms 8300 KB Output isn't correct
17 Incorrect 1451 ms 55028 KB Output isn't correct
18 Incorrect 1433 ms 55052 KB Output isn't correct
19 Incorrect 1435 ms 48360 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 2 ms 380 KB Output isn't correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Incorrect 2 ms 256 KB Output isn't correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 3 ms 376 KB Output isn't correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Incorrect 2 ms 504 KB Output isn't correct
16 Incorrect 2 ms 376 KB Output isn't correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Incorrect 2 ms 396 KB Output isn't correct
20 Incorrect 2 ms 256 KB Output isn't correct
21 Incorrect 2 ms 256 KB Output isn't correct
22 Incorrect 2 ms 256 KB Output isn't correct
23 Incorrect 2 ms 256 KB Output isn't correct
24 Incorrect 2 ms 256 KB Output isn't correct
25 Incorrect 2 ms 256 KB Output isn't correct
26 Incorrect 2 ms 256 KB Output isn't correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Incorrect 3 ms 380 KB Output isn't correct
30 Incorrect 3 ms 376 KB Output isn't correct
31 Incorrect 2 ms 256 KB Output isn't correct
32 Incorrect 2 ms 376 KB Output isn't correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 256 KB Output is correct
35 Correct 2 ms 380 KB Output is correct
36 Incorrect 24 ms 1784 KB Output isn't correct
37 Incorrect 20 ms 1528 KB Output isn't correct
38 Incorrect 16 ms 888 KB Output isn't correct
39 Incorrect 4 ms 508 KB Output isn't correct
40 Incorrect 19 ms 1144 KB Output isn't correct
41 Correct 52 ms 1784 KB Output is correct
42 Incorrect 24 ms 1784 KB Output isn't correct
43 Incorrect 2 ms 376 KB Output isn't correct
44 Incorrect 20 ms 1400 KB Output isn't correct
45 Correct 4 ms 504 KB Output is correct
46 Incorrect 17 ms 1268 KB Output isn't correct
47 Incorrect 21 ms 1144 KB Output isn't correct
48 Incorrect 22 ms 1272 KB Output isn't correct
49 Incorrect 7 ms 632 KB Output isn't correct
50 Incorrect 6 ms 504 KB Output isn't correct
51 Incorrect 7 ms 504 KB Output isn't correct
52 Incorrect 5 ms 632 KB Output isn't correct
53 Correct 25 ms 1784 KB Output is correct
54 Incorrect 13 ms 888 KB Output isn't correct
55 Correct 24 ms 1828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 2 ms 380 KB Output isn't correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Incorrect 2 ms 256 KB Output isn't correct
9 Correct 2 ms 376 KB Output is correct
10 Incorrect 3 ms 376 KB Output isn't correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Incorrect 2 ms 504 KB Output isn't correct
16 Incorrect 2 ms 376 KB Output isn't correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Incorrect 2 ms 396 KB Output isn't correct
20 Incorrect 2 ms 256 KB Output isn't correct
21 Incorrect 2 ms 256 KB Output isn't correct
22 Incorrect 2 ms 256 KB Output isn't correct
23 Incorrect 2 ms 256 KB Output isn't correct
24 Incorrect 2 ms 256 KB Output isn't correct
25 Incorrect 2 ms 256 KB Output isn't correct
26 Incorrect 2 ms 256 KB Output isn't correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Incorrect 3 ms 380 KB Output isn't correct
30 Incorrect 3 ms 376 KB Output isn't correct
31 Incorrect 2 ms 256 KB Output isn't correct
32 Incorrect 2 ms 376 KB Output isn't correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 2 ms 256 KB Output is correct
35 Correct 2 ms 380 KB Output is correct
36 Correct 2 ms 504 KB Output is correct
37 Correct 2 ms 256 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Incorrect 11 ms 760 KB Output isn't correct
40 Incorrect 590 ms 16136 KB Output isn't correct
41 Incorrect 1453 ms 55048 KB Output isn't correct
42 Incorrect 1450 ms 53216 KB Output isn't correct
43 Incorrect 2 ms 376 KB Output isn't correct
44 Incorrect 1301 ms 50796 KB Output isn't correct
45 Incorrect 1451 ms 53608 KB Output isn't correct
46 Incorrect 320 ms 9068 KB Output isn't correct
47 Incorrect 1529 ms 54984 KB Output isn't correct
48 Incorrect 1437 ms 53992 KB Output isn't correct
49 Incorrect 169 ms 7784 KB Output isn't correct
50 Incorrect 1382 ms 34256 KB Output isn't correct
51 Incorrect 108 ms 8300 KB Output isn't correct
52 Incorrect 1451 ms 55028 KB Output isn't correct
53 Incorrect 1433 ms 55052 KB Output isn't correct
54 Incorrect 1435 ms 48360 KB Output isn't correct
55 Incorrect 24 ms 1784 KB Output isn't correct
56 Incorrect 20 ms 1528 KB Output isn't correct
57 Incorrect 16 ms 888 KB Output isn't correct
58 Incorrect 4 ms 508 KB Output isn't correct
59 Incorrect 19 ms 1144 KB Output isn't correct
60 Correct 52 ms 1784 KB Output is correct
61 Incorrect 24 ms 1784 KB Output isn't correct
62 Incorrect 2 ms 376 KB Output isn't correct
63 Incorrect 20 ms 1400 KB Output isn't correct
64 Correct 4 ms 504 KB Output is correct
65 Incorrect 17 ms 1268 KB Output isn't correct
66 Incorrect 21 ms 1144 KB Output isn't correct
67 Incorrect 22 ms 1272 KB Output isn't correct
68 Incorrect 7 ms 632 KB Output isn't correct
69 Incorrect 6 ms 504 KB Output isn't correct
70 Incorrect 7 ms 504 KB Output isn't correct
71 Incorrect 5 ms 632 KB Output isn't correct
72 Correct 25 ms 1784 KB Output is correct
73 Incorrect 13 ms 888 KB Output isn't correct
74 Correct 24 ms 1828 KB Output is correct
75 Incorrect 1943 ms 59392 KB Output isn't correct
76 Incorrect 1124 ms 38780 KB Output isn't correct
77 Incorrect 619 ms 7016 KB Output isn't correct
78 Incorrect 101 ms 5992 KB Output isn't correct
79 Correct 1274 ms 17896 KB Output is correct
80 Incorrect 1924 ms 59240 KB Output isn't correct
81 Incorrect 32 ms 1016 KB Output isn't correct
82 Incorrect 1751 ms 53084 KB Output isn't correct
83 Correct 180 ms 7656 KB Output is correct
84 Incorrect 1568 ms 46372 KB Output isn't correct
85 Incorrect 1656 ms 34152 KB Output isn't correct
86 Incorrect 1657 ms 34280 KB Output isn't correct
87 Incorrect 199 ms 9080 KB Output isn't correct
88 Incorrect 186 ms 9064 KB Output isn't correct
89 Incorrect 1943 ms 59280 KB Output isn't correct
90 Incorrect 1937 ms 59240 KB Output isn't correct
91 Incorrect 1918 ms 59252 KB Output isn't correct
92 Correct 1960 ms 57196 KB Output is correct
93 Incorrect 1669 ms 34152 KB Output isn't correct
94 Incorrect 1946 ms 59204 KB Output isn't correct
95 Incorrect 2106 ms 59280 KB Output isn't correct