답안 #683070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683070 2023-01-17T16:01:34 Z ThegeekKnight16 말 (IOI15_horses) C++17
17 / 100
131 ms 92464 KB
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
typedef long long ll;
const int MAXN = 5e5 + 10;
const ll MOD = 1e9 + 7;
ll X[MAXN], Y[MAXN];
struct node
{
	ll k, x;
	ll val;
	ll lzK = 1, lzX = -1;

	node(ll KK = 0, ll XX = 0) {k = KK; x = XX; val = ((k * x) % MOD);}

	node operator+(node outro)
	{
		if (val > outro.val) return *this;
		return outro;
	}

} seg[4*MAXN];
int N;

ll exp(ll x, ll y)
{
	if (y == 0) return 1;
	if (y == 1) return x;
	if (y % 2) return ((x * exp(x, y-1)) % MOD);
	else
	{
		ll aux = exp(x, (y / 2));
		return ((aux * aux) % MOD);
	}
}

void refreshK(int pos, int ini, int fim)
{
	if (seg[pos].lzK == 1) return;
	seg[pos].k = ((seg[pos].k * seg[pos].lzK) % MOD);
	seg[pos].val = ((seg[pos].x * seg[pos].k) % MOD);

	if (ini != fim)
	{
		int e = 2*pos; int d = 2*pos + 1;
		seg[e].lzK *= seg[pos].lzK; seg[e].lzK %= MOD;
		seg[d].lzK *= seg[pos].lzK; seg[d].lzK %= MOD;
	}

	seg[pos].lzK = 1;
}

void refreshX(int pos, int ini, int fim)
{
	if (seg[pos].lzX == -1) return;
	seg[pos].x = seg[pos].lzX;
	seg[pos].val = ((seg[pos].k * seg[pos].x) % MOD);

	//Nesse caso, sempre temos que ini == fim

	seg[pos].lzX = -1;
}

void refresh(int pos, int ini, int fim)
{
	refreshK(pos, ini, fim);
	refreshX(pos, ini, fim);
}

void update(int pos, int ini, int fim, int p, int q, ll valK, ll valX)
{
	refresh(pos, ini, fim);
	if (q < ini || p > fim) return;
	if (p <= ini && fim <= q)
	{
		if (valX == -1) seg[pos].lzK = valK;
		else seg[pos].lzX = valX;
		refresh(pos, ini, fim);
		return;
	}
	int m = (ini + fim) >> 1;
	int e = 2*pos; int d = 2*pos + 1;
	update(e, ini, m, p, q, valK, valX);
	update(d, m+1, fim, p, q, valK, valX);
	seg[pos] = seg[e] + seg[d];
}

void build(int pos, int ini, int fim)
{
	if (ini == fim)
	{
		seg[pos] = node(X[ini], Y[ini]);
		return;
	}
	int m = ((ini + fim) >> 1);
	int e = 2*pos; int d = 2*pos + 1;
	build(e, ini, m);
	build(d, m+1, fim);
	seg[pos] = seg[e] + seg[d];
}

int init(int _N, int _X[], int _Y[])
{
	N = _N;
	X[0] = 1;
	for (int i = 1; i <= N; i++) {X[i] = (((long long)(_X[i-1]) * X[i-1]) % MOD); Y[i] = _Y[i-1];}
	build(1, 1, N);


	return (int)(seg[1].val);
}

int updateX(int id, int _val)
{
	id++;
	ll val = (long long)(_val);
	update(1, 1, N, id, N, ((exp(X[id], (MOD-2)) * val) % MOD), -1);
	X[id] = val;

	return (int)(seg[1].val);
}

int updateY(int id, int _val)
{
	id++;
	ll val = (long long)(_val);
	update(1, 1, N, id, id, 1, val);
	Y[id] = val;

	return (int)(seg[1].val);
}

Compilation message

horses.cpp: In function 'void refreshX(int, int, int)':
horses.cpp:53:28: warning: unused parameter 'ini' [-Wunused-parameter]
   53 | void refreshX(int pos, int ini, int fim)
      |                        ~~~~^~~
horses.cpp:53:37: warning: unused parameter 'fim' [-Wunused-parameter]
   53 | void refreshX(int pos, int ini, int fim)
      |                                 ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 78548 KB Output is correct
