# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
641122 |
2022-09-16T03:40:47 Z |
ymm |
Horses (IOI15_horses) |
C++17 |
|
756 ms |
45352 KB |
#include "horses.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
static const int N = 1<<19;
static const int mod = 1e9+7;
static int n;
int seg[N<<1];
static int get(int l, int r, int i=0, int b=0, int e=n)
{
if (l <= b && e <= r)
return seg[i];
if (r <= b || e <= l)
return 0;
return max(get(l,r,2*i+1,b,(b+e)/2),get(l,r,2*i+2,(b+e)/2,e));
}
static void sset(int p, int x, int i=0, int b=0, int e=n)
{
if (e-b == 1) {
seg[i] = x;
return;
}
if (p < (b+e)/2)
sset(p,x,2*i+1,b,(b+e)/2);
else
sset(p,x,2*i+2,(b+e)/2,e);
seg[i] = max(seg[2*i+1], seg[2*i+2]);
}
int *X, *Y;
set<int> nonone;
ll proall;
static ll mpow(ll x, ll y){ll ans=1;while(y){ans=y&1?ans*x%mod:ans;x=x*x%mod;y>>=1;}return ans;}
static int calc()
{
ll ansn = 0, ansd = 1;
ll suf = 1;
auto it = --nonone.end();
while (it != nonone.begin() && suf < INT_MAX) {
int r = *(it--);
int l = *it;
ll mx = get(l, r);
// if (mx / suf > ansn / ansd)
if (mx * ansd > ansn * suf) {
ansn = mx;
ansd = suf;
}
suf *= X[l];
}
ansn %= mod;
ansd %= mod;
return proall * ansn % mod * mpow(ansd, mod-2) % mod;
}
int init(int n, int X[], int Y[]) {
::X = X; ::Y = Y; ::n = n;
proall = 1;
Loop (i,0,n) {
proall = proall * X[i] % mod;
sset(i, Y[i]);
if (i==0 || X[i] != 1)
nonone.insert(i);
}
nonone.insert(n);
return calc();
}
int updateX(int pos, int val) {
if (pos==0 || X[pos] != 1) nonone.erase(pos);
proall = proall * mpow(X[pos], mod-2) % mod;
X[pos] = val;
if (pos==0 || X[pos] != 1) nonone.insert(pos);
proall = proall * X[pos] % mod;
return calc();
}
int updateY(int pos, int val) {
Y[pos] = val;
sset(pos, val);
return calc();
}
Compilation message
horses.cpp: In function 'int calc()':
horses.cpp:62:49: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
62 | return proall * ansn % mod * mpow(ansd, mod-2) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:65:30: warning: declaration of 'Y' shadows a global declaration [-Wshadow]
65 | int init(int n, int X[], int Y[]) {
| ~~~~^~~
horses.cpp:38:10: note: shadowed declaration is here
38 | int *X, *Y;
| ^
horses.cpp:65:21: warning: declaration of 'X' shadows a global declaration [-Wshadow]
65 | int init(int n, int X[], int Y[]) {
| ~~~~^~~
horses.cpp:38:6: note: shadowed declaration is here
38 | int *X, *Y;
| ^
horses.cpp:65:14: warning: declaration of 'n' shadows a global declaration [-Wshadow]
65 | int init(int n, int X[], int Y[]) {
| ~~~~^
horses.cpp:12:12: note: shadowed declaration is here
12 | static int n;
| ^
horses.cpp:70:8: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
70 | sset(i, Y[i]);
| ^
horses.cpp:72:18: warning: conversion from 'll' {aka 'long long int'} to 'std::set<int>::value_type' {aka 'int'} may change value [-Wconversion]
72 | nonone.insert(i);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
320 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
352 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
756 ms |
34472 KB |
Output is correct |
2 |
Correct |
351 ms |
45240 KB |
Output is correct |
3 |
Correct |
368 ms |
36472 KB |
Output is correct |
4 |
Correct |
467 ms |
40396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
228 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
316 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
316 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
324 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
91 ms |
12456 KB |
Output is correct |
34 |
Correct |
90 ms |
12384 KB |
Output is correct |
35 |
Correct |
248 ms |
42700 KB |
Output is correct |
36 |
Correct |
222 ms |
42644 KB |
Output is correct |
37 |
Correct |
143 ms |
10500 KB |
Output is correct |
38 |
Correct |
145 ms |
23376 KB |
Output is correct |
39 |
Correct |
79 ms |
10376 KB |
Output is correct |
40 |
Correct |
233 ms |
37720 KB |
Output is correct |
41 |
Correct |
103 ms |
10432 KB |
Output is correct |
42 |
Correct |
126 ms |
10412 KB |
Output is correct |
43 |
Correct |
224 ms |
38160 KB |
Output is correct |
44 |
Correct |
200 ms |
38056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 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 |
316 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
725 ms |
36652 KB |
Output is correct |
34 |
Correct |
372 ms |
45352 KB |
Output is correct |
35 |
Correct |
356 ms |
36668 KB |
Output is correct |
36 |
Correct |
474 ms |
40380 KB |
Output is correct |
37 |
Correct |
96 ms |
12456 KB |
Output is correct |
38 |
Correct |
88 ms |
12348 KB |
Output is correct |
39 |
Correct |
232 ms |
42752 KB |
Output is correct |
40 |
Correct |
223 ms |
42688 KB |
Output is correct |
41 |
Correct |
136 ms |
10592 KB |
Output is correct |
42 |
Correct |
149 ms |
23284 KB |
Output is correct |
43 |
Correct |
80 ms |
10292 KB |
Output is correct |
44 |
Correct |
205 ms |
37804 KB |
Output is correct |
45 |
Correct |
108 ms |
10444 KB |
Output is correct |
46 |
Correct |
127 ms |
10488 KB |
Output is correct |
47 |
Correct |
200 ms |
38140 KB |
Output is correct |
48 |
Correct |
216 ms |
38172 KB |
Output is correct |
49 |
Correct |
179 ms |
15364 KB |
Output is correct |
50 |
Correct |
171 ms |
15420 KB |
Output is correct |
51 |
Correct |
369 ms |
44544 KB |
Output is correct |
52 |
Correct |
283 ms |
44120 KB |
Output is correct |
53 |
Correct |
686 ms |
13736 KB |
Output is correct |
54 |
Correct |
310 ms |
27304 KB |
Output is correct |
55 |
Correct |
186 ms |
11428 KB |
Output is correct |
56 |
Correct |
290 ms |
39556 KB |
Output is correct |
57 |
Correct |
429 ms |
11996 KB |
Output is correct |
58 |
Correct |
584 ms |
12768 KB |
Output is correct |
59 |
Correct |
193 ms |
38196 KB |
Output is correct |