intmain(){ int n; cin >> n; for (int i = 1; i <= n; ++i) for (int j = 1; j <= 5; ++j) champ[getid()] = true; cin >> n; for (int i = 1; i <= n; ++i) { int id = getid(), pos; cin >> pos; tot += champ[id]; cnt[pos]++; } for (int i = 1; i <= 5; ++i) tot = min(tot, cnt[i]); printf("%d\n", tot); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define fr first #define sc second #define mp make_pair #define pb push_back
#define N 100007
bool del[N];
int a[N], res[N], op[N];
int A, B;
inlineboolcheck(int n, int dlt){ int lim = sqrt(n); for (int i = 1; i <= lim; ++i) if (n % i == 0) if (n - i - n / i == dlt) {A = i; B = n / i; returntrue;} returnfalse; }
int nodecnt, totlim;
structnode {int ls = 0, rs = 0, x = 0, tim = 0;} c[N];
intmain(){ int n = rd(); for (int i = 1; i <= n; ++i) a[i] = rd(); int tot = n, cnt1 = 0; for (int i = n - 1; i; --i) if (a[i] > a[i + 1]) {del[i] = true; ++cnt1; res[tot--] = 1; op[i] = tot;} for (int i = 1; i <= n; ++i) if (i < n && a[i] > a[i + 1]) {a[i] -= cnt1; --cnt1;} else a[i] -= cnt1; c[nodecnt = 1].x = a[n]; for (int i = n - 1; i; --i) if (!del[i]) lim[++totlim] = make_pair(a[i + 1] - a[i], i); if (!dfs(1, set<int>{1}, multiset<int>{a[n]})) {puts("-1"); return0;} build(1); for (int i = 1; i <= n; ++i) printf("%d ", res[i]); puts(""); for (int i = 1; i < n; ++i) printf("%d\n", op[i]); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define fr first #define sc second #define mp make_pair #define pb push_back
#define N 25007
#define letp const P
structP { ll x, y; P operator - (letp &p) const {return {x - p.x, y - p.y};} ll operator | (letp &p) const {return x * p.x + y * p.y;} // dot ll operator ^ (letp &p) const {return x * p.y - y * p.x;} // cross } a[N], p[6];
inlinevoidwork(){ int n = rd(); for (int i = 1; i <= n; ++i) {a[i].x = rd(); a[i].y = rd();} if (n <= 4) {puts("NO"); return;} int tot = 2; p[1] = a[1]; p[2] = a[2]; bool fl = false; for (int i = 3; i <= n && tot < 5; ++i) if (fl || tot < 4) { p[++tot] = a[i]; if (((p[i] - p[1]) ^ (p[2] - p[1])) != 0) fl = true; } elseif (((a[i] - p[1]) ^ (p[2] - p[1])) != 0) { fl = true; p[++tot] = a[i]; } if (tot < 5) {puts("NO"); return;} puts("YES"); for (int i = 1; i <= 5; ++i) { bool fl = true; for (int j = 1; j <= 5; ++j) if (j != i) for (int k = 1; k <= 5; ++k) if (k != i && k != j) if (((p[k] - p[i]) ^ (p[j] - p[i])) == 0 && ((p[k] - p[i]) | (p[j] - p[i])) >= 0) { fl = false; break; } if (fl) { printf("%lld %lld\n", p[i].x, p[i].y); for (int j = 1; j <= 5; ++j) if (j != i) printf("%lld %lld\n", p[j].x, p[j].y); return; } }
}
intmain(){ for (int t = rd(); t; --t) work(); return0; }
intmain(){ int n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i]; if (a[i] < k) { printf("Python 3.%d will be faster than C++\n", i); return0; } } int add = a[n] - a[n - 1]; if (add >= 0) puts("Python will never be faster than C++"); else { k = a[n] - k; add = -add; int ans = k / add; while (ans * add <= k) ++ans; printf("Python 3.%d will be faster than C++", n + ans); return0; } return0; }
template<typename T> inlineboolgetmin(T &a, T b){return a > b ? (a = b, true) : false;}
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 307 #define inf 4000000000000000000ll
bool e[N][N];
int col[N], w[N];
ll dis[N][N], mx[N][N], ans[N][N];
inlinevoidwork(){ int n = rd(), m = rd(); rep(i, 1, n) rep(j, 1, n) {e[i][j] = false; mx[i][j] = dis[i][j] = inf;} rep(i, 1, n) col[i] = rd(); rep(i, 1, n) {w[i] = rd(); mx[i][i] = dis[i][i] = 0;} rep(i, 1, m) { int u = rd(), v = rd(); e[u][v] = e[v][u] = true; dis[u][v] = w[v]; dis[v][u] = w[u]; } // floyd for same color rep(k, 1, n) rep(u, 1, n) rep(v, 1, n) getmin(dis[u][v], dis[u][k] + dis[k][v]); rep(u, 1, n) rep(v, 1, n) dis[u][v] += w[u]; // new graph : a path of same color points + an another color point rep(u, 1, n) rep(k, 1, n) if (col[u] == col[k]) rep(v, 1, n) if (col[k] != col[v] && e[k][v]) getmin(mx[u][v], dis[u][k] + w[v]); // floyd on new graph rep(k, 1, n) rep(u, 1, n) rep(v, 1, n) getmin(mx[u][v], max(mx[u][k], mx[k][v])); // consider adding a path of same color in the end rep(u, 1, n) rep(v, 1, n) { ans[u][v] = mx[u][v]; rep(k, 1, n) if (col[v] == col[k]) getmin(ans[u][v], max(mx[u][k], dis[k][v])); } rep(u, 1, n) { rep(v, 1, n) printf("%lld ", ans[u][v]); puts(""); } }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
G. Grade 2
给定 \(x\) ,多次询问 \([l,r]\) ,计算 \(\sum_{k=l}^r[\operatorname{gcd}(k x \oplus x,
x)=1]\)
inline ll rd(){ ll x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 10000007
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
int sum[N];
intmain(){ int x = rd(), n = rd(); int period = 2 << __lg(x); for (int i = 0; i < period; ++i) sum[i] = sum[i - 1] + (gcd((1ll * i * x) ^ x, x) == 1ll); auto calc = [&](ll p) { return sum[period - 1] * (p / period) + sum[p % period]; }; for (int i = 1; i <= n; ++i) { ll l = rd(), r = rd(); printf("%lld\n", calc(r) - calc(l - 1)); } return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 100007
int a[N];
#define fr first #define sc second #define mp make_pair #define pb push_back
vector<pii> lim, tmplim;
vector<int> tmp;
inlinevoidwork(){ lim.clear(); int n = rd(), k = rd(); for (int i = 1; i <= n; ++i) a[i] = rd(); sort(a + 1, a + 1 + n); for (int i = 1; i <= k; ++i) { int x = rd(), y = rd(); lim.push_back(mp(x, y)); } lim.push_back(mp(1000000001, 0)); sort(lim.begin(), lim.end()); int ptr = 1, den = -1, mx = 0; ll ans = 0; auto calc = [&](){ int id = 0; ll sum = 0, cnt = tmp.size(); for (auto x : tmp) sum += x; ll fin = 0; for (int i = den + 1, limid = tmplim.size(); i <= mx; ++i, ++id) { if (id >= limid) {fin = i; break;} if (tmplim[id].fr > i) {fin = i; break;} ll t = min(cnt, (ll)tmplim[id].sc); cnt -= t; sum -= t * i; if (!cnt) break; } sum -= cnt * fin; ans += sum; tmp.clear(); tmplim.clear(); }; for (auto [x, y] : lim) { while (ptr <= n && a[ptr] < x) tmp.pb(a[ptr++]); if (y == 0) {mx = x - 1; calc(); den = x;} else tmplim.push_back(mp(x, y)); } tmplim.clear(); tmp.clear(); puts((ans & 1) ? "Pico" : "FuuFuu"); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }