# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
583782 |
2022-06-26T08:01:02 Z |
M_W |
Horses (IOI15_horses) |
C++17 |
|
549 ms |
33428 KB |
#include <bits/stdc++.h>
using namespace std;
long long tp[500001 << 2], tmd[500001 << 2];
const long long md = 1e9 + 7;
int N;
void upd_product(int v, int tl, int tr, int pos, int val){
if(tl == pos && tl == tr){
tp[v] = tmd[v] = val * 1ll;
return;
}
int tm = (tl + tr) >> 1;
if(pos <= tm) upd_product(v * 2, tl, tm, pos, val);
else upd_product(v * 2 + 1, tm + 1, tr, pos, val);
tmd[v] = (tmd[v * 2] * tmd[v * 2 + 1]) % md;
tp[v] = tp[v * 2] * tp[v * 2 + 1];
if(tp[v] > 1e9 || tp[v * 2] == -1 || tp[v * 2 + 1] == -1) tp[v] = -1;
}
long long query_product(int v, int tl, int tr, int l, int r){
if(l > r) return 1ll;
if(tl == l && tr == r) return tp[v];
int tm = (tl + tr) >> 1;
long long left = query_product(v * 2, tl, tm, l, min(r, tm));
long long right = query_product(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
if(left == -1 || right == -1 || left * right > 1e9) return -1;
return left * right;
}
long long query_md(int v, int tl, int tr, int l, int r){
if(l > r) return 1ll;
if(tl == l && tr == r) return tmd[v];
int tm = (tl + tr) >> 1;
long long left = query_product(v * 2, tl, tm, l, min(r, tm));
long long right = query_product(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
return (left * right) % md;
}
// Actual query tree
int t[500001 << 2];
long long Y[500001];
void build(int v, int tl, int tr){
if(tl == tr){
t[v] = tl;
return;
}
int tm = (tl + tr) >> 1;
build(v * 2, tl, tm);
build(v * 2 + 1, tm + 1, tr);
long long Yl = Y[t[v * 2]], Yr = Y[t[v * 2 + 1]];
long long prod = query_product(1, 0, N - 1, t[v * 2] + 1, t[v * 2 + 1]);
if(prod == -1 || prod * Yr > Yl) t[v] = t[v * 2 + 1];
else t[v] = t[v * 2];
}
void ins(int v, int tl, int tr, int pos){
if(tl == pos && tl == tr) return;
int tm = (tl + tr) >> 1;
if(pos <= tm) ins(v * 2, tl, tm, pos);
else ins(v * 2 + 1, tm + 1, tr, pos);
long long Yl = Y[t[v * 2]], Yr = Y[t[v * 2 + 1]];
long long prod = query_product(1, 0, N - 1, t[v * 2] + 1, t[v * 2 + 1]);
if(prod == -1 || prod * Yr > Yl) t[v] = t[v * 2 + 1];
else t[v] = t[v * 2];
}
int init(int N_tmp, int X[], int Y_tmp[]){
N = N_tmp;
for(int i = 0; i < N; i++) upd_product(1, 0, N - 1, i, X[i]);
for(int i = 0; i < N; i++) Y[i] = Y_tmp[i] * 1ll;
build(1, 0, N - 1);
return (query_md(1, 0, N - 1, 0, t[1]) * Y[t[1]]) % md;
}
int updateX(int pos, int val){
upd_product(1, 0, N - 1, pos, val);
ins(1, 0, N - 1, pos);
return (query_md(1, 0, N - 1, 0, t[1]) * Y[t[1]]) % md;
}
int updateY(int pos, int val){
Y[pos] = val;
ins(1, 0, N - 1, pos);
return (query_md(1, 0, N - 1, 0, t[1]) * Y[t[1]]) % md;
}
Compilation message
horses.cpp: In function 'void upd_product(int, int, int, int, int)':
horses.cpp:18:9: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
18 | if(tp[v] > 1e9 || tp[v * 2] == -1 || tp[v * 2 + 1] == -1) tp[v] = -1;
| ~~~~^
horses.cpp: In function 'long long int query_product(int, int, int, int, int)':
horses.cpp:29:39: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
29 | if(left == -1 || right == -1 || left * right > 1e9) return -1;
| ~~~~~^~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:85:52: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
85 | return (query_md(1, 0, N - 1, 0, t[1]) * Y[t[1]]) % md;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:91:52: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
91 | return (query_md(1, 0, N - 1, 0, t[1]) * Y[t[1]]) % md;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:97:52: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
97 | return (query_md(1, 0, N - 1, 0, t[1]) * Y[t[1]]) % md;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
549 ms |
33428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |