//@ Main Function intmain(){ int _; for (scanf("%d", &_); _; _--) { int k, m, q; scanf("%d%d%d", &k, &m, &q); rep(i, 0, k) scanf("%s%d", a[i].s, &a[i].v), a[i].w = i; rep(i, 0, m) scanf("%d%d", &c[i].first, &c[i].second); sort(c, c + m);
int cur = 0; priority_queue< node*, vector<node*>, cmp > p; vector<node*> ans; ans.reserve(k); rep(i, 0, m) { for (int x = c[i].first; cur < x; ++cur) p.push(a + cur); for (int x = c[i].second; x && !p.empty(); --x, p.pop()) ans.push_back(p.top()); } for (; cur < k; ++cur) p.push(a + cur); for (; !p.empty(); p.pop()) ans.push_back(p.top());
graph g; int n, m, a[maxn], b[maxm], c[maxm]; int d[maxn]; bool e[maxn];
voidbfs(){ queue<int> q; rep(i, 1, n+1) if (d[i] <= 1) q.push(i); while (!q.empty()) { int u = q.front(); q.pop(); if (e[u]) continue; e[u] = true; if (d[u] != 1) continue; for (edge i = g.getHead(u); i; i = i->next) { int v = i->to; if (e[v]) continue; if ((--d[v]) == 1) q.push(v); } } }
node dfs(int u){ node res(1,a[u]); e[u] = true; for (edge i = g.getHead(u); i; i = i->next) { int v = i->to; if (e[v]) continue; node tmp = dfs(v); res.first += tmp.first; res.second += tmp.second; } return res; }
//@ Main Function intmain(){ int _; scanf("%d", &_); while (_--) { scanf("%d%d", &n, &m); rep(i, 1, n+1) scanf("%d", a+i); rep(i, 0, m) scanf("%d%d", b+i, c+i);
/* * Name : hdu5441.cpp * Date : 2015年9月13日 上午9:23:47 * Copyright : fateud.com * Anti-Mage : The magic ends here. */
#define maxn 20010 #define maxm 100010 #define maxq 5010 int s[maxn]; int a[maxm],b[maxm],c[maxm],d[maxm],f[maxm]; int g[maxn],h[maxn];
boolcmp(constint& a, constint& b){ return c[a] < c[b]; }
introot(int u){ return g[u] == u ? u : g[u] = root(g[u]); }
intmerge(int u, int v){ int ru = root(u); int rv = root(v); if (ru == rv) return0; int ret = s[h[ru]] + s[h[rv]]; g[rv] = ru; h[ru] += h[rv]; return s[h[ru]] - ret; }
//@ Main Function intmain(){ rep(i, 1, maxn) s[i] = i * (i-1) / 2; int _; for (scanf("%d", &_); _; _--) { int n, m, q; scanf("%d%d%d", &n, &m, &q); rep(i, 0, m) scanf("%d%d%d", a+i, b+i, c+i), d[i]=i; sort(d, d+m, cmp);
rep(i, 1, n+1) g[i]=i, h[i]=1; int cnt = 0; rep(i, 0, m) { int j = d[i]; f[j] = (cnt += merge(a[j],b[j])); }
rep(i, 0, q) { int x; scanf("%d", &x); int l = 0, r = m-1; while (l < r) { int m = (l + r) >> 1; if (c[d[m]] <= x) l = m+1; else r = m; } if (l && c[d[l]] > x) --l; printf("%d\n", c[d[l]] <= x ? f[d[l]] << 1 : 0); } } return0; }
//@ Including Header #include <csl_std.h> #include <csl_algo.h>
/* * Name : hdu5442.cpp * Date : 2015年9月17日 上午11:47:07 * Copyright : fateud.com * Anti-Mage : The magic ends here. */
#define maxn 20010 char s[maxn], t1[maxn*2], t2[maxn*2]; //@ Main Function intmain(){ int _; scanf("%d", &_); while (_--) { int n; scanf("%d", &n); scanf("%s", s);
rep(i, 0, n) t1[i] = t1[n+i] = s[i]; rep(i, 0, n) t2[i] = t2[n+i] = s[n-1-i]; t1[2*n] = 0, t2[2*n] = 0; int x = csl::isomorph_min(t1, n, std::greater<char>()); int y = csl::isomorph_max(t2, n, std::greater<char>()); t1[x+n] = 0, t2[y+n] = 0;
int ans1 = x + 1, ans2 = n - y; int z = strcmp(t1+x, t2+y); if (z) printf("%d %d\n", z > 0 ? ans1 : ans2, z <= 0); else printf("%d %d\n", min(ans1,ans2), ans1 > ans2); } return0; }
/* * Name : hdu5444.cpp * Date : 2015年9月18日 下午4:20:29 * Copyright : fateud.com * Anti-Mage : The magic ends here. */
#define maxn 1010 int a[maxn], b[maxn], c[maxn];
intdfs(int l, int r){ if (l > r) return -1; int x = l; for (int i = l + 1; i <= r; ++i) if (a[i] < a[x]) x = i; b[x] = dfs(l, x - 1); c[x] = dfs(x + 1, r); return x; }
//@ Main Function intmain(){ int _; scanf("%d", &_); while (_--) { int n; scanf("%d", &n); rep(i, 0, n) { int x; scanf("%d", &x); a[x] = i + 1; } int r = dfs(1, n);
int q; scanf("%d", &q); while (q--) { int x; scanf("%d", &x); int t = r; while (t != x) { printf("%c", t > x ? 'E' : 'W'); t = (t > x) ? b[t] : c[t]; } printf("\n"); } } return0; }
ll com(ll n, ll m, ll mod){ if (m > n) return0; return fac[n] * csl::inv(fac[m] * fac[n-m], mod) % mod; }
ll lucas(ll n, ll m, ll mod){ fac[0] = 1, fac[mod] = 0; rep(i, 1, mod) fac[i] = fac[i-1] * i % mod;
ll res = 1; while (m) { res = res * com(n % mod, m % mod, mod) % mod; n /= mod, m /= mod; } return res; }
//@ Main Function intmain(){ int _; scanf("%d", &_); while (_--) { ll n, m; scanf(i64 i64, &n, &m); int k; scanf("%d", &k); rep(i, 0, k) scanf(i64, a+i);
ll M = 1; rep(i, 0, k) M *= a[i]; ll ans = 0; rep(i, 0, k) { ll p = lucas(n, m, a[i]); ll q = M / a[i]; ans += csl::mul(p, csl::mul(q, csl::inv(q, a[i]), M), M); ans %= M; } printf(i64 "\n", ans); } return0; }