QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#421454#6753. MediansFugeg#AC ✓2218ms258148kbC++173.0kb2024-05-25 19:07:322024-05-25 19:07:32

Judging History

你现在查看的是最新测评结果

  • [2024-05-25 19:07:32]
  • 评测
  • 测评结果:AC
  • 用时:2218ms
  • 内存:258148kb
  • [2024-05-25 19:07:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 10, M = 4e5;
ll n, m, q;
struct node
{
	ll v, sex, f, id;
} e[N], e1[N];
bool cmp2(node a, node b)
{
	return a.v > b.v;
}
#define MAXN 10000005
ll a[MAXN], p[MAXN];
ll p1 = 1000000009, p2 = 998244353, p3 = 1000000007;
ll qim(ll a, ll b, ll p)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
		{
			res = res * a % p;
		}
		a = a * a % p;
		b >>= 1;
	}

	return res;
}
void solve1()
{
	cin >> n >> a[0];

	for (int i = 1; i <= n; i++)
	{
		p[i] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		a[i] = (a[i - 1] * p2 % p1 + p3) % p1;
		swap(p[i], p[a[i] % i + 1]);
		// cout << p[i] << endl;
	}

	ll res = 0, mid = 0;
	priority_queue<ll> qmax;
	priority_queue<ll, vector<ll>, greater<ll>> qmin;
	qmax.push(p[1]);
	mid = p[1];
	res = mid * qim(19, 1, p2) % p2;
	for (int i = 2; i <= n; i++)
	{
		if (p[i] > mid)
		{
			if (i % 2 == 1)
			{
				int maxx = qmin.top();
				if (maxx >= p[i])
				{
					mid = p[i];
				}
				else
				{
					mid = maxx;
					qmin.pop();
					qmin.push(p[i]);
				}
				qmax.push(mid);
			}
			else
			{
				qmin.push(p[i]);
			}
		}
		else
		{
			if (i % 2 == 1)
			{
				qmax.push(p[i]);
			}
			else
			{
				qmax.pop();
				qmin.push(mid);

				qmax.push(p[i]);
				mid = qmax.top();
			}
		}


		res = (res + mid * qim(19, i, p2) % p2) % p2;
	}

	cout << res << endl;
}
void solve()
{

	/*cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
	{
		cin >> e[i].v >> e[i].sex;
		e[i].id = i;
	}
	ll maxx = -1, f = -1;
	for (int i = 1; i <= n; i++)
	{
		e1[i].sex = e[i].sex;
		e1[i].v = e[i].v;
		e1[i].id = e[i].id;
		e1[i].f = 0;
		e[i].f = 0;
		if (e1[i].sex == 1)
		{
			maxx = max(maxx, e1[i].v);
			f = i;
		}
	}
	if (maxx == -1)
	{
		sort(e1 + 1, e1 + n + 1, cmp2);
		for (int i = 1; i <= m; i++)
		{
			e[e1[i].id].f = 1;
		}
	}
	else
	{
		e[f].f = 1;
		sort(e1 + 1, e1 + n + 1, cmp2);
		for (int i = 1; i <= m - 1; i++)
		{
			e[e1[i].id].f = 1;
		}
	}
	while (q--)
	{
		int op;
		cin >> op;

		if (op == 1)
		{

			int a, b;
			cin >> a >> b;
			e[a].sex = b;
			ll maxx = -1, f = -1;
			for (int i = 1; i <= n; i++)
			{
				e[i].f = 0;
				e1[i].sex = e[i].sex;
				e1[i].v = e[i].v;
				e1[i].id = e[i].id;
				e1[i].f = 0;
				if (e1[i].sex == 1)
				{
					maxx = max(maxx, e1[i].v);
					f = i;
				}
			}
			if (maxx == -1)
			{
				sort(e1 + 1, e1 + n + 1, cmp2);
				for (int i = 1; i <= m; i++)
				{
					e[e1[i].id].f = 1;
				}
			}
			else
			{
				e[f].f = 1;
				sort(e1 + 1, e1 + n + 1, cmp2);
				for (int i = 1; i <= m - 1; i++)
				{
					e[e1[i].id].f = 1;
				}
			}
		}
		else
		{
			int x;
			cin >> x;
			if (e[x].f)
				cout << 1 << endl;
			else
				cout << 0 << endl;
		}
	}*/
}
int main()
{
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	std::cout.tie(0);
	int t = 1;
	// cin >> t;
	while (t--)
		solve1();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3536kb

input:

5 0

output:

7703113

result:

ok 1 number(s): "7703113"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

5 1

output:

7840977

result:

ok 1 number(s): "7840977"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

2 1361955

output:

399

result:

ok 1 number(s): "399"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

4 207579012

output:

274740

result:

ok 1 number(s): "274740"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

8 628145516

output:

783389330

result:

ok 1 number(s): "783389330"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

16 376140462

output:

772072366

result:

ok 1 number(s): "772072366"

Test #7:

score: 0
Accepted
time: 1ms
memory: 3696kb

input:

32 883515280

output:

822906393

result:

ok 1 number(s): "822906393"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

64 186969585

output:

536948870

result:

ok 1 number(s): "536948870"

Test #9:

score: 0
Accepted
time: 1ms
memory: 3588kb

input:

128 762888635

output:

914896632

result:

ok 1 number(s): "914896632"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

256 326402539

output:

816864808

result:

ok 1 number(s): "816864808"

Test #11:

score: 0
Accepted
time: 1ms
memory: 3900kb

input:

512 98152102

output:

792934555

result:

ok 1 number(s): "792934555"

Test #12:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

1024 158176572

output:

187304261

result:

ok 1 number(s): "187304261"

Test #13:

score: 0
Accepted
time: 1ms
memory: 3696kb

input:

2048 61402883

output:

881629018

result:

ok 1 number(s): "881629018"

Test #14:

score: 0
Accepted
time: 0ms
memory: 4000kb

input:

4096 127860889

output:

926052991

result:

ok 1 number(s): "926052991"

Test #15:

score: 0
Accepted
time: 1ms
memory: 3872kb

input:

8192 9580638

output:

18767865

result:

ok 1 number(s): "18767865"

Test #16:

score: 0
Accepted
time: 3ms
memory: 4196kb

input:

16384 570870044

output:

676635475

result:

ok 1 number(s): "676635475"

Test #17:

score: 0
Accepted
time: 2ms
memory: 4296kb

input:

32768 646139319

output:

121314798

result:

ok 1 number(s): "121314798"

Test #18:

score: 0
Accepted
time: 11ms
memory: 4892kb

input:

65536 178509022

output:

518784793

result:

ok 1 number(s): "518784793"

Test #19:

score: 0
Accepted
time: 22ms
memory: 6460kb

input:

131072 484027666

output:

783563468

result:

ok 1 number(s): "783563468"

Test #20:

score: 0
Accepted
time: 42ms
memory: 9548kb

input:

262144 61263304

output:

560815556

result:

ok 1 number(s): "560815556"

Test #21:

score: 0
Accepted
time: 92ms
memory: 16668kb

input:

524288 841082555

output:

478037004

result:

ok 1 number(s): "478037004"

Test #22:

score: 0
Accepted
time: 187ms
memory: 29628kb

input:

1048576 558212774

output:

145045199

result:

ok 1 number(s): "145045199"

Test #23:

score: 0
Accepted
time: 398ms
memory: 53996kb

input:

2097152 940563715

output:

267114566

result:

ok 1 number(s): "267114566"

Test #24:

score: 0
Accepted
time: 859ms
memory: 102016kb

input:

4194304 26389620

output:

535216368

result:

ok 1 number(s): "535216368"

Test #25:

score: 0
Accepted
time: 1831ms
memory: 201496kb

input:

8388608 579113528

output:

926081338

result:

ok 1 number(s): "926081338"

Test #26:

score: 0
Accepted
time: 2182ms
memory: 258008kb

input:

10000000 496147999

output:

872799419

result:

ok 1 number(s): "872799419"

Test #27:

score: 0
Accepted
time: 2163ms
memory: 258068kb

input:

10000000 925801172

output:

676521567

result:

ok 1 number(s): "676521567"

Test #28:

score: 0
Accepted
time: 2173ms
memory: 258016kb

input:

10000000 837151740

output:

617759049

result:

ok 1 number(s): "617759049"

Test #29:

score: 0
Accepted
time: 2188ms
memory: 258064kb

input:

10000000 70301164

output:

413391579

result:

ok 1 number(s): "413391579"

Test #30:

score: 0
Accepted
time: 2178ms
memory: 258148kb

input:

10000000 656585275

output:

505441893

result:

ok 1 number(s): "505441893"

Test #31:

score: 0
Accepted
time: 2158ms
memory: 257980kb

input:

10000000 285845005

output:

465986348

result:

ok 1 number(s): "465986348"

Test #32:

score: 0
Accepted
time: 2218ms
memory: 258068kb

input:

10000000 902071050

output:

964328151

result:

ok 1 number(s): "964328151"