Submission #725998

# Submission time Handle Problem Language Result Execution time Memory
725998 2023-04-18T09:49:42 Z TheSahib Horses (IOI15_horses) C++17
34 / 100
1500 ms 24324 KB
#include "horses.h"
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, ll>

using namespace std;

const int MOD = 1e9 + 7;
const ll oo = 1e9 + 9;
const int MAX = 5e5 + 5;

struct DATA{
    int index, leftMultipliyer, rightMultiplier;
};

int n;
int price[MAX], cnt[MAX];
DATA tree[MAX * 4];


DATA merge(DATA a, DATA b){
    ll m = min(oo, 1ll * a.rightMultiplier * b.leftMultipliyer);
    if(price[a.index] / m >= price[b.index]){
        return {a.index, a.leftMultipliyer, min(oo, m * b.rightMultiplier)};
    }
    else{
        return {b.index, min(oo, m * a.leftMultipliyer), b.rightMultiplier};
    }
}

void build(int node, int l, int r){
    if(l == r){
        tree[node] = {l, cnt[l], 1};
        return;
    }

    int mid = (l + r) / 2;
    build(node << 1 | 1, l, mid);
    build((node + 1) << 1, mid + 1, r);

    tree[node] = merge(tree[(node << 1) | 1], tree[(node + 1) << 1]);
}

int calcAns(){
    DATA ans = tree[0];
    ll a = 1;
    for (int i = 0; i <= ans.index; i++)
    {
        a *= cnt[i];
        a %= MOD;
    }
    a = (a * price[ans.index]) % MOD;
    return a;
}


int init(int N, int X[], int Y[]) {
    n = N;
    for (int i = 0; i < n; i++)
    {
        cnt[i] = X[i];
        price[i] = Y[i];
    }
    build(0, 0, n - 1);
    return calcAns();
}

int updateX(int pos, int val) {	
	cnt[pos] = val;
    build(0, 0, n - 1);
    return calcAns();
}

int updateY(int pos, int val) {
	price[pos] = val;
    build(0, 0, n - 1);
    return calcAns();
}

Compilation message

horses.cpp: In function 'DATA merge(DATA, DATA)':
horses.cpp:25:48: warning: narrowing conversion of '(long long int)std::min<long long int>(oo, (m * ((long long int)b.DATA::rightMultiplier)))' from 'long long int' to 'int' [-Wnarrowing]
   25 |         return {a.index, a.leftMultipliyer, min(oo, m * b.rightMultiplier)};
      |                                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:25:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
horses.cpp:28:29: warning: narrowing conversion of '(long long int)std::min<long long int>(oo, (m * ((long long int)a.DATA::leftMultipliyer)))' from 'long long int' to 'int' [-Wnarrowing]
   28 |         return {b.index, min(oo, m * a.leftMultipliyer), b.rightMultiplier};
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:28:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
horses.cpp: In function 'int calcAns()':
horses.cpp:54:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   54 |     return a;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 1 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 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 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 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 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 1 ms 308 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 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 1 ms 212 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 312 KB Output is correct
23 Correct 42 ms 340 KB Output is correct
24 Correct 35 ms 388 KB Output is correct
25 Correct 35 ms 404 KB Output is correct
26 Correct 31 ms 340 KB Output is correct
27 Correct 31 ms 380 KB Output is correct
28 Correct 33 ms 340 KB Output is correct
29 Correct 31 ms 340 KB Output is correct
30 Correct 35 ms 380 KB Output is correct
31 Correct 28 ms 340 KB Output is correct
32 Correct 30 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1565 ms 22480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 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 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 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 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 34 ms 380 KB Output is correct
24 Correct 33 ms 376 KB Output is correct
25 Correct 30 ms 388 KB Output is correct
26 Correct 32 ms 396 KB Output is correct
27 Correct 34 ms 320 KB Output is correct
28 Correct 33 ms 384 KB Output is correct
29 Correct 32 ms 376 KB Output is correct
30 Correct 30 ms 340 KB Output is correct
31 Correct 30 ms 340 KB Output is correct
32 Correct 27 ms 340 KB Output is correct
33 Execution timed out 1551 ms 24324 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 308 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 212 KB Output is correct
12 Correct 0 ms 304 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 248 KB Output is correct
18 Correct 1 ms 312 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 39 ms 372 KB Output is correct
24 Correct 41 ms 380 KB Output is correct
25 Correct 33 ms 340 KB Output is correct
26 Correct 37 ms 340 KB Output is correct
27 Correct 33 ms 380 KB Output is correct
28 Correct 33 ms 340 KB Output is correct
29 Correct 31 ms 340 KB Output is correct
30 Correct 31 ms 364 KB Output is correct
31 Correct 32 ms 376 KB Output is correct
32 Correct 31 ms 376 KB Output is correct
33 Execution timed out 1559 ms 22604 KB Time limit exceeded
34 Halted 0 ms 0 KB -