Submission #683067

# Submission time Handle Problem Language Result Execution time Memory
683067 2023-01-17T15:56:52 Z ThegeekKnight16 Horses (IOI15_horses) C++17
17 / 100
111 ms 95148 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 K = 0, ll X = 0) {k = K; x = X; 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
	{
		int 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, int valK, int 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++;
	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++;
	update(1, 1, N, id, id, 1, val);
	Y[id] = val;

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

Compilation message

horses.cpp: In constructor 'node::node(ll, ll)':
horses.cpp:14:20: warning: declaration of 'X' shadows a global declaration [-Wshadow]
   14 |  node(ll K = 0, ll X = 0) {k = K; x = X; val = ((k * x) % MOD);}
      |                 ~~~^~~~~
horses.cpp:7:4: note: shadowed declaration is here
    7 | ll X[MAXN], Y[MAXN];
      |    ^
horses.cpp: In constructor 'node::node(ll, ll)':
horses.cpp:14:20: warning: declaration of 'X' shadows a global declaration [-Wshadow]
   14 |  node(ll K = 0, ll X = 0) {k = K; x = X; val = ((k * x) % MOD);}
      |                 ~~~^~~~~
horses.cpp:7:4: note: shadowed declaration is here
    7 | ll X[MAXN], Y[MAXN];
      |    ^
horses.cpp: In constructor 'node::node(ll, ll)':
horses.cpp:14:20: warning: declaration of 'X' shadows a global declaration [-Wshadow]
   14 |  node(ll K = 0, ll X = 0) {k = K; x = X; val = ((k * x) % MOD);}
      |                 ~~~^~~~~
horses.cpp:7:4: note: shadowed declaration is here
    7 | ll X[MAXN], Y[MAXN];
      |    ^
horses.cpp: In function 'll exp(ll, ll)':
horses.cpp:32:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   32 |   int aux = exp(x, (y / 2));
      |             ~~~^~~~~~~~~~~~
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)
      |                                 ~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:116:54: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  116 |  update(1, 1, N, id, N, ((exp(X[id], (MOD-2)) * val) % MOD), -1);
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 31 ms 78536 KB Output is correct
2 Correct 31 ms 78476 KB Output is correct
3 Correct 31 ms 78468 KB Output is correct
4 Correct 33 ms 78576 KB Output is correct
5 Correct 32 ms 78608 KB Output is correct
6 Correct 30 ms 78540 KB Output is correct
7 Correct 32 ms 78572 KB Output is correct
8 Correct 31 ms 78560 KB Output is correct
9 Correct 31 ms 78572 KB Output is correct
10 Correct 30 ms 78564 KB Output is correct
11 Correct 31 ms 78580 KB Output is correct
12 Correct 34 ms 78568 KB Output is correct
13 Correct 31 ms 78552 KB Output is correct
14 Correct 37 ms 78468 KB Output is correct
15 Correct 33 ms 78564 KB Output is correct
16 Correct 32 ms 78572 KB Output is correct
17 Correct 31 ms 78540 KB Output is correct
18 Correct 32 ms 78540 KB Output is correct
19 Correct 31 ms 78572 KB Output is correct
20 Correct 35 ms 78548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 78540 KB Output is correct
2 Correct 30 ms 78568 KB Output is correct
3 Correct 34 ms 78516 KB Output is correct
4 Correct 31 ms 78532 KB Output is correct
5 Correct 32 ms 78472 KB Output is correct
6 Correct 36 ms 78560 KB Output is correct
7 Correct 33 ms 78548 KB Output is correct
8 Correct 31 ms 78600 KB Output is correct
9 Correct 32 ms 78576 KB Output is correct
10 Correct 37 ms 78540 KB Output is correct
11 Correct 32 ms 78576 KB Output is correct
12 Correct 37 ms 78540 KB Output is correct
13 Correct 32 ms 78548 KB Output is correct
14 Correct 32 ms 78524 KB Output is correct
15 Correct 32 ms 78584 KB Output is correct
16 Correct 33 ms 78556 KB Output is correct
17 Correct 33 ms 78548 KB Output is correct
18 Correct 32 ms 78512 KB Output is correct
19 Correct 34 ms 78572 KB Output is correct
20 Correct 32 ms 78544 KB Output is correct
21 Incorrect 35 ms 78468 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 95148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 78536 KB Output is correct
2 Correct 33 ms 78532 KB Output is correct
3 Correct 31 ms 78548 KB Output is correct
4 Correct 32 ms 78504 KB Output is correct
5 Correct 32 ms 78508 KB Output is correct
6 Correct 35 ms 78472 KB Output is correct
7 Correct 33 ms 78624 KB Output is correct
8 Correct 32 ms 78468 KB Output is correct
9 Correct 32 ms 78584 KB Output is correct
10 Correct 32 ms 78568 KB Output is correct
11 Correct 36 ms 78572 KB Output is correct
12 Correct 32 ms 78508 KB Output is correct
13 Correct 39 ms 78544 KB Output is correct
14 Correct 34 ms 78604 KB Output is correct
15 Correct 32 ms 78572 KB Output is correct
16 Correct 33 ms 78576 KB Output is correct
17 Correct 32 ms 78484 KB Output is correct
18 Correct 37 ms 78652 KB Output is correct
19 Correct 32 ms 78548 KB Output is correct
20 Correct 32 ms 78496 KB Output is correct
21 Incorrect 32 ms 78484 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 78572 KB Output is correct
2 Correct 32 ms 78468 KB Output is correct
3 Correct 34 ms 78560 KB Output is correct
4 Correct 34 ms 78576 KB Output is correct
5 Correct 31 ms 78524 KB Output is correct
6 Correct 32 ms 78496 KB Output is correct
7 Correct 32 ms 78488 KB Output is correct
8 Correct 33 ms 78456 KB Output is correct
9 Correct 32 ms 78540 KB Output is correct
10 Correct 31 ms 78488 KB Output is correct
11 Correct 33 ms 78536 KB Output is correct
12 Correct 31 ms 78576 KB Output is correct
13 Correct 32 ms 78544 KB Output is correct
14 Correct 32 ms 78680 KB Output is correct
15 Correct 33 ms 78516 KB Output is correct
16 Correct 33 ms 78684 KB Output is correct
17 Correct 32 ms 78568 KB Output is correct
18 Correct 33 ms 78476 KB Output is correct
19 Correct 34 ms 78480 KB Output is correct
20 Correct 32 ms 78516 KB Output is correct
21 Incorrect 31 ms 78616 KB Output isn't correct
22 Halted 0 ms 0 KB -