voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n; cin >> n; int l = 0, r = INT_MAX; set<int> s; for (int i = 0; i < n; ++i) { int o, x; cin >> o >> x; if (o == 1) l = max(l, x); elseif (o == 2) r = min(r, x); else s.insert(x); } int cnt = r - l + 1; for (auto& v: s) if (v <= r && v >= l) --cnt; cout << max(0, cnt) << endl; } }
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n, k, x; cin >> n >> k >> x; vector<int> data(n); for (auto& i: data) cin >> i; sort(data.begin(), data.end(), greater<>()); int total = 0, fx = 0; for (int i = 0; i < n; ++i) { total += data[i]; fx += i < x ? data[i] : 0; } int cur = 0, ma = 0; for (int l = 0, r = x; l < k; ++l, ++r) { cur -= r < n ? 2 * data[r] : 0; cur += data[l]; ma = max(ma, cur); } cout << total - fx - fx + ma << endl; } }
intgcd(constint a, constint b){ return b == 0 ? a : gcd(b, a % b); } voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n; cin >> n; vector<int> data(n); for (auto& i: data) cin >> i; auto check = [&](constint x) { constint len = n / x; int tmp = 0; for (int i = 1; i < x; ++i) for (int j = 0; j < len; ++j) tmp = gcd(abs(data[i * len + j] - data[(i - 1) * len + j]), tmp); return tmp != 1; }; int ans = 0; for (int i = 1; i * i <= n; ++i) { if (n % i) continue; ans += check(i); if (i * i != n) ans += check(n / i); } cout << ans << endl; } }
#define int long long voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n, q; cin >> n >> q; vector<pair<int, int>> data(n); for (auto& [fst, snd]: data) cin >> fst >> snd; map<int, list<int>> mp; int maxK = 0; for (int i = 0; i < q; ++i) { int tmp; cin >> tmp; mp[tmp].push_back(i); maxK = max(maxK, tmp); } int tot = 0, i = 0; for (; i < n; ++i) { if (data[i].first == 1) ++tot; else { if ((maxK + tot - 1) / tot <= 1 + data[i].second) data[i].second = (maxK + tot - 1) / tot; tot *= 1 + data[i].second; } if (tot >= maxK) break; } vector<int> ans(q); for (; i >= 0; --i) { if (data[i].first == 1) { if (constauto iter = mp.find(tot); iter != mp.end()) for (constauto& v: iter->second) ans[v] = data[i].second; mp.erase(tot); --tot; } else { constint len = tot / (1 + data[i].second); for (auto iter = mp.upper_bound(len); iter != mp.end(); ) { list<int>& l = mp[(iter->first - 1) % len + 1]; l.splice(l.end(), iter->second); auto nxtIter = iter; ++nxtIter; mp.erase(iter); iter = nxtIter; } tot = len; } } for (int i = 0; i < q; ++i) cout << ans[i] << " \n"[i == q - 1]; } }