Submission #649424

#TimeUsernameProblemLanguageResultExecution timeMemory
649424ToroTNHorses (IOI15_horses)C++14
34 / 100
1588 ms19912 KiB
#include<bits/stdc++.h>
using namespace std;
#include "horses.h"
#define ll long long
ll n,x[500005],y[500005],z[500005],node,ans,md=1000000007;
int init(int N, int X[], int Y[]) {
	n=N;
	for(int i=1;i<=n;i++)
	{
		x[i]=X[i-1];
		y[i]=Y[i-1];
	}
	node=n;
	z[n]=y[n];
	for(int i=n-1;i>=1;i--)
	{
		if(x[i+1]>1e9||z[i+1]>1e9)
		{
			z[i]=1e18;
		}else
		{
			if(z[i+1]*x[i+1]<y[i])
			{
				node=i;
				z[i]=y[i];
			}else
			{
				z[i]=z[i+1]*x[i+1];
			}
		}
	}
	ans=1;
	for(int i=1;i<=node;i++)
	{
		ans*=x[i];
		ans%=md;
	}
	ans*=y[node];
	ans%=md;
	return ans;
}

int updateX(int pos, int val) {
	pos+=1;
	x[pos]=val;
	z[n]=y[n];
	node=n;
	for(int i=n-1;i>=1;i--)
	{
		if(x[i+1]>1e9||z[i+1]>1e9)
		{
			z[i]=1e18;
		}else
		{
			if(z[i+1]*x[i+1]<y[i])
			{
				node=i;
				z[i]=y[i];
			}else
			{
				z[i]=z[i+1]*x[i+1];
			}
		}
	}
	ans=1;
	for(int i=1;i<=node;i++)
	{
		ans*=x[i];
		ans%=md;
	}
	ans*=y[node];
	ans%=md;
	return ans;
}

int updateY(int pos, int val) {
	pos+=1;
	y[pos]=val;
	z[n]=y[n];
	node=n;
	for(int i=n-1;i>=1;i--)
	{
		if(x[i+1]>1e9||z[i+1]>1e9)
		{
			z[i]=1e18;
		}else
		{
			if(z[i+1]*x[i+1]<y[i])
			{
				node=i;
				z[i]=y[i];
			}else
			{
				z[i]=z[i+1]*x[i+1];
			}
		}
	}
	ans=1;
	for(int i=1;i<=node;i++)
	{
		ans*=x[i];
		ans%=md;
	}
	ans*=y[node];
	ans%=md;
	return ans;
}

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:15:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   15 |  for(int i=n-1;i>=1;i--)
      |            ~^~
horses.cpp:17:11: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   17 |   if(x[i+1]>1e9||z[i+1]>1e9)
      |      ~~~~~^
horses.cpp:17:23: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   17 |   if(x[i+1]>1e9||z[i+1]>1e9)
      |                  ~~~~~^
horses.cpp:40:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   40 |  return ans;
      |         ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:48:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   48 |  for(int i=n-1;i>=1;i--)
      |            ~^~
horses.cpp:50:11: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   50 |   if(x[i+1]>1e9||z[i+1]>1e9)
      |      ~~~~~^
horses.cpp:50:23: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   50 |   if(x[i+1]>1e9||z[i+1]>1e9)
      |                  ~~~~~^
horses.cpp:73:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   73 |  return ans;
      |         ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:81:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   81 |  for(int i=n-1;i>=1;i--)
      |            ~^~
horses.cpp:83:11: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   83 |   if(x[i+1]>1e9||z[i+1]>1e9)
      |      ~~~~~^
horses.cpp:83:23: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   83 |   if(x[i+1]>1e9||z[i+1]>1e9)
      |                  ~~~~~^
horses.cpp:106:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  106 |  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...