# weekly-contest-290

## A

### Statement

``````输入：nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]

nums[0] = [3,1,2,4,5]，nums[1] = [1,2,3,4]，nums[2] = [3,4,5,6]，在 nums 中每个数组中都出现的数字是 3 和 4 ，所以返回 [3,4] 。``````

``````输入：nums = [[1,2,3],[4,5,6]]

``````

• `1 <= nums.length <= 1000`
• `1 <= sum(nums[i].length) <= 1000`
• `1 <= nums[i][j] <= 1000`
• `nums[i]` 中的所有值 互不相同

Given a 2D integer array `nums` where `nums[i]` is a non-empty array of distinct positive integers, return the list of integers that are present in each array of `nums` sorted in ascending order.

Example 1:

``````Input: nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]
Output: [3,4]
Explanation:
The only integers present in each of nums[0] = [3,1,2,4,5], nums[1] = [1,2,3,4], and nums[2] = [3,4,5,6] are 3 and 4, so we return [3,4].``````

Example 2:

``````Input: nums = [[1,2,3],[4,5,6]]
Output: []
Explanation:
There does not exist any integer present both in nums[0] and nums[1], so we return an empty list [].
``````

Constraints:

• `1 <= nums.length <= 1000`
• `1 <= sum(nums[i].length) <= 1000`
• `1 <= nums[i][j] <= 1000`
• All the values of `nums[i]` are unique.

### Solution

``````#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <vector>

#define endl "\n"
#define fi first
#define se second
#define all(x) begin(x), end(x)
#define rall rbegin(a), rend(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define complete_unique(a) a.erase(unique(begin(a), end(a)), end(a))
#define mst(x, a) memset(x, a, sizeof(x))
#define MP make_pair

using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
using VLL = std::vector<ll>;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T, typename S>
inline bool chmax(T &a, const S &b) {
return a < b ? a = b, 1 : 0;
}

template <typename T, typename S>
inline bool chmin(T &a, const S &b) {
return a > b ? a = b, 1 : 0;
}

#ifdef LOCAL
#include <debug.hpp>
#else
#define dbg(...)
#endif

class Solution {
public:
vector<int> intersection(vector<vector<int>> &nums) {
int n = nums.size();
map<int, int> mp;
for (const auto &v : nums) {
for (const auto &a : v) {
mp[a]++;
}
}

auto res = vector<int>();
for (const auto &[k, v] : mp) {
if (v == n) {
res.push_back(k);
}
}

return res;
}
};

#ifdef LOCAL

int main() {
return 0;
}

#endif
``````

## B

### Statement

• 格点 是指整数坐标对应的点。
• 圆周上的点 也被视为出现在圆内的点。

``````输入：circles = [[2,2,1]]

``````输入：circles = [[2,2,2],[3,4,1]]

``````

• `1 <= circles.length <= 200`
• `circles[i].length == 3`
• `1 <= xi, yi <= 100`
• `1 <= ri <= min(xi, yi)`

Given a 2D integer array `circles` where `circles[i] = [xi, yi, ri]` represents the center `(xi, yi)` and radius `ri` of the `ith` circle drawn on a grid, return the number of lattice points that are present inside at least one circle.

Note:

• A lattice point is a point with integer coordinates.
• Points that lie on the circumference of a circle are also considered to be inside it.

Example 1:

``````Input: circles = [[2,2,1]]
Output: 5
Explanation:
The figure above shows the given circle.
The lattice points present inside the circle are (1, 2), (2, 1), (2, 2), (2, 3), and (3, 2) and are shown in green.
Other points such as (1, 1) and (1, 3), which are shown in red, are not considered inside the circle.
Hence, the number of lattice points present inside at least one circle is 5.``````

Example 2:

``````Input: circles = [[2,2,2],[3,4,1]]
Output: 16
Explanation:
The figure above shows the given circles.
There are exactly 16 lattice points which are present inside at least one circle.
Some of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4).
``````

Constraints:

• `1 <= circles.length <= 200`
• `circles[i].length == 3`
• `1 <= xi, yi <= 100`
• `1 <= ri <= min(xi, yi)`

### Solution

``````#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define endl "\n"
#define fi first
#define se second
#define all(x) begin(x), end(x)
#define rall rbegin(a), rend(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define complete_unique(a) a.erase(unique(begin(a), end(a)), end(a))
#define mst(x, a) memset(x, a, sizeof(x))
#define MP make_pair

using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
using VLL = std::vector<ll>;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T, typename S>
inline bool chmax(T &a, const S &b) {
return a < b ? a = b, 1 : 0;
}

template <typename T, typename S>
inline bool chmin(T &a, const S &b) {
return a > b ? a = b, 1 : 0;
}

#ifdef LOCAL
#include <debug.hpp>
#else
#define dbg(...)
#endif

