Submission #734785

# Submission time Handle Problem Language Result Execution time Memory
734785 2023-05-03T05:41:20 Z phoebe Horses (IOI15_horses) C++17
0 / 100
15 ms 8736 KB
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define ll long long

const int INF = 1e9 + 7, maxn = 10;
ll n, x[maxn], y[maxn], total = 1, tree[maxn * 4] = {0};
set<ll> bruh; 

void update(int x, int v, int tl = 0, int tr = maxn, int i = 1){
    if (tl > x || x > tr) return;
    if (tl == tr){
        tree[i] = v; return;
    }
    int tm = (tl + tr) / 2;
    update(x, v, tl, tm, i * 2); update(x, v, tm + 1, tr, i * 2 + 1);
    tree[i] = max(tree[i * 2], tree[i * 2 + 1]);
}

ll query(int l, int r, int tl = 0, int tr = maxn, int i = 1){
    if (l > tr || tl > r) return 0;
    if (l <= tl && tr <= r) return tree[i];
    int tm = (tl + tr) / 2;
    return max(query(l, r, tl, tm, i * 2), query(l, r, tm + 1, tr, i * 2 + 1));
}

ll mod_inverse(ll a){
    ll e = INF - 2, re = 1;
    while (e){
        if (e % 2) re = (re * a) % INF;
        a = (a * a) % INF;
        e /= 2;
    }
    return re;
}

int solve(){
    ll re = 1, product = 1;
    int start = *bruh.rbegin();
    for (auto it = bruh.rbegin(); it != bruh.rend(); it++){
        if (product > INF || *it == 0) break;
        start = *it; product *= x[start];
    }
    product = 1;
    for (auto it = bruh.lower_bound(start); it != bruh.end(); it++){
        int i = *it; 
        if (i > n) break;
        product *= x[i];
        int best_y = query(i, n);
        re = max(re, best_y * product);
    }
    ll pre = (total * mod_inverse(product)) % INF;
    re %= INF; re = (re * pre) % INF;
    return (int)re;
}

int init(int N, int X[], int Y[]){
    n = N; 
    FOR(i, n) x[i + 1] = X[i], y[i + 1] = Y[i];
    bruh.insert(0); bruh.insert(n + 1);
    for (int i = 1; i <= n; i++){
        if (x[i] == 1) continue;
        total = (total * x[i]) % INF;
        bruh.insert(i);
    }
    for (int i = 1; i <= n; i++) update(i, y[i]);
    return solve();
}

int updateX(int pos, int val){
    pos += 1; 
    if (bruh.count(pos)){
        total = (total * mod_inverse(x[pos])) % INF;
        bruh.erase(pos);
    }
    x[pos] = val;
    if (x[pos] != 1){
        bruh.insert(pos);
        total = (total * x[pos]) % INF;
    }
    return solve();
}

int updateY(int pos, int val){
    pos += 1; update(pos, val);
    return solve();
}

Compilation message

horses.cpp: In function 'void update(int, int, int, int, int)':
horses.cpp:12:17: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   12 | void update(int x, int v, int tl = 0, int tr = maxn, int i = 1){
      |             ~~~~^
horses.cpp:9:7: note: shadowed declaration is here
    9 | ll n, x[maxn], y[maxn], total = 1, tree[maxn * 4] = {0};
      |       ^
horses.cpp: In function 'int solve()':
horses.cpp:41:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   41 |     int start = *bruh.rbegin();
      |                 ^~~~~~~~~~~~~~
horses.cpp:44:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   44 |         start = *it; product *= x[start];
      |                 ^~~
horses.cpp:48:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   48 |         int i = *it;
      |                 ^~~
horses.cpp:51:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   51 |         int best_y = query(i, n);
      |                               ^
horses.cpp:51:27: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   51 |         int best_y = query(i, n);
      |                      ~~~~~^~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:68:47: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   68 |     for (int i = 1; i <= n; i++) update(i, y[i]);
      |                                            ~~~^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 8736 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Incorrect 1 ms 304 KB Output isn't correct
3 Halted 0 ms 0 KB -