답안 #734835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734835 2023-05-03T07:00:20 Z phoebe 말 (IOI15_horses) C++17
17 / 100
711 ms 41848 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 = 5e5 + 10;
ll n, x[maxn], y[maxn], total = 1;
int tree[maxn * 4] = {0};
set<int> 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]);
}

int 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 = 0;
    for (auto it = bruh.rbegin(); it != bruh.rend(); it++){
        if (product * x[*it] > INF) break;
        start = *it; product *= x[*it];
    }
    product = 1;
    for (auto it = bruh.lower_bound(start); it != bruh.end(); it++){
        int i = *it; 
        product *= x[i];
        ll 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; x[0] = 1;
    FOR(i, n) x[i + 1] = X[i], y[i + 1] = Y[i];
    bruh.insert(0);
    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++;
    if (x[pos] != 1){
        total = (total * mod_inverse(x[pos])) % INF;
        bruh.erase(pos);
    }
    x[pos] = val;
    if (x[pos] != 1){
        total = (total * x[pos]) % INF;
        bruh.insert(pos);
    }
    return solve();
}

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

Compilation message

horses.cpp: In function 'void update(int, int, int, int, int)':
horses.cpp:13:17: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   13 | 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;
      |       ^
horses.cpp: In function 'int solve()':
horses.cpp:51:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   51 |         ll 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]);
      |                                            ~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 436 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 272 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Incorrect 1 ms 308 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 711 ms 41848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Incorrect 1 ms 340 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 416 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 312 KB Output is correct
22 Incorrect 1 ms 340 KB Output isn't correct
23 Halted 0 ms 0 KB -