답안 #734870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734870 2023-05-03T07:41:06 Z phoebe 말 (IOI15_horses) C++17
100 / 100
790 ms 51528 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] > (1<<30)) 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 0 ms 340 KB Output is correct
7 Correct 1 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 1 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 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 0 ms 260 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 1 ms 340 KB Output is correct
16 Correct 0 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 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 472 KB Output is correct
27 Correct 7 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 320 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 5 ms 340 KB Output is correct
32 Correct 7 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 760 ms 40688 KB Output is correct
2 Correct 379 ms 40828 KB Output is correct
3 Correct 480 ms 40892 KB Output is correct
4 Correct 503 ms 40700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 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 1 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 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 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 1 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 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 444 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 7 ms 316 KB Output is correct
28 Correct 4 ms 444 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 6 ms 416 KB Output is correct
33 Correct 126 ms 18832 KB Output is correct
34 Correct 125 ms 18336 KB Output is correct
35 Correct 244 ms 41712 KB Output is correct
36 Correct 251 ms 41668 KB Output is correct
37 Correct 171 ms 18228 KB Output is correct
38 Correct 184 ms 30156 KB Output is correct
39 Correct 116 ms 18036 KB Output is correct
40 Correct 238 ms 41620 KB Output is correct
41 Correct 141 ms 18124 KB Output is correct
42 Correct 151 ms 18516 KB Output is correct
43 Correct 290 ms 46088 KB Output is correct
44 Correct 223 ms 46236 KB Output is correct
# 결과 실행 시간 메모리 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 340 KB Output is correct
5 Correct 1 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 1 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 1 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 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 7 ms 340 KB Output is correct
28 Correct 3 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 774 ms 42608 KB Output is correct
34 Correct 380 ms 42580 KB Output is correct
35 Correct 431 ms 42600 KB Output is correct
36 Correct 469 ms 42516 KB Output is correct
37 Correct 131 ms 18308 KB Output is correct
38 Correct 110 ms 18268 KB Output is correct
39 Correct 255 ms 41708 KB Output is correct
40 Correct 264 ms 41668 KB Output is correct
41 Correct 169 ms 18288 KB Output is correct
42 Correct 181 ms 30152 KB Output is correct
43 Correct 108 ms 18148 KB Output is correct
44 Correct 238 ms 41676 KB Output is correct
45 Correct 143 ms 18128 KB Output is correct
46 Correct 156 ms 18560 KB Output is correct
47 Correct 237 ms 46096 KB Output is correct
48 Correct 225 ms 46148 KB Output is correct
49 Correct 252 ms 23472 KB Output is correct
50 Correct 187 ms 23384 KB Output is correct
51 Correct 429 ms 51528 KB Output is correct
52 Correct 335 ms 51480 KB Output is correct
53 Correct 790 ms 21776 KB Output is correct
54 Correct 349 ms 35356 KB Output is correct
55 Correct 245 ms 19484 KB Output is correct
56 Correct 364 ms 47720 KB Output is correct
57 Correct 480 ms 20096 KB Output is correct
58 Correct 649 ms 20524 KB Output is correct
59 Correct 229 ms 46092 KB Output is correct