Submission #234552

# Submission time Handle Problem Language Result Execution time Memory
234552 2020-05-24T13:01:04 Z triple_fault Horses (IOI15_horses) C++14
100 / 100
831 ms 72824 KB
#include "horses.h"
#include <vector>
#include <algorithm>
#include <cstdio>

#define MAX 500000
#define ll long long

#define lft 2 * v
#define rht (2 * v) + 1

ll MOD = 1e9 + 7;
using namespace std;

ll n;
ll y[MAX];
ll x[MAX];

vector<ll> seg_prod(MAX * 4);
vector<ll> seg_prod_max(MAX * 4);
vector<ll> seg_y(MAX * 4); 

void build(ll v, ll tl, ll tr) {
    if (tl == tr) {
        seg_prod[v] = x[tl];
        seg_prod_max[v] = x[tl];
    } else {
        ll mid = (tl + tr) / 2;
        build(lft, tl, mid);
        build(rht, mid + 1, tr);

        seg_prod[v] = (seg_prod[lft] * seg_prod[rht]) % MOD;
        seg_prod_max[v] = min(seg_prod_max[lft] * seg_prod_max[rht], MOD);
    }
}

void update(ll v, ll idx, ll tl, ll tr) {
    if (tl > tr) return;
    if (tl == idx && tl == tr) {
        seg_prod[v] = x[idx];
        seg_prod_max[v] = x[idx];
        return;
    }
    ll mid = (tl + tr) / 2;
    if (idx > mid) update(rht, idx, mid + 1, tr);
    else update(lft, idx, tl, mid);

    seg_prod[v] = (seg_prod[lft] * seg_prod[rht]) % MOD;
    seg_prod_max[v] = min(seg_prod_max[lft] * seg_prod_max[rht], MOD);
}

ll query1(ll v, ll l, ll r, ll tl, ll tr) {
    if (l > r) return 1;
    if (tl == l && tr == r) return seg_prod[v];

    ll mid = (tl + tr) / 2;
    ll ret = query1(lft, l, min(r, mid), tl, mid) *
        query1(rht, max(l, mid + 1), r, mid + 1, tr);
    return ret % MOD;
}

ll query2(ll v, ll l, ll r, ll tl, ll tr) {
    if (l > r) return 1;
    if (tl == l && tr == r) return seg_prod_max[v]; 

    ll mid = (tl + tr) / 2;
    ll ret = query2(lft, l, min(r, mid), tl, mid) *
        query2(rht, max(l, mid + 1), r, mid + 1, tr);
    return min(MOD, ret);
}

void build_y(ll v, ll tl, ll tr) {
    if (tl == tr) seg_y[v] = tl;
    else {
        ll mid = (tl + tr) / 2;
        build_y(lft, tl, mid);
        build_y(rht, mid + 1, tr);

        ll left = seg_y[lft];
        ll right = seg_y[rht];

        ll p1 = y[left]; ll p2 = query2(1, left + 1, right, 0, n - 1) * y[right];
        if (p2 > p1) seg_y[v] = right;
        else seg_y[v] = left;
    }
}

void update_y(ll v, ll idx, ll tl, ll tr) {
    if (tl > tr) return;
    if (tl == tr && tl == idx) {
        seg_y[v] = idx;
        return;
    }
    ll mid = (tl + tr) / 2;
    if (idx > mid) update_y(rht, idx, mid + 1, tr);
    else update_y(lft, idx, tl, mid);
    ll left = seg_y[lft];
    ll right = seg_y[rht];

    ll p1 = y[left]; ll p2 = query2(1, left + 1, right, 0, n - 1) * y[right];
    if (p2 > p1) seg_y[v] = right;
    else seg_y[v] = left;
}

ll find() {
    return (query1(1, 0, seg_y[1], 0, n - 1) * y[seg_y[1]]) % MOD;
}

int init(int N, int X[], int Y[]) {
    n = (ll)N;
    for (ll i = 0; i < n; ++i) y[i] = (ll)Y[i];
    for (ll i = 0; i < n; ++i) x[i] = (ll)X[i];

    build(1, 0, n - 1);
    build_y(1, 0, n - 1);
	return find();
}

int updateX(int pos, int val) {	
    x[pos] = val;
    update(1, pos, 0, n - 1);
    update_y(1, pos, 0, n - 1);
    return find();
}

