# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
819971 |
2023-08-10T16:41:12 Z |
Kerim |
Horses (IOI15_horses) |
C++17 |
|
184 ms |
55520 KB |
#include "horses.h"
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 5e5+5;
const int INF = 1e9+7;
int a[MAXN], b[MAXN], n;
double pref[MAXN];
struct node{
int mul;
int ans;
double p;
node(){
mul = ans = 0;
p = 0;
}
node(int _mul, int _ans){
mul = _mul;
ans = _ans;
}
}s[MAXN<<2];
node merge(node x, node y){
node z = node(0, 0);
if (x.p < y.p)
z.ans = y.ans, z.p = y.p;
else
z.ans = x.ans, z.p = x.p;
z.mul = (x.mul * 1LL * y.mul) % INF;
return z;
}
void build(int nd, int x, int y){
if (x == y){
s[nd].ans = x;
s[nd].mul = a[x];
s[nd].p = pref[x];
return;
}
int mid = (x+y) >> 1;
build(nd<<1, x, mid);
build(nd<<1|1, mid+1, y);
s[nd] = merge(s[nd<<1], s[nd<<1|1]);
}
double lazy[MAXN<<2];
void shift(int nd){
double &ret = lazy[nd];
lazy[nd<<1] += ret; s[nd<<1].p += ret;
lazy[nd<<1|1] += ret; s[nd<<1|1].p += ret;
ret = 0;
}
void inc(int l, int r, double val, int nd, int x, int y){
if (l > y or x > r)
return;
if (l <= x and y <= r){
s[nd].p += val;
lazy[nd] += val;
return;
}
shift(nd);
int mid = (x+y) >> 1;
inc(l, r, val, nd<<1, x, mid);
inc(l, r, val, nd<<1|1, mid+1, y);
s[nd] = merge(s[nd<<1], s[nd<<1|1]);
}
void upd(int p, double val, int nd, int x, int y){
if (x == y){
s[nd].mul = a[p];
s[nd].p += val;
return;
}
shift(nd);
int mid = (x+y) >> 1;
if (p <= mid)
upd(p, val, nd<<1, x, mid);
else
upd(p, val, nd<<1|1, mid+1, y);
s[nd] = merge(s[nd<<1], s[nd<<1|1]);
}
int get(int l, int r, int nd, int x, int y){
if (l > y or x > r)
return 1;
if (l <= x and y <= r)
return s[nd].mul;
int mid = (x+y) >> 1;
return (get(l, r, nd<<1, x, mid) *1LL* get(l, r, nd<<1|1, mid+1, y)) % INF;
}
int ask(int pos){
return (get(0, pos, 1, 0, n-1) *1LL* b[pos]) % INF;
}
int init(int N, int X[], int Y[]) {
n = N;
double sum = 0;
for (int i = 0; i < n; i++){
a[i] = X[i], b[i] = Y[i];
sum += log(a[i]);
pref[i] = sum + log(b[i]);
}
build(1, 0, n-1);
return ask(s[1].ans);
}
int updateX(int pos, int val) {
inc(pos, n-1, -log(a[pos]) + log(val), 1, 0, n-1);
a[pos] = val;
upd(pos, 0, 1, 0, n-1);
return ask(s[1].ans);
}
int updateY(int pos, int val) {
upd(pos, log(val) - log(b[pos]), 1, 0, n-1);
b[pos] = val;
return ask(s[1].ans);
}
Compilation message
horses.cpp: In function 'node merge(node, node)':
horses.cpp:30:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
30 | z.mul = (x.mul * 1LL * y.mul) % INF;
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get(int, int, int, int, int)':
horses.cpp:89:71: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
89 | return (get(l, r, nd<<1, x, mid) *1LL* get(l, r, nd<<1|1, mid+1, y)) % INF;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int ask(int)':
horses.cpp:93:47: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
93 | return (get(0, pos, 1, 0, n-1) *1LL* b[pos]) % INF;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
31536 KB |
Output is correct |
2 |
Correct |
13 ms |
31548 KB |
Output is correct |
3 |
Correct |
13 ms |
31632 KB |
Output is correct |
4 |
Correct |
12 ms |
31572 KB |
Output is correct |
5 |
Correct |
12 ms |
31532 KB |
Output is correct |
6 |
Correct |
13 ms |
31700 KB |
Output is correct |
7 |
Correct |
12 ms |
31568 KB |
Output is correct |
8 |
Correct |
13 ms |
31648 KB |
Output is correct |
9 |
Correct |
14 ms |
31588 KB |
Output is correct |
10 |
Correct |
12 ms |
31612 KB |
Output is correct |
11 |
Correct |
14 ms |
31560 KB |
Output is correct |
12 |
Correct |
12 ms |
31548 KB |
Output is correct |
13 |
Correct |
11 ms |
31632 KB |
Output is correct |
14 |
Correct |
15 ms |
31516 KB |
Output is correct |
15 |
Correct |
15 ms |
31580 KB |
Output is correct |
16 |
Correct |
12 ms |
31588 KB |
Output is correct |
17 |
Correct |
12 ms |
31524 KB |
Output is correct |
18 |
Correct |
15 ms |
31576 KB |
Output is correct |
19 |
Correct |
11 ms |
31616 KB |
Output is correct |
20 |
Correct |
12 ms |
31584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
31572 KB |
Output is correct |
2 |
Correct |
12 ms |
31536 KB |
Output is correct |
3 |
Correct |
12 ms |
31572 KB |
Output is correct |
4 |
Correct |
15 ms |
31520 KB |
Output is correct |
5 |
Correct |
12 ms |
31568 KB |
Output is correct |
6 |
Correct |
12 ms |
31572 KB |
Output is correct |
7 |
Correct |
15 ms |
31572 KB |
Output is correct |
8 |
Correct |
12 ms |
31572 KB |
Output is correct |
9 |
Correct |
12 ms |
31616 KB |
Output is correct |
10 |
Correct |
12 ms |
31572 KB |
Output is correct |
11 |
Correct |
11 ms |
31572 KB |
Output is correct |
12 |
Correct |
12 ms |
31572 KB |
Output is correct |
13 |
Correct |
12 ms |
31572 KB |
Output is correct |
14 |
Correct |
12 ms |
31536 KB |
Output is correct |
15 |
Correct |
12 ms |
31584 KB |
Output is correct |
16 |
Correct |
11 ms |
31624 KB |
Output is correct |
17 |
Correct |
11 ms |
31572 KB |
Output is correct |
18 |
Correct |
11 ms |
31572 KB |
Output is correct |
19 |
Correct |
11 ms |
31536 KB |
Output is correct |
20 |
Correct |
12 ms |
31608 KB |
Output is correct |
21 |
Correct |
12 ms |
31640 KB |
Output is correct |
22 |
Correct |
12 ms |
31532 KB |
Output is correct |
23 |
Correct |
12 ms |
31664 KB |
Output is correct |
24 |
Correct |
12 ms |
31572 KB |
Output is correct |
25 |
Correct |
13 ms |
31572 KB |
Output is correct |
26 |
Correct |
11 ms |
31592 KB |
Output is correct |
27 |
Correct |
12 ms |
31648 KB |
Output is correct |
28 |
Correct |
12 ms |
31648 KB |
Output is correct |
29 |
Correct |
12 ms |
31576 KB |
Output is correct |
30 |
Correct |
12 ms |
31592 KB |
Output is correct |
31 |
Correct |
12 ms |
31680 KB |
Output is correct |
32 |
Correct |
15 ms |
31572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
44308 KB |
Output is correct |
2 |
Correct |
159 ms |
52536 KB |
Output is correct |
3 |
Correct |
148 ms |
52508 KB |
Output is correct |
4 |
Correct |
184 ms |
52460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
31572 KB |
Output is correct |
2 |
Correct |
11 ms |
31624 KB |
Output is correct |
3 |
Correct |
11 ms |
31532 KB |
Output is correct |
4 |
Correct |
11 ms |
31572 KB |
Output is correct |
5 |
Correct |
11 ms |
31528 KB |
Output is correct |
6 |
Correct |
14 ms |
31632 KB |
Output is correct |
7 |
Correct |
15 ms |
31584 KB |
Output is correct |
8 |
Correct |
11 ms |
31612 KB |
Output is correct |
9 |
Correct |
11 ms |
31560 KB |
Output is correct |
10 |
Correct |
11 ms |
31572 KB |
Output is correct |
11 |
Correct |
11 ms |
31624 KB |
Output is correct |
12 |
Correct |
11 ms |
31572 KB |
Output is correct |
13 |
Correct |
11 ms |
31536 KB |
Output is correct |
14 |
Correct |
11 ms |
31572 KB |
Output is correct |
15 |
Correct |
11 ms |
31572 KB |
Output is correct |
16 |
Correct |
11 ms |
31572 KB |
Output is correct |
17 |
Correct |
11 ms |
31572 KB |
Output is correct |
18 |
Correct |
12 ms |
31628 KB |
Output is correct |
19 |
Correct |
14 ms |
31540 KB |
Output is correct |
20 |
Correct |
13 ms |
31572 KB |
Output is correct |
21 |
Correct |
16 ms |
31536 KB |
Output is correct |
22 |
Correct |
14 ms |
31580 KB |
Output is correct |
23 |
Correct |
13 ms |
31572 KB |
Output is correct |
24 |
Correct |
14 ms |
31640 KB |
Output is correct |
25 |
Correct |
17 ms |
31648 KB |
Output is correct |
26 |
Correct |
17 ms |
31676 KB |
Output is correct |
27 |
Correct |
15 ms |
31572 KB |
Output is correct |
28 |
Correct |
13 ms |
31672 KB |
Output is correct |
29 |
Correct |
17 ms |
31564 KB |
Output is correct |
30 |
Correct |
16 ms |
31668 KB |
Output is correct |
31 |
Correct |
16 ms |
31572 KB |
Output is correct |
32 |
Correct |
13 ms |
31564 KB |
Output is correct |
33 |
Correct |
54 ms |
51580 KB |
Output is correct |
34 |
Correct |
64 ms |
51536 KB |
Output is correct |
35 |
Correct |
67 ms |
43488 KB |
Output is correct |
36 |
Correct |
67 ms |
43420 KB |
Output is correct |
37 |
Correct |
57 ms |
51596 KB |
Output is correct |
38 |
Correct |
46 ms |
46636 KB |
Output is correct |
39 |
Correct |
39 ms |
45540 KB |
Output is correct |
40 |
Correct |
58 ms |
49644 KB |
Output is correct |
41 |
Correct |
38 ms |
46412 KB |
Output is correct |
42 |
Correct |
39 ms |
45540 KB |
Output is correct |
43 |
Incorrect |
56 ms |
49792 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
31572 KB |
Output is correct |
2 |
Correct |
13 ms |
31536 KB |
Output is correct |
3 |
Correct |
14 ms |
31572 KB |
Output is correct |
4 |
Correct |
12 ms |
31600 KB |
Output is correct |
5 |
Correct |
13 ms |
31616 KB |
Output is correct |
6 |
Correct |
13 ms |
31572 KB |
Output is correct |
7 |
Correct |
13 ms |
31628 KB |
Output is correct |
8 |
Correct |
13 ms |
31700 KB |
Output is correct |
9 |
Correct |
12 ms |
31616 KB |
Output is correct |
10 |
Correct |
14 ms |
31540 KB |
Output is correct |
11 |
Correct |
13 ms |
31576 KB |
Output is correct |
12 |
Correct |
13 ms |
31572 KB |
Output is correct |
13 |
Correct |
14 ms |
31612 KB |
Output is correct |
14 |
Correct |
13 ms |
31572 KB |
Output is correct |
15 |
Correct |
13 ms |
31624 KB |
Output is correct |
16 |
Correct |
13 ms |
31616 KB |
Output is correct |
17 |
Correct |
14 ms |
31620 KB |
Output is correct |
18 |
Correct |
13 ms |
31572 KB |
Output is correct |
19 |
Correct |
13 ms |
31588 KB |
Output is correct |
20 |
Correct |
13 ms |
31580 KB |
Output is correct |
21 |
Correct |
13 ms |
31572 KB |
Output is correct |
22 |
Correct |
13 ms |
31572 KB |
Output is correct |
23 |
Correct |
13 ms |
31572 KB |
Output is correct |
24 |
Correct |
13 ms |
31572 KB |
Output is correct |
25 |
Correct |
13 ms |
31612 KB |
Output is correct |
26 |
Correct |
13 ms |
31680 KB |
Output is correct |
27 |
Correct |
14 ms |
31572 KB |
Output is correct |
28 |
Correct |
13 ms |
31660 KB |
Output is correct |
29 |
Correct |
14 ms |
31648 KB |
Output is correct |
30 |
Correct |
13 ms |
31592 KB |
Output is correct |
31 |
Correct |
13 ms |
31572 KB |
Output is correct |
32 |
Correct |
14 ms |
31660 KB |
Output is correct |
33 |
Correct |
84 ms |
44392 KB |
Output is correct |
34 |
Correct |
146 ms |
52548 KB |
Output is correct |
35 |
Correct |
121 ms |
52508 KB |
Output is correct |
36 |
Correct |
173 ms |
52552 KB |
Output is correct |
37 |
Correct |
53 ms |
51656 KB |
Output is correct |
38 |
Correct |
51 ms |
55520 KB |
Output is correct |
39 |
Correct |
71 ms |
54316 KB |
Output is correct |
40 |
Correct |
71 ms |
54284 KB |
Output is correct |
41 |
Correct |
55 ms |
53712 KB |
Output is correct |
42 |
Correct |
49 ms |
46668 KB |
Output is correct |
43 |
Correct |
40 ms |
45532 KB |
Output is correct |
44 |
Correct |
57 ms |
49556 KB |
Output is correct |
45 |
Correct |
38 ms |
46436 KB |
Output is correct |
46 |
Correct |
39 ms |
45528 KB |
Output is correct |
47 |
Incorrect |
56 ms |
49696 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |