Submission #819898

#TimeUsernameProblemLanguageResultExecution timeMemory
819898KerimHorses (IOI15_horses)C++17
34 / 100
1568 ms27704 KiB
#include "horses.h"
#include "bits/stdc++.h"
using namespace std;

const int MAXN = 5e5+5;
const int INF = 1e9+7;
int a[MAXN], b[MAXN], n;

struct node{
	int mul, mod;
	node(){
		mul = mod = 0;
	}
	node(int _mul, int _mod){
		mul = _mul;
		mod = _mod;
	}
}s[MAXN<<2];

node merge(node x, node y){
	node z = node(0, 0);
	z.mul = min(x.mul * 1LL * y.mul, INF * 1LL);
	z.mod = (x.mod * 1LL * y.mod) % INF;
	return z;
}

void upd(int p, int nd, int x, int y){
	if (x == y){
		s[nd].mul = s[nd].mod = a[p];
		return;
	}
	int mid = (x+y) >> 1;
	if (p <= mid)
		upd(p, nd<<1, x, mid);
	else	
		upd(p, nd<<1|1, mid+1, y);
	s[nd] = merge(s[nd<<1], s[nd<<1|1]);
}

node get(int l, int r, int nd, int x, int y){
	if (l > y or x > r)
		return node(1, 1);
	if (l <= x and y <= r)
		return s[nd];
	int mid = (x+y) >> 1;
	return merge(get(l, r, nd<<1, x, mid), get(l, r, nd<<1|1, mid+1, y));
}

int cmp(int x, int y){
	if (x > y)
		swap(x, y);
	return b[x] < b[y] * 1LL * get(x+1, y, 1, 0, n-1).mul;
}

int ask(){
	int best_pos = 0;
	for (int i = 1; i < n; i++)
		if (cmp(best_pos, i))
			best_pos = i;
	return (get(0, best_pos, 1, 0, n-1).mod * 1LL* b[best_pos]) % INF;
}
int init(int N, int X[], int Y[]) {
	n = N;
	for (int i = 0; i < n; i++){
		a[i] = X[i], b[i] = Y[i];
		upd(i, 1, 0, n-1);
	}
	return ask();
}

int updateX(int pos, int val) {	
	a[pos] = val;
	upd(pos, 1, 0, n-1);
	return ask();
}

int updateY(int pos, int val) {
	b[pos] = val;
	return ask();
}

Compilation message (stderr)

horses.cpp: In function 'node merge(node, node)':
horses.cpp:22:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   22 |  z.mul = min(x.mul * 1LL * y.mul, INF * 1LL);
      |          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:23:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   23 |  z.mod = (x.mod * 1LL * y.mod) % INF;
      |          ~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int ask()':
horses.cpp:60:62: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   60 |  return (get(0, best_pos, 1, 0, n-1).mod * 1LL* b[best_pos]) % INF;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
#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...