# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
288305 |
2020-09-01T11:57:56 Z |
shayan_p |
Horses (IOI15_horses) |
C++17 |
|
1035 ms |
53436 KB |
#include<bits/stdc++.h>
#include "horses.h"
#define F first
#define S second
#define PB push_back
#define sz(s) (int(s.size()))
#define bit(n, k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
const int maxn = 5e5 + 10, mod = 1e9 + 7;
set<int> st; // reverse points
int n;
int val[4 * maxn], zr[4 * maxn];
void add(int pos, int x, int l = 0, int r = n, int id = 1){
if(r-l == 1){
val[id] = x;
return;
}
int mid = (l+r) >> 1;
if(pos < mid)
add(pos, x, l, mid, 2*id);
else
add(pos, x, mid, r, 2*id+1);
val[id] = max(val[2*id], val[2*id+1]);
}
int ask(int f, int s, int l = 0, int r = n, int id = 1){
if(f >= s || l >= r || s <= l || r <= f)
return 0;
if(f <= l && r <= s)
return val[id];
int mid = (l+r) >> 1;
return max(ask(f, s, l, mid, 2*id), ask(f, s, mid, r, 2*id+1));
}
void put(int pos, int x, int l = 0, int r = n, int id = 1){
if(r-l == 1){
zr[id] = x;
return;
}
int mid = (l+r) >> 1;
if(pos < mid)
put(pos, x, l, mid, 2*id);
else
put(pos, x, mid, r, 2*id+1);
zr[id] = 1ll * zr[2*id] * zr[2*id+1] % mod;
}
int zar(int pos, int l = 0, int r = n, int id = 1){
if(pos <= l)
return 1;
if(r <= pos)
return zr[id];
int mid = (l + r) >> 1;
return 1ll * zar(pos, l, mid, 2*id) * zar(pos, mid, r, 2*id+1) % mod;
}
int a[maxn], b[maxn];
int calc(){
int bst = 0, lst = n;
bool gr = 0;
for(int x : st){
x*=-1;
bst = max(bst, ask(x, lst));
lst = x;
ll num = 1ll * a[x] * bst;
bst = num % mod;
if(num >= mod){
gr = 1;
break;
}
}
if(!gr)
return max(bst, ask(0, lst));
else
return 1ll * bst * zar(lst) % mod;
}
int init(int n, int X[], int Y[]){
::n = n;
for(int i = 0; i < n; i++){
a[i] = X[i], b[i] = Y[i];
if(a[i] != 1)
st.insert(-i);
put(i, a[i]), add(i, b[i]);
}
return calc();
}
int updateX(int pos, int val){
if(val == 1)
st.erase(-pos);
else
st.insert(-pos);
a[pos] = val;
put(pos, val);
return calc();
}
int updateY(int pos, int val){
b[pos] = val;
add(pos, val);
return calc();
}
Compilation message
horses.cpp: In function 'void put(int, int, int, int, int)':
horses.cpp:52:42: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
52 | zr[id] = 1ll * zr[2*id] * zr[2*id+1] % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int zar(int, int, int, int)':
horses.cpp:60:68: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
60 | return 1ll * zar(pos, l, mid, 2*id) * zar(pos, mid, r, 2*id+1) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int calc()':
horses.cpp:73:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
73 | bst = num % mod;
| ~~~~^~~~~
horses.cpp:82:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
82 | return 1ll * bst * zar(lst) % mod;
| ~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:84:33: warning: declaration of 'n' shadows a global declaration [-Wshadow]
84 | int init(int n, int X[], int Y[]){
| ^
horses.cpp:19:5: note: shadowed declaration is here
19 | int n;
| ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:94:29: warning: declaration of 'val' shadows a global declaration [-Wshadow]
94 | int updateX(int pos, int val){
| ^
horses.cpp:20:5: note: shadowed declaration is here
20 | int val[4 * maxn], zr[4 * maxn];
| ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:103:29: warning: declaration of 'val' shadows a global declaration [-Wshadow]
103 | int updateY(int pos, int val){
| ^
horses.cpp:20:5: note: shadowed declaration is here
20 | int val[4 * maxn], zr[4 * maxn];
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
896 ms |
41080 KB |
Output is correct |
2 |
Correct |
562 ms |
40912 KB |
Output is correct |
3 |
Correct |
591 ms |
40868 KB |
Output is correct |
4 |
Correct |
581 ms |
40824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
512 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
226 ms |
16604 KB |
Output is correct |
34 |
Correct |
228 ms |
20472 KB |
Output is correct |
35 |
Correct |
392 ms |
42360 KB |
Output is correct |
36 |
Correct |
387 ms |
42340 KB |
Output is correct |
37 |
Correct |
319 ms |
18748 KB |
Output is correct |
38 |
Correct |
304 ms |
31480 KB |
Output is correct |
39 |
Correct |
217 ms |
18428 KB |
Output is correct |
40 |
Correct |
371 ms |
45124 KB |
Output is correct |
41 |
Correct |
249 ms |
18552 KB |
Output is correct |
42 |
Correct |
271 ms |
18552 KB |
Output is correct |
43 |
Correct |
385 ms |
44996 KB |
Output is correct |
44 |
Correct |
370 ms |
44848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
360 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
929 ms |
42476 KB |
Output is correct |
34 |
Correct |
550 ms |
53436 KB |
Output is correct |
35 |
Correct |
595 ms |
44580 KB |
Output is correct |
36 |
Correct |
583 ms |
48436 KB |
Output is correct |
37 |
Correct |
232 ms |
20600 KB |
Output is correct |
38 |
Correct |
234 ms |
20600 KB |
Output is correct |
39 |
Correct |
403 ms |
51064 KB |
Output is correct |
40 |
Correct |
403 ms |
50724 KB |
Output is correct |
41 |
Correct |
302 ms |
18744 KB |
Output is correct |
42 |
Correct |
303 ms |
31584 KB |
Output is correct |
43 |
Correct |
222 ms |
18424 KB |
Output is correct |
44 |
Correct |
381 ms |
45924 KB |
Output is correct |
45 |
Correct |
258 ms |
18552 KB |
Output is correct |
46 |
Correct |
273 ms |
18552 KB |
Output is correct |
47 |
Correct |
380 ms |
46216 KB |
Output is correct |
48 |
Correct |
366 ms |
46300 KB |
Output is correct |
49 |
Correct |
370 ms |
23496 KB |
Output is correct |
50 |
Correct |
334 ms |
23484 KB |
Output is correct |
51 |
Correct |
582 ms |
52728 KB |
Output is correct |
52 |
Correct |
478 ms |
52220 KB |
Output is correct |
53 |
Correct |
1035 ms |
21860 KB |
Output is correct |
54 |
Correct |
471 ms |
35576 KB |
Output is correct |
55 |
Correct |
334 ms |
19576 KB |
Output is correct |
56 |
Correct |
482 ms |
47696 KB |
Output is correct |
57 |
Correct |
630 ms |
20216 KB |
Output is correct |
58 |
Correct |
878 ms |
20728 KB |
Output is correct |
59 |
Correct |
383 ms |
46336 KB |
Output is correct |