Submission #1004418

# Submission time Handle Problem Language Result Execution time Memory
1004418 2024-06-21T08:47:15 Z HasanV11010238 Horses (IOI15_horses) C++17
0 / 100
42 ms 58244 KB
#include "horses.h"
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int n;
vector<ll> x, y, tr;
void build(int v, int l, int r){
	if (l == r){
		tr[v] = x[l];
		return;
	}
	int mid = (l + r) / 2;
	build(v * 2, l, mid);
	build(v * 2 + 1, mid + 1, r);
	tr[v] = (tr[v * 2] * tr[v * 2 + 1]) % mod;
}
void update(int v, int l, int r, int pos, ll val){
	if (l == r){
		tr[v] = val;
	}
	else{
		int mid = (l + r) / 2;
		if (pos <= mid){
			update(v * 2, l, mid, pos, val);
		}
		else{
			update(v * 2 + 1, mid + 1, r, pos, val);
		}
		tr[v] = (tr[v * 2] * tr[v * 2 + 1]) % mod;
	}
}
ll query(int v, int l, int r, int ql, int qr){
	if (l > qr || r < ql){
		return 1;
	}
	else if (ql <= l && r <= qr){
		return tr[v];
	}
	int mid = (l + r) / 2;
	return (query(v * 2, l, mid, ql, qr) * query(v * 2 + 1, mid + 1, r, ql, qr)) % mod;
}
ll calc(){
	ll ti = 1, in = n - 1;
	for (int i = n - 1; i >= 0; i++){
		ti *= x[i];
		if (ti < mod){
			in--;
		}
		else{
			break;
		}
	}
	ll ma = 0;
	ll prmult = 1;
	for (int i = 0; i < n; i++){
		prmult *= x[i];
		ma = max(ma, 1ll * prmult * y[i]);
	}
	ll ext = 1;
	if (ti != 0){
		ext = query(1, 0, n - 1, 0, ti - 1);
	}
	return ((ma % mod) * ext) % mod;
}
int init(int N, int X[], int Y[]) {
	n = N;
	x.resize(N), y.resize(N), tr.assign(N * 4, 1);
	for (int i = 0; i < N; i++){
		x[i] = X[i];
		y[i] = Y[i];
	}
	build(1, 0, n - 1);
	return calc();
}

int updateX(int pos, int val){	
	x[pos] = val;
	update(1, 0, n - 1, pos, val);
	return calc();
}

int updateY(int pos, int val){
	y[pos] = val;
	return calc();
}

Compilation message

horses.cpp: In function 'long long int calc()':
horses.cpp:62:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   62 |   ext = query(1, 0, n - 1, 0, ti - 1);
      |                               ~~~^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:74:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   74 |  return calc();
      |         ~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:80:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   80 |  return calc();
      |         ~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:85:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   85 |  return calc();
      |         ~~~~^~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 388 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 42 ms 58244 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -