id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 0 | {
"code": "class Fenwick {\n vector<int> cnts, vals; \npublic: \n Fenwick(int n) {\n cnts.resize(n+1); \n vals.resize(n+1); \n }\n \n void add(int k, int v) {\n for (int i = k+1; i < cnts.size(); i += i & -i) {\n cnts[i] += v; \n vals[i] += v*k; \n }\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 0 | {
"code": "class BIT {\n vector<int> data;\n\n int next(int i) {\n return i + (i & -i);\n }\n\n int prev(int i) {\n return i - (i & -i);\n }\npublic:\n BIT () {\n\n }\n\n BIT(int n) {\n // offset = 1\n data.resize(n + 1, 0);\n }\n\n void add(int i, int v) {\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 0 | {
"code": "class BIT {\n vector<int> data;\n\n int next(int i) {\n return i + (i & -i);\n }\n\n int prev(int i) {\n return i - (i & -i);\n }\npublic:\n BIT () {\n\n }\n\n BIT(int n) {\n // offset = 1\n data.resize(n + 1, 0);\n }\n\n void add(int i, int v) {\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 0 | {
"code": "/*\nqueries[i]: (1, size) query groups with size\nqueries[i]: (2, index, color) set colors[index] to c\n\nwhen an interval is quried, its prev and succesor may affect\n\ng1 g2 g3\n(0...0)(0...0)(0...0)\n*/\nconst int RED = 0;\nconst int BLUE = 1;\n\nstruct Interval{\n int start, end, length;\n\n Inte... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 0 | {
"code": "vector<long long> tree1(5e4+1, 0);\nvector<long long> tree2(5e4+1, 0);\nint N;\nclass Solution {\npublic:\n int sum(int k, vector<long long> &tree)\n {\n long long s=0;\n while(k>=1) \n {\n s+=tree[k];\n k-=k&-k;\n }\n return s;\n }\n\n v... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 1 | {
"code": "const int N=5e4;\narray<int,2> seg[4*N+15];\n\n\narray<int,2> getval(int low,int high,int l,int r,int pos)\n{\n if (r<low || high<l) return {0,0};\n if (l<=low && high<=r){\n return seg[pos];\n }\n int mid=(low+high)/2;\n auto left=getval(low,mid,l,r,2*pos+1);\n auto right=getval(m... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 1 | {
"code": "class Solution {\npublic:\n\n vector<int> alt,ct;\n\n //set stores contiguous blocks of 1s in alt as \n //{starting index, size of block}\n set<pair<int,int>> st;\n \n //finds block of 1 which contains index\n //if index==0 return {-1,-1}\n pair<int,int> findGroup(int index){\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 1 | {
"code": "template<class T> struct BIT { //try to always use long long\n\tvector<T> bit;\n int n;\n\tBIT(int n): n(n) {\n\t\tbit.resize(n + 1);\n\t}\n\tvoid upd(int i, T val) {\n\t\tfor (++i; i <= n; i += i & -i)\n\t\t\tbit[i] += val;\n\t}\n\tT qry(int i) {T res = 0;\n\t\tfor (++i; i > 0; i -= i & -i)\n\t\t\tres ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 1 | {
"code": "class Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int>& colors, vector<vector<int>>& queries) {\n int n = colors.size();\n vector<int> sum(n+1,0);\n vector<int> count(n+1,0);\n vector<int> ans;\n set<int> s;\n for(int i = 1;i< n; i++){\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "#define ss second\n#define ff first\n#define mp make_pair\n\nclass SegmentTree {\n vector<int> tree1;\n vector<int> tree2;\n int n;\npublic:\n SegmentTree(int n) {\n tree1.clear();\n tree2.clear();\n tree1.resize(4*n-1, 0);\n tree2.resize(4*n-1, 0);\n this->n=... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "#define ss second\n#define ff first\n#define mp make_pair\n\nclass SegmentTree {\n vector<int> tree1;\n vector<int> tree2;\n int n;\npublic:\n SegmentTree(int n) {\n tree1.clear();\n tree2.clear();\n tree1.resize(4*n, 0);\n tree2.resize(4*n, 0);\n this->n=n;\n... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "typedef long long ll;\n#define sz(v) int(v.size())\ntemplate<class T>\nstruct FT {\n vector<T> bit;\n FT(int n) : bit(n) {}\n FT(){}\n void upd(int i, T x) {\n for (; i < sz(bit); i |= i+1) bit[i] += x;\n }\n T qry(int r) {\n T ans = T();\n for (++r; r > 0; r &= r-1) ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "/*********************** Chandrachur Mukherjee ***********************/\n\n#include<bits/stdc++.h>\n// #include<ext/pb_ds/assoc_container.hpp>\n// #include<ext/pb_ds/tree_policy.hpp>\n\nusing namespace std; \nusing namespace chrono;\n// using namespace __gnu_pbds;\n\n#define fastio() ios_base::sync_with_st... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class BIT {\npublic:\n vector<vector<int>> tree;\n int n;\n BIT(int n) {\n tree.resize(n+1, vector<int>(2));\n this->n = n+1;\n }\n\n void update(int size, int op) {\n int i = n - size;\n while (i < n) {\n tree[i][0] += op;\n tree[i][1] += op... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class SegTree {\n vector<pair<int, int>> st; // from left to right: sum of index*value, sum of values\n vector<int> arr;\n\n public:\n SegTree(vector<int> &a, int maxValue) {\n st.resize(4 * maxValue);\n arr.resize(maxValue + 1, 0);\n for (auto &x : a)\n arr[x]++... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class SegTree {\n vector<pair<int, int>> st; // from left to right: sum of index*value, sum of values\n vector<int> arr;\n\n public:\n SegTree(vector<int> &a, int maxValue) {\n st.resize(4 * maxValue);\n arr.resize(maxValue + 1, 0);\n for (auto &x : a)\n arr[x]++... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\npublic:\n struct BIT {\n vector<int> arr;\n BIT(){}\n BIT(int n) {\n arr.assign(n, 0);\n }\n int low_bit(int x) {\n return x & (-x);\n }\n void add(int pos, int x) {\n for(int i = pos; i < arr.size(); i +... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "#define lli long long\nclass Solution {\npublic:\n lli rsum(lli left, lli right, lli i, lli l, lli r, vector<lli> &seg)\n{\n lli mid = (l + r) / 2;\n if (l >= left && r <= right)\n {\n return seg[i];\n }\n if (l > right || r < left)\n {\n return 0;\n }\n // lli a=up... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class SegmentTree{\npublic:\n int n;\n vector<int> v1, v2;\n \n SegmentTree(int n){\n this->n = n;\n v1 = vector<int>(n+n+1, 0);\n v2 = vector<int>(n+n+1, 0);\n }\n \n void update(int idx, int delta){\n int diff1 = delta, diff2 = delta * idx;\n idx +=... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class SegmentTree{\npublic:\n int n;\n vector<int> v1, v2;\n \n SegmentTree(int n){\n this->n = n;\n v1 = vector<int>(n+n+1, 0);\n v2 = vector<int>(n+n+1, 0);\n }\n \n void update(int idx, int delta){\n //cout<<\"update: \"<<idx<<endl;\n int diff1 = d... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int>& C, vector<vector<int>>& Q) {\n int n = C.size();\n set<pair<int,int>> I;\n map<int,int> M; // size --> count\n int start = 0, prv = -1;\n for (int i = 0; i < n; i++) {\n if (C[i] ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\n // 1-indexed\n struct BIT {\n vector<int> bit;\n BIT(int sz) : bit(sz+1) {}\n \n int sum(int x) {\n assert(0 <= x);\n assert(x < bit.size());\n int ans = 0;\n for (; x; x -= x & -x)\n ans += bit[... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\n // minimize b*16 + 5e4/b (16=log(N), 5e4=N)\n const int BSZ = 60;\n \n // 1-indexed\n struct BIT {\n vector<int> bit;\n BIT(int sz) : bit(sz+1) {}\n \n int sum(int x) {\n assert(0 <= x);\n assert(x < bit.size());\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\npublic:\n \n int n;\n int last_start = 0, last_end = 0;\n \n void Upsert(int left, int right, set<pair<int, int>>& st, map<int, int>& sizes) {\n if (left <= n - 1 && right >= n - 1) {\n last_start = left, last_end = right;\n }\n if (left < n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "// The answer to a [1, x] query is sum((length-x+1) * amount for length, amt in count), \n// where count[l] denotes how many segments have length l.\n// (length-x+1) * amount = length * amount - x * amount + amount\n\n// Query index is inside a segment.\n// This splits the segment into 3 pieces\n// Query... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "#include <vector>\n#include <set>\n#include <map>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int>& a, vector<vector<int>>& queries) {\n int n = a.size();\n set<pair<int, int>> sl;\n map<int, int> cnt;\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "#include <vector>\n#include <set>\n#include <map>\n#include <algorithm>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int>& a, vector<vector<int>>& queries) {\n int n = a.size();\n set<pair<int, int>> sl;\n map<int, int> cnt;\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int>& colors, vector<vector<int>>& queries) {\n \n vector<int> a=colors;\n int n = a.size();\n set<pair<int, int>> sl;\n map<int, int> cnt;\n int i = 0;\n \n while (i < n) {\n... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\n class TBT {\n vector<bool> buffer;\n int len, total, max_level;\n \n public:\n template<class container>\n TBT(container& state) : len(state.size()), buffer(state.begin(), state.end()), total(0), max_level(0) {\n // level_size = (((len-1) >... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "#define f first\n#define s second\n#define all(x) (x).begin(), (x).end()\n#define rall(x) (x).rbegin(), (x).rend()\n#define sz(x) ((int) (x).size())\n#define pb push_back\n#define mp make_pair\n\nusing namespace std;\n\ntemplate <typename T> inline bool umin(T &a, const T &b) { if(a > b) { a = b; return 1;... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\npublic:\n map<int, int> sizeMap, startMap, endMap;\n \n void reset() {\n sizeMap.clear();\n startMap.clear();\n endMap.clear();\n }\n\n void set(int start, int end, int size) {\n sizeMap[size]++;\n startMap[start] = size;\n endMap[e... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int>& colors, vector<vector<int>>& queries) {\n const int N = colors.size();\n map<int, int> counts;\n map<int, int> parts;\n auto get_next = [&](int i) {\n auto next = parts.upper_bound(i);\n... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\n\ntemplate <typename CItr, typename Itr, typename Cmp, typename Alloc>\nstruct node_update {\n typedef struct {\n int sum, cnt;\n } metadata_type;\n pair<int, int> query(int len) {\n pair ans{0, 0};\n for (auto it = node_beg... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\n#ifdef LC_LOCAL\n#include \"parser.hpp\"\n#else\n#define dbg(...)\n#endif\n\n// ----- CHANGE FOR PROBLEM -----\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\n\ntemplate <typename CItr, typename Itr, typename Cmp, typename Alloc>\nst... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\n\ntemplate <typename CItr, typename Itr, typename Cmp, typename Alloc>\nstruct node_update {\n typedef struct {\n int sum, cnt;\n } metadata_type;\n pair<int, int> query(int len) {\n pair ans{0, 0};\n for (auto it = node_beg... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int>& colors, vector<vector<int>>& queries) {\n class FenwickTree\n {\n std::vector<std::array<int, 2> > tree;\n public:\n FenwickTree(int n) : tree(n + 1) {}\n void update(int ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class FenwickTree {\n vector<array<int, 2>> tree;\npublic:\n FenwickTree(int n) : tree(n + 1) {}\n\n void update(int size, int op) {\n for (int i = tree.size() - size; i < tree.size(); i += i & -i) {\n tree[i][0] += op;\n tree[i][1] += op * size;\n }\n }\n\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class FenwickTree {\n vector<array<int, 2>> tree;\npublic:\n FenwickTree(int n) : tree(n + 1) {}\n\n // op=1,添加一个 size\n // op=-1,移除一个 size\n void update(int size, int op) {\n for (int i = tree.size() - size; i < tree.size(); i += i & -i) {\n tree[i][0] += op;\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\n private:\n class FenwickTree {\n public:\n FenwickTree(const int n) : tree_(n) {\n }\n \n int read(const int i) const {\n int ret = 0;\n for (int index = i; index > 0; index -= index & -index) {\n ret += tree_[index - 1];\n }\n return ret;\n }... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\n public:\n\tvector<int> numberOfAlternatingGroups(vector<int>& colors, vector<vector<int>>& queries) {\n\t\tinitialize(colors);\n\n\t\tvector<int> ans;\n\t\tfor (auto& q : queries) {\n\t\t\tif (q[0] == 1) {\n\t\t\t\tans.push_back(query(q[1]));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tupdateColo... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "#define f first\n#define s second\n\ntypedef pair<int, int> ii;\n\nclass Solution {\npublic:\n const static int maxN = 1e5 + 10;\n\n int n;\n int st[maxN << 2], lazy[maxN << 2], L[maxN << 2], R[maxN << 2];\n\n void build(int id, int l, int r) {\n L[id] = l; R[id] = r;\n if (l == r... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "void print(set<pair<int, int> > s) {\n cout<<\"set:\";\n for (auto it = s.begin(); it!=s.end(); it++) {\n cout<<format(\"({}, {})\", it->first, it->second);\n }\n cout<<\"\\n\";\n}\n\nvoid printm(map<int, int> m) {\n cout<<\"map:\";\n for (auto it = m.begin(); it!=m.end(); it++) {\... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "#define lowbit(v) (v&-v)\ntypedef pair<int,int> pii;\nconst int N = 10 + 1e5;\n\n/* ---------------------------------------------------------------------------------------------------- */\n// 1D Fenwick Tree Difference\nint T;\nint t1[N];\nint t2[N];\n\nvoid update(int k, ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int> colors, const vector<vector<int>>& qs) {\n int n = colors.size();\n Segment_tree st(n + 1);\n std::set<std::pair<int, int>> ints{};\n bool is_alternating_circle = false;\n for (int i = 0, end... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\npublic:\n void add(int d, map<int, int> &cnt, int n) {\n d = d < 0 ? d + n : d;\n if (d > 2)\n ++cnt[d];\n }\n void erase(int d, map<int, int> &cnt, int n) {\n d = d < 0 ? d + n : d;\n if (d > 2)\n if (auto it = cnt.find(d); --it-... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\npublic:\n void print_cnt(map<int, int> &cnt) {\n // cout << \"Count: \";\n // for (auto [n, cnt] : cnt) \n // cout << n << \":\" << cnt << \" \";\n // cout << endl; \n }\n void add(int d, map<int, int> &cnt, int n) {\n d = d < 0 ? d +... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "class Solution {\npublic:\n void add(int d, map<int, int> &cnt, int n) {\n d = d < 0 ? d + n : d;\n if (d > 2)\n ++cnt[d];\n }\n void erase(int d, map<int, int> &cnt, int n) {\n d = d < 0 ? d + n : d;\n if (d > 2)\n if (auto it = cnt.find(d); --it-... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "struct SegmentTree {\n public:\n explicit SegmentTree(int n)\n : n(n), treeIntervalCounts(4 * n), treeIntervalLengths(4 * n) {}\n\n // Adds val to count[i].\n void add(int i, int val) {\n add(0, 0, n - 1, i, val);\n }\n\n // Returns sum(intervalCounts[i..n - 1]).\n int queryIntervalCounts(int... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 2 | {
"code": "struct SegmentTree {\n public:\n explicit SegmentTree(int n) : n(n), treeCountSum(4 * n), treeCount(4 * n) {}\n\n // Adds val to count[i].\n void add(int i, int val) {\n add(0, 0, n - 1, i, val);\n }\n\n // Returns sum(countSum[i..n - 1]).\n int queryCountSum(int i) {\n return queryCountSum(0, ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "struct SegmentTree {\n explicit SegmentTree(int n)\n : n(n), treeCounts(4 * n), treeLengths(4 * n) {}\n\n void add(int i, int val) {\n modify(0, 0, n - 1, i, val);\n }\n\n int queryCounts(int i) const {\n return query(treeCounts, 0, 0, n - 1, i, n - 1);\n }\n\n int queryLengths(int i) cons... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class SegmentTree {\npublic:\n SegmentTree(int n) : n(n) {\n sum1.assign(2 * n, 0);\n sum2.assign(2 * n, 0);\n }\n\n void update(int idx, int delta) {\n if(idx == 0)\n return;\n int diff1 = delta;\n int diff2 = delta * idx;\n\n for (int i = idx ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class SegmentTree {\npublic:\n SegmentTree(int n) : n(n) {\n sum1.assign(2 * n, 0);\n sum2.assign(2 * n, 0);\n }\n\n void update(int idx, int delta) {\n if(idx == 0)\n return;\n int diff1 = delta;\n int diff2 = delta * idx;\n\n for (int i = idx ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class SegmentTree {\npublic:\n SegmentTree(int n) : n(n) {\n sum1.assign(2 * n, 0);\n sum2.assign(2 * n, 0);\n }\n\n void update(int idx, int delta) {\n if(idx == 0)\n return;\n int diff1 = delta;\n int diff2 = delta * idx;\n\n for (int i = idx ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dp;\n int n;\n map<int, int> mp;\n map<int, int> cnt;\n\n int count(int x)\n {\n auto iter = cnt.rbegin();\n int ans = 0;\n if (iter->first == n && (dp[0] != dp[n- 1]))\n {\n ans += n;\n return ans;\... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dp;\n int n;\n map<int, int> mp;\n map<int, int> cnt;\n\n int count(int x)\n {\n auto iter = cnt.rbegin();\n int ans = 0;\n if (iter->first == n && (dp[0] != dp[n- 1]))\n {\n ans += n;\n return ans;\... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n //ct and seg are two segment trees\n vector<int> alt,ct,seg;\n set<pair<int,int>> st;\n int n;\n \n pair<int,int> findGroup(int index){\n auto it=st.upper_bound({index,100000});\n if(it==st.begin()) return {-1,-1};\n it--;\n if(it->f... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n //ct and seg are two segment trees\n vector<int> alt,ct,seg;\n set<pair<int,int>> st;\n int n;\n \n pair<int,int> findGroup(int index){\n auto it=st.upper_bound({index,100000});\n if(it==st.begin()) return {-1,-1};\n it--;\n if(it->f... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n //ct and seg are two segment trees\n vector<int> alt,ct,seg;\n set<pair<int,int>> st;\n int n;\n \n pair<int,int> findGroup(int index){\n auto it=st.upper_bound({index,100000});\n if(it==st.begin()) return {-1,-1};\n it--;\n if(it->f... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "namespace segment_tree_impl {\n\ntemplate <typename DataType, class Operator, bool LazyAssignment>\nstruct LazyAssignmentComponent {};\n\ntemplate <typename DataType, class Operator>\nstruct LazyAssignmentComponent<DataType, Operator, true> {\n bool has_lazy_assignment = false;\n DataType lazy_assignment... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "namespace segment_tree_impl {\n\ntemplate <typename DataType, class Operator, bool LazyAssignment>\nstruct LazyAssignmentComponent {};\n\ntemplate <typename DataType, class Operator>\nstruct LazyAssignmentComponent<DataType, Operator, true> {\n bool has_lazy_assignment = false;\n DataType lazy_assign... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "namespace segment_tree_impl {\n\ntemplate <typename DataType, class Operator, bool LazyAssignment>\nstruct LazyAssignmentComponent {};\n\ntemplate <typename DataType, class Operator>\nstruct LazyAssignmentComponent<DataType, Operator, true> {\n bool has_lazy_assignment = false;\n DataType lazy_assignment... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n void print(set<int> s){\n cout<<\"s \";\n for(auto p:s)cout<<p<<\" \";\n cout<<endl;\n }\n void print(map<int,int> m){\n cout<<\"m\"<<endl;\n for(auto p:m)cout<<p.first<<\" \"<<p.second<<endl;\n }\n\n\n vector<int> numberOfAltern... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "struct Operation {\n int a;\n int d;\n};\n \nstruct segtree {\n int n;\n Operation NO_OPERATION = {0, 0};\n vector<Operation> ops;\n \n void init(int n) {\n this->n = n;\n int size = 1;\n while (size < n) {\n size *= 2;\n }\n ops.assign(size *... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\n map<int,int> groupTable;\n vector<int> frequencySegmentTree,sizeSegmentTree;\n int n = 0;\n int segmentTreeLength = 0;\n int circularSize = 0;\n // insert a group in groupSize to segment trees.\n void insert(int groupSize) {\n int index = groupSize + n;\n frequencySegmentTre... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "#define pb push_back\ntypedef long long ll;\n\n// STRONGEST 1-D SEGMENT TREE\n\nll P2[31] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "/*\n\tJAI JAGANNATH!\n*/\n//@Author : zanj0\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define ff first\n#define ss second\n#define pb push_back\n#define MOD 1000000007\n#define inf INT_MAX\n\ntypedef long long int lli;\n\nclass Segmen... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "/*\n\tJAI JAGANNATH!\n*/\n//@Author : zanj0\n\n#include<bits/stdc++.h>\nusing namespace std;\n\n#define ff first\n#define ss second\n#define pb push_back\n#define MOD 1000000007\n#define inf INT_MAX\n\ntypedef long long int lli;\n\nclass Segmen... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "const int N = 5e4 + 4;\nclass Solution {\npublic:\n int n;\n int BITcnt[N << 1], BITsum[N << 1];\n \n void update(int a[], int p, int val) {\n while (p) {\n a[p] += val;\n p ^= p & -p;\n }\n }\n\n int Get(int a[], int p) {\n int res = 0;\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "#ifndef LOCAL\n#pragma GCC optimize(\"Ofast\", \"unroll-loops\")\n#endif\n\n#include <bits/stdc++.h>\n\nnamespace mitsuha{\ntemplate <typename T, typename U>\nstd::ostream &operator<<(std::ostream &os, const std::pair<T, U> &A) {\n os << A.first << \" \" << A.second;\n return os;\n}\n\ntemplate <type... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "typedef long long ll;\n\n#define pb push_back\n#define sz(x) (int)x.size()\n#define all(x) begin(x),end(x)\n#define lb(x,y) lower_bound(all(x),y)-begin(x)\nclass Solution {\npublic:\n int rangeSum(vector<int> &tree, int l, int r) {\n l += sz(tree) / 2; r += sz(tree) / 2;\n int res = 0;\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n int rangeSum(vector<int> &tree, int l, int r) {\n l += tree.size() / 2; r += tree.size() / 2;\n int res = 0;\n while (l <= r) {\n if (l % 2 == 1) {\n res += tree[l];\n l >>= 1;\n l++;\n } ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n int rangeSum(vector<int> &tree, int l, int r) {\n l += tree.size() / 2; r += tree.size() / 2;\n int res = 0;\n while (l <= r) {\n if (l % 2 == 1) {\n res += tree[l];\n l >>= 1;\n l++;\n } ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "#ifndef LOCAL\n#pragma GCC optimize(\"Ofast\", \"unroll-loops\")\n#endif\n\n#include <bits/stdc++.h>\n\nnamespace mitsuha{\ntemplate <typename T, typename U>\nstd::ostream &operator<<(std::ostream &os, const std::pair<T, U> &A) {\n os << A.first << \" \" << A.second;\n return os;\n}\n\ntemplate <type... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx,avx2,fma\")\n#pragma GCC target(\"sse4,popcnt,abm,mmx,tune=native\")\n#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\n\n#define pb... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int>& colors, vector<vector<int>>& queries) {\n\n vector<int> res;\n\n int nc = colors.size();\n int n = 2*nc;\n\n vector<int> arr(n);\n for( int i=0; i<nc; i++) {\n arr[i] = arr[i+nc] ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "struct BIT {\n vector<int> bit;\n int n;\n BIT(int n) : n(n), bit(n + 1) {}\n void upd(int idx, int val) {\n while (idx <= n) {\n bit[idx] += val;\n idx += idx & -idx;\n }\n }\n int get(int idx) {\n int ret = 0;\n while (idx) {\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "struct BIT {\n vector<int> bit;\n int n;\n BIT(int n) : n(n), bit(n + 1) {}\n void upd(int idx, int val) {\n while (idx <= n) {\n bit[idx] += val;\n idx += idx & -idx;\n }\n }\n int get(int idx) {\n int ret = 0;\n while (idx) {\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n\n class SegTree {\n private:\n vector<pair<int, int>> tree;\n int n;\n public:\n SegTree(int n) {\n this->n = n;\n tree.assign(4 * n + 1, {0, 0});\n }\n void st_update(int i, int x) {\n st_update(1, n, ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\n public:\n\n class SegTree {\n private: vector < pair < int, int > > tree;\n int n;\n public: SegTree(int n) {\n this->n = n;\n tree.assign(4 * n + 1, {0, 0});\n }\n void st_update(int i, int x)... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\n public:\n\n class SegTree {\n private: vector < pair < int, int > > tree;\n int n;\n public: SegTree(int n) {\n this->n = n;\n tree.assign(4 * n + 1, {0, 0});\n }\n void st_update(int i, int x)... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\n struct SegTree {\n static inline int L(int i) { return i << 1; }\n static inline int R(int i) { return L(i) ^ 1; }\n\n int m = 1;\n vector<int> a, s;\n\n void init(int n) {\n m = 1;\n while (m < n) {\n m <<= 1;\n }\n a = vector<int>(m + m, 0);\n... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n//1 1 1 0 1\n class SegTree {\n private:\n vector<pair<int, int>> tree;\n int n;\n public:\n SegTree(int n) {\n this->n = n;\n tree.assign(4 * n + 1, {0, 0}); // Initialize the segment tree\n }\n void st_update(in... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n #define fi first\n #define se second\n #define all(m) (m).begin(), (m).end()\n #define rall(m) (m).rbegin(), (m).rend()\n #define vec vector\n #define mp make_pair\n\n typedef long long ll;\n typedef long double ld;\n typedef unsigned long long ull;\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "struct SegementTree {\n int n;\n vector<int> count, num;\n\n SegementTree (int n) {\n this->n = n;\n count = vector<int>(4 * n + 1, 0);\n num = vector<int>(4 * n + 1);\n }\n SegementTree (vector<int> &freqs) : SegementTree(freqs.size()) {\n build(freqs, 1, 0, n - ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n struct node{\n node *l,*r;\n int a,b;\n int pre,suf;\n node(int _a,int _b):a(_a),b(_b),l(NULL),r(NULL){\n \n }\n }*root;\n void pull(node *n){\n n->pre=n->l->pre;\n if(n->l->pre==n->l->b-n->l->a+1)n->pre+=n->r->pre... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n struct node{\n node *l,*r;\n int a,b;\n int pre,suf;\n node(int _a,int _b):a(_a),b(_b),l(NULL),r(NULL){\n \n }\n }*root;\n void pull(node *n){\n n->pre=n->l->pre;\n if(n->l->pre==n->l->b-n->l->a+1)n->pre+=n->r->pre... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n struct node{\n node *l,*r;\n int a,b;\n int pre,suf;\n node(int _a,int _b):a(_a),b(_b),l(NULL),r(NULL){\n \n }\n }*root;\n void pull(node *n){\n n->pre=n->l->pre;\n if(n->l->pre==n->l->b-n->l->a+1)n->pre+=n->r->pre... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "class Solution {\npublic:\n typedef long long ll;\n vector<int> numberOfAlternatingGroups(vector<int>& col, vector<vector<int>>& qu) {\n ll i, j, k, ty, sta, ed, x, y, val, n = (ll)col.size(), q = (ll)qu.size(), a[321][2] = {}, md = (ll)1000000007, prevflg, x2, x3, x4, y2, y3, y4;\n vec... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <... | 3 | {
"code": "struct SegmentTree {\n public:\n explicit SegmentTree(int n)\n : n(n), treeIntervalCounts(4 * n), treeIntervalLengths(4 * n) {}\n\n // Adds val to intervalCounts[i] and updates intervalLengths[i] accordingly.\n void add(int i, int val) {\n add(0, 0, n - 1, i, val);\n }\n\n // Returns sum(inter... |
3,202 | <p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 <= i <= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of ... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findHighAccessEmployees(vector<vector<string>>& arr) {\n \n sort(arr.begin(), arr.end());\n\n vector<string> ans;\n int i = 0;\n int n = arr.size();\n\n while(i < n)\n {\n string ch = arr[i][0];\n ... |
3,202 | <p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 <= i <= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of ... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findHighAccessEmployees(vector<vector<string>>& arr) {\n sort(arr.begin(), arr.end(), [&](vector<string>& a, vector<string>& b){\n if(a[0] == b[0])\n return a[1] < b[1];\n \n return a[0] < b[0];\n })... |
3,202 | <p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 <= i <= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of ... | 0 | {
"code": "class Solution {\npublic:\n\n static bool sortbysecond(const vector<string> &a, const vector<string> &b){\n if(a[0]==b[0]){\n return a[1] < b[1];\n }\n return a[0] < b[0];\n }\n\n vector<string> findHighAccessEmployees(vector<vector<string>>& access_times) {\n ... |
3,202 | <p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 <= i <= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of ... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findHighAccessEmployees(vector<vector<string>>& access_times) {\n std::unordered_set<std::string> result;\n std::sort(access_times.begin(), access_times.end());\n for (int i = 0, n = static_cast<int>(access_times.size()); i + 2 < n; ++i)\n ... |
3,202 | <p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 <= i <= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of ... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findHighAccessEmployees(vector<vector<string>>& access_times) {\n sort(access_times.begin(),access_times.end());\n int n=access_times.size();\n vector<string> v;\n unordered_map<string, int>m;\n for(int i=0;i<n-2;i++)\n ... |
3,202 | <p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 <= i <= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of ... | 0 | {
"code": "#include <vector>\n#include <string>\n#include <algorithm>\n\nclass Solution {\npublic:\n vector<string> findHighAccessEmployees(vector<vector<string>>& access_times) {\n vector<string> ans;\n sort(access_times.begin(), access_times.end());\n int n = access_times.size();\n fo... |
3,202 | <p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 <= i <= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of ... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findHighAccessEmployees(vector<vector<string>>& access_times) {\n int n = access_times.size();\n vector<string> ans;\n unordered_set<string> uniqueEmployees; // To track unique employees in the result\n \n for (int i = 0; i <... |
3,202 | <p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 <= i <= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of ... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findHighAccessEmployees(vector<vector<string>>& nums) {\n sort(nums.begin(),nums.end());\n unordered_set<string>s;\n int n=nums.size();\n for(int i=2;i<n;i++){\n string a=nums[i][0];\n string b=nums[i-2][0];\n ... |
3,202 | <p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 <= i <= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of ... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findHighAccessEmployees(vector<vector<string>>& vec) {\n sort(vec.begin(), vec.end());\n vector<string> ans;\n string skip;\n for (int i = 0, j = 1; j < vec.size(); j++) {\n if (vec[j][0] == skip) {\n contin... |
3,202 | <p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 <= i <= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of ... | 0 | {
"code": "class Solution {\npublic:\n // a 1, a 2, a 3, a 4, a 5, b 1\n vector<string> findHighAccessEmployees(vector<vector<string>>& vec) {\n if (vec.size() < 3) {\n return vector<string>();\n }\n sort(vec.begin(), vec.end());\n vector<string> ans;\n for (int i =... |
3,202 | <p>You are given a 2D <strong>0-indexed</strong> array of strings, <code>access_times</code>, with size <code>n</code>. For each <code>i</code> where <code>0 <= i <= n - 1</code>, <code>access_times[i][0]</code> represents the name of an employee, and <code>access_times[i][1]</code> represents the access time of ... | 0 | {
"code": "class Solution {\npublic:\n vector<string> findHighAccessEmployees(vector<vector<string>>& vec) {\n sort(vec.begin(), vec.end());\n vector<string> ans;\n for (int i = 0; i < int(vec.size())-2; i++) {\n int j = i + 2;\n if (vec[i][0] != vec[j][0]) {\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.