Submission #1117091

#TimeUsernameProblemLanguageResultExecution timeMemory
1117091ZflopHorses (IOI15_horses)C++14
17 / 100
1558 ms17488 KiB
#include <bits/stdc++.h>
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#define ll long long
const int NMAX = (int)1e5 * 6;
const ll MOD = (int)1e9 + 7;
int A[NMAX],B[NMAX],n;
ll over_two[NMAX],prod[NMAX];
ll POW(ll x,int p) {
	ll res = 1;
	while (p) {
		if (p % 2) 
			res = res * x % MOD;
		p /= 2;
		x = x * x % MOD;
		}
	return res;
	}
int init(int N, int X[], int Y[]) {
	prod[0] = 1;
	for (int i = 0; i < N;++i) {
		A[i] = X[i];
		B[i] = Y[i];
		over_two[i] = (X[i] >= 2);
		prod[i] = X[i];
		if (i) {
			over_two[i] += over_two[i - 1];
			prod[i] = prod[i] * prod[i - 1] % MOD;
			}
		}
	n = N;
	ll ans = (ll)X[0] * (ll)Y[0] % MOD;
	ll y_ans = Y[0];
	int i_ans = 0;
	ll x = X[0];
	for (int i = 1; i < N;++i) {
		x = x * (ll)X[i] % MOD;
		bool ok = false;
		if (over_two[i] - over_two[i_ans] > 30)
			ok = true;
		if (Y[i] * (prod[i] * POW(prod[i_ans],MOD - 2) % MOD) > y_ans)
			ok = true;
		if (ok) {
			y_ans = Y[i];
			i_ans = i;
			ans = x * Y[i] % MOD;
			}
		}
	return ans;
}

int updateX(int pos, int val) {	
	A[pos] = val;
	return init(n,A,B);
}

int updateY(int pos, int val) {
	B[pos] = val;
	return init(n,A,B);
}

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:52:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   52 |  return ans;
      |         ^~~
#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...