답안 #683626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683626 2023-01-18T23:55:09 Z ThegeekKnight16 말 (IOI15_horses) C++17
17 / 100
106 ms 95460 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], MX[MAXN];
struct node
{
	ll k, x;
	ll val;
	ll lzK = 1, lzX = -1;

	node(ll KK = 1, 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; seg[pos].lzK %= MOD;}
		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(MX[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;
	MX[0] = 1;
	for (int i = 1; i <= N; i++) {X[i] = _X[i-1]; MX[i] = ((X[i] * MX[i-1]) % MOD); Y[i] = _Y[i-1];}
	build(1, 1, N);

	// for (int i = 1; i <= N; i++) cerr << X[i] << '\n';

  	refresh(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;

  	refresh(1, 1, N);
	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;

  	refresh(1, 1, N);
	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 33 ms 78540 KB Output is correct
2 Correct 30 ms 78608 KB Output is correct
3 Correct 30 ms 78556 KB Output is correct
4 Correct 31 ms 78588 KB Output is correct
5 Correct 30 ms 78540 KB Output is correct
6 Correct 30 ms 78548 KB Output is correct
7 Correct 32 ms 78544 KB Output is correct
8 Correct 30 ms 78560 KB Output is correct
9 Correct 30 ms 78548 KB Output is correct
10 Correct 31 ms 78568 KB Output is correct
11 Correct 31 ms 78512 KB Output is correct
12 Correct 34 ms 78596 KB Output is correct
13 Correct 32 ms 78492 KB Output is correct
14 Correct 33 ms 78600 KB Output is correct
15 Correct 31 ms 78576 KB Output is correct
16 Correct 31 ms 78588 KB Output is correct
17 Correct 30 ms 78572 KB Output is correct
18 Correct 31 ms 78564 KB Output is correct
19 Correct 31 ms 78592 KB Output is correct
20 Correct 31 ms 78588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 78588 KB Output is correct
2 Correct 32 ms 78584 KB Output is correct
3 Correct 31 ms 78492 KB Output is correct
4 Correct 33 ms 78532 KB Output is correct
5 Correct 31 ms 78612 KB Output is correct
6 Correct 30 ms 78548 KB Output is correct
7 Correct 33 ms 78480 KB Output is correct
8 Correct 31 ms 78476 KB Output is correct
9 Correct 31 ms 78512 KB Output is correct
10 Correct 31 ms 78540 KB Output is correct
11 Correct 31 ms 78540 KB Output is correct
12 Correct 35 ms 78572 KB Output is correct
13 Correct 31 ms 78548 KB Output is correct
14 Correct 33 ms 78576 KB Output is correct
15 Correct 31 ms 78584 KB Output is correct
16 Correct 31 ms 78512 KB Output is correct
17 Correct 32 ms 78564 KB Output is correct
18 Correct 36 ms 78560 KB Output is correct
19 Correct 35 ms 78576 KB Output is correct
20 Correct 34 ms 78540 KB Output is correct
21 Incorrect 32 ms 78504 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 106 ms 95460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 78568 KB Output is correct
2 Correct 31 ms 78588 KB Output is correct
3 Correct 31 ms 78560 KB Output is correct
4 Correct 39 ms 78516 KB Output is correct
5 Correct 39 ms 78548 KB Output is correct
6 Correct 37 ms 78544 KB Output is correct
7 Correct 32 ms 78548 KB Output is correct
8 Correct 32 ms 78560 KB Output is correct
9 Correct 32 ms 78540 KB Output is correct
10 Correct 31 ms 78548 KB Output is correct
11 Correct 37 ms 78572 KB Output is correct
12 Correct 33 ms 78540 KB Output is correct
13 Correct 33 ms 78540 KB Output is correct
14 Correct 32 ms 78528 KB Output is correct
15 Correct 32 ms 78540 KB Output is correct
16 Correct 31 ms 78504 KB Output is correct
17 Correct 33 ms 78588 KB Output is correct
18 Correct 33 ms 78540 KB Output is correct
19 Correct 32 ms 78508 KB Output is correct
20 Correct 32 ms 78572 KB Output is correct
21 Incorrect 31 ms 78504 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 78524 KB Output is correct
2 Correct 33 ms 78540 KB Output is correct
3 Correct 32 ms 78544 KB Output is correct
4 Correct 31 ms 78548 KB Output is correct
5 Correct 32 ms 78540 KB Output is correct
6 Correct 33 ms 78500 KB Output is correct
7 Correct 32 ms 78540 KB Output is correct
8 Correct 32 ms 78476 KB Output is correct
9 Correct 34 ms 78528 KB Output is correct
10 Correct 34 ms 78576 KB Output is correct
11 Correct 32 ms 78512 KB Output is correct
12 Correct 31 ms 78588 KB Output is correct
13 Correct 31 ms 78504 KB Output is correct
14 Correct 32 ms 78548 KB Output is correct
15 Correct 33 ms 78588 KB Output is correct
16 Correct 31 ms 78584 KB Output is correct
17 Correct 33 ms 78568 KB Output is correct
18 Correct 31 ms 78564 KB Output is correct
19 Correct 31 ms 78592 KB Output is correct
20 Correct 31 ms 78548 KB Output is correct
21 Incorrect 31 ms 78508 KB Output isn't correct
22 Halted 0 ms 0 KB -