Submission #592311

# Submission time Handle Problem Language Result Execution time Memory
592311 2022-07-08T22:41:34 Z stevancv Horses (IOI15_horses) C++14
100 / 100
382 ms 76804 KB
#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

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 time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 608 KB Output is correct
25 Correct 1 ms 476 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 444 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 67964 KB Output is correct
2 Correct 332 ms 76772 KB Output is correct
3 Correct 312 ms 67936 KB Output is correct
4 Correct 311 ms 71832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 444 KB Output is correct
25 Correct 1 ms 444 KB Output is correct
26 Correct 2 ms 444 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 484 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 122 ms 67192 KB Output is correct
34 Correct 114 ms 67188 KB Output is correct
35 Correct 109 ms 74120 KB Output is correct
36 Correct 135 ms 74100 KB Output is correct
37 Correct 103 ms 65452 KB Output is correct
38 Correct 97 ms 66272 KB Output is correct
39 Correct 99 ms 65280 KB Output is correct
40 Correct 131 ms 69460 KB Output is correct
41 Correct 104 ms 65304 KB Output is correct
42 Correct 97 ms 65420 KB Output is correct
43 Correct 94 ms 69580 KB Output is correct
44 Correct 105 ms 69624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 308 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 472 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 476 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 188 ms 68064 KB Output is correct
34 Correct 354 ms 76804 KB Output is correct
35 Correct 379 ms 67992 KB Output is correct
36 Correct 341 ms 71888 KB Output is correct
37 Correct 133 ms 67220 KB Output is correct
38 Correct 126 ms 67248 KB Output is correct
39 Correct 119 ms 74160 KB Output is correct
40 Correct 128 ms 74152 KB Output is correct
41 Correct 116 ms 65396 KB Output is correct
42 Correct 127 ms 66308 KB Output is correct
43 Correct 99 ms 65340 KB Output is correct
44 Correct 113 ms 69224 KB Output is correct
45 Correct 107 ms 65320 KB Output is correct
46 Correct 111 ms 65380 KB Output is correct
47 Correct 95 ms 69544 KB Output is correct
48 Correct 121 ms 69600 KB Output is correct
49 Correct 314 ms 69216 KB Output is correct
50 Correct 382 ms 69284 KB Output is correct
51 Correct 224 ms 76004 KB Output is correct
52 Correct 224 ms 75588 KB Output is correct
53 Correct 276 ms 67632 KB Output is correct
54 Correct 238 ms 68044 KB Output is correct
55 Correct 221 ms 66340 KB Output is correct
56 Correct 241 ms 71056 KB Output is correct
57 Correct 191 ms 67020 KB Output is correct
58 Correct 228 ms 67496 KB Output is correct
59 Correct 116 ms 69640 KB Output is correct