Submission #1050603

# Submission time Handle Problem Language Result Execution time Memory
1050603 2024-08-09T11:41:05 Z ArthuroWich Horses (IOI15_horses) C++17
37 / 100
156 ms 35100 KB
#include "horses.h"
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int n, x[500005], y[500005], segs[4*500005], mod = 1e9+7;
void build(int n, int l, int r) {
    if (l == r) {
        segs[n] = x[l];
    } else {
        int m = (l+r)/2;
        build(2*n, l, m);
        build(2*n+1, m+1, r);
        segs[n] = segs[2*n] * segs[2*n+1];
        segs[n] %= mod;
    }
}
void update(int n, int l, int r, int i, int v) {
    if (l == r) {
        segs[n] = v;
    } else {
        int m = (l+r)/2;
        if (l <= i && i <= m) {
            update(2*n, l, m, i, v);
        } else {
            update(2*n+1, m+1, r, i, v);
        }
        segs[n] = segs[2*n] * segs[2*n+1];
        segs[n] %= mod;
    }
}
int query(int n, int l, int r, int a, int b) {
    if (b < l || r < a) {
        return 1;
    } else if (a <= l && r <= b) {
        return segs[n];
    } else {
        int m = (l+r)/2;
        return (query(2*n, l, m, a, b)*query(2*n+1, m+1, r, a, b))%mod;
    }
}
int32_t calc() {
    int ind = 0;
    long double v = 0, a = 0, b = 0;
    for (int i = max(n-31, 0LL); i < n; i++) {
        a += log2(x[i]);
        if (a+log2(y[i]) > v) {
            v = a+log2(y[i]);
            ind = i;
        }
    }
    return (query(1, 0, n-1, 0, ind)*y[ind]) % mod;
}
int32_t init(int32_t N, int32_t X[], int32_t Y[]) {
    n = N;
    for (int i = 0; i < n; i++) {
        x[i] = X[i];
        y[i] = Y[i];
    }
    build(1, 0, n-1);
    return calc();
}
int32_t updateX(int32_t pos, int32_t val) {	
    x[pos] = val;
    update(1, 0, n-1, pos, val);
    return calc();
}
int32_t updateY(int32_t pos, int32_t val) {
    y[pos] = val;
    return calc();
}

Compilation message

horses.cpp: In function 'void build(long long int, long long int, long long int)':
horses.cpp:6:16: warning: declaration of 'n' shadows a global declaration [-Wshadow]
    6 | void build(int n, int l, int r) {
      |                ^
horses.cpp:5:5: note: shadowed declaration is here
    5 | int n, x[500005], y[500005], segs[4*500005], mod = 1e9+7;
      |     ^
horses.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:17:17: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   17 | void update(int n, int l, int r, int i, int v) {
      |                 ^
horses.cpp:5:5: note: shadowed declaration is here
    5 | int n, x[500005], y[500005], segs[4*500005], mod = 1e9+7;
      |     ^
horses.cpp: In function 'long long int query(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:31:15: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   31 | int query(int n, int l, int r, int a, int b) {
      |               ^
horses.cpp:5:5: note: shadowed declaration is here
    5 | int n, x[500005], y[500005], segs[4*500005], mod = 1e9+7;
      |     ^
horses.cpp: In function 'int32_t calc()':
horses.cpp:51:46: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
   51 |     return (query(1, 0, n-1, 0, ind)*y[ind]) % mod;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:43:31: warning: unused variable 'b' [-Wunused-variable]
   43 |     long double v = 0, a = 0, b = 0;
      |                               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4544 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4456 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 4536 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Incorrect 1 ms 4696 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 26496 KB Output is correct
2 Correct 156 ms 35100 KB Output is correct
3 Correct 101 ms 26340 KB Output is correct
4 Correct 134 ms 30288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4440 KB Output is correct
2 Correct 0 ms 4544 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4540 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4544 KB Output is correct
18 Correct 0 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
21 Correct 1 ms 4696 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Incorrect 1 ms 4444 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4548 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 0 ms 4444 KB Output is correct
6 Correct 0 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 0 ms 4444 KB Output is correct
9 Correct 0 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 0 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 0 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 0 ms 4444 KB Output is correct
17 Correct 0 ms 4444 KB Output is correct
18 Correct 0 ms 4444 KB Output is correct
19 Correct 0 ms 4444 KB Output is correct
20 Correct 0 ms 4444 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 0 ms 4444 KB Output is correct
23 Incorrect 1 ms 4444 KB Output isn't correct
24 Halted 0 ms 0 KB -