#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
#define ll long long
#define int ll
#define fi first
#define se second
#define ld long double
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
static const int mod = 1e9 + 7;
int pot(int a, int b) {
if (b == 0) return 1;
int x = pot(a, b / 2);
if (b % 2) return x * x % mod * a % mod;
return x * x % mod;
}
struct segment {
static const int dim = 1 << 19;
struct node {
ld log = 0;
int mod = 1;
ld lazy_log = 0;
int lazy_mod = 1;
};
vector<node> s = vector<node>(2 * dim);
void prop(int pos) {
if (s[pos].lazy_log != 0) {
s[pos].log += s[pos].lazy_log;
if (pos < dim) {
s[2 * pos].lazy_log += s[pos].lazy_log;
s[2 * pos + 1].lazy_log += s[pos].lazy_log;
}
s[pos].lazy_log = 0;
}
if (s[pos].lazy_mod > 1) {
s[pos].mod = s[pos].mod * s[pos].lazy_mod % mod;
if (pos < dim) {
s[2 * pos].lazy_mod = s[2 * pos].lazy_mod * s[pos].lazy_mod % mod;
s[2 * pos + 1].lazy_mod = s[2 * pos + 1].lazy_mod * s[pos].lazy_mod % mod;
}
s[pos].lazy_mod = 1;
}
}
void upd(int pos, int l, int r, int a, int b, ld log_, int mod_) {
prop(pos);
if (b < l || r < a) return;
if (a <= l && r <= b) {
s[pos].lazy_log += log_;
s[pos].lazy_mod = s[pos].lazy_mod * mod_ % mod;
prop(pos);
return;
}
int m = (l + r) / 2;
upd(2 * pos, l, m, a, b, log_, mod_);
upd(2 * pos + 1, m + 1, r, a, b, log_, mod_);
if (s[2 * pos].log > s[2 * pos + 1].log)
s[pos] = s[2 * pos];
else
s[pos] = s[2 * pos + 1];
}
void upd(int a, int b, ld log_, int mod_) {
upd(1, 0, dim - 1, a, b, log_, mod_);
}
int query() {
prop(1);
// cout << s[1].log << " " << s[1].lazy_mod << " " << s[1].lazy_log << endl;
return s[1].mod;
}
} seg;
vector<int> X, Y;
int N;
int calc() {
int ma = 0;
int cur = 1;
for (int i = 0; i < N; i++) {
cur *= X[i];
ma = max(ma, cur * Y[i] % mod);
}
return ma;
}
signed init(signed N, signed x[], signed y[]) {
::N = N;
for (int i = 0; i < N; i++) {
X.pb(x[i]);
Y.pb(y[i]);
seg.upd(i, N, log(X[i]), X[i]);
seg.upd(i, i, log(Y[i]), Y[i]);
}
return seg.query();
}
signed updateX(signed pos, signed val) {
seg.upd(pos, N, -log(X[pos]) + log(val), val * pot(X[pos], mod - 2) % mod);
X[pos] = val;
// seg.upd(pos, N, log(val), val);
return seg.query();
}
signed updateY(signed pos, signed val) {
seg.upd(pos, pos, -log(Y[pos]) + log(val), pot(Y[pos], mod - 2) * val % mod);
Y[pos] = val;
// seg.upd(pos, pos, log(val), val);
return seg.query();
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:86:20: warning: declaration of 'N' shadows a global declaration [-Wshadow]
86 | signed init(signed N, signed x[], signed y[]) {
| ~~~~~~~^
horses.cpp:76:5: note: shadowed declaration is here
76 | int N;
| ^
horses.cpp:94:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
94 | return seg.query();
| ~~~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:101:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
101 | return seg.query();
| ~~~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:108:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
108 | return seg.query();
| ~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
65892 KB |
Output is correct |
2 |
Correct |
34 ms |
65952 KB |
Output is correct |
3 |
Correct |
37 ms |
65872 KB |
Output is correct |
4 |
Correct |
38 ms |
65868 KB |
Output is correct |
5 |
Correct |
35 ms |
65944 KB |
Output is correct |
6 |
Correct |
37 ms |
65876 KB |
Output is correct |
7 |
Correct |
36 ms |
65872 KB |
Output is correct |
8 |
Correct |
36 ms |
65864 KB |
Output is correct |
9 |
Correct |
36 ms |
65848 KB |
Output is correct |
10 |
Correct |
36 ms |
65868 KB |
Output is correct |
11 |
Correct |
36 ms |
65876 KB |
Output is correct |
12 |
Correct |
37 ms |
65864 KB |
Output is correct |
13 |
Correct |
36 ms |
65892 KB |
Output is correct |
14 |
Correct |
36 ms |
65932 KB |
Output is correct |
15 |
Correct |
35 ms |
65876 KB |
Output is correct |
16 |
Correct |
36 ms |
65868 KB |
Output is correct |
17 |
Correct |
35 ms |
65896 KB |
Output is correct |
18 |
Correct |
36 ms |
65928 KB |
Output is correct |
19 |
Correct |
38 ms |
65948 KB |
Output is correct |
20 |
Correct |
36 ms |
65976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
65968 KB |
Output is correct |
2 |
Correct |
35 ms |
65868 KB |
Output is correct |
3 |
Correct |
36 ms |
65964 KB |
Output is correct |
4 |
Correct |
36 ms |
65960 KB |
Output is correct |
5 |
Correct |
36 ms |
65876 KB |
Output is correct |
6 |
Correct |
37 ms |
65904 KB |
Output is correct |
7 |
Correct |
35 ms |
65876 KB |
Output is correct |
8 |
Correct |
36 ms |
65844 KB |
Output is correct |
9 |
Correct |
36 ms |
65908 KB |
Output is correct |
10 |
Correct |
36 ms |
65904 KB |
Output is correct |
11 |
Correct |
35 ms |
65868 KB |
Output is correct |
12 |
Correct |
37 ms |
65948 KB |
Output is correct |
13 |
Correct |
37 ms |
65844 KB |
Output is correct |
14 |
Correct |
38 ms |
65916 KB |
Output is correct |
15 |
Correct |
36 ms |
65996 KB |
Output is correct |
16 |
Correct |
36 ms |
65868 KB |
Output is correct |
17 |
Correct |
35 ms |
65892 KB |
Output is correct |
18 |
Correct |
36 ms |
65892 KB |
Output is correct |
19 |
Correct |
36 ms |
65940 KB |
Output is correct |
20 |
Correct |
38 ms |
65868 KB |
Output is correct |
21 |
Correct |
36 ms |
65896 KB |
Output is correct |
22 |
Correct |
36 ms |
65928 KB |
Output is correct |
23 |
Correct |
38 ms |
65896 KB |
Output is correct |
24 |
Correct |
38 ms |
65892 KB |
Output is correct |
25 |
Correct |
37 ms |
65996 KB |
Output is correct |
26 |
Correct |
38 ms |
65928 KB |
Output is correct |
27 |
Correct |
37 ms |
65920 KB |
Output is correct |
28 |
Correct |
38 ms |
65996 KB |
Output is correct |
29 |
Correct |
37 ms |
65992 KB |
Output is correct |
30 |
Correct |
38 ms |
65996 KB |
Output is correct |
31 |
Correct |
37 ms |
65944 KB |
Output is correct |
32 |
Correct |
37 ms |
65924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
663 ms |
78892 KB |
Output is correct |
2 |
Correct |
839 ms |
78888 KB |
Output is correct |
3 |
Correct |
804 ms |
78972 KB |
Output is correct |
4 |
Correct |
839 ms |
78872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
65876 KB |
Output is correct |
2 |
Correct |
35 ms |
65912 KB |
Output is correct |
3 |
Correct |
36 ms |
65940 KB |
Output is correct |
4 |
Correct |
35 ms |
65940 KB |
Output is correct |
5 |
Correct |
36 ms |
65876 KB |
Output is correct |
6 |
Correct |
36 ms |
65836 KB |
Output is correct |
7 |
Correct |
36 ms |
65868 KB |
Output is correct |
8 |
Correct |
35 ms |
65956 KB |
Output is correct |
9 |
Correct |
37 ms |
65940 KB |
Output is correct |
10 |
Correct |
37 ms |
65836 KB |
Output is correct |
11 |
Correct |
36 ms |
65952 KB |
Output is correct |
12 |
Correct |
36 ms |
65908 KB |
Output is correct |
13 |
Correct |
36 ms |
65956 KB |
Output is correct |
14 |
Correct |
36 ms |
65924 KB |
Output is correct |
15 |
Correct |
36 ms |
65840 KB |
Output is correct |
16 |
Correct |
36 ms |
65892 KB |
Output is correct |
17 |
Correct |
38 ms |
65860 KB |
Output is correct |
18 |
Correct |
36 ms |
65948 KB |
Output is correct |
19 |
Correct |
36 ms |
65860 KB |
Output is correct |
20 |
Correct |
36 ms |
65868 KB |
Output is correct |
21 |
Correct |
36 ms |
65868 KB |
Output is correct |
22 |
Correct |
36 ms |
65924 KB |
Output is correct |
23 |
Correct |
38 ms |
65956 KB |
Output is correct |
24 |
Correct |
38 ms |
65984 KB |
Output is correct |
25 |
Correct |
37 ms |
65988 KB |
Output is correct |
26 |
Correct |
37 ms |
65996 KB |
Output is correct |
27 |
Correct |
37 ms |
65988 KB |
Output is correct |
28 |
Correct |
38 ms |
65988 KB |
Output is correct |
29 |
Correct |
37 ms |
65988 KB |
Output is correct |
30 |
Correct |
38 ms |
65936 KB |
Output is correct |
31 |
Correct |
37 ms |
65932 KB |
Output is correct |
32 |
Correct |
37 ms |
65928 KB |
Output is correct |
33 |
Correct |
553 ms |
78000 KB |
Output is correct |
34 |
Correct |
515 ms |
77912 KB |
Output is correct |
35 |
Correct |
630 ms |
78152 KB |
Output is correct |
36 |
Correct |
630 ms |
78028 KB |
Output is correct |
37 |
Correct |
503 ms |
78116 KB |
Output is correct |
38 |
Correct |
530 ms |
78092 KB |
Output is correct |
39 |
Correct |
488 ms |
78004 KB |
Output is correct |
40 |
Correct |
609 ms |
77920 KB |
Output is correct |
41 |
Correct |
466 ms |
78020 KB |
Output is correct |
42 |
Correct |
474 ms |
77932 KB |
Output is correct |
43 |
Correct |
607 ms |
77860 KB |
Output is correct |
44 |
Correct |
611 ms |
77944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
65876 KB |
Output is correct |
2 |
Correct |
35 ms |
65852 KB |
Output is correct |
3 |
Correct |
36 ms |
65920 KB |
Output is correct |
4 |
Correct |
38 ms |
65868 KB |
Output is correct |
5 |
Correct |
37 ms |
65860 KB |
Output is correct |
6 |
Correct |
36 ms |
65868 KB |
Output is correct |
7 |
Correct |
37 ms |
65848 KB |
Output is correct |
8 |
Correct |
37 ms |
65920 KB |
Output is correct |
9 |
Correct |
38 ms |
65888 KB |
Output is correct |
10 |
Correct |
36 ms |
65836 KB |
Output is correct |
11 |
Correct |
34 ms |
65876 KB |
Output is correct |
12 |
Correct |
36 ms |
65920 KB |
Output is correct |
13 |
Correct |
37 ms |
65952 KB |
Output is correct |
14 |
Correct |
36 ms |
65880 KB |
Output is correct |
15 |
Correct |
36 ms |
65972 KB |
Output is correct |
16 |
Correct |
37 ms |
65940 KB |
Output is correct |
17 |
Correct |
36 ms |
65836 KB |
Output is correct |
18 |
Correct |
37 ms |
65908 KB |
Output is correct |
19 |
Correct |
36 ms |
65964 KB |
Output is correct |
20 |
Correct |
35 ms |
65848 KB |
Output is correct |
21 |
Correct |
36 ms |
65948 KB |
Output is correct |
22 |
Correct |
36 ms |
65928 KB |
Output is correct |
23 |
Correct |
39 ms |
65996 KB |
Output is correct |
24 |
Correct |
38 ms |
65928 KB |
Output is correct |
25 |
Correct |
38 ms |
66004 KB |
Output is correct |
26 |
Correct |
38 ms |
65988 KB |
Output is correct |
27 |
Correct |
37 ms |
65924 KB |
Output is correct |
28 |
Correct |
38 ms |
65984 KB |
Output is correct |
29 |
Correct |
38 ms |
65992 KB |
Output is correct |
30 |
Correct |
38 ms |
65920 KB |
Output is correct |
31 |
Correct |
37 ms |
65908 KB |
Output is correct |
32 |
Correct |
39 ms |
65900 KB |
Output is correct |
33 |
Correct |
644 ms |
79048 KB |
Output is correct |
34 |
Correct |
824 ms |
79104 KB |
Output is correct |
35 |
Correct |
796 ms |
78892 KB |
Output is correct |
36 |
Correct |
835 ms |
79108 KB |
Output is correct |
37 |
Correct |
529 ms |
78124 KB |
Output is correct |
38 |
Correct |
506 ms |
77988 KB |
Output is correct |
39 |
Correct |
626 ms |
77980 KB |
Output is correct |
40 |
Correct |
674 ms |
78000 KB |
Output is correct |
41 |
Correct |
476 ms |
77916 KB |
Output is correct |
42 |
Correct |
534 ms |
78072 KB |
Output is correct |
43 |
Correct |
476 ms |
77940 KB |
Output is correct |
44 |
Correct |
612 ms |
77944 KB |
Output is correct |
45 |
Correct |
466 ms |
78192 KB |
Output is correct |
46 |
Correct |
471 ms |
77928 KB |
Output is correct |
47 |
Correct |
599 ms |
77860 KB |
Output is correct |
48 |
Correct |
605 ms |
77824 KB |
Output is correct |
49 |
Correct |
727 ms |
83912 KB |
Output is correct |
50 |
Correct |
711 ms |
84060 KB |
Output is correct |
51 |
Correct |
703 ms |
90980 KB |
Output is correct |
52 |
Correct |
733 ms |
90160 KB |
Output is correct |
53 |
Correct |
636 ms |
82236 KB |
Output is correct |
54 |
Correct |
635 ms |
82876 KB |
Output is correct |
55 |
Correct |
588 ms |
81164 KB |
Output is correct |
56 |
Correct |
734 ms |
85792 KB |
Output is correct |
57 |
Correct |
526 ms |
81620 KB |
Output is correct |
58 |
Correct |
532 ms |
82184 KB |
Output is correct |
59 |
Correct |
606 ms |
84320 KB |
Output is correct |