This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "rainbow.h"
#include <algorithm>
#include <vector>
using ll = long long;
int row, col, mn_x, mx_x, mn_y, mx_y;
struct segT
{
int rt[200005], lson[10000005], rson[10000005], sum[10000005], t_cnt = 0;
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, col, L, R) - query(rt[l], 0, col, L, R);
}
} seg[4];
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++)
{
if (str[i] == 'N')
x--;
else if (str[i] == 'S')
x++;
else if (str[i] == 'W')
y--;
else
y++;
mn_x = std::min(mn_x, x);
mx_x = std::max(mx_x, x);
mn_y = std::min(mn_y, y);
mx_y = std::max(mx_y, y);
add(x, y);
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j <= row; j++)
{
seg[i].rt[j + 1] = seg[i].rt[j];
std::sort(vec[i][j].begin(), vec[i][j].end());
vec[i][j].erase(std::unique(vec[i][j].begin(), vec[i][j].end()), vec[i][j].end());
for (int k : vec[i][j])
seg[i].modify(seg[i].rt[j + 1], seg[i].rt[j + 1], 0, col, k);
}
}
}
int colour(int xl, int yl, int xr, int yr)
{
ll ans = (ll)(--xr - --xl + 1) * (--yr - --yl + 1);
ans -= seg[0].query(xl + 1, xr + 1, yl + 1, yr + 1); // 1 * 1
ans -= (ll)(xr - xl) * (yr - yl + 1) - seg[1].query(xl + 1, xr, yl + 1, yr + 1); // 2 * 1
ans -= (ll)(xr - xl + 1) * (yr - yl) - seg[2].query(xl + 1, xr + 1, yl + 1, yr); // 1 * 2
ans += (ll)(xr - xl) * (yr - yl) - seg[3].query(xl + 1, xr, yl + 1, yr); // 2 * 2
return ans + (xl < mn_x && xr > mx_x && yl < mn_y && yr > mx_y); // circle
}
Compilation message (stderr)
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;
~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |