Submission #1291136

#TimeUsernameProblemLanguageResultExecution timeMemory
1291136kustov_vadim_533말 (IOI15_horses)C++20
17 / 100
369 ms103124 KiB
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <array>
#include <map>
#include <random>
#include <bitset>
#include <stack>
#include <deque>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <chrono>

using namespace std;

typedef long long ll;
typedef long double ld;

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

const int M = 1e9 + 7;

struct obj {
	int x = 1, y = 1;
	ld mx = 1, my = 1;
	obj() = default;
	obj(int a, int b) {
		x = a;
		y = (a * 1ll * b) % M;
		mx = a;
		my = a * b;
	}
};


obj merge(obj a, obj b) {
	obj c;
	c.x = (a.x * 1ll * b.x) % M;
	c.mx = a.mx * b.mx;

	if (a.my > a.mx * b.my) {
		c.y = a.y;
		c.my = a.my;
	}
	else {
		c.y = (a.x * 1ll * b.y) % M;
		c.my = a.mx * b.my;
	}
	return c;
}


vector<pair<int, int>> a;
vector<obj> tree;

void build(int v, int l, int r) {
	if (r - l == 1) {
		tree[v] = obj(a[l].first, a[l].second);
		return;
	}
	int m = (l + r) / 2;
	build(v * 2, l, m);
	build(v * 2 + 1, m, r);
	tree[v] = merge(tree[v * 2], tree[v * 2 + 1]);
}

int n;
int init(int N, int X[], int Y[]) {
	tree.resize(4 * N);
	n = N;

	a.resize(N);

	for (int i = 0; i < N; ++i) {
		a[i].first = X[i];
		a[i].second = Y[i];
	}
	build(1, 0, N);
	return tree[1].y;
}

void upd(int v, int l, int r, int qi) {
	if (r - l == 1) {
		tree[v] = obj(a[l].first, a[l].second);
		return;
	}
	int m = (l + r) / 2;
	if (qi < m) upd(v * 2, l, m, qi);
	else upd(v * 2 + 1, m, r, qi);
	tree[v] = merge(tree[v * 2], tree[v * 2 + 1]);
}

int updateX(int pos, int val) {
	a[pos].first = val;
	upd(1, 0, n, pos);
	return tree[1].y;
}


int updateY(int pos, int val) {
	a[pos].second = val;
	upd(1, 0, n, pos);
	return tree[1].y;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...