답안 #734871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734871 2023-05-03T07:48:00 Z phoebe 말 (IOI15_horses) C++17
100 / 100
735 ms 41160 KB
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;

#define ll long long

const int INF = 1e9 + 7, maxn = 5e5 + 10;
ll n, x[maxn], total = 1, 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]);
}

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 = 0;
    for (auto it = bruh.rbegin(); it != bruh.rend(); it++){
        if (product * x[*it] > INF) break;
        start = *it; product *= x[*it];
    }
    int last = 0; 
    if (start != 0) last = *(--bruh.lower_bound(start));
    re = query(last, n);
    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;
    bruh.insert(0);
    for (int i = 1; i <= n; i++){
        x[i] = X[i - 1]; update(i, Y[i - 1]);
        if (x[i] == 1) continue;
        total = (total * x[i]) % INF;
        bruh.insert(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:11:17: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   11 | void update(int x, int v, int tl = 0, int tr = maxn, int i = 1){
      |             ~~~~^
horses.cpp:8:7: note: shadowed declaration is here
    8 | ll n, x[maxn], total = 1, tree[maxn * 4] = {0};
      |       ^
horses.cpp: In function 'int solve()':
horses.cpp:47:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   47 |     re = query(last, n);
      |                      ^
horses.cpp:52:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   52 |         ll best_y = query(i, n);
      |                              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 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 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 388 KB Output is correct
27 Correct 6 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 2 ms 400 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 6 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 735 ms 40920 KB Output is correct
2 Correct 377 ms 40884 KB Output is correct
3 Correct 380 ms 40748 KB Output is correct
4 Correct 459 ms 40748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 7 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 7 ms 340 KB Output is correct
32 Correct 7 ms 340 KB Output is correct
33 Correct 136 ms 16660 KB Output is correct
34 Correct 108 ms 16508 KB Output is correct
35 Correct 235 ms 39988 KB Output is correct
36 Correct 235 ms 39980 KB Output is correct
37 Correct 164 ms 16500 KB Output is correct
38 Correct 164 ms 28344 KB Output is correct
39 Correct 120 ms 16588 KB Output is correct
40 Correct 223 ms 40164 KB Output is correct
41 Correct 134 ms 16716 KB Output is correct
42 Correct 147 ms 16688 KB Output is correct
43 Correct 213 ms 39992 KB Output is correct
44 Correct 209 ms 40084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 324 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 6 ms 320 KB Output is correct
28 Correct 5 ms 448 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 7 ms 340 KB Output is correct
33 Correct 712 ms 41144 KB Output is correct
34 Correct 374 ms 41160 KB Output is correct
35 Correct 379 ms 41152 KB Output is correct
36 Correct 458 ms 41156 KB Output is correct
37 Correct 111 ms 16824 KB Output is correct
38 Correct 109 ms 16716 KB Output is correct
39 Correct 234 ms 40132 KB Output is correct
40 Correct 233 ms 39836 KB Output is correct
41 Correct 162 ms 16756 KB Output is correct
42 Correct 175 ms 28620 KB Output is correct
43 Correct 107 ms 16536 KB Output is correct
44 Correct 222 ms 39808 KB Output is correct
45 Correct 126 ms 16652 KB Output is correct
46 Correct 148 ms 16588 KB Output is correct
47 Correct 209 ms 40036 KB Output is correct
48 Correct 224 ms 40044 KB Output is correct
49 Correct 213 ms 18648 KB Output is correct
50 Correct 190 ms 18764 KB Output is correct
51 Correct 394 ms 41096 KB Output is correct
52 Correct 314 ms 40988 KB Output is correct
53 Correct 719 ms 18628 KB Output is correct
54 Correct 330 ms 31476 KB Output is correct
55 Correct 218 ms 16716 KB Output is correct
56 Correct 322 ms 41112 KB Output is correct
57 Correct 474 ms 17552 KB Output is correct
58 Correct 617 ms 17616 KB Output is correct
59 Correct 211 ms 40180 KB Output is correct