voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int a, b, xk, yk, xq, yq; cin >> a >> b >> xk >> yk >> xq >> yq; constint arr[4][2] = {1, 1, 1, -1, -1, 1, -1, -1}; set<pair<int, int>> s; for (constauto ar: arr) { s.insert({xk + a * ar[0], yk + b * ar[1]}); s.insert({xk + b * ar[0], yk + a * ar[1]}); }
int ans = 0; for (constauto ar: arr) { if (s.count({xq + a * ar[0], yq + b * ar[1]})) { s.erase({xq + a * ar[0], yq + b * ar[1]}); ++ans; } if (s.count({xq + b * ar[0], yq + a * ar[1]})) { s.erase({xq + b * ar[0], yq + a * ar[1]}); ++ans; } }
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n; cin >> n; vector<pair<int, int>> data(n); for (auto& [fst, snd]: data) cin >> fst; for (int i = 0; i < n; ++i) data[i].second = i; sort(data.begin(), data.end()); vector<int> ans(n); int l = 0, sum = 0; while (l < n) { int r = l + 1; sum += data[l].first; while (r < n && sum >= data[r].first) { sum += data[r].first; ++r; } for (int i = l; i < r; ++i) ans[data[i].second] = r - 1;
l = r; } for (int i = 0; i < n; ++i) cout << ans[i] << " \n"[i == n - 1]; } }
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n; cin >> n; vector<int> a(n), b(n), la(n, 0), ra(n, n); int r = n - 1; for (auto& i: a) cin >> i; for (auto& i: b) cin >> i; stack<int> st; for (int i = 0; i < n; ++i) { while (!st.empty() && a[st.top()] < a[i]) { ra[st.top()] = i; st.pop(); } st.push(i); } while (!st.empty()) st.pop();
for (int i = n - 1; i >= 0; --i) { while (!st.empty() && a[st.top()] < a[i]) { la[st.top()] = i + 1; st.pop(); } st.push(i); } while (!st.empty()) st.pop();
bool flag = true; for (int i = n - 1; i >= 0; --i) { while (r >= 0 && (a[r] != b[i] || la[r] > i || ra[r] <= i)) --r; if (a[r] != b[i] || la[r] > i || ra[r] <= i) { flag = false; break; } }