#include <bits/stdc++.h>
using namespace std;
#ifndef wambule
#include "horses.h"
#else
#endif
const int mod = 1e9 + 7;
const int MXY = 1e9;
int MG(int a, int b) {
return 1ll * a * b % mod;
}
int G(int a, int b) {
if(a == -1 || b == -1) return -1;
if(1ll * a * b > MXY) return -1;
return a * b;
}
struct ovo {
ovo *l, *r;
int a, x, y, xm, ym;
ovo() {
l = r = NULL;
a = x = y = xm = ym = 1;
}
int AP() {
return MG(a, xm);
}
void P() {
if(l == NULL) l = new ovo();
if(r == NULL) r = new ovo();
int p = G(l->y, G(r->x, r->a));
if(p == -1 || p > l->a) {
a = r->a;
x = G(l->x, G(l->y, r->x));
y = r->y;
xm = MG(l->xm, MG(l->ym, r->xm));
ym = r->ym;
} else {
a = l->a;
x = l->x;
y = G(l->y, G(r->x, r->y));
xm = l->xm;
ym = MG(l->ym, MG(r->xm, r->ym));
}
}
void C(int vl, int rm) {
if(rm) a = vl;
else x = xm = vl, y = ym = 1;
}
} *rt;
int globn;
void gng(int si, int vl, int rm, int l = 0, int r = globn - 1, ovo *&t = rt) {
if(t == NULL) t = new ovo();
int m = (l + r) / 2;
if(l == r) return t->C(vl, rm);
else if(m >= si) gng(si, vl, rm, l, m, t->l);
else gng(si, vl, rm, m + 1, r, t->r);
return t->P();
}
int updateX(int i, int x) {
gng(i, x, 0);
return rt->AP();
}
int updateY(int i, int y) {
gng(i, y, 1);
return rt->AP();
}
int init(int n, int x[], int y[]) {
rt = NULL, globn = n;
for(int i = 0; i < n; ++i) {
updateX(i, x[i]);
updateY(i, y[i]);
}
return rt->AP();
}
#ifdef wambule
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
return 0;
}
#endif
Compilation message
horses.cpp: In function 'int MG(int, int)':
horses.cpp:12:21: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
12 | return 1ll * a * b % mod;
| ~~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
640 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
2 ms |
492 KB |
Output is correct |
32 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
477 ms |
52180 KB |
Output is correct |
2 |
Correct |
620 ms |
64876 KB |
Output is correct |
3 |
Correct |
557 ms |
56044 KB |
Output is correct |
4 |
Correct |
573 ms |
59844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
2 ms |
492 KB |
Output is correct |
32 |
Correct |
2 ms |
492 KB |
Output is correct |
33 |
Correct |
483 ms |
55276 KB |
Output is correct |
34 |
Correct |
467 ms |
55404 KB |
Output is correct |
35 |
Correct |
478 ms |
62188 KB |
Output is correct |
36 |
Correct |
458 ms |
62316 KB |
Output is correct |
37 |
Correct |
443 ms |
53472 KB |
Output is correct |
38 |
Correct |
422 ms |
54252 KB |
Output is correct |
39 |
Correct |
434 ms |
53380 KB |
Output is correct |
40 |
Correct |
429 ms |
57196 KB |
Output is correct |
41 |
Correct |
470 ms |
53500 KB |
Output is correct |
42 |
Correct |
439 ms |
53356 KB |
Output is correct |
43 |
Correct |
424 ms |
57596 KB |
Output is correct |
44 |
Correct |
419 ms |
57728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
268 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
2 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
470 ms |
56044 KB |
Output is correct |
34 |
Correct |
570 ms |
64748 KB |
Output is correct |
35 |
Correct |
544 ms |
56044 KB |
Output is correct |
36 |
Correct |
583 ms |
59884 KB |
Output is correct |
37 |
Correct |
453 ms |
55276 KB |
Output is correct |
38 |
Correct |
456 ms |
55276 KB |
Output is correct |
39 |
Correct |
479 ms |
62372 KB |
Output is correct |
40 |
Correct |
448 ms |
62096 KB |
Output is correct |
41 |
Correct |
447 ms |
53612 KB |
Output is correct |
42 |
Correct |
427 ms |
54352 KB |
Output is correct |
43 |
Correct |
470 ms |
53308 KB |
Output is correct |
44 |
Correct |
491 ms |
57340 KB |
Output is correct |
45 |
Correct |
453 ms |
53404 KB |
Output is correct |
46 |
Correct |
483 ms |
53472 KB |
Output is correct |
47 |
Correct |
476 ms |
57708 KB |
Output is correct |
48 |
Correct |
424 ms |
57580 KB |
Output is correct |
49 |
Correct |
610 ms |
57324 KB |
Output is correct |
50 |
Correct |
616 ms |
57452 KB |
Output is correct |
51 |
Correct |
500 ms |
64236 KB |
Output is correct |
52 |
Correct |
516 ms |
63596 KB |
Output is correct |
53 |
Correct |
574 ms |
55760 KB |
Output is correct |
54 |
Correct |
480 ms |
56172 KB |
Output is correct |
55 |
Correct |
563 ms |
54380 KB |
Output is correct |
56 |
Correct |
504 ms |
58988 KB |
Output is correct |
57 |
Correct |
496 ms |
55148 KB |
Output is correct |
58 |
Correct |
525 ms |
55532 KB |
Output is correct |
59 |
Correct |
465 ms |
57624 KB |
Output is correct |