Submission #349213

# Submission time Handle Problem Language Result Execution time Memory
349213 2021-01-17T05:39:47 Z mjhmjh1104 Horses (IOI15_horses) C++14
100 / 100
1152 ms 46060 KB
#include "horses.h"
#include <algorithm>
using namespace std;

const long long MOD = 1e9 + 7;

long long tree_x[1048576];
long long tree_y[1048576];
long long real_x[1048576];
long long real_y[500006];

long long query_x(int i, int b, int e, int l, int r) {
    if (r < b || e < l) return 1;
    if (l <= b && e <= r) return tree_x[i];
    int m = (b + e) / 2;
    return min(query_x(i * 2 + 1, b, m, l, r) * query_x(i * 2 + 2, m + 1, e, l, r), MOD);
}

long long update_x(int i, int b, int e, int p, int v) {
    if (p < b || e < p) return tree_x[i];
    if (b == e) return tree_x[i] = v;
    int m = (b + e) / 2;
    return tree_x[i] = min(update_x(i * 2 + 1, b, m, p, v) * update_x(i * 2 + 2, m + 1, e, p, v), MOD);
}

long long query_rx(int i, int b, int e, int l, int r) {
    if (r < b || e < l) return 1;
    if (l <= b && e <= r) return real_x[i];
    int m = (b + e) / 2;
    return query_rx(i * 2 + 1, b, m, l, r) * query_rx(i * 2 + 2, m + 1, e, l, r) % MOD;
}

long long update_rx(int i, int b, int e, int p, int v) {
    if (p < b || e < p) return real_x[i];
    if (b == e) return real_x[i] = v;
    int m = (b + e) / 2;
    return real_x[i] = update_rx(i * 2 + 1, b, m, p, v) * update_rx(i * 2 + 2, m + 1, e, p, v) % MOD;
}

bool compare(int x, int y) {
    long long t = query_x(0, 0, 524287, x + 1, y);
    if (t == MOD) return true;
    return real_y[x] < t * real_y[y];
}

long long query_y(int i, int b, int e, int l, int r) {
    if (r < b || e < l) return -1;
    if (l <= b && e <= r) return tree_y[i];
    int m = (b + e) / 2;
    int first = query_y(i * 2 + 1, b, m, l, r);
    int second = query_y(i * 2 + 2, m + 1, e, l, r);
    if (first == -1 || second == -1) return first + second + 1;
    if (compare(first, second)) return second;
    return first;
}

long long update_y(int i, int b, int e, int p) {
    if (p < b || e < p) return tree_y[i];
    if (b == e) return tree_y[i];
    int m = (b + e) / 2;
    int first = update_y(i * 2 + 1, b, m, p);
    int second = update_y(i * 2 + 2, m + 1, e, p);
    if (first == -1 || second == -1) return tree_y[i] = first + second + 1;
    if (compare(first, second)) return tree_y[i] = second;
    return tree_y[i] = first;
}

int init(int N, int X[], int Y[]) {
    for (int i = 0; i < N; i++) tree_x[524287 + i] = X[i];
    for (int i = 524286; i >= 0; i--) tree_x[i] = min(tree_x[i * 2 + 1] * tree_x[i * 2 + 2], MOD);
    for (int i = 0; i < N; i++) real_x[524287 + i] = X[i];
    for (int i = 524286; i >= 0; i--) real_x[i] = real_x[i * 2 + 1] * real_x[i * 2 + 2] % MOD;
    for (int i = 0; i < N; i++) real_y[i] = Y[i];
    for (int i = 0; i < 524288; i++) tree_y[524287 + i] = -1;
    for (int i = 0; i < N; i++) tree_y[524287 + i] = i;
    for (int i = 524286; i >= 0; i--) {
        if (compare(tree_y[i * 2 + 1], tree_y[i * 2 + 2])) tree_y[i] = tree_y[i * 2 + 2];
        else tree_y[i] = tree_y[i * 2 + 1];
    }
	int t = tree_y[0];
	return query_rx(0, 0, 524287, 0, t) * real_y[t] % MOD;
}

int updateX(int pos, int val) {
    update_x(0, 0, 524287, pos, val);
    update_rx(0, 0, 524287, pos, val);
    update_y(0, 0, 524287, pos);
    int t = tree_y[0];
	return query_rx(0, 0, 524287, 0, t) * real_y[t] % MOD;
}

int updateY(int pos, int val) {
    real_y[pos] = val;
    update_y(0, 0, 524287, pos);
	int t = tree_y[0];
	return query_rx(0, 0, 524287, 0, t) * real_y[t] % MOD;
}

Compilation message

horses.cpp: In function 'long long int query_y(int, int, int, int, int)':
horses.cpp:50:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   50 |     int first = query_y(i * 2 + 1, b, m, l, r);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:51:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   51 |     int second = query_y(i * 2 + 2, m + 1, e, l, r);
      |                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'long long int update_y(int, int, int, int)':
