답안 #778226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
778226 2023-07-10T07:34:54 Z danikoynov 말 (IOI15_horses) C++14
54 / 100
1500 ms 27508 KB
#include "horses.h"
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 5e5 + 10;
const ll mod = 1e9 + 7;
ll x[maxn], y[maxn], n;

ll prod_tree[4 * maxn];

void build_prod_tree(int root, int left, int right)
{
    if (left == right)
    {
        prod_tree[root] = x[left];
        return;
    }

    int mid = (left + right) / 2;
    build_prod_tree(root * 2, left, mid);
    build_prod_tree(root * 2 + 1, mid + 1, right);

    prod_tree[root] = (prod_tree[root * 2] * prod_tree[root * 2 + 1]) % mod;
}

void update_prod(int root, int left, int right, int pos)
{
    if (left == right)
    {
        prod_tree[root] = x[left];
        return;
    }

    int mid = (left + right) / 2;
    if (pos <= mid)
        update_prod(root * 2, left, mid, pos);
    else
        update_prod(root * 2 + 1, mid + 1, right, pos);

    prod_tree[root] = (prod_tree[root * 2] * prod_tree[root * 2 + 1]) % mod;
}

ll prod_query(int root, int left, int right, int qleft, int qright)
{
    if (left > qright || right < qleft)
        return 1;
    if (left >= qleft && right <= qright)
        return prod_tree[root];

    int mid = (left + right) / 2;
    return (prod_query(root * 2, left, mid, qleft, qright) *
            prod_query(root * 2 + 1, mid + 1, right, qleft, qright)) % mod;
}

ll action()
{
    ll up = y[n - 1], dw = 1, pos = n - 1;
    ll div = 1;
    for (int i = n - 2; i >= 0; i --)
    {
        div = div * x[i + 1];
        if (div > 1e9)
            break;
            ///cout << i << " : " << y[i] << " " << div << endl;
        /// y[i] / div >? up / dw
        if (y[i] * dw >= up * div)
        {

            ///cout << " " << up << " : " << dw << endl;
            up = y[i];
            dw = div;
            pos = i;
        }
    }

    ///cout << pos << endl;
    ll ans = prod_query(1, 0, n - 1, 0, pos);
    //for (int i = 0; i <= pos; i ++)
      //  ans = (ans * x[i]) % mod;
    ans = (ans * y[pos]) % mod;
    return ans;
}
int init(int N, int X[], int Y[])
{
    n = N;
    for (int i = 0; i < n; i ++)
    {
        x[i] = X[i];
        y[i] = Y[i];
    }
    build_prod_tree(1, 0, n - 1);
    return action();
}

int updateX(int pos, int val)
{
    x[pos] = val;
    update_prod(1, 0, n - 1, pos);
    return action();
}

int updateY(int pos, int val)
{
    y[pos] = val;
    return action();
}

Compilation message

horses.cpp: In function 'll action()':
horses.cpp:61:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   61 |     for (int i = n - 2; i >= 0; i --)
      |                  ~~^~~
horses.cpp:64:13: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
   64 |         if (div > 1e9)
      |             ^~~
horses.cpp:79:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   79 |     ll ans = prod_query(1, 0, n - 1, 0, pos);
      |                               ~~^~~
horses.cpp:79:41: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   79 |     ll ans = prod_query(1, 0, n - 1, 0, pos);
      |                                         ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:93:29: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   93 |     build_prod_tree(1, 0, n - 1);
      |                           ~~^~~
horses.cpp:94:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   94 |     return action();
      |            ~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:100:25: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  100 |     update_prod(1, 0, n - 1, pos);
      |                       ~~^~~
horses.cpp:101:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  101 |     return action();
      |            ~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:107:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  107 |     return action();
      |            ~~~~~~^~
# 결과 실행 시간 메모리 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 1 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 1 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
# 결과 실행 시간 메모리 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 1 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 1 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 1 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 1 ms 340 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 22744 KB Output is correct
2 Correct 94 ms 27476 KB Output is correct
3 Correct 62 ms 25000 KB Output is correct
4 Correct 82 ms 27508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 220 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 1 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 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 3 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 110 ms 20328 KB Output is correct
34 Correct 30 ms 24224 KB Output is correct
35 Correct 57 ms 26556 KB Output is correct
36 Correct 54 ms 26836 KB Output is correct
37 Correct 571 ms 22420 KB Output is correct
38 Correct 31 ms 23244 KB Output is correct
39 Execution timed out 1571 ms 22212 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 232 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 1 ms 212 KB Output is correct
18 Correct 1 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 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 3 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 54 ms 22824 KB Output is correct
34 Correct 82 ms 27468 KB Output is correct
35 Correct 57 ms 24972 KB Output is correct
36 Correct 96 ms 27452 KB Output is correct
37 Correct 109 ms 24188 KB Output is correct
38 Correct 31 ms 24264 KB Output is correct
39 Correct 65 ms 26592 KB Output is correct
40 Correct 54 ms 26620 KB Output is correct
41 Correct 586 ms 22380 KB Output is correct
42 Correct 30 ms 23288 KB Output is correct
43 Execution timed out 1561 ms 22188 KB Time limit exceeded
44 Halted 0 ms 0 KB -