Type: Default 2000ms 256MiB

A郭弋楷签到

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e6 + 10;
const ll inf = 1ll << 30, mod = 1e9 + 7, Mul = 1e8;
#define db double
inline ll read()
{
	ll f = 1, x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = (x << 1) + (x << 3) + (s ^ 48), s = getchar();
    x *= f;
	return x;
}
int a[N], ans[N];
ll b[N];
int vis[N], Vis[N];
int cir[N];
char c[N];
int Len;
int solve(int x)
{
	ll h = 0;
	for(int i = Len; i >= 1; i --)
	{
		h = (h * Mul + b[i]) % x;
	}
	return (h - 1 + x) % x;
}
int main()
{
	int n = read();
	for(int i = 1; i <= n; i ++)
	{
		a[i] = read(); vis[i] = -1;
	}
	scanf("%s", c + 1);
	int len = strlen(c + 1);
	Len = len / 8;
	for(int i = 1; i <= Len; i ++)
	{
		int L = len - i * 8 + 1, R = len - (i - 1) * 8;
		for(int j = L; j <= R; j ++)b[i] = b[i] * 10 + c[j] - '0';
	}
	if(len % 8 != 0)
	{
		Len ++;
		for(int j = 1; j <= len - len / 8 * 8; j ++)b[Len] = b[Len] * 10 + c[j] - '0';
	}
	
	for(int i = 1; i <= n; i ++)
	{
		int cnt = 0, p = i;
		while(Vis[p] == 0)
		{
			Vis[p] = 1;
			cnt ++;
			cir[cnt] = p;
			p = a[p]; 
		}
		
		if(vis[cnt] == -1)
		{
			vis[cnt] = solve(cnt);
		}
		//if(cnt == 8)vis[cnt] = 6;
		for(int j = 1; j <= cnt; j ++)
		{
			int d = j - vis[cnt];
			if(d <= 0)d += cnt;
			ans[cir[d]] = a[cir[j]];
		}
	}
	
	for(int i = 1; i <= n; i ++)printf("%d ", ans[i]);
}

7.31日竞赛3班造数据

Not Attended
Status
Done
Rule
IOI
Problem
8
Start at
2025-7-31 18:00
End at
2025-7-31 21:00
Duration
3 hour(s)
Host
Partic.
8