답안 #97201

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97201 2019-02-14T10:47:53 Z diamond_duke 무지개나라 (APIO17_rainbow) C++11
100 / 100
1572 ms 167800 KB
#include "rainbow.h"
#include <algorithm>
#include <string>
#include <vector>
using ll = long long;
struct segT
{
	int rt[200005], lson[10000005], rson[10000005], sum[10000005], t_cnt = 0, lim;
	void modify(int &u, int v, int l, int r, int pos)
	{
		u = ++t_cnt;
		lson[u] = lson[v];
		rson[u] = rson[v];
		sum[u] = sum[v] + 1;
		if (l == r)
			return;
		int m = l + r >> 1;
		if (pos <= m)
			modify(lson[u], lson[v], l, m, pos);
		else
			modify(rson[u], rson[v], m + 1, r, pos);
	}
	int query(int u, int l, int r, int L, int R)
	{
		if (!u)
			return 0;
		if (L <= l && r <= R)
			return sum[u];
		int m = l + r >> 1, res = 0;
		if (L <= m)
			res += query(lson[u], l, m, L, R);
		if (m < R)
			res += query(rson[u], m + 1, r, L, R);
		return res;
	}
	int query(int l, int r, int L, int R)
	{
		if (l > r || L > R)
			return 0;
		return query(rt[r + 1], 0, lim, L, R) - query(rt[l], 0, lim, L, R);
	}
	inline void build(std::vector<int> *vec, int n, int m)
	{
		lim = m;
		for (int i = 0; i <= n; i++)
		{
			std::sort(vec[i].begin(), vec[i].end());
			vec[i].erase(std::unique(vec[i].begin(), vec[i].end()), vec[i].end());
			rt[i + 1] = rt[i];
			for (int x : vec[i])
				modify(rt[i + 1], rt[i + 1], 0, m, x);
		}
	}
} seg[4];
int row, col, mn_x, mn_y, mx_x, mx_y;
std::vector<int> vec[4][200005];
inline void add(int x, int y)
{
	vec[0][++x].push_back(++y);
	for (int i = 0; i < 2; i++)
	{
		vec[1][x - i].push_back(y);
		vec[2][x].push_back(y - i);
		for (int j = 0; j < 2; j++)
			vec[3][x - i].push_back(y - j);
	}
}
void init(int R, int C, int x, int y, int len, char *str)
{
	row = R;
	col = C;
	mn_x = mx_x = --x;
	mn_y = mx_y = --y;
	add(x, y);
	for (int i = 0; i < len; i++)
	{
		static constexpr int dx[] = { -1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
		int d = std::string("NSWE").find(str[i]);
		x += dx[d];
		y += dy[d];
		mn_x = std::min(mn_x, x);
		mn_y = std::min(mn_y, y);
		mx_x = std::max(mx_x, x);
		mx_y = std::max(mx_y, y);
		add(x, y);
	}
	for (int i = 0; i < 4; i++)
		seg[i].build(vec[i], row, col);
}
int colour(int xl, int yl, int xr, int yr)
{
	xl--;
	xr--;
	yl--;
	yr--;
	ll ans = (ll)(xr - xl + 1) * (yr - yl + 1) - seg[0].query(xl + 1, xr + 1, yl + 1, yr + 1);
	ans -= (ll)(xr - xl) * (yr - yl + 1) - seg[1].query(xl + 1, xr, yl + 1, yr + 1);
	ans -= (ll)(xr - xl + 1) * (yr - yl) - seg[2].query(xl + 1, xr + 1, yl + 1, yr);
	ans += (ll)(xr - xl) * (yr - yl) - seg[3].query(xl + 1, xr, yl + 1, yr);
	return ans + (xl < mn_x && xr > mx_x && yl < mn_y && yr > mx_y);
}

Compilation message

rainbow.cpp: In member function 'void segT::modify(int&, int, int, int, int)':
rainbow.cpp:17:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l + r >> 1;
           ~~^~~
rainbow.cpp: In member function 'int segT::query(int, int, int, int, int)':
rainbow.cpp:29:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l + r >> 1, res = 0;
           ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 19456 KB Output is correct
2 Correct 23 ms 19712 KB Output is correct
3 Correct 21 ms 19456 KB Output is correct
4 Correct 23 ms 19456 KB Output is correct
5 Correct 25 ms 19832 KB Output is correct
6 Correct 22 ms 19328 KB Output is correct
7 Correct 20 ms 19172 KB Output is correct
8 Correct 18 ms 19200 KB Output is correct
9 Correct 19 ms 19200 KB Output is correct
10 Correct 23 ms 19200 KB Output is correct
11 Correct 21 ms 19584 KB Output is correct
12 Correct 22 ms 19584 KB Output is correct
13 Correct 22 ms 19968 KB Output is correct
14 Correct 24 ms 20224 KB Output is correct
15 Correct 21 ms 19200 KB Output is correct
16 Correct 18 ms 19200 KB Output is correct
17 Correct 21 ms 19172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 19200 KB Output is correct
2 Correct 21 ms 19172 KB Output is correct
3 Correct 464 ms 104780 KB Output is correct
4 Correct 717 ms 158812 KB Output is correct
5 Correct 710 ms 158040 KB Output is correct
6 Correct 551 ms 128264 KB Output is correct
7 Correct 783 ms 126256 KB Output is correct
8 Correct 172 ms 27616 KB Output is correct
9 Correct 900 ms 158812 KB Output is correct
10 Correct 895 ms 157928 KB Output is correct
11 Correct 609 ms 127548 KB Output is correct
12 Correct 316 ms 149460 KB Output is correct
13 Correct 319 ms 158684 KB Output is correct
14 Correct 343 ms 157624 KB Output is correct
15 Correct 286 ms 128088 KB Output is correct
16 Correct 536 ms 119380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 19200 KB Output is correct
2 Correct 236 ms 158116 KB Output is correct
3 Correct 260 ms 164184 KB Output is correct
4 Correct 229 ms 161244 KB Output is correct
5 Correct 224 ms 127800 KB Output is correct
6 Correct 107 ms 52448 KB Output is correct
7 Correct 149 ms 76540 KB Output is correct
8 Correct 272 ms 127044 KB Output is correct
9 Correct 208 ms 112872 KB Output is correct
10 Correct 69 ms 39928 KB Output is correct
11 Correct 143 ms 80468 KB Output is correct
12 Correct 274 ms 158244 KB Output is correct
13 Correct 267 ms 164344 KB Output is correct
14 Correct 269 ms 161272 KB Output is correct
15 Correct 219 ms 127680 KB Output is correct
16 Correct 89 ms 47096 KB Output is correct
17 Correct 132 ms 76892 KB Output is correct
18 Correct 230 ms 158804 KB Output is correct
19 Correct 251 ms 163392 KB Output is correct
20 Correct 226 ms 163136 KB Output is correct
21 Correct 236 ms 127072 KB Output is correct
22 Correct 242 ms 113052 KB Output is correct
23 Correct 70 ms 39928 KB Output is correct
24 Correct 161 ms 80472 KB Output is correct
25 Correct 276 ms 158096 KB Output is correct
26 Correct 324 ms 164344 KB Output is correct
27 Correct 290 ms 161372 KB Output is correct
28 Correct 207 ms 127552 KB Output is correct
29 Correct 99 ms 47092 KB Output is correct
30 Correct 125 ms 76920 KB Output is correct
31 Correct 230 ms 158856 KB Output is correct
32 Correct 233 ms 163452 KB Output is correct
33 Correct 274 ms 163264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 19456 KB Output is correct
2 Correct 23 ms 19712 KB Output is correct
3 Correct 21 ms 19456 KB Output is correct
4 Correct 23 ms 19456 KB Output is correct
5 Correct 25 ms 19832 KB Output is correct
6 Correct 22 ms 19328 KB Output is correct
7 Correct 20 ms 19172 KB Output is correct
8 Correct 18 ms 19200 KB Output is correct
9 Correct 19 ms 19200 KB Output is correct
10 Correct 23 ms 19200 KB Output is correct
11 Correct 21 ms 19584 KB Output is correct
12 Correct 22 ms 19584 KB Output is correct
13 Correct 22 ms 19968 KB Output is correct
14 Correct 24 ms 20224 KB Output is correct
15 Correct 21 ms 19200 KB Output is correct
16 Correct 18 ms 19200 KB Output is correct
17 Correct 21 ms 19172 KB Output is correct
18 Correct 1022 ms 66888 KB Output is correct
19 Correct 316 ms 24732 KB Output is correct
20 Correct 220 ms 22892 KB Output is correct
21 Correct 233 ms 23304 KB Output is correct
22 Correct 302 ms 23544 KB Output is correct
23 Correct 306 ms 24624 KB Output is correct
24 Correct 184 ms 23160 KB Output is correct
25 Correct 253 ms 23544 KB Output is correct
26 Correct 282 ms 23868 KB Output is correct
27 Correct 320 ms 59512 KB Output is correct
28 Correct 248 ms 43128 KB Output is correct
29 Correct 326 ms 57080 KB Output is correct
30 Correct 566 ms 105036 KB Output is correct
31 Correct 26 ms 19320 KB Output is correct
32 Correct 822 ms 59128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 19456 KB Output is correct
2 Correct 23 ms 19712 KB Output is correct
3 Correct 21 ms 19456 KB Output is correct
4 Correct 23 ms 19456 KB Output is correct
5 Correct 25 ms 19832 KB Output is correct
6 Correct 22 ms 19328 KB Output is correct
7 Correct 20 ms 19172 KB Output is correct
8 Correct 18 ms 19200 KB Output is correct
9 Correct 19 ms 19200 KB Output is correct
10 Correct 23 ms 19200 KB Output is correct
11 Correct 21 ms 19584 KB Output is correct
12 Correct 22 ms 19584 KB Output is correct
13 Correct 22 ms 19968 KB Output is correct
14 Correct 24 ms 20224 KB Output is correct
15 Correct 21 ms 19200 KB Output is correct
16 Correct 18 ms 19200 KB Output is correct
17 Correct 21 ms 19172 KB Output is correct
18 Correct 1022 ms 66888 KB Output is correct
19 Correct 316 ms 24732 KB Output is correct
20 Correct 220 ms 22892 KB Output is correct
21 Correct 233 ms 23304 KB Output is correct
22 Correct 302 ms 23544 KB Output is correct
23 Correct 306 ms 24624 KB Output is correct
24 Correct 184 ms 23160 KB Output is correct
25 Correct 253 ms 23544 KB Output is correct
26 Correct 282 ms 23868 KB Output is correct
27 Correct 320 ms 59512 KB Output is correct
28 Correct 248 ms 43128 KB Output is correct
29 Correct 326 ms 57080 KB Output is correct
30 Correct 566 ms 105036 KB Output is correct
31 Correct 26 ms 19320 KB Output is correct
32 Correct 822 ms 59128 KB Output is correct
33 Correct 236 ms 158116 KB Output is correct
34 Correct 260 ms 164184 KB Output is correct
35 Correct 229 ms 161244 KB Output is correct
36 Correct 224 ms 127800 KB Output is correct
37 Correct 107 ms 52448 KB Output is correct
38 Correct 149 ms 76540 KB Output is correct
39 Correct 272 ms 127044 KB Output is correct
40 Correct 208 ms 112872 KB Output is correct
41 Correct 69 ms 39928 KB Output is correct
42 Correct 143 ms 80468 KB Output is correct
43 Correct 274 ms 158244 KB Output is correct
44 Correct 267 ms 164344 KB Output is correct
45 Correct 269 ms 161272 KB Output is correct
46 Correct 219 ms 127680 KB Output is correct
47 Correct 89 ms 47096 KB Output is correct
48 Correct 132 ms 76892 KB Output is correct
49 Correct 230 ms 158804 KB Output is correct
50 Correct 251 ms 163392 KB Output is correct
51 Correct 226 ms 163136 KB Output is correct
52 Correct 236 ms 127072 KB Output is correct
53 Correct 242 ms 113052 KB Output is correct
54 Correct 70 ms 39928 KB Output is correct
55 Correct 161 ms 80472 KB Output is correct
56 Correct 276 ms 158096 KB Output is correct
57 Correct 324 ms 164344 KB Output is correct
58 Correct 290 ms 161372 KB Output is correct
59 Correct 207 ms 127552 KB Output is correct
60 Correct 99 ms 47092 KB Output is correct
61 Correct 125 ms 76920 KB Output is correct
62 Correct 230 ms 158856 KB Output is correct
63 Correct 233 ms 163452 KB Output is correct
64 Correct 274 ms 163264 KB Output is correct
65 Correct 1572 ms 130532 KB Output is correct
66 Correct 1541 ms 116560 KB Output is correct
67 Correct 488 ms 43384 KB Output is correct
68 Correct 474 ms 83920 KB Output is correct
69 Correct 721 ms 161656 KB Output is correct
70 Correct 456 ms 167800 KB Output is correct
71 Correct 506 ms 164676 KB Output is correct
72 Correct 388 ms 131236 KB Output is correct
73 Correct 204 ms 50612 KB Output is correct
74 Correct 271 ms 80504 KB Output is correct
75 Correct 440 ms 162424 KB Output is correct
76 Correct 657 ms 166968 KB Output is correct
77 Correct 556 ms 166848 KB Output is correct
78 Correct 464 ms 104780 KB Output is correct
79 Correct 717 ms 158812 KB Output is correct
80 Correct 710 ms 158040 KB Output is correct
81 Correct 551 ms 128264 KB Output is correct
82 Correct 783 ms 126256 KB Output is correct
83 Correct 172 ms 27616 KB Output is correct
84 Correct 900 ms 158812 KB Output is correct
85 Correct 895 ms 157928 KB Output is correct
86 Correct 609 ms 127548 KB Output is correct
87 Correct 316 ms 149460 KB Output is correct
88 Correct 319 ms 158684 KB Output is correct
89 Correct 343 ms 157624 KB Output is correct
90 Correct 286 ms 128088 KB Output is correct
91 Correct 536 ms 119380 KB Output is correct