#include "horses.h"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class RangeMax {
public:
vector<int>dat; int size_ = 0;
void init(int sz) {
size_ = 1;
while (size_ <= sz) size_ *= 2;
dat.resize(size_ * 2, 0);
}
void update(int p, int x) {
p += size_; dat[p] = x; p >>= 1;
while (p >= 1) { dat[p] = max(dat[p * 2], dat[p * 2 + 1]); p >>= 1; }
}
int getmax_(int l, int r, int a, int b, int u) {
if (b <= l || r <= a) return -1;
if (l <= a && b <= r) return dat[u];
return max(getmax_(l, r, a, (a + b) >> 1, u * 2), getmax_(l, r, (a + b) >> 1, b, u * 2 + 1));
}
int getmax(int l, int r) {
return getmax_(l, r, 0, size_, 1);
}
};
int bit[524299];
void add(int pos, int x) {
pos++;
while (pos < 524299) { bit[pos] += x; pos += (pos&-pos); }
}
int sum(int pos) {
int s = 0; pos++;
while (pos >= 1) { s += bit[pos]; pos -= (pos&-pos); }
return s;
}
long long N, X[500009], Y[500009], Allval = 0, mod = 1000000007;
RangeMax Q;
long long modpow(long long a, long long b, long long m) {
long long p = 1, q = a;
for (int i = 0; i < 31; i++) {
if ((b&(1LL << i)) != 0) { p *= q; p %= m; }
q *= q; q %= m;
}
return p;
}
long long Div(long long a, long long b, long long m) {
return (1LL * a*modpow(b, m - 2, m)) % m;
}
int solve() {
pair<int, int>maxid = make_pair(0, 1);
long long P = 1, cx = N - 1;
while (true) {
// 二分探索 Phase
long long M = 0, I = sum(cx), J = 0;
for (int i = 18; i >= 0; i--) {
if (bit[M + (1 << i)] + J < I) { M += (1 << i); J += bit[M]; }
}
// 結果を求める Phase
long long YY = Q.getmax(M, cx + 1);
if (maxid.first * P < maxid.second * YY) maxid = make_pair(YY, P);
P *= X[M]; cx = M - 1;
if (P > (1LL << 30) || cx < 0) break;
}
long long J = Div(Allval, maxid.second, mod);
J *= maxid.first; J %= mod;
return J;
}
int init(int NN, int XX[], int YY[]) {
N = NN; Allval = 1; Q.init(N + 2);
for (int i = 0; i < N; i++) { X[i] = XX[i]; Allval *= X[i]; Allval %= mod; if (X[i] >= 2) add(i, 1); }
for (int i = 0; i < N; i++) { Y[i] = YY[i]; Q.update(i, Y[i]); }
return solve();
}
int updateX(int pos, int val) {
Allval = Div(Allval, X[pos], mod); if (X[pos] >= 2) add(pos, -1);
X[pos] = val;
Allval *= X[pos]; Allval %= mod; if (X[pos] >= 2) add(pos, 1);
return solve();
}
int updateY(int pos, int val) {
Y[pos] = val; Q.update(pos, Y[pos]);
return solve();
}
Compilation message
horses.cpp: In function 'int solve()':
horses.cpp:62:30: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
long long M = 0, I = sum(cx), J = 0;
^
horses.cpp:68:36: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
long long YY = Q.getmax(M, cx + 1);
^
horses.cpp:68:33: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
long long YY = Q.getmax(M, cx + 1);
~~~^~~
horses.cpp:76:9: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return J;
^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:80:31: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
N = NN; Allval = 1; Q.init(N + 2);
~~^~~
horses.cpp:82:61: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
for (int i = 0; i < N; i++) { Y[i] = YY[i]; Q.update(i, Y[i]); }
~~~^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:94:35: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
Y[pos] = val; Q.update(pos, Y[pos]);
~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
564 KB |
Output is correct |
4 |
Correct |
2 ms |
564 KB |
Output is correct |
5 |
Correct |
3 ms |
564 KB |
Output is correct |
6 |
Correct |
3 ms |
564 KB |
Output is correct |
7 |
Correct |
3 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
3 ms |
620 KB |
Output is correct |
11 |
Correct |
2 ms |
620 KB |
Output is correct |
12 |
Correct |
2 ms |
620 KB |
Output is correct |
13 |
Correct |
2 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
3 ms |
620 KB |
Output is correct |
17 |
Correct |
2 ms |
632 KB |
Output is correct |
18 |
Correct |
3 ms |
632 KB |
Output is correct |
19 |
Correct |
2 ms |
632 KB |
Output is correct |
20 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
724 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
2 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
2 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
724 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
2 ms |
724 KB |
Output is correct |
19 |
Correct |
3 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
724 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Correct |
3 ms |
724 KB |
Output is correct |
23 |
Correct |
6 ms |
724 KB |
Output is correct |
24 |
Correct |
6 ms |
724 KB |
Output is correct |
25 |
Correct |
5 ms |
724 KB |
Output is correct |
26 |
Correct |
4 ms |
724 KB |
Output is correct |
27 |
Correct |
10 ms |
724 KB |
Output is correct |
28 |
Correct |
6 ms |
724 KB |
Output is correct |
29 |
Correct |
5 ms |
724 KB |
Output is correct |
30 |
Correct |
6 ms |
724 KB |
Output is correct |
31 |
Correct |
9 ms |
796 KB |
Output is correct |
32 |
Correct |
9 ms |
796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
842 ms |
19556 KB |
Output is correct |
2 |
Correct |
325 ms |
19556 KB |
Output is correct |
3 |
Correct |
313 ms |
19556 KB |
Output is correct |
4 |
Correct |
464 ms |
19556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
19556 KB |
Output is correct |
2 |
Correct |
2 ms |
19556 KB |
Output is correct |
3 |
Correct |
3 ms |
19556 KB |
Output is correct |
4 |
Correct |
3 ms |
19556 KB |
Output is correct |
5 |
Correct |
2 ms |
19556 KB |
Output is correct |
6 |
Correct |
2 ms |
19556 KB |
Output is correct |
7 |
Correct |
3 ms |
19556 KB |
Output is correct |
8 |
Correct |
0 ms |
19556 KB |
Output is correct |
9 |
Correct |
2 ms |
19556 KB |
Output is correct |
10 |
Correct |
3 ms |
19556 KB |
Output is correct |
11 |
Correct |
2 ms |
19556 KB |
Output is correct |
12 |
Correct |
2 ms |
19556 KB |
Output is correct |
13 |
Correct |
2 ms |
19556 KB |
Output is correct |
14 |
Correct |
2 ms |
19556 KB |
Output is correct |
15 |
Correct |
3 ms |
19556 KB |
Output is correct |
16 |
Correct |
3 ms |
19556 KB |
Output is correct |
17 |
Correct |
2 ms |
19556 KB |
Output is correct |
18 |
Correct |
2 ms |
19556 KB |
Output is correct |
19 |
Correct |
2 ms |
19556 KB |
Output is correct |
20 |
Correct |
3 ms |
19556 KB |
Output is correct |
21 |
Correct |
2 ms |
19556 KB |
Output is correct |
22 |
Correct |
3 ms |
19556 KB |
Output is correct |
23 |
Correct |
5 ms |
19556 KB |
Output is correct |
24 |
Correct |
4 ms |
19556 KB |
Output is correct |
25 |
Correct |
6 ms |
19556 KB |
Output is correct |
26 |
Correct |
4 ms |
19556 KB |
Output is correct |
27 |
Correct |
8 ms |
19556 KB |
Output is correct |
28 |
Correct |
6 ms |
19556 KB |
Output is correct |
29 |
Correct |
5 ms |
19556 KB |
Output is correct |
30 |
Correct |
5 ms |
19556 KB |
Output is correct |
31 |
Correct |
6 ms |
19556 KB |
Output is correct |
32 |
Correct |
8 ms |
19556 KB |
Output is correct |
33 |
Correct |
127 ms |
19556 KB |
Output is correct |
34 |
Correct |
91 ms |
19556 KB |
Output is correct |
35 |
Correct |
142 ms |
19556 KB |
Output is correct |
36 |
Correct |
126 ms |
19556 KB |
Output is correct |
37 |
Correct |
157 ms |
19556 KB |
Output is correct |
38 |
Correct |
108 ms |
19556 KB |
Output is correct |
39 |
Correct |
81 ms |
19556 KB |
Output is correct |
40 |
Correct |
118 ms |
19556 KB |
Output is correct |
41 |
Correct |
108 ms |
19556 KB |
Output is correct |
42 |
Correct |
144 ms |
19556 KB |
Output is correct |
43 |
Correct |
90 ms |
19556 KB |
Output is correct |
44 |
Correct |
94 ms |
19556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
19556 KB |
Output is correct |
2 |
Correct |
3 ms |
19556 KB |
Output is correct |
3 |
Correct |
2 ms |
19556 KB |
Output is correct |
4 |
Correct |
2 ms |
19556 KB |
Output is correct |
5 |
Correct |
3 ms |
19556 KB |
Output is correct |
6 |
Correct |
2 ms |
19556 KB |
Output is correct |
7 |
Correct |
4 ms |
19556 KB |
Output is correct |
8 |
Correct |
3 ms |
19556 KB |
Output is correct |
9 |
Correct |
2 ms |
19556 KB |
Output is correct |
10 |
Correct |
2 ms |
19556 KB |
Output is correct |
11 |
Correct |
2 ms |
19556 KB |
Output is correct |
12 |
Correct |
3 ms |
19556 KB |
Output is correct |
13 |
Correct |
3 ms |
19556 KB |
Output is correct |
14 |
Correct |
3 ms |
19556 KB |
Output is correct |
15 |
Correct |
2 ms |
19556 KB |
Output is correct |
16 |
Correct |
3 ms |
19556 KB |
Output is correct |
17 |
Correct |
3 ms |
19556 KB |
Output is correct |
18 |
Correct |
2 ms |
19556 KB |
Output is correct |
19 |
Correct |
2 ms |
19556 KB |
Output is correct |
20 |
Correct |
2 ms |
19556 KB |
Output is correct |
21 |
Correct |
3 ms |
19556 KB |
Output is correct |
22 |
Correct |
2 ms |
19556 KB |
Output is correct |
23 |
Correct |
4 ms |
19556 KB |
Output is correct |
24 |
Correct |
5 ms |
19556 KB |
Output is correct |
25 |
Correct |
6 ms |
19556 KB |
Output is correct |
26 |
Correct |
5 ms |
19556 KB |
Output is correct |
27 |
Correct |
9 ms |
19556 KB |
Output is correct |
28 |
Correct |
7 ms |
19556 KB |
Output is correct |
29 |
Correct |
6 ms |
19556 KB |
Output is correct |
30 |
Correct |
6 ms |
19556 KB |
Output is correct |
31 |
Correct |
7 ms |
19556 KB |
Output is correct |
32 |
Correct |
11 ms |
19556 KB |
Output is correct |
33 |
Correct |
856 ms |
19572 KB |
Output is correct |
34 |
Correct |
338 ms |
19572 KB |
Output is correct |
35 |
Correct |
330 ms |
19572 KB |
Output is correct |
36 |
Correct |
474 ms |
19588 KB |
Output is correct |
37 |
Correct |
107 ms |
19588 KB |
Output is correct |
38 |
Correct |
93 ms |
19588 KB |
Output is correct |
39 |
Correct |
139 ms |
19588 KB |
Output is correct |
40 |
Correct |
118 ms |
19588 KB |
Output is correct |
41 |
Correct |
150 ms |
19588 KB |
Output is correct |
42 |
Correct |
103 ms |
19588 KB |
Output is correct |
43 |
Correct |
86 ms |
19588 KB |
Output is correct |
44 |
Correct |
114 ms |
24508 KB |
Output is correct |
45 |
Correct |
130 ms |
25164 KB |
Output is correct |
46 |
Correct |
162 ms |
26776 KB |
Output is correct |
47 |
Correct |
100 ms |
34952 KB |
Output is correct |
48 |
Correct |
94 ms |
41320 KB |
Output is correct |
49 |
Correct |
308 ms |
47540 KB |
Output is correct |
50 |
Correct |
295 ms |
52452 KB |
Output is correct |
51 |
Correct |
399 ms |
64244 KB |
Output is correct |
52 |
Correct |
280 ms |
75580 KB |
Output is correct |
53 |
Correct |
920 ms |
78372 KB |
Output is correct |
54 |
Correct |
505 ms |
83040 KB |
Output is correct |
55 |
Correct |
310 ms |
83492 KB |
Output is correct |
56 |
Correct |
333 ms |
92832 KB |
Output is correct |
57 |
Correct |
639 ms |
94212 KB |
Output is correct |
58 |
Correct |
802 ms |
97196 KB |
Output is correct |
59 |
Correct |
105 ms |
104352 KB |
Output is correct |