int updateY(int pos, int val) {
    y[pos] = val;
    update_y(1, pos, 0, n - 1);
    return find();
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:116:13: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return find();
         ~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:123:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return find();
            ~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:129:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return find();
            ~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47360 KB Output is correct
2 Correct 27 ms 47232 KB Output is correct
3 Correct 27 ms 47352 KB Output is correct
4 Correct 27 ms 47224 KB Output is correct
5 Correct 27 ms 47360 KB Output is correct
6 Correct 27 ms 47360 KB Output is correct
7 Correct 28 ms 47360 KB Output is correct
8 Correct 27 ms 47232 KB Output is correct
9 Correct 27 ms 47360 KB Output is correct
10 Correct 28 ms 47352 KB Output is correct
11 Correct 27 ms 47352 KB Output is correct
12 Correct 28 ms 47232 KB Output is correct
13 Correct 27 ms 47352 KB Output is correct
14 Correct 27 ms 47232 KB Output is correct
15 Correct 27 ms 47360 KB Output is correct
16 Correct 27 ms 47232 KB Output is correct
17 Correct 27 ms 47360 KB Output is correct
18 Correct 28 ms 47232 KB Output is correct
19 Correct 28 ms 47488 KB Output is correct
20 Correct 27 ms 47232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47352 KB Output is correct
2 Correct 27 ms 47360 KB Output is correct
3 Correct 27 ms 47232 KB Output is correct
4 Correct 27 ms 47360 KB Output is correct
5 Correct 28 ms 47360 KB Output is correct
6 Correct 27 ms 47360 KB Output is correct
7 Correct 28 ms 47232 KB Output is correct
8 Correct 29 ms 47232 KB Output is correct
9 Correct 27 ms 47360 KB Output is correct
10 Correct 28 ms 47360 KB Output is correct
11 Correct 27 ms 47360 KB Output is correct
12 Correct 27 ms 47232 KB Output is correct
13 Correct 29 ms 47352 KB Output is correct
14 Correct 28 ms 47360 KB Output is correct
15 Correct 27 ms 47360 KB Output is correct
16 Correct 27 ms 47352 KB Output is correct
17 Correct 28 ms 47360 KB Output is correct
18 Correct 27 ms 47360 KB Output is correct
19 Correct 27 ms 47360 KB Output is correct
20 Correct 27 ms 47352 KB Output is correct
21 Correct 28 ms 47360 KB Output is correct
22 Correct 27 ms 47352 KB Output is correct
23 Correct 28 ms 47360 KB Output is correct
24 Correct 30 ms 47360 KB Output is correct
25 Correct 29 ms 47360 KB Output is correct
26 Correct 28 ms 47360 KB Output is correct
27 Correct 29 ms 47360 KB Output is correct
28 Correct 29 ms 47360 KB Output is correct
29 Correct 29 ms 47360 KB Output is correct
30 Correct 29 ms 47352 KB Output is correct
31 Correct 29 ms 47316 KB Output is correct
32 Correct 29 ms 47360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 419 ms 61816 KB Output is correct
2 Correct 514 ms 72696 KB Output is correct
3 Correct 563 ms 63908 KB Output is correct
4 Correct 583 ms 67960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47232 KB Output is correct
2 Correct 28 ms 47360 KB Output is correct
3 Correct 27 ms 47360 KB Output is correct
4 Correct 27 ms 47360 KB Output is correct
5 Correct 27 ms 47224 KB Output is correct
6 Correct 28 ms 47360 KB Output is correct
7 Correct 29 ms 47224 KB Output is correct
8 Correct 27 ms 47360 KB Output is correct
9 Correct 27 ms 47360 KB Output is correct
10 Correct 28 ms 47360 KB Output is correct
11 Correct 28 ms 47488 KB Output is correct
12 Correct 29 ms 47360 KB Output is correct
13 Correct 28 ms 47360 KB Output is correct
14 Correct 27 ms 47360 KB Output is correct
15 Correct 27 ms 47352 KB Output is correct
16 Correct 27 ms 47232 KB Output is correct
17 Correct 27 ms 47360 KB Output is correct
18 Correct 27 ms 47488 KB Output is correct
19 Correct 27 ms 47224 KB Output is correct
20 Correct 29 ms 47360 KB Output is correct
21 Correct 27 ms 47232 KB Output is correct
22 Correct 28 ms 47360 KB Output is correct
23 Correct 29 ms 47360 KB Output is correct
24 Correct 30 ms 47352 KB Output is correct
25 Correct 29 ms 47352 KB Output is correct
26 Correct 30 ms 47480 KB Output is correct
27 Correct 30 ms 47360 KB Output is correct
28 Correct 29 ms 47360 KB Output is correct
29 Correct 29 ms 47360 KB Output is correct
30 Correct 29 ms 47352 KB Output is correct
31 Correct 28 ms 47360 KB Output is correct
32 Correct 29 ms 47360 KB Output is correct
33 Correct 228 ms 59256 KB Output is correct
34 Correct 215 ms 63272 KB Output is correct
35 Correct 200 ms 70008 KB Output is correct
36 Correct 193 ms 70088 KB Output is correct
37 Correct 218 ms 61304 KB Output is correct
38 Correct 177 ms 62200 KB Output is correct
39 Correct 183 ms 61048 KB Output is correct
40 Correct 178 ms 65144 KB Output is correct
41 Correct 185 ms 61176 KB Output is correct
42 Correct 174 ms 61176 KB Output is correct
43 Correct 159 ms 65448 KB Output is correct
44 Correct 149 ms 65528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47352 KB Output is correct
2 Correct 28 ms 47360 KB Output is correct
3 Correct 27 ms 47360 KB Output is correct
4 Correct 28 ms 47224 KB Output is correct
5 Correct 26 ms 47360 KB Output is correct
6 Correct 27 ms 47232 KB Output is correct
7 Correct 26 ms 47232 KB Output is correct
8 Correct 27 ms 47360 KB Output is correct
9 Correct 27 ms 47232 KB Output is correct
10 Correct 27 ms 47360 KB Output is correct
11 Correct 27 ms 47360 KB Output is correct
12 Correct 27 ms 47360 KB Output is correct
13 Correct 28 ms 47224 KB Output is correct
14 Correct 30 ms 47360 KB Output is correct
15 Correct 27 ms 47352 KB Output is correct
16 Correct 27 ms 47224 KB Output is correct
17 Correct 27 ms 47232 KB Output is correct
18 Correct 27 ms 47232 KB Output is correct
19 Correct 26 ms 47232 KB Output is correct
20 Correct 26 ms 47232 KB Output is correct
21 Correct 29 ms 47360 KB Output is correct
22 Correct 27 ms 47232 KB Output is correct
23 Correct 28 ms 47336 KB Output is correct
24 Correct 28 ms 47360 KB Output is correct
25 Correct 33 ms 47352 KB Output is correct
26 Correct 28 ms 47360 KB Output is correct
27 Correct 29 ms 47360 KB Output is correct
28 Correct 28 ms 47360 KB Output is correct
29 Correct 30 ms 47360 KB Output is correct
30 Correct 28 ms 47352 KB Output is correct
31 Correct 28 ms 47360 KB Output is correct
32 Correct 28 ms 47360 KB Output is correct
33 Correct 414 ms 61688 KB Output is correct
34 Correct 498 ms 72824 KB Output is correct
35 Correct 600 ms 63864 KB Output is correct
36 Correct 593 ms 67832 KB Output is correct
37 Correct 219 ms 63096 KB Output is correct
38 Correct 225 ms 63096 KB Output is correct
39 Correct 198 ms 70136 KB Output is correct
40 Correct 194 ms 70008 KB Output is correct
41 Correct 203 ms 61176 KB Output is correct
42 Correct 180 ms 62200 KB Output is correct
43 Correct 193 ms 61176 KB Output is correct
44 Correct 180 ms 65016 KB Output is correct
45 Correct 177 ms 61176 KB Output is correct
46 Correct 183 ms 61432 KB Output is correct
47 Correct 157 ms 65404 KB Output is correct
48 Correct 145 ms 65400 KB Output is correct
49 Correct 808 ms 65216 KB Output is correct
50 Correct 761 ms 65224 KB Output is correct
51 Correct 496 ms 71928 KB Output is correct
52 Correct 373 ms 71416 KB Output is correct
53 Correct 831 ms 63480 KB Output is correct
54 Correct 456 ms 63992 KB Output is correct
55 Correct 628 ms 62328 KB Output is correct
56 Correct 549 ms 66808 KB Output is correct
57 Correct 554 ms 63072 KB Output is correct
58 Correct 613 ms 63404 KB Output is correct
59 Correct 168 ms 65400 KB Output is correct