class Solution {
public:
int countLatticePoints(vector<vector<int>> &circles) {
const auto ok = [&](int x, int y) {
for (const auto &c : circles) {
int cx = c[0];
int cy = c[1];
int r = c[2];
int xx = (x - cx);
int yy = (y - cy);

if (xx * xx + yy * yy <= r * r) {
return true;
}
}

return false;
};

int res = 0;

for (int i = -200; i <= 200; i++) {
for (int j = -200; j <= 200; j++) {
if (ok(i, j)) {
++res;
}
}
}

return res;
}
};

#ifdef LOCAL

int main() {
return 0;
}

#endif
``````

## C

### Statement

``````输入：rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]

``````

``````输入：rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]]

``````

• `1 <= rectangles.length, points.length <= 5 * 104`
• `rectangles[i].length == points[j].length == 2`
• `1 <= li, xj <= 109`
• `1 <= hi, yj <= 100`
• 所有 `rectangles` 互不相同 。
• 所有 `points` 互不相同 。

You are given a 2D integer array `rectangles` where `rectangles[i] = [li, hi]` indicates that `ith` rectangle has a length of `li` and a height of `hi`. You are also given a 2D integer array `points` where `points[j] = [xj, yj]` is a point with coordinates `(xj, yj)`.

The `ith` rectangle has its bottom-left corner point at the coordinates `(0, 0)` and its top-right corner point at `(li, hi)`.

Return an integer array `count` of length `points.length` where `count[j]` is the number of rectangles that contain the `jth` point.

The `ith` rectangle contains the `jth` point if `0 <= xj <= li` and `0 <= yj <= hi`. Note that points that lie on the edges of a rectangle are also considered to be contained by that rectangle.

Example 1:

``````Input: rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]
Output: [2,1]
Explanation:
The first rectangle contains no points.
The second rectangle contains only the point (2, 1).
The third rectangle contains the points (2, 1) and (1, 4).
The number of rectangles that contain the point (2, 1) is 2.
The number of rectangles that contain the point (1, 4) is 1.
Therefore, we return [2, 1].
``````

Example 2:

``````Input: rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]]
Output: [1,3]
Explanation:
The first rectangle contains only the point (1, 1).
The second rectangle contains only the point (1, 1).
The third rectangle contains the points (1, 3) and (1, 1).
The number of rectangles that contain the point (1, 3) is 1.
The number of rectangles that contain the point (1, 1) is 3.
Therefore, we return [1, 3].
``````

Constraints:

• `1 <= rectangles.length, points.length <= 5 * 104`
• `rectangles[i].length == points[j].length == 2`
• `1 <= li, xj <= 109`
• `1 <= hi, yj <= 100`
• All the `rectangles` are unique.
• All the `points` are unique.

### Solution

``````#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <vector>

#define endl "\n"
#define fi first
#define se second
#define all(x) begin(x), end(x)
#define rall rbegin(a), rend(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define complete_unique(a) a.erase(unique(begin(a), end(a)), end(a))
#define mst(x, a) memset(x, a, sizeof(x))
#define MP make_pair

using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
using VLL = std::vector<ll>;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T, typename S>
inline bool chmax(T& a, const S& b) {
return a < b ? a = b, 1 : 0;
}

template <typename T, typename S>
inline bool chmin(T& a, const S& b) {
return a > b ? a = b, 1 : 0;
}

#ifdef LOCAL
#include <debug.hpp>
#else
#define dbg(...)
#endif

struct R {
int l, h, ix;
bool operator<(const R& other) const {
if (l == other.l) {
return h < other.h;
}

return l < other.l;
}
};

const int N = 1e5 + 10;

struct BIT {
int a[N];
int n;
void init(int n) {
this->n = n;
memset(a, 0, sizeof(a[0]) * (n + 5));
}
int lowbit(int x) {
return x & -x;
}
void add(int x, ll v) {
for (int i = x; i < n; i += lowbit(i)) a[i] += v;
}
ll query(int x) {
ll ret = 0;
for (int i = x; i > 0; i -= lowbit(i)) ret += a[i];
return ret;
}

ll query(int l, int r) {
if (l > r)
return 0;
return query(r) - query(l - 1);
}
void add(int l, int r, ll v) {
if (l > r)
return;
}
} bit;

struct Hash {
vector<db> a;
db& operator[](int x) {
return a[x - 1];
}
int size() {
return a.size();
}
void init() {
a.clear();
}
a.push_back(x);
}
void gao() {
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
}
int get(db x) {
return lower_bound(a.begin(), a.end(), x) - a.begin() + 1;
}
} hl, hh;

