# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
396781 |
2021-04-30T18:10:26 Z |
ly20 |
Horses (IOI15_horses) |
C++17 |
|
223 ms |
58752 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 512345, MOD = 1e9 + 7;
int x[MAXN], y[MAXN];
int seg[4 * MAXN];
long long multe[4 * MAXN], multd[4 * MAXN], ide[4 * MAXN], idd[4 * MAXN];
int n;
int acha() {
//printf("%d\n", seg[1]);
return ((long long) y[seg[1]] * multe[1]) % MOD;
}
int mult (int a, int b) {
long long c = ((long long) a * (long long) b);
if(c >= (long long) MOD) return MOD;
else return (int) c;
}
void build(int cur ,int ini, int fim) {
if(ini == fim) {
seg[cur] = ini;
multe[cur] = x[ini];
multd[cur] = 1;
return;
}
int m = (ini + fim) /2;
int e = 2 * cur, d = 2 * cur + 1;
build(e, ini, m); build(d, m + 1, fim);
int ye = y[seg[e]], yd = y[seg[d]];
if(ide[d] == 1) {
seg[cur] = seg[d];
multe[cur] = (((multe[e] * multd[e]) % MOD) * multe[d]) % MOD;
multd[cur] = multd[d];
ide[cur] = 1;
idd[cur] = idd[d];
return;
}
int md = mult(mult(multe[d], multd[e]), y[seg[d]]);
if(md > y[seg[e]]) {
seg[cur] = seg[d];
multe[cur] = (((multe[e] * multd[e]) % MOD) * multe[d]) % MOD;
multd[cur] = multd[d];
if(mult(multe[e], mult(multd[e], multe[d])) == MOD) ide[cur] = 1;
else ide[cur] = 0;
idd[cur] = idd[d];
return;
}
else {
seg[cur] = seg[e];
int teste = (mult(multd[d], multe[d]), multd[e]);
multe[cur] = multe[e];
ide[cur] = ide[e];
multd[cur] = (((multd[e] * multe[d]) % MOD) * multd[d] )% MOD;
if(teste == MOD) idd[cur] = 1;
else idd[cur] = 0;
}
}
void update(int cur, int ini, int fim, int id) {
if(ini > id || fim < id) return;
if(ini == fim) {
seg[cur] = ini;
multe[cur] = x[ini];
multd[cur] = 1;
ide[cur] = 0;
idd[cur] = 0;
return;
}
int m = (ini + fim) /2;
int e = 2 * cur, d = 2 * cur + 1;
update(e, ini, m, id); update(d, m + 1, fim, id);
if(ide[d] == 1) {
seg[cur] = seg[d];
multe[cur] = (((multe[e] * multd[e]) % MOD) * multe[d]) % MOD;
multd[cur] = multd[d];
ide[cur] = 1;
idd[cur] = idd[d];
return;
}
int md = mult(mult(multe[d], multd[e]), y[seg[d]]);
if(md > y[seg[e]]) {
seg[cur] = seg[d];
multe[cur] = (((multe[e] * multd[e]) % MOD) * multe[d]) % MOD;
multd[cur] = multd[d];
if(mult(multe[e], mult(multd[e], multe[d])) == MOD) ide[cur] = 1;
else ide[cur] = 0;
idd[cur] = idd[d];
return;
}
else {
seg[cur] = seg[e];
int teste = (mult(multd[d], multe[d]), multd[e]);
multe[cur] = multe[e];
ide[cur] = ide[e];
multd[cur] = (((multd[e] * multe[d]) % MOD) * multd[d] )% MOD;
if(teste == MOD) idd[cur] = 1;
else idd[cur] = 0;
}
}
int init(int N, int X[], int Y[]) {
n = N;
for(int i = 0; i < n; i++) {
x[i] = X[i]; y[i] = Y[i];
}
build(1, 0, n - 1);
return acha();
}
int updateX(int pos, int val) {
x[pos] = val;
update(1, 0, n - 1, pos);
return acha();
}
int updateY(int pos, int val) {
y[pos] = val;
update(1, 0, n - 1, pos);
return acha();
}
/*int main() {
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%d", &x[i]);
}
for(int i = 0; i < n; i++) {
scanf("%d", &y[i]);
}
printf("%d\n", init(n, x, y));
int m;
scanf("%d", &m);
for(int i = 0; i < m; i++) {
int tp, pos, val;
scanf("%d %d %d", &tp, &pos, &val);
if(tp == 1) printf("%d\n", updateX(pos, val));
else printf("%d\n", updateY(pos, val));
}
}*/
/*
10
3 2 7 5 11 13 107 23 51 3
1 1 1 1 1000000000 1 1 1 1 1
16
1 1 1
1 2 1
1 0 1
1 8 1
1 7 1
1 9 1
1 1 25
1 8 123456789
1 4 1
1 6 1
1 3 1
1 5 1
1 5 12345
1 6 123456
1 7 1234567
2 4 3
*/
Compilation message
horses.cpp: In function 'int acha()':
horses.cpp:11:47: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
11 | return ((long long) y[seg[1]] * multe[1]) % MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:37:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
37 | int md = mult(mult(multe[d], multd[e]), y[seg[d]]);
| ~~~~~~~^
horses.cpp:37:41: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
37 | int md = mult(mult(multe[d], multd[e]), y[seg[d]]);
| ~~~~~~~^
horses.cpp:42:39: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
42 | if(mult(multe[e], mult(multd[e], multe[d])) == MOD) ide[cur] = 1;
| ~~~~~~~^
horses.cpp:42:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
42 | if(mult(multe[e], mult(multd[e], multe[d])) == MOD) ide[cur] = 1;
| ~~~~~~~^
horses.cpp:42:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
42 | if(mult(multe[e], mult(multd[e], multe[d])) == MOD) ide[cur] = 1;
| ~~~~~~~^
horses.cpp:49:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
49 | int teste = (mult(multd[d], multe[d]), multd[e]);
| ~~~~~~~^
horses.cpp:49:44: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
49 | int teste = (mult(multd[d], multe[d]), multd[e]);
| ~~~~~~~^
horses.cpp:49:46: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
49 | int teste = (mult(multd[d], multe[d]), multd[e]);
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
horses.cpp:28:9: warning: unused variable 'ye' [-Wunused-variable]
28 | int ye = y[seg[e]], yd = y[seg[d]];
| ^~
horses.cpp:28:25: warning: unused variable 'yd' [-Wunused-variable]
28 | int ye = y[seg[e]], yd = y[seg[d]];
| ^~
horses.cpp: In function 'void update(int, int, int, int)':
horses.cpp:78:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
78 | int md = mult(mult(multe[d], multd[e]), y[seg[d]]);
| ~~~~~~~^
horses.cpp:78:41: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
78 | int md = mult(mult(multe[d], multd[e]), y[seg[d]]);
| ~~~~~~~^
horses.cpp:83:39: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
83 | if(mult(multe[e], mult(multd[e], multe[d])) == MOD) ide[cur] = 1;
| ~~~~~~~^
horses.cpp:83:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
83 | if(mult(multe[e], mult(multd[e], multe[d])) == MOD) ide[cur] = 1;
| ~~~~~~~^
horses.cpp:83:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
83 | if(mult(multe[e], mult(multd[e], multe[d])) == MOD) ide[cur] = 1;
| ~~~~~~~^
horses.cpp:90:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
90 | int teste = (mult(multd[d], multe[d]), multd[e]);
| ~~~~~~~^
horses.cpp:90:44: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
90 | int teste = (mult(multd[d], multe[d]), multd[e]);
| ~~~~~~~^
horses.cpp:90:46: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
90 | int teste = (mult(multd[d], multe[d]), multd[e]);
| ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 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 |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 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 |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
37812 KB |
Output is correct |
2 |
Correct |
192 ms |
58752 KB |
Output is correct |
3 |
Correct |
162 ms |
49828 KB |
Output is correct |
4 |
Correct |
181 ms |
53716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
63 ms |
45152 KB |
Output is correct |
34 |
Correct |
65 ms |
49024 KB |
Output is correct |
35 |
Correct |
79 ms |
47812 KB |
Output is correct |
36 |
Correct |
76 ms |
47776 KB |
Output is correct |
37 |
Correct |
52 ms |
47240 KB |
Output is correct |
38 |
Correct |
46 ms |
40116 KB |
Output is correct |
39 |
Correct |
40 ms |
39004 KB |
Output is correct |
40 |
Correct |
62 ms |
43116 KB |
Output is correct |
41 |
Correct |
46 ms |
39284 KB |
Output is correct |
42 |
Correct |
41 ms |
39108 KB |
Output is correct |
43 |
Correct |
52 ms |
43288 KB |
Output is correct |
44 |
Correct |
53 ms |
43260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
408 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 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 |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
97 ms |
37884 KB |
Output is correct |
34 |
Correct |
223 ms |
58584 KB |
Output is correct |
35 |
Correct |
162 ms |
49808 KB |
Output is correct |
36 |
Correct |
207 ms |
53672 KB |
Output is correct |
37 |
Correct |
78 ms |
49092 KB |
Output is correct |
38 |
Correct |
74 ms |
49052 KB |
Output is correct |
39 |
Correct |
96 ms |
47820 KB |
Output is correct |
40 |
Correct |
81 ms |
47812 KB |
Output is correct |
41 |
Correct |
59 ms |
47284 KB |
Output is correct |
42 |
Correct |
49 ms |
40132 KB |
Output is correct |
43 |
Correct |
41 ms |
38984 KB |
Output is correct |
44 |
Correct |
63 ms |
42980 KB |
Output is correct |
45 |
Correct |
43 ms |
39348 KB |
Output is correct |
46 |
Correct |
60 ms |
39044 KB |
Output is correct |
47 |
Correct |
56 ms |
43244 KB |
Output is correct |
48 |
Correct |
55 ms |
43244 KB |
Output is correct |
49 |
Correct |
187 ms |
51020 KB |
Output is correct |
50 |
Correct |
176 ms |
51104 KB |
Output is correct |
51 |
Correct |
148 ms |
49656 KB |
Output is correct |
52 |
Correct |
128 ms |
49216 KB |
Output is correct |
53 |
Correct |
174 ms |
49436 KB |
Output is correct |
54 |
Correct |
134 ms |
43428 KB |
Output is correct |
55 |
Correct |
107 ms |
40068 KB |
Output is correct |
56 |
Correct |
114 ms |
46276 KB |
Output is correct |
57 |
Correct |
108 ms |
40912 KB |
Output is correct |
58 |
Correct |
114 ms |
41084 KB |
Output is correct |
59 |
Correct |
56 ms |
43280 KB |
Output is correct |