2 Correct 39 ms 78524 KB Output is correct
3 Correct 41 ms 78556 KB Output is correct
4 Correct 33 ms 78496 KB Output is correct
5 Correct 33 ms 78576 KB Output is correct
6 Correct 34 ms 78548 KB Output is correct
7 Correct 36 ms 78580 KB Output is correct
8 Correct 37 ms 78500 KB Output is correct
9 Correct 38 ms 78540 KB Output is correct
10 Correct 40 ms 78540 KB Output is correct
11 Correct 37 ms 78540 KB Output is correct
12 Correct 34 ms 78672 KB Output is correct
13 Correct 35 ms 78540 KB Output is correct
14 Correct 34 ms 78484 KB Output is correct
15 Correct 34 ms 78568 KB Output is correct
16 Correct 37 ms 78580 KB Output is correct
17 Correct 35 ms 78600 KB Output is correct
18 Correct 34 ms 78496 KB Output is correct
19 Correct 37 ms 78548 KB Output is correct
20 Correct 34 ms 78508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 78548 KB Output is correct
2 Correct 35 ms 78544 KB Output is correct
3 Correct 43 ms 78536 KB Output is correct
4 Correct 35 ms 78492 KB Output is correct
5 Correct 35 ms 78576 KB Output is correct
6 Correct 33 ms 78572 KB Output is correct
7 Correct 37 ms 78720 KB Output is correct
8 Correct 33 ms 78560 KB Output is correct
9 Correct 31 ms 78516 KB Output is correct
10 Correct 39 ms 78564 KB Output is correct
11 Correct 31 ms 78504 KB Output is correct
12 Correct 38 ms 78504 KB Output is correct
13 Correct 39 ms 78588 KB Output is correct
14 Correct 47 ms 78548 KB Output is correct
15 Correct 48 ms 78464 KB Output is correct
16 Correct 38 ms 78540 KB Output is correct
17 Correct 42 ms 78492 KB Output is correct
18 Correct 41 ms 78536 KB Output is correct
19 Correct 39 ms 78528 KB Output is correct
20 Correct 48 ms 78468 KB Output is correct
21 Incorrect 46 ms 78532 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 131 ms 92464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 78584 KB Output is correct
2 Correct 45 ms 78544 KB Output is correct
3 Correct 42 ms 78532 KB Output is correct
4 Correct 40 ms 78492 KB Output is correct
5 Correct 42 ms 78488 KB Output is correct
6 Correct 47 ms 78504 KB Output is correct
7 Correct 42 ms 78580 KB Output is correct
8 Correct 41 ms 78580 KB Output is correct
9 Correct 42 ms 78504 KB Output is correct
10 Correct 41 ms 78504 KB Output is correct
11 Correct 47 ms 78524 KB Output is correct
12 Correct 37 ms 78572 KB Output is correct
13 Correct 37 ms 78468 KB Output is correct
14 Correct 39 ms 78500 KB Output is correct
15 Correct 53 ms 78496 KB Output is correct
16 Correct 38 ms 78476 KB Output is correct
17 Correct 44 ms 78528 KB Output is correct
18 Correct 40 ms 78568 KB Output is correct
19 Correct 36 ms 78508 KB Output is correct
20 Correct 41 ms 78552 KB Output is correct
21 Incorrect 43 ms 78512 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 78548 KB Output is correct
2 Correct 35 ms 78540 KB Output is correct
3 Correct 37 ms 78560 KB Output is correct
4 Correct 40 ms 78524 KB Output is correct
5 Correct 39 ms 78548 KB Output is correct
6 Correct 51 ms 78532 KB Output is correct
7 Correct 44 ms 78468 KB Output is correct
8 Correct 38 ms 78584 KB Output is correct
9 Correct 41 ms 78576 KB Output is correct
10 Correct 40 ms 78532 KB Output is correct
11 Correct 36 ms 78564 KB Output is correct
12 Correct 46 ms 78524 KB Output is correct
13 Correct 45 ms 78460 KB Output is correct
14 Correct 37 ms 78540 KB Output is correct
15 Correct 38 ms 78584 KB Output is correct
16 Correct 36 ms 78576 KB Output is correct
17 Correct 41 ms 78480 KB Output is correct
18 Correct 42 ms 78548 KB Output is correct
19 Correct 45 ms 78576 KB Output is correct
20 Correct 45 ms 78584 KB Output is correct
21 Incorrect 40 ms 78584 KB Output isn't correct
22 Halted 0 ms 0 KB -