class Solution {
public:
vector<int> countRectangles(vector<vector<int>>& rectangles, vector<vector<int>>& points) {
int np = points.size();

hl.init();
hh.init();

for (const auto& r : rectangles) {
}

for (const auto& p : points) {
}

hl.gao();
hh.gao();

auto vr = vector<vector<R>>(hl.size() + 1, vector<R>());
for (const auto& r : rectangles) {
int l = hl.get(r[0]);
int h = hh.get(r[1]);

vr[l].push_back({
.l = l,
.h = h,
.ix = 0,
});
}

int ix = 0;
auto vp = vector<vector<R>>(hl.size() + 1, vector<R>());
for (const auto& p : points) {
int l = hl.get(p[0]);
int h = hh.get(p[1]);

vp[l].push_back({
.l = l,
.h = h,
.ix = ix,
});

ix++;
}

auto res = vector<int>(np, 0);

bit.init(hh.size() + 5);

for (int i = hl.size(); i >= 1; i--) {
for (const auto& r : vr[i]) {
}

for (const auto& p : vp[i]) {
res[p.ix] = bit.query(p.h, hh.size());
}
}

return res;
}
};

#ifdef LOCAL

int main() {
return 0;
}

#endif
``````

## D

### Statement

``````输入：flowers = [[1,6],[3,7],[9,12],[4,13]], persons = [2,3,7,11]

``````

``````输入：flowers = [[1,10],[3,3]], persons = [3,3,2]

``````

• `1 <= flowers.length <= 5 * 104`
• `flowers[i].length == 2`
• `1 <= starti <= endi <= 109`
• `1 <= persons.length <= 5 * 104`
• `1 <= persons[i] <= 109`

You are given a 0-indexed 2D integer array `flowers`, where `flowers[i] = [starti, endi]` means the `ith` flower will be in full bloom from `starti` to `endi` (inclusive). You are also given a 0-indexed integer array `persons` of size `n`, where `persons[i]` is the time that the `ith` person will arrive to see the flowers.

Return an integer array `answer` of size `n`, where `answer[i]` is the number of flowers that are in full bloom when the `ith` person arrives.

Example 1:

``````Input: flowers = [[1,6],[3,7],[9,12],[4,13]], persons = [2,3,7,11]
Output: [1,2,2,2]
Explanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.
For each person, we return the number of flowers in full bloom during their arrival.
``````

Example 2:

``````Input: flowers = [[1,10],[3,3]], persons = [3,3,2]
Output: [2,2,1]
Explanation: The figure above shows the times when the flowers are in full bloom and when the people arrive.
For each person, we return the number of flowers in full bloom during their arrival.
``````

Constraints:

• `1 <= flowers.length <= 5 * 104`
• `flowers[i].length == 2`
• `1 <= starti <= endi <= 109`
• `1 <= persons.length <= 5 * 104`
• `1 <= persons[i] <= 109`

### Solution

``````#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <vector>

#define endl "\n"
#define fi first
#define se second
#define all(x) begin(x), end(x)
#define rall rbegin(a), rend(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define complete_unique(a) a.erase(unique(begin(a), end(a)), end(a))
#define mst(x, a) memset(x, a, sizeof(x))
#define MP make_pair

using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
using VLL = std::vector<ll>;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T, typename S>
inline bool chmax(T& a, const S& b) {
return a < b ? a = b, 1 : 0;
}

template <typename T, typename S>
inline bool chmin(T& a, const S& b) {
return a > b ? a = b, 1 : 0;
}

#ifdef LOCAL
#include <debug.hpp>
#else
#define dbg(...)
#endif

const int N = 2e5 + 10;

struct BIT {
int a[N];
int n;
void init(int n) {
this->n = n;
memset(a, 0, sizeof(a[0]) * (n + 5));
}
int lowbit(int x) {
return x & -x;
}
void add(int x, ll v) {
for (int i = x; i < n; i += lowbit(i)) a[i] += v;
}
ll query(int x) {
ll ret = 0;
for (int i = x; i > 0; i -= lowbit(i)) ret += a[i];
return ret;
}

ll query(int l, int r) {
if (l > r)
return 0;
return query(r) - query(l - 1);
}
void add(int l, int r, ll v) {
if (l > r)
return;
}
} bit;

struct Hash {
vector<db> a;
db& operator[](int x) {
return a[x - 1];
}
int size() {
return a.size();
}
void init() {
a.clear();
}
a.push_back(x);
}
void gao() {
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
}
int get(db x) {
return lower_bound(a.begin(), a.end(), x) - a.begin() + 1;
}
} hs;

class Solution {
public:
vector<int> fullBloomFlowers(vector<vector<int>>& flowers, vector<int>& persons) {
hs.init();

for (const auto& f : flowers) {
}

for (const auto& p : persons) {
}

hs.gao();

bit.init(hs.size() + 5);

for (const auto& f : flowers) {
int l = hs.get(f[0]);
int r = hs.get(f[1]);
}

auto res = vector<int>();
for (const auto& p : persons) {
res.push_back(bit.query(hs.get(p)));
}

return res;
}
};

#ifdef LOCAL

int main() {
return 0;
}

#endif
``````