# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
432995 |
2021-06-18T17:15:16 Z |
timmyfeng |
Horses (IOI15_horses) |
C++17 |
|
259 ms |
80384 KB |
#include <bits/stdc++.h>
using namespace std;
#include "horses.h"
const int M = 1000000007;
struct mint {
int value;
bool mod;
mint(int x = 0, bool y = false) {
value = x, mod = y;
}
friend mint operator*(mint l, mint r) {
long long product = (long long) l.value * r.value;
return mint(product % M, product >= M || l.mod || r.mod);
}
};
struct segtree {
segtree *left, *right;
mint product, suffix, price, value;
void pull() {
product = left->product * right->product;
mint temp = right->value * left->suffix;
if (temp.mod || temp.value > left->price.value) {
suffix = right->suffix;
price = right->price;
value = right->value * left->product;
} else {
suffix = left->suffix * right->product;
price = left->price;
value = left->value;
}
}
segtree(int l, int r, int x[], int y[]) {
if (l == r) {
product = x[l];
price = y[l];
suffix = 1;
value = product * price;
} else {
int m = (l + r) / 2;
left = new segtree(l, m, x, y);
right = new segtree(m + 1, r, x, y);
pull();
}
}
void update(int a, int x, int y, int l, int r) {
if (l == r) {
product = x > 0 ? mint(x) : product;
price = y > 0 ? mint(y) : price;
value = product * price;
} else {
int m = (l + r) / 2;
if (a <= m) {
left->update(a, x, y, l, m);
} else {
right->update(a, x, y, m + 1, r);
}
pull();
}
}
};
segtree *ans;
int n;
int init(int N, int X[], int Y[]) {
ans = new segtree(0, N - 1, X, Y), n = N;
return ans->value.value;
}
int updateX(int pos, int val) {
ans->update(pos, val, 0, 0, n - 1);
return ans->value.value;
}
int updateY(int pos, int val) {
ans->update(pos, 0, val, 0, n - 1);
return ans->value.value;
}
Compilation message
horses.cpp: In function 'mint operator*(mint, mint)':
horses.cpp:18:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
18 | return mint(product % M, product >= M || l.mod || r.mod);
| ~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
288 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
292 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
288 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
292 KB |
Output is correct |
20 |
Correct |
0 ms |
292 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
296 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
432 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
436 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
128 ms |
71540 KB |
Output is correct |
2 |
Correct |
259 ms |
80384 KB |
Output is correct |
3 |
Correct |
228 ms |
71480 KB |
Output is correct |
4 |
Correct |
238 ms |
75464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
436 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
428 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
106 ms |
70780 KB |
Output is correct |
34 |
Correct |
106 ms |
70764 KB |
Output is correct |
35 |
Correct |
124 ms |
77716 KB |
Output is correct |
36 |
Correct |
121 ms |
77636 KB |
Output is correct |
37 |
Correct |
95 ms |
68980 KB |
Output is correct |
38 |
Correct |
94 ms |
69828 KB |
Output is correct |
39 |
Correct |
91 ms |
68804 KB |
Output is correct |
40 |
Correct |
121 ms |
72812 KB |
Output is correct |
41 |
Correct |
82 ms |
68856 KB |
Output is correct |
42 |
Correct |
84 ms |
69060 KB |
Output is correct |
43 |
Correct |
102 ms |
73184 KB |
Output is correct |
44 |
Correct |
100 ms |
73284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
288 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
292 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
436 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
123 ms |
71628 KB |
Output is correct |
34 |
Correct |
257 ms |
80320 KB |
Output is correct |
35 |
Correct |
214 ms |
71596 KB |
Output is correct |
36 |
Correct |
240 ms |
75440 KB |
Output is correct |
37 |
Correct |
106 ms |
70748 KB |
Output is correct |
38 |
Correct |
110 ms |
70724 KB |
Output is correct |
39 |
Correct |
123 ms |
77828 KB |
Output is correct |
40 |
Correct |
123 ms |
77616 KB |
Output is correct |
41 |
Correct |
116 ms |
68916 KB |
Output is correct |
42 |
Correct |
92 ms |
69812 KB |
Output is correct |
43 |
Correct |
85 ms |
68820 KB |
Output is correct |
44 |
Correct |
104 ms |
72868 KB |
Output is correct |
45 |
Correct |
84 ms |
68836 KB |
Output is correct |
46 |
Correct |
83 ms |
68908 KB |
Output is correct |
47 |
Correct |
99 ms |
73108 KB |
Output is correct |
48 |
Correct |
99 ms |
73160 KB |
Output is correct |
49 |
Correct |
239 ms |
72744 KB |
Output is correct |
50 |
Correct |
237 ms |
72772 KB |
Output is correct |
51 |
Correct |
160 ms |
79612 KB |
Output is correct |
52 |
Correct |
158 ms |
79192 KB |
Output is correct |
53 |
Correct |
231 ms |
71240 KB |
Output is correct |
54 |
Correct |
138 ms |
71704 KB |
Output is correct |
55 |
Correct |
125 ms |
70076 KB |
Output is correct |
56 |
Correct |
145 ms |
74560 KB |
Output is correct |
57 |
Correct |
121 ms |
70468 KB |
Output is correct |
58 |
Correct |
124 ms |
71108 KB |
Output is correct |
59 |
Correct |
99 ms |
73100 KB |
Output is correct |