Submission #726546

# Submission time Handle Problem Language Result Execution time Memory
726546 2023-04-19T04:40:46 Z becaido Horses (IOI15_horses) C++17
100 / 100
253 ms 113600 KB
#ifndef WAIMAI
#include "horses.h"
#endif
#include <bits/stdc++.h>
using namespace std;

#define lpos pos*2
#define rpos pos*2+1

const int MOD = 1e9 + 7;
const int SIZE = 5e5 + 5;

struct Node {
    int pro = 1;
    long double sum = 0, mx = 0;
    Node operator + (const Node& rhs) const {
        Node re;
        re.pro = 1ll * pro * rhs.pro % MOD;
        re.sum = sum + rhs.sum;
        re.mx = max(mx, sum + rhs.mx);
        return re;
    }
};
vector<Node> node;

int n;
vector<int> y;

void upd(int pos, int l, int r, int p, int ty, int x) {
    if (l == r) {
        if (ty == 1) {
            node[pos].pro = x;
            node[pos].sum = log((long double) x);
        }
        if (ty == 2) {
            y[p] = x;
        }
        node[pos].mx = node[pos].sum + log((long double) y[p]);
        return;
    }
    int mid = (l + r) / 2;
    if (p <= mid) upd(lpos, l, mid, p, ty, x);
    else upd(rpos, mid + 1, r, p, ty, x);
    node[pos] = node[lpos] + node[rpos];
}

int que(int pos, int l, int r, int cur = 1) {
    if (l == r) return 1ll * cur * node[pos].pro % MOD * y[l] % MOD;
    int mid = (l + r) / 2;
    if (node[lpos].mx >= node[lpos].sum + node[rpos].mx) return que(lpos, l, mid, cur);
    else return que(rpos, mid + 1, r, 1ll * cur * node[lpos].pro % MOD);
}

void build(int pos, int l, int r, int X[], int Y[]) {
    if (l == r) {
        node[pos].pro = X[l];
        node[pos].sum = log((long double) X[l]);
        node[pos].mx = node[pos].sum + log((long double) (y[l] = Y[l]));
        return;
    }
    int mid = (l + r) / 2;
    build(lpos, l, mid, X, Y);
    build(rpos, mid + 1, r, X, Y);
    node[pos] = node[lpos] + node[rpos];
}

int init(int N, int X[], int Y[]) {
    n = N;
    node.resize(4 * n);
    y.resize(n);
    build(1, 0, n - 1, X, Y);
    return que(1, 0, n - 1);
}

int updateX(int pos, int val) {
    upd(1, 0, n - 1, pos, 1, val);
    return que(1, 0, n - 1);
}

int updateY(int pos, int val) {
    upd(1, 0, n - 1, pos, 2, val);
    return que(1, 0, n - 1);
}

Compilation message

horses.cpp: In member function 'Node Node::operator+(const Node&) const':
horses.cpp:18:38: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   18 |         re.pro = 1ll * pro * rhs.pro % MOD;
      |                  ~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int que(int, int, int, int)':
horses.cpp:48:63: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   48 |     if (l == r) return 1ll * cur * node[pos].pro % MOD * y[l] % MOD;
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:51:66: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   51 |     else return que(rpos, mid + 1, r, 1ll * cur * node[lpos].pro % MOD);
      |                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 224 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 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 2 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 440 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 180 ms 101148 KB Output is correct
2 Correct 253 ms 111160 KB Output is correct
3 Correct 253 ms 103976 KB Output is correct
4 Correct 238 ms 108776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 436 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 440 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 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 143 ms 104012 KB Output is correct
34 Correct 138 ms 104036 KB Output is correct
35 Correct 150 ms 111008 KB Output is correct
36 Correct 145 ms 110916 KB Output is correct
37 Correct 135 ms 102200 KB Output is correct
38 Correct 129 ms 103160 KB Output is correct
39 Correct 130 ms 102152 KB Output is correct
40 Correct 143 ms 106028 KB Output is correct
41 Correct 130 ms 102204 KB Output is correct
42 Correct 131 ms 102176 KB Output is correct
43 Correct 137 ms 106444 KB Output is correct
44 Correct 139 ms 106476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 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 468 KB Output is correct
27 Correct 2 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 1 ms 436 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 185 ms 104852 KB Output is correct
34 Correct 246 ms 113600 KB Output is correct
35 Correct 225 ms 104780 KB Output is correct
36 Correct 235 ms 108696 KB Output is correct
37 Correct 139 ms 104024 KB Output is correct
38 Correct 137 ms 104064 KB Output is correct
39 Correct 149 ms 111008 KB Output is correct
40 Correct 148 ms 110916 KB Output is correct
41 Correct 134 ms 102196 KB Output is correct
42 Correct 126 ms 103140 KB Output is correct
43 Correct 130 ms 102128 KB Output is correct
44 Correct 154 ms 106076 KB Output is correct
45 Correct 132 ms 102220 KB Output is correct
46 Correct 136 ms 102280 KB Output is correct
47 Correct 140 ms 106468 KB Output is correct
48 Correct 139 ms 106400 KB Output is correct
49 Correct 240 ms 106236 KB Output is correct
50 Correct 241 ms 106092 KB Output is correct
51 Correct 205 ms 112868 KB Output is correct
52 Correct 204 ms 112380 KB Output is correct
53 Correct 224 ms 104448 KB Output is correct
54 Correct 189 ms 105040 KB Output is correct
55 Correct 185 ms 103160 KB Output is correct
56 Correct 209 ms 107872 KB Output is correct
57 Correct 185 ms 103884 KB Output is correct
58 Correct 179 ms 104344 KB Output is correct
59 Correct 136 ms 106376 KB Output is correct