跳到正文

个人记录

fasdfasdfasd fqs

koukilee约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月11日
篇幅
约 3 分钟

版本

  1. v1当前
C++
/* The code is from koukilee*/
#include <bits/stdc++.h>

using i32 = int; using i64 = long long;
constexpr i64 MAXN = 1010100, mod = 1e9 + 7, INF = 992009100720100812;

//static char buf[1000000], *p1 = buf, *p2 = buf, obuf[1000000], *p3 = obuf;
//#define getchar() p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++
//#define putchar(x) (p3 - obuf < 1000000) ? (*p3++ = x) : (fwrite(obuf, p3 - obuf, 1, stdout), p3 = obuf, *p3++ = x)
inline void read (i64 &sum) noexcept {
    i64 tf = 0; char ch = getchar(); sum = 0;
    while (ch < '0' || ch > '9') tf = ch == '-' ? 1 : 0, ch = getchar();
    while (ch >= '0' && ch <= '9') sum = (sum << 1) + (sum << 3) + (ch ^ 48), ch = getchar();
    (tf) && (sum =- sum);
}template <typename i64,typename ...Args>
inline void read (i64 &tmp, Args &...tmps) noexcept{read(tmp); read(tmps...);}
void printt (i64 x) noexcept {if(x >= 10) printt(x / 10); putchar(x % 10 + '0');}
inline void print (i64 x) noexcept{x < 0 ? putchar('-'), printt(-x) : printt(x);}
inline void put (i64 x) noexcept{print(x), putchar('\n');}

i64 n, s[MAXN], k, ans;
std::unordered_map <i64, i64> vis;
std::set <i64> p;

int main() noexcept{
	read (n);

	for (i32 i = 1; i <= n; i++)
		read (s[i]), vis[s[i]]++, p.insert (s[i]);

	while (!p.empty ()) {
		i64 Min = *p.begin (), l = Min;

		while (vis[Min]){
			vis[Min]--;
			if (!vis[Min]) p.erase (p.find (Min));
			Min++;
		}

		k++, ans += Min - l;
	}

	print (ans), putchar (' '), put (k);
    //fwrite(obuf,p3-obuf,1,stdout);
    return 0;
}
原文