Submission #592311

#TimeUsernameProblemLanguageResultExecution timeMemory
592311stevancvHorses (IOI15_horses)C++14
100 / 100
382 ms76804 KiB
#include <bits/stdc++.h>
#include "horses.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 5e5 + 2;
const int mod = 1e9 + 7;
int Mul(int a, int b) {
    ll c = a; c *= b; c %= mod;
    return c;
}
int Exp(int a, int b) {
    int ans = 1;
    while (b > 0) {
        if (b & 1) ans = Mul(ans, a);
        a = Mul(a, a);
        b >>= 1;
    }
    return ans;
}
int Div(int a, int b) {
    return Mul(a, Exp(b, mod - 2));
}
struct Node {
    ld mx, lzymx;
    int f, lzyf;
}st[4 * N];
int n, x[N], y[N], prod[N];
double sum[N];
void Pull(int node) {
    if (st[2 * node].mx > st[2 * node + 1].mx) st[node] = st[2 * node];
    else st[node] = st[2 * node + 1];
}
void Build(int node, int l, int r) {
    if (l == r) {
        st[node].mx = sum[l] + log10l(y[l]); st[node].lzymx = 0;
        st[node].f = Mul(prod[l], y[l]); st[node].lzyf = 1;
        return;
    }
    int mid = l + r >> 1;
    Build(2 * node, l, mid);
    Build(2 * node + 1, mid + 1, r);
    Pull(node);
}
void Push(int node, int l, int r) {
    if (st[node].lzymx == 0) return;
    if (l < r) {
        st[2 * node].lzymx += st[node].lzymx;
        st[2 * node].lzyf = Mul(st[2 * node].lzyf, st[node].lzyf);
        st[2 * node + 1].lzymx += st[node].lzymx;
        st[2 * node + 1].lzyf = Mul(st[2 * node + 1].lzyf, st[node].lzyf);
    }
    st[node].mx += st[node].lzymx;
    st[node].f = Mul(st[node].f, st[node].lzyf);
    st[node].lzymx = 0;
    st[node].lzyf = 1;
}
int init(int N, int X[], int Y[]) {
    n = N;
    sum[0] = 0;
    prod[0] = 1;
    for (int i = 1; i <= n; i++) {
        x[i] = X[i - 1];
        y[i] = Y[i - 1];
        sum[i] = sum[i - 1] + log10l(x[i]);
        prod[i] = Mul(prod[i - 1], x[i]);
    }
    Build(1, 1, n);
    return st[1].f;
}
void Update(int node, int l, int r, int ql, int qr, ld x, int y) {
    Push(node, l, r);
    if (r < ql || qr < l) return;
    if (ql <= l && r <= qr) {
        st[node].lzymx += x;
        st[node].lzyf = Mul(st[node].lzyf, y);
        Push(node, l, r);
        return;
    }
    int mid = l + r >> 1;
    Update(2 * node, l, mid, ql, qr, x, y);
    Update(2 * node + 1, mid + 1, r, ql, qr, x, y);
    Pull(node);
}
int updateX(int pos, int val) {
    pos += 1;
    Update(1, 1, n, pos, n, log10l(val) - log10l(x[pos]), Div(val, x[pos]));
    x[pos] = val;
    return st[1].f;
}
int updateY(int pos, int val) {
    pos += 1;
    Update(1, 1, n, pos, pos, log10l(val) - log10l(y[pos]), Div(val, y[pos]));
    y[pos] = val;
    return st[1].f;
}

Compilation message (stderr)

horses.cpp: In function 'int Mul(int, int)':
horses.cpp:14:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   14 |     return c;
      |            ^
horses.cpp: In function 'void Build(int, int, int)':
horses.cpp:44:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |     int mid = l + r >> 1;
      |               ~~^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:62:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   62 | int init(int N, int X[], int Y[]) {
      |          ~~~~^
horses.cpp:10:11: note: shadowed declaration is here
   10 | const int N = 5e5 + 2;
      |           ^
horses.cpp:69:29: warning: conversion from 'long double' to 'double' may change value [-Wfloat-conversion]
   69 |         sum[i] = sum[i - 1] + log10l(x[i]);
      |                  ~~~~~~~~~~~^~~~~~~~~~~~~~
horses.cpp: In function 'void Update(int, int, int, int, int, long double, int)':
horses.cpp:75:63: warning: declaration of 'y' shadows a global declaration [-Wshadow]
   75 | void Update(int node, int l, int r, int ql, int qr, ld x, int y) {
      |                                                           ~~~~^
horses.cpp:32:14: note: shadowed declaration is here
   32 | int n, x[N], y[N], prod[N];
      |              ^
horses.cpp:75:56: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   75 | void Update(int node, int l, int r, int ql, int qr, ld x, int y) {
      |                                                        ^
horses.cpp:32:8: note: shadowed declaration is here
   32 | int n, x[N], y[N], prod[N];
      |        ^
horses.cpp:84:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   84 |     int mid = l + r >> 1;
      |               ~~^~~
#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...