标签:acm
const int MAXN = 310000; struct Node { int n, num; int operator< (const Node& a) const { return num < a.num; } } ipt[MAXN]; int cnt[MAXN]; int cmp(Node& a, int b) { return a.num < b; } int main() { // freopen("in.txt", "r", stdin); int n, k, a, b; while (~RII(n, k)) { CLR(cnt, 0); map<pair<int, int>, int> mp; FE(i, 1, n) ipt[i].n = i; FE(i, 1, n) ipt[i].num = 0; REP(i, n) { RI(a); ipt[a].num++; cnt[a]++; RI(b); ipt[b].num++; cnt[b]++; if (a > b) swap(a, b); mp[MP(a, b)]++; } sort(ipt + 1, ipt + n + 1); LL ans = 0; FE(i, 1, n) { int ind = lower_bound(ipt + i + 1, ipt + n + 1, k - ipt[i].num, cmp) - ipt; ans += n - ind + 1; } FC(it, mp) { a = (it->first).first; b = (it->first).second; if (cnt[a] + cnt[b] >= k && cnt[a] + cnt[b] - it->second < k) ans--; } cout << ans << endl; } return 0; }
Coder-Strike 2014 - Finals (online edition, Div. 2)——Bug in Code
标签:acm
原文地址:http://blog.csdn.net/wty__/article/details/24666549