horses.cpp:61:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   61 |     int first = update_y(i * 2 + 1, b, m, p);
      |                 ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
horses.cpp:62:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   62 |     int second = update_y(i * 2 + 2, m + 1, e, p);
      |                  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:77:37: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   77 |         if (compare(tree_y[i * 2 + 1], tree_y[i * 2 + 2])) tree_y[i] = tree_y[i * 2 + 2];
      |                     ~~~~~~~~~~~~~~~~^
horses.cpp:77:56: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   77 |         if (compare(tree_y[i * 2 + 1], tree_y[i * 2 + 2])) tree_y[i] = tree_y[i * 2 + 2];
      |                                        ~~~~~~~~~~~~~~~~^
horses.cpp:80:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   80 |  int t = tree_y[0];
      |          ~~~~~~~~^
horses.cpp:81:50: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   81 |  return query_rx(0, 0, 524287, 0, t) * real_y[t] % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:88:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   88 |     int t = tree_y[0];
      |             ~~~~~~~~^
horses.cpp:89:50: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   89 |  return query_rx(0, 0, 524287, 0, t) * real_y[t] % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:95:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   95 |  int t = tree_y[0];
      |          ~~~~~~~~^
horses.cpp:96:50: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   96 |  return query_rx(0, 0, 524287, 0, t) * real_y[t] % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16748 KB Output is correct
2 Correct 14 ms 16748 KB Output is correct
3 Correct 14 ms 16748 KB Output is correct
4 Correct 15 ms 16748 KB Output is correct
5 Correct 14 ms 16748 KB Output is correct
6 Correct 15 ms 16748 KB Output is correct
7 Correct 15 ms 16748 KB Output is correct
8 Correct 14 ms 16748 KB Output is correct
9 Correct 14 ms 16748 KB Output is correct
10 Correct 15 ms 16748 KB Output is correct
11 Correct 15 ms 16748 KB Output is correct
12 Correct 14 ms 16748 KB Output is correct
13 Correct 15 ms 16748 KB Output is correct
14 Correct 14 ms 16748 KB Output is correct
15 Correct 14 ms 16748 KB Output is correct
16 Correct 15 ms 16748 KB Output is correct
17 Correct 15 ms 16748 KB Output is correct
18 Correct 14 ms 16748 KB Output is correct
19 Correct 15 ms 16748 KB Output is correct
20 Correct 15 ms 16748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 16748 KB Output is correct
2 Correct 17 ms 16748 KB Output is correct
3 Correct 17 ms 16748 KB Output is correct
4 Correct 18 ms 16748 KB Output is correct
5 Correct 15 ms 16748 KB Output is correct
6 Correct 14 ms 16748 KB Output is correct
7 Correct 15 ms 16876 KB Output is correct
8 Correct 15 ms 16748 KB Output is correct
9 Correct 15 ms 16748 KB Output is correct
10 Correct 14 ms 16748 KB Output is correct
11 Correct 15 ms 16748 KB Output is correct
12 Correct 14 ms 16876 KB Output is correct
13 Correct 15 ms 16748 KB Output is correct
14 Correct 16 ms 16896 KB Output is correct
15 Correct 15 ms 16748 KB Output is correct
16 Correct 15 ms 16748 KB Output is correct
17 Correct 15 ms 16748 KB Output is correct
18 Correct 14 ms 16748 KB Output is correct
19 Correct 14 ms 16748 KB Output is correct
20 Correct 14 ms 16748 KB Output is correct
21 Correct 14 ms 16748 KB Output is correct
22 Correct 16 ms 16748 KB Output is correct
23 Correct 18 ms 16876 KB Output is correct
24 Correct 18 ms 16896 KB Output is correct
25 Correct 18 ms 16876 KB Output is correct
26 Correct 17 ms 16876 KB Output is correct
27 Correct 18 ms 16876 KB Output is correct
28 Correct 22 ms 16876 KB Output is correct
29 Correct 19 ms 16748 KB Output is correct
30 Correct 18 ms 16876 KB Output is correct
31 Correct 18 ms 16876 KB Output is correct
32 Correct 18 ms 16876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 470 ms 37144 KB Output is correct
2 Correct 682 ms 46060 KB Output is correct
3 Correct 808 ms 37356 KB Output is correct
4 Correct 832 ms 41068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16748 KB Output is correct
2 Correct 14 ms 16748 KB Output is correct
3 Correct 15 ms 16748 KB Output is correct
4 Correct 15 ms 16748 KB Output is correct
5 Correct 15 ms 16748 KB Output is correct
6 Correct 14 ms 16748 KB Output is correct
7 Correct 14 ms 16748 KB Output is correct
8 Correct 15 ms 16748 KB Output is correct
9 Correct 14 ms 16748 KB Output is correct
10 Correct 14 ms 16748 KB Output is correct
11 Correct 14 ms 16748 KB Output is correct
12 Correct 19 ms 16748 KB Output is correct
13 Correct 14 ms 16876 KB Output is correct
14 Correct 15 ms 16748 KB Output is correct
15 Correct 14 ms 16748 KB Output is correct
16 Correct 14 ms 16748 KB Output is correct
17 Correct 14 ms 16748 KB Output is correct
18 Correct 14 ms 16748 KB Output is correct
19 Correct 14 ms 16896 KB Output is correct
20 Correct 15 ms 16748 KB Output is correct
21 Correct 14 ms 16748 KB Output is correct
22 Correct 14 ms 16748 KB Output is correct
23 Correct 18 ms 16876 KB Output is correct
24 Correct 18 ms 16876 KB Output is correct
25 Correct 17 ms 16876 KB Output is correct
26 Correct 17 ms 16876 KB Output is correct
27 Correct 19 ms 16876 KB Output is correct
28 Correct 18 ms 16876 KB Output is correct
29 Correct 17 ms 16748 KB Output is correct
30 Correct 17 ms 16876 KB Output is correct
31 Correct 17 ms 16876 KB Output is correct
32 Correct 20 ms 16876 KB Output is correct
33 Correct 257 ms 36588 KB Output is correct
34 Correct 257 ms 36588 KB Output is correct
35 Correct 216 ms 43372 KB Output is correct
36 Correct 205 ms 43388 KB Output is correct
37 Correct 277 ms 34540 KB Output is correct
38 Correct 201 ms 35564 KB Output is correct
39 Correct 226 ms 34540 KB Output is correct
40 Correct 207 ms 38452 KB Output is correct
41 Correct 206 ms 34540 KB Output is correct
42 Correct 214 ms 34540 KB Output is correct
43 Correct 164 ms 38852 KB Output is correct
44 Correct 165 ms 38764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16748 KB Output is correct
2 Correct 14 ms 16748 KB Output is correct
3 Correct 15 ms 16748 KB Output is correct
4 Correct 17 ms 16748 KB Output is correct
5 Correct 18 ms 16748 KB Output is correct
6 Correct 14 ms 16748 KB Output is correct
7 Correct 16 ms 16748 KB Output is correct
8 Correct 14 ms 16748 KB Output is correct
9 Correct 14 ms 16748 KB Output is correct
10 Correct 14 ms 16804 KB Output is correct
11 Correct 14 ms 16748 KB Output is correct
12 Correct 13 ms 16748 KB Output is correct
13 Correct 14 ms 16748 KB Output is correct
14 Correct 14 ms 16876 KB Output is correct
15 Correct 17 ms 16748 KB Output is correct
16 Correct 14 ms 16748 KB Output is correct
17 Correct 14 ms 16748 KB Output is correct
18 Correct 14 ms 16748 KB Output is correct
19 Correct 13 ms 16748 KB Output is correct
20 Correct 14 ms 16748 KB Output is correct
21 Correct 14 ms 16748 KB Output is correct
22 Correct 14 ms 16748 KB Output is correct
23 Correct 17 ms 16876 KB Output is correct
24 Correct 17 ms 16876 KB Output is correct
25 Correct 17 ms 16876 KB Output is correct
26 Correct 17 ms 16876 KB Output is correct
27 Correct 17 ms 16876 KB Output is correct
28 Correct 17 ms 16876 KB Output is correct
29 Correct 17 ms 16748 KB Output is correct
30 Correct 18 ms 16876 KB Output is correct
31 Correct 17 ms 16876 KB Output is correct
32 Correct 17 ms 16876 KB Output is correct
33 Correct 470 ms 37228 KB Output is correct
34 Correct 668 ms 46060 KB Output is correct
35 Correct 829 ms 37316 KB Output is correct
36 Correct 828 ms 41068 KB Output is correct
37 Correct 262 ms 36460 KB Output is correct
38 Correct 256 ms 36572 KB Output is correct
39 Correct 211 ms 43372 KB Output is correct
40 Correct 206 ms 43372 KB Output is correct
41 Correct 252 ms 34540 KB Output is correct
42 Correct 193 ms 35564 KB Output is correct
43 Correct 226 ms 34540 KB Output is correct
44 Correct 205 ms 38380 KB Output is correct
45 Correct 209 ms 34540 KB Output is correct
46 Correct 210 ms 34668 KB Output is correct
47 Correct 160 ms 38764 KB Output is correct
48 Correct 160 ms 38764 KB Output is correct
49 Correct 1092 ms 38660 KB Output is correct
50 Correct 1061 ms 38508 KB Output is correct
51 Correct 538 ms 45420 KB Output is correct
52 Correct 466 ms 44780 KB Output is correct
53 Correct 1152 ms 36844 KB Output is correct
54 Correct 602 ms 37484 KB Output is correct
55 Correct 884 ms 35820 KB Output is correct
56 Correct 699 ms 40428 KB Output is correct
57 Correct 689 ms 36588 KB Output is correct
58 Correct 727 ms 36844 KB Output is correct
59 Correct 167 ms 38764 KB Output is correct