Submission #117718

#TimeUsernameProblemLanguageResultExecution timeMemory
117718zubecHorses (IOI15_horses)C++14
100 / 100
293 ms70904 KiB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;


const ll MOD = 1e9+7;
const int N = 500100;
const ll MAX = 2000000000;

int n;

int tmx[N*4], a[N], b[N];

struct node{
    int val, ans;
    ld sum, mx;
};

node combine(node lft, node rgt){
    node res;
    if (lft.mx < lft.sum+rgt.mx){
        res.mx = lft.sum+rgt.mx;
        res.ans = (lft.val*1ll*rgt.ans)%MOD;
    } else {
        res.mx = lft.mx;
        res.ans = lft.ans;
    }
    res.val = (lft.val*1ll*rgt.val)%MOD;
    res.sum = (lft.sum+rgt.sum);
    return res;
}

node t[N*4];

void build(int v, int l, int r){
    if (l == r){
        t[v].val = a[l];
        t[v].sum = log((ld)a[l]);
        t[v].mx = log((ld)a[l])+log((ld)b[l]);
        t[v].ans = a[l]*1ll*b[l]%MOD;
        return;
    }
    int mid = (l+r)>>1;
    build(v+v, l, mid);
    build(v+v+1, mid+1, r);
    t[v] = combine(t[v+v], t[v+v+1]);
}

void update(int v, int l, int r, int pos){
    if (l == r){
        t[v].val = a[l];
        t[v].sum = log((ld)a[l]);
        t[v].mx = log((ld)a[l])+log((ld)b[l]);
        t[v].ans = a[l]*1ll*b[l]%MOD;
        return;
    }
    int mid = (l+r)>>1;
    if (pos <= mid)
        update(v+v, l, mid, pos); else
        update(v+v+1, mid+1, r, pos);
    t[v] = combine(t[v+v], t[v+v+1]);
}

int query(){
    return t[1].ans;
}

int init(int N, int X[], int Y[]) {
    n = N;
    for (int i = 1; i <= n; i++){
        a[i] = X[i-1];
        b[i] = Y[i-1];
    }
    build(1, 1, n);
    return query();
}

int updateX(int pos, int val) {
    ++pos;
    a[pos] = val;
    update(1, 1, n, pos);
    return query();
}

int updateY(int pos, int val) {
    ++pos;
    b[pos] = val;
    update(1, 1, n, pos);
    return query();
}

/**

3
2 1 3
3 4 1
1
2 1 2



*/

Compilation message (stderr)

horses.cpp: In function 'node combine(node, node)':
horses.cpp:25:40: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         res.ans = (lft.val*1ll*rgt.ans)%MOD;
                   ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp:30:36: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     res.val = (lft.val*1ll*rgt.val)%MOD;
               ~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:42:33: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         t[v].ans = a[l]*1ll*b[l]%MOD;
                    ~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void update(int, int, int, int)':
horses.cpp:56:33: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         t[v].ans = a[l]*1ll*b[l]%MOD;
                    ~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:70:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 int init(int N, int X[], int Y[]) {
                                 ^
horses.cpp:9:11: note: shadowed declaration is here
 const int N = 500100;
           ^
#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...