Submission #387178

# Submission time Handle Problem Language Result Execution time Memory
387178 2021-04-08T06:03:42 Z ParsaAlizadeh Horses (IOI15_horses) C++17
100 / 100
290 ms 73456 KB
#include  <bits/stdc++.h>
#include "horses.h"
using namespace std;

#define lc (id << 1)
#define rc (lc | 1)

typedef long long ll;

struct Node {
    int ind;
    ll v1 = 1, v2 = 1;
};

int const MOD = 1e9 + 7;

int n;
vector<int> A, B;
vector<Node> mxseg;
vector<ll> valseg;

inline ll mul(ll x, ll y) {
    return x * y > MOD ? 0 : x * y;
}

Node mxmerge(Node const& l, Node const& r) {
    Node res;
    ll val = mul(l.v2, mul(r.v1, B[r.ind]));
    if (val == 0 || val >= B[l.ind]) {
        res.ind = r.ind;
        res.v1 = mul(l.v1, mul(l.v2, r.v1));
        res.v2 = r.v2;
    }
    else {
        res.ind = l.ind;
        res.v1 = l.v1;
        res.v2 = mul(l.v2, mul(r.v1, r.v2));
    }
    return res;
}

void mxbuild(int id, int l, int r, int ind) {
    if (ind != -1 && (ind < l || r <= ind))
        return;
    if (r - l == 1) {
        mxseg[id].ind = l;
        mxseg[id].v1 = A[l];
        return;
    }
    int mid = (l + r) >> 1;
    mxbuild(lc, l, mid, ind);
    mxbuild(rc, mid, r, ind);
    mxseg[id] = mxmerge(mxseg[lc], mxseg[rc]);
}

void valbuild(int id, int l, int r, int ind) {
    if (ind != -1 && (ind < l || r <= ind))
        return;
    if (r - l == 1) {
        valseg[id] = A[l];
        return;
    }
    int mid = (l + r) >> 1;
    valbuild(lc, l, mid, ind);
    valbuild(rc, mid, r, ind);
    valseg[id] = valseg[lc] * valseg[rc] % MOD;
}

ll valget(int id, int l, int r, int qr) {
    if (r <= qr)
        return valseg[id];
    if (qr <= l)
        return 1;
    int mid = (l + r) >> 1;
    return valget(lc, l, mid, qr) * valget(rc, mid, r, qr) % MOD;
}

int query() {
    int ind = mxseg[1].ind;
    return valget(1, 0, n, ind + 1) * B[ind] % MOD;
}

int init(int N, int X[], int Y[]) {
    n = N;
    A.assign(X, X + n);
    B.assign(Y, Y + n);
    mxseg.resize((n + 1) << 2);
    valseg.resize((n + 1) << 2);
    mxbuild(1, 0, n, -1);
    valbuild(1, 0, n, -1);
    return query();
}

int updateX(int pos, int val) {
    A[pos] = val;
    mxbuild(1, 0, n, pos);
    valbuild(1, 0, n, pos);
    return query();
}

int updateY(int pos, int val) {
    B[pos] = val;
    mxbuild(1, 0, n, pos);
    valbuild(1, 0, n, pos);
    return query();
}

Compilation message

horses.cpp: In function 'int query()':
horses.cpp:80:46: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   80 |     return valget(1, 0, n, ind + 1) * B[ind] % MOD;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 3 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 72556 KB Output is correct
2 Correct 289 ms 72172 KB Output is correct
3 Correct 260 ms 72684 KB Output is correct
4 Correct 279 ms 72300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 516 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 106 ms 71660 KB Output is correct
34 Correct 104 ms 71660 KB Output is correct
35 Correct 118 ms 71276 KB Output is correct
36 Correct 115 ms 71328 KB Output is correct
37 Correct 92 ms 71660 KB Output is correct
38 Correct 94 ms 71660 KB Output is correct
39 Correct 83 ms 71532 KB Output is correct
40 Correct 97 ms 71404 KB Output is correct
41 Correct 83 ms 71660 KB Output is correct
42 Correct 87 ms 71660 KB Output is correct
43 Correct 92 ms 71276 KB Output is correct
44 Correct 90 ms 71276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 3 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 195 ms 72556 KB Output is correct
34 Correct 290 ms 72172 KB Output is correct
35 Correct 257 ms 72556 KB Output is correct
36 Correct 279 ms 72812 KB Output is correct
37 Correct 105 ms 72428 KB Output is correct
38 Correct 104 ms 72428 KB Output is correct
39 Correct 121 ms 71532 KB Output is correct
40 Correct 116 ms 71660 KB Output is correct
41 Correct 92 ms 72428 KB Output is correct
42 Correct 91 ms 72556 KB Output is correct
43 Correct 83 ms 72300 KB Output is correct
44 Correct 98 ms 71788 KB Output is correct
45 Correct 83 ms 72428 KB Output is correct
46 Correct 86 ms 72440 KB Output is correct
47 Correct 92 ms 71660 KB Output is correct
48 Correct 90 ms 71660 KB Output is correct
49 Correct 289 ms 72684 KB Output is correct
50 Correct 271 ms 72684 KB Output is correct
51 Correct 234 ms 72684 KB Output is correct
52 Correct 190 ms 72428 KB Output is correct
53 Correct 273 ms 73280 KB Output is correct
54 Correct 211 ms 73196 KB Output is correct
55 Correct 164 ms 72684 KB Output is correct
56 Correct 190 ms 72684 KB Output is correct
57 Correct 175 ms 73456 KB Output is correct
58 Correct 191 ms 73452 KB Output is correct
59 Correct 91 ms 71660 KB Output is correct