社区讨论
月赛 C RE
学术版参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @ltldwavl
- 此快照首次捕获于
- 2024/03/10 18:41 2 年前
- 此快照最后确认于
- 2024/03/10 20:24 2 年前
CPP
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ls (rt << 1)
#define rs (rt << 1 | 1)
#define lowbit(x) x & -x
#define fup(x, l, r) for (int x = (l), eNd = (r); x <= eNd; ++ x )
#define fdw(x, r, l) for (int x = (r), eNd = (l); x >= eNd; -- x )
typedef long long ll;
typedef unsigned long long LL;
typedef pair<int, int> PII;
struct fastread {
template <typename T>
fastread& operator >>(T& x) {
x = 0; bool flg = false; char c = getchar();
while (c < '0' || c > '9') flg |= (c == '-'), c = getchar();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
if (flg) x = -x; return *this;
}
template <typename T>
fastread& operator >>(vector<T>& x) {
for (auto it = x.begin(); it != x.end(); ++ it ) (*this) >> *it;
return *this;
}
}fin;
struct fastwrite {
template <typename T>
fastwrite& operator <<(T x) {
if (x < 0) x = -x, putchar('-');
static int buf[35]; int top = 0;
do buf[top ++ ] = x % 10, x /= 10; while (x);
while (top) putchar(buf[ -- top] + '0');
return *this;
}
fastwrite& operator <<(char x) {
putchar(x); return *this;
}
template <typename T>
fastwrite& operator <<(vector<T> x) {
for (auto it = x.begin(); it != x.end(); ++ it ) (*this) << *it, putchar(' ');
putchar('\n');
return *this;
}
}fout;
const int N = 3e6 + 10;
const int P = 998244353;
int T;
int n, k;
int a[N];
int cnt;
struct node
{
int m, d;
}g[N], b[N];
int fpm(int a, int n)
{
int res = 1;
while(n)
{
if(n & 1) res = res * a;
a = a * a;
n >>= 1;
}
return res;
}
int fen(int x)
{
int cnt = 0;
while(x)
{
cnt++;
x /= 10;
}
return cnt;
}
bool cmp(node a, node b)
{
if(a.m < b.m) return 1;
else if(a.m == b.m) return a.d < b.d;
else return 0;
}
int res[N];
void solve()
{
cnt = 0;
memset(res, 0, sizeof res);
memset(a, 0, sizeof a);
memset(b, 0, sizeof b);
fin >> n >> k;
fup(i, 1, n) fin >> a[i];
if(k == 1)
{
fout << 0 << '\n';
return ;
}
res[0] = 1;
res[1] = k;
int e = 0;
fup(i, 2, 64)
{
if(res[i] > 1e18 || res[i] < 0) continue;
res[i] = res[i - 1] * k;
e++;
}
//fout << e << '\n';
fup(i, 1, e)
{
int len = fen(res[i]);
// fout << len << ' ' << res[i] << '\n';
if(res[i] <= 10) continue;
fup(i, 0, len - 1)
{
if((res[i] / fpm(10, len - i - 1)) % 10 == 0) continue;
int qian = res[i] / fpm(10, len - i);
int hou = res[i] % fpm(10, len - i);
//fout << qian << ' ' << hou << '\n';
if(qian <= n && qian != 0 && hou != 0 && hou <= a[qian])
{
cnt++;
g[cnt].m = qian, g[cnt].d = hou;
}
}
}
int ans = 0;
sort(g + 1, g + cnt + 1, cmp);
fup(i, 1, cnt)
{
if(!(g[i - 1].m == g[i].m && g[i - 1].d == g[i].d)) ans++;
}
fout << ans << '\n';
fup(i, 1, cnt)
{
if(!(g[i - 1].m == g[i].m && g[i - 1].d == g[i].d)) fout << g[i].m << ' ' << g[i].d << '\n';
}
}
main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
fin >> T;
while(T--) solve();
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...