# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
710955 |
2023-03-16T06:15:33 Z |
ToroTN |
Horses (IOI15_horses) |
C++14 |
|
958 ms |
50296 KB |
#include<bits/stdc++.h>
using namespace std;
#include "horses.h"
//#include "grader.cpp"
#define ll long long
ll MOD=1000000007;
ll n,x[500005],y[500005],mul[2000005],ans[2000005];
void build_mul(ll tree,ll st,ll ed)
{
ll md=(st+ed)/2;
if(st==ed)
{
mul[tree]=x[st];
ans[tree]=x[st];
return;
}
build_mul(2*tree,st,md);
build_mul(2*tree+1,md+1,ed);
ans[tree]=(ans[2*tree]*ans[2*tree+1])%MOD;
if(mul[2*tree]==-1||mul[2*tree+1]==-1)
{
mul[tree]=-1;
}else if(mul[2*tree]*mul[2*tree+1]>1e9)
{
mul[tree]=-1;
}else
{
mul[tree]=mul[2*tree]*mul[2*tree+1];
}
}
void update_mul(ll tree,ll st,ll ed,ll idx,ll val)
{
ll md=(st+ed)/2;
if(st==ed)
{
mul[tree]=val;
ans[tree]=val;
return;
}
if(idx<=md)
{
update_mul(2*tree,st,md,idx,val);
}else
{
update_mul(2*tree+1,md+1,ed,idx,val);
}
ans[tree]=(ans[2*tree]*ans[2*tree+1])%MOD;
if(mul[2*tree]==-1||mul[2*tree+1]==-1)
{
mul[tree]=-1;
}else if(mul[2*tree]*mul[2*tree+1]>1e9)
{
mul[tree]=-1;
}else
{
mul[tree]=mul[2*tree]*mul[2*tree+1];
}
}
ll query_mul(ll tree,ll st,ll ed,ll l,ll r)
{
ll md=(st+ed)/2;
if(st>r||ed<l)return 1;
if(st>=l&&ed<=r)return mul[tree];
ll lft=query_mul(2*tree,st,md,l,r),rht=query_mul(2*tree+1,md+1,ed,l,r);
if(lft==-1||rht==-1)return -1;
if(lft*rht>1e9)return -1;
return lft*rht;
}
ll query_ans(ll tree,ll st,ll ed,ll l,ll r)
{
ll md=(st+ed)/2;
if(st>r||ed<l)return 1;
if(st>=l&&ed<=r)return ans[tree];
return (query_ans(2*tree,st,md,l,r)*query_ans(2*tree+1,md+1,ed,l,r))%MOD;
}
ll seg[2000005];
void build(ll tree,ll st,ll ed)
{
ll md=(st+ed)/2;
if(st==ed)
{
seg[tree]=st;
return;
}
build(2*tree,st,md);
build(2*tree+1,md+1,ed);
ll l_idx=seg[2*tree],r_idx=seg[2*tree+1];
ll rng=query_mul(1,1,n,l_idx+1,r_idx);
if(rng!=-1)
{
if(rng*y[r_idx]>1e9)
{
rng=-1;
}else
{
rng*=y[r_idx];
}
}
if(rng==-1)
{
seg[tree]=r_idx;
}else
{
if(rng>y[l_idx])
{
seg[tree]=r_idx;
}else
{
seg[tree]=l_idx;
}
}
}
void update(ll tree,ll st,ll ed,ll idx)
{
ll md=(st+ed)/2;
if(st==ed)
{
seg[tree]=idx;
return;
}
if(idx<=md)
{
update(2*tree,st,md,idx);
}else
{
update(2*tree+1,md+1,ed,idx);
}
ll l_idx=seg[2*tree],r_idx=seg[2*tree+1];
ll rng=query_mul(1,1,n,l_idx+1,r_idx);
if(rng!=-1)
{
if(rng*y[r_idx]>1e9)
{
rng=-1;
}else
{
rng*=y[r_idx];
}
}
if(rng==-1)
{
seg[tree]=r_idx;
}else
{
if(rng>y[l_idx])
{
seg[tree]=r_idx;
}else
{
seg[tree]=l_idx;
}
}
}
void debug(ll tree,ll st,ll ed)
{
ll md=(st+ed)/2;
if(st==ed)
{
printf("%lld %lld %lld\n",st,ed,mul[tree]);
return;
}
debug(2*tree,st,md);
debug(2*tree+1,md+1,ed);
printf("%lld %lld %lld\n",st,ed,mul[tree]);
}
void debug_seg(ll tree,ll st,ll ed)
{
ll md=(st+ed)/2;
if(st==ed)
{
printf("%lld %lld %lld\n",st,ed,seg[tree]);
return;
}
debug_seg(2*tree,st,md);
debug_seg(2*tree+1,md+1,ed);
printf("%lld %lld %lld\n",st,ed,seg[tree]);
}
int init(int N, int X[], int Y[])
{
n=N;for(int i=1;i<=n;i++)x[i]=X[i-1],y[i]=Y[i-1];
/*for(int i=1;i<=n;i++)
{
printf("%lld ",ans[i]);
}
printf("\n");*/
build_mul(1,1,n);
build(1,1,n);
//debug_seg(1,1,n);
//debug(1,1,n);
//printf("%lld\n",mul[1]);
return (query_ans(1,1,n,1,seg[1])*y[seg[1]])%MOD;
}
int updateX(int pos, int val)
{
++pos;
//printf("krit3379 %lld %lld\n",pos,val);
x[pos]=val;
update_mul(1,1,n,pos,val);
update(1,1,n,pos);
//debug(1,1,n);
//debug_seg(1,1,n);
return (query_ans(1,1,n,1,seg[1])*y[seg[1]])%MOD;
}
int updateY(int pos, int val)
{
++pos;
//printf("Jomnoi %lld %lld\n",pos,val);
y[pos]=val;
update(1,1,n,pos);
//debug_seg(1,1,n);
return (query_ans(1,1,n,1,seg[1])*y[seg[1]])%MOD;
}
Compilation message
horses.cpp: In function 'void build_mul(long long int, long long int, long long int)':
horses.cpp:23:25: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
23 | }else if(mul[2*tree]*mul[2*tree+1]>1e9)
| ~~~~~~~~~~~^~~~~~~~~~~~~~
horses.cpp: In function 'void update_mul(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:51:25: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
51 | }else if(mul[2*tree]*mul[2*tree+1]>1e9)
| ~~~~~~~~~~~^~~~~~~~~~~~~~
horses.cpp: In function 'long long int query_mul(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:66:11: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
66 | if(lft*rht>1e9)return -1;
| ~~~^~~~
horses.cpp: In function 'void build(long long int, long long int, long long int)':
horses.cpp:91:15: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
91 | if(rng*y[r_idx]>1e9)
| ~~~^~~~~~~~~
horses.cpp: In function 'void update(long long int, long long int, long long int, long long int)':
horses.cpp:132:15: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
132 | if(rng*y[r_idx]>1e9)
| ~~~^~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:191:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
191 | return (query_ans(1,1,n,1,seg[1])*y[seg[1]])%MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:202:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
202 | return (query_ans(1,1,n,1,seg[1])*y[seg[1]])%MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:212:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
212 | return (query_ans(1,1,n,1,seg[1])*y[seg[1]])%MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
308 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 |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
224 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 |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
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 |
340 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 |
340 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 |
340 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 |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
316 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
432 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
3 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
465 ms |
40220 KB |
Output is correct |
2 |
Correct |
445 ms |
50296 KB |
Output is correct |
3 |
Correct |
601 ms |
41432 KB |
Output is correct |
4 |
Correct |
582 ms |
45292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
304 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 |
304 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 |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
308 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 |
304 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 |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
308 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
452 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
3 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
247 ms |
40648 KB |
Output is correct |
34 |
Correct |
238 ms |
40664 KB |
Output is correct |
35 |
Correct |
195 ms |
47556 KB |
Output is correct |
36 |
Correct |
203 ms |
47532 KB |
Output is correct |
37 |
Correct |
223 ms |
38872 KB |
Output is correct |
38 |
Correct |
175 ms |
39760 KB |
Output is correct |
39 |
Correct |
197 ms |
38684 KB |
Output is correct |
40 |
Correct |
209 ms |
42648 KB |
Output is correct |
41 |
Correct |
221 ms |
38780 KB |
Output is correct |
42 |
Correct |
221 ms |
38788 KB |
Output is correct |
43 |
Correct |
182 ms |
42984 KB |
Output is correct |
44 |
Correct |
171 ms |
43056 KB |
Output is correct |
# |
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 |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 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 |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
1 ms |
304 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 |
304 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 |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
4 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
316 KB |
Output is correct |
25 |
Correct |
3 ms |
448 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
416 KB |
Output is correct |
29 |
Correct |
3 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
328 KB |
Output is correct |
32 |
Correct |
4 ms |
316 KB |
Output is correct |
33 |
Correct |
615 ms |
41464 KB |
Output is correct |
34 |
Correct |
480 ms |
50192 KB |
Output is correct |
35 |
Correct |
601 ms |
41388 KB |
Output is correct |
36 |
Correct |
637 ms |
45196 KB |
Output is correct |
37 |
Correct |
227 ms |
40628 KB |
Output is correct |
38 |
Correct |
226 ms |
40668 KB |
Output is correct |
39 |
Correct |
194 ms |
47540 KB |
Output is correct |
40 |
Correct |
182 ms |
47480 KB |
Output is correct |
41 |
Correct |
232 ms |
38996 KB |
Output is correct |
42 |
Correct |
201 ms |
39780 KB |
Output is correct |
43 |
Correct |
228 ms |
38632 KB |
Output is correct |
44 |
Correct |
194 ms |
42652 KB |
Output is correct |
45 |
Correct |
194 ms |
38728 KB |
Output is correct |
46 |
Correct |
207 ms |
38800 KB |
Output is correct |
47 |
Correct |
142 ms |
42984 KB |
Output is correct |
48 |
Correct |
150 ms |
43056 KB |
Output is correct |
49 |
Correct |
863 ms |
42796 KB |
Output is correct |
50 |
Correct |
775 ms |
42656 KB |
Output is correct |
51 |
Correct |
498 ms |
49392 KB |
Output is correct |
52 |
Correct |
357 ms |
48984 KB |
Output is correct |
53 |
Correct |
958 ms |
41128 KB |
Output is correct |
54 |
Correct |
500 ms |
41556 KB |
Output is correct |
55 |
Correct |
733 ms |
39952 KB |
Output is correct |
56 |
Correct |
509 ms |
44500 KB |
Output is correct |
57 |
Correct |
657 ms |
40488 KB |
Output is correct |
58 |
Correct |
750 ms |
40916 KB |
Output is correct |
59 |
Correct |
172 ms |
42956 KB |
Output is correct |