Submission #64804

# Submission time Handle Problem Language Result Execution time Memory
64804 2018-08-05T17:30:34 Z Kubalionzzale Horses (IOI15_horses) C++14
Compilation error
0 ms 0 KB
#include "horses.h"
#include <algorithm>

int n;
long long int mod = 1e9 + 7;

long long int product[2000010] = { 0 };
long long int mediumProduct[2000010] = { 0 };
int curBest[2000010] = { 0 };
int x[500010], y[500010];

int getBetter(int one, int two)
{
    long long int producted;

    producted = queryMediumProduct(0, n - 1, one + 1, two, 0);

    if (producted == 0)
        return two;
    else
    {
        long double oneans = y[one];
        long double twoans = producted * y[two];

        if (oneans > twoans)
            return one;
        else
            return two;
    }
}

void constructProduct(int low, int high, int pos)
{
    if (low == high)
    {
        product[pos] = x[low] * 1LL;
        mediumProduct[pos] = x[low] * 1LL;
        curBest[pos] = low;
        return;
    }

    int mid = low + (high - low) / 2;

    constructProduct(low, mid, pos * 2 + 1);
    constructProduct(mid + 1, high, pos * 2 + 2);

    product[pos] = (product[pos * 2 + 1] * product[pos * 2 + 2]) % mod;
    curBest[pos] = getBetter(curBest[pos * 2 + 1], curBest[pos * 2 + 2]);
    long long int val = mediumProduct[pos * 2 + 1] * mediumProduct[pos * 2 + 2];

    if (val > 1e9)
        mediumProduct[pos] = 0;
    else
        mediumProduct[pos] = val;
}

void updateProduct(int qpoint, int low, int high, int pos)
{
    if (qpoint < low || qpoint > high)
        return;

    if (low == high)
    {
        product[pos] = x[low] * 1LL;
        mediumProduct[pos] = x[low] * 1LL;
        curBest[pos] = low;
        return;
    }

    int mid = low + (high - low) / 2;

    updateProduct(qpoint, low, mid, pos * 2 + 1);
    updateProduct(qpoint, mid + 1, high, pos * 2 + 2);

    product[pos] = (product[pos * 2 + 1] * product[pos * 2 + 2]) % mod;
    curBest[pos] = getBetter(curBest[pos * 2 + 1], curBest[pos * 2 + 2]);

    long long int val = mediumProduct[pos * 2 + 1] * mediumProduct[pos * 2 + 2];

    if (val > 1e9)
        mediumProduct[pos] = 0;
    else
        mediumProduct[pos] = val;
}

long long int queryProduct(int low, int high, int qlow, int qhigh, int pos)
{
    if (high < qlow || low > qhigh)
        return 1;

    if (qlow <= low && high <= qhigh)
    {
        return product[pos];
    }

    int mid = low + (high - low) / 2;

    return ((queryProduct(low, mid, qlow, qhigh, pos * 2 + 1) * queryProduct(mid + 1, high, qlow, qhigh, pos * 2 + 2)) % mod);
}

long long int queryMediumProduct(int low, int high, int qlow, int qhigh, int pos)
{
    if (high < qlow || low > qhigh)
        return 1;

    if (qlow <= low && high <= qhigh)
    {
        return mediumProduct[pos];
    }

    int mid = low + (high - low) / 2;

    long long int val1 = queryMediumProduct(low, mid, qlow, qhigh, pos * 2 + 1);
    long long int val2 = queryMediumProduct(mid + 1, high, qlow, qhigh, pos * 2 + 2);

    if (val1 * val2 > 1e9)
        return 0;
    else
        return val1 * val2;
}

void updateAnswer(int qpoint, int low, int high, int pos)
{
    if (qpoint < low || qpoint > high)
        return;

    if (low == high)
    {
        curBest[pos] = low;
        return;
    }

    int mid = low + (high - low) / 2;

    updateAnswer(qpoint, low, mid, pos * 2 + 1);
    updateAnswer(qpoint, mid + 1, high, pos * 2 + 2);

    curBest[pos] = getBetter(curBest[pos * 2 + 1], curBest[pos * 2 + 2]);
}

int init(int N, int inx[], int iny[]) {
    n = N;

    for (int i = 0; i < n; ++i)
    {
        x[i] = inx[i];
        y[i] = iny[i];
    }

    constructProduct(0, n - 1, 0);

    return (queryProduct(0, n - 1, 0, curBest[0], 0) * y[curBest[0]]) % mod;
}

int updateX(int position, int val) {
    x[position] = val;

    updateProduct(position, 0, n - 1, 0);

	return (queryProduct(0, n - 1, 0, curBest[0], 0) * y[curBest[0]]) % mod;
}

int updateY(int position, int val) {
    y[position] = val;
    updateAnswer(position, 0, n - 1, 0);

	return (queryProduct(0, n - 1, 0, curBest[0], 0) * y[curBest[0]]) % mod;
}

Compilation message

horses.cpp: In function 'int getBetter(int, int)':
horses.cpp:16:17: error: 'queryMediumProduct' was not declared in this scope
     producted = queryMediumProduct(0, n - 1, one + 1, two, 0);
                 ^~~~~~~~~~~~~~~~~~
horses.cpp:16:17: note: suggested alternative: 'mediumProduct'
     producted = queryMediumProduct(0, n - 1, one + 1, two, 0);
                 ^~~~~~~~~~~~~~~~~~
                 mediumProduct
horses.cpp: In function 'void constructProduct(int, int, int)':
horses.cpp:51:15: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
     if (val > 1e9)
               ^~~
horses.cpp: In function 'void updateProduct(int, int, int, int)':
horses.cpp:80:15: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
     if (val > 1e9)
               ^~~
horses.cpp: In function 'long long int queryMediumProduct(int, int, int, int, int)':
horses.cpp:116:14: warning: conversion to 'double' from 'long long int' may alter its value [-Wconversion]
     if (val1 * val2 > 1e9)
         ~~~~~^~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:152:71: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return (queryProduct(0, n - 1, 0, curBest[0], 0) * y[curBest[0]]) % mod;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:160:68: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return (queryProduct(0, n - 1, 0, curBest[0], 0) * y[curBest[0]]) % mod;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:167:68: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return (queryProduct(0, n - 1, 0, curBest[0], 0) * y[curBest[0]]) % mod;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~