#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define Tree int h,int l,int r
#define left 2*h,l,(l+r)/2
#define right 2*h+1,(l+r)/2+1,r
#define Pb push_back
#define Mp make_pair
#define F first
#define S second
long long inf=2000000008;
long long Mod=1000000007;
int n,x[500002],y[500002],ANS;
int v[2000002];
int V[2000002];
int Suf[2000002];
int Pre[2000002];
int L,R;
int Pro(Tree)
{
if (L>r || l>R) return 1;
if (L<=l && r<=R) return v[h];
return (1LL*Pro(left)*Pro(right))%Mod;
}
void UpPro(Tree)
{
if (l>L || r<L) return ;
if (L==l && r==L) { v[h]=R%Mod; return ; }
UpPro(left);
UpPro(right);
v[h]=(1LL*v[2*h]*v[2*h+1])%Mod;
}
void Upd(Tree)
{
if (L>r || L<l) return ;
if (L==l && L==r)
{
V[h]=L;
Pre[h]=R;
Suf[h]=1;
return ;
}
Upd(left);
Upd(right);
if (y[V[2*h]]<1LL*min(inf,1LL*Suf[2*h]*Pre[2*h+1])*y[V[2*h+1]])
{
V[h]=V[2*h+1];
Pre[h]=min(min(1LL*Pre[2*h]*Suf[2*h],inf)*Pre[2*h+1],inf);
Suf[h]=Suf[2*h+1];
}
else
{
V[h]=V[2*h];
Pre[h]=Pre[2*h];
Suf[h]=min(min(1LL*Pre[2*h+1]*Suf[2*h+1],inf)*Suf[2*h],inf);
}
}
pair < int , pair < int , int > > Get(Tree)
{
if (L>r || l>R) return Mp(0,Mp(1,1));
if (L<=l && r<=R) return Mp(V[h],Mp(Pre[h],Suf[h]));
pair < int , pair < int , int > > X1=Get(left);
pair < int , pair < int , int > > X2=Get(right);
if (y[X1.F]<min(1LL*y[X2.F]*min(1LL*X2.S.F*X1.S.S,inf),inf))
return Mp(X2.F,Mp(min(1LL*min(1LL*X1.S.F*X1.S.S,inf)*X2.S.F,inf),X2.S.S));
if (y[X1.F]>=min(1LL*y[X2.F]*min(1LL*X2.S.F*X1.S.S,inf),inf))
return Mp(X1.F,Mp(X1.S.F,min(1LL*min(1LL*X2.S.F*X2.S.S,inf)*X1.S.S,inf)));
}
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++) {
L=i; R=x[i];
Upd(1,1,n);
UpPro(1,1,n);
}
L=1; R=n;
R=Get(1,1,n).F; L=1;
return (1LL*Pro(1,1,n)*y[R])%Mod;
}
int updateX(int pos, int val) {
pos++;
L=pos; R=val;
x[pos]=val;
Upd(1,1,n);
UpPro(1,1,n);
L=1; R=n;
R=Get(1,1,n).F; L=1;
return (1LL*Pro(1,1,n)*y[R])%Mod;
}
int updateY(int pos, int val) {
pos++;
L=pos; R=x[pos];
y[pos]=val;
Upd(1,1,n);
L=1; R=n;
R=Get(1,1,n).F; L=1;
return (1LL*Pro(1,1,n)*y[R])%Mod;
}
Compilation message
horses.cpp: In function 'int Pro(int, int, int)':
horses.cpp:29:35: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (1LL*Pro(left)*Pro(right))%Mod;
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void UpPro(int, int, int)':
horses.cpp:35:28: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if (L==l && r==L) { v[h]=R%Mod; return ; }
~^~~~
horses.cpp:40:28: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
v[h]=(1LL*v[2*h]*v[2*h+1])%Mod;
~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void Upd(int, int, int)':
horses.cpp:60:13: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
Pre[h]=min(min(1LL*Pre[2*h]*Suf[2*h],inf)*Pre[2*h+1],inf);
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:67:13: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
Suf[h]=min(min(1LL*Pre[2*h+1]*Suf[2*h+1],inf)*Suf[2*h],inf);
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:103:30: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (1LL*Pro(1,1,n)*y[R])%Mod;
~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:120:31: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (1LL*Pro(1,1,n)*y[R])%Mod;
~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:136:31: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return (1LL*Pro(1,1,n)*y[R])%Mod;
~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'std::pair<int, std::pair<int, int> > Get(int, int, int)':
horses.cpp:84:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
2 ms |
608 KB |
Output is correct |
7 |
Correct |
2 ms |
740 KB |
Output is correct |
8 |
Correct |
2 ms |
740 KB |
Output is correct |
9 |
Correct |
2 ms |
740 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
740 KB |
Output is correct |
12 |
Correct |
2 ms |
740 KB |
Output is correct |
13 |
Correct |
2 ms |
740 KB |
Output is correct |
14 |
Correct |
2 ms |
740 KB |
Output is correct |
15 |
Correct |
2 ms |
740 KB |
Output is correct |
16 |
Correct |
2 ms |
740 KB |
Output is correct |
17 |
Correct |
2 ms |
740 KB |
Output is correct |
18 |
Correct |
2 ms |
740 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
2 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
740 KB |
Output is correct |
2 |
Correct |
2 ms |
784 KB |
Output is correct |
3 |
Correct |
2 ms |
784 KB |
Output is correct |
4 |
Correct |
2 ms |
784 KB |
Output is correct |
5 |
Correct |
2 ms |
784 KB |
Output is correct |
6 |
Correct |
2 ms |
784 KB |
Output is correct |
7 |
Correct |
2 ms |
784 KB |
Output is correct |
8 |
Correct |
2 ms |
784 KB |
Output is correct |
9 |
Correct |
2 ms |
784 KB |
Output is correct |
10 |
Correct |
2 ms |
784 KB |
Output is correct |
11 |
Correct |
2 ms |
784 KB |
Output is correct |
12 |
Correct |
2 ms |
784 KB |
Output is correct |
13 |
Correct |
2 ms |
784 KB |
Output is correct |
14 |
Correct |
2 ms |
784 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
856 KB |
Output is correct |
19 |
Correct |
2 ms |
856 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
22 |
Correct |
2 ms |
856 KB |
Output is correct |
23 |
Correct |
3 ms |
856 KB |
Output is correct |
24 |
Correct |
3 ms |
948 KB |
Output is correct |
25 |
Correct |
3 ms |
984 KB |
Output is correct |
26 |
Correct |
3 ms |
984 KB |
Output is correct |
27 |
Correct |
3 ms |
984 KB |
Output is correct |
28 |
Correct |
3 ms |
984 KB |
Output is correct |
29 |
Correct |
3 ms |
996 KB |
Output is correct |
30 |
Correct |
3 ms |
1008 KB |
Output is correct |
31 |
Correct |
3 ms |
1028 KB |
Output is correct |
32 |
Correct |
3 ms |
1044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
503 ms |
30116 KB |
Output is correct |
2 |
Correct |
588 ms |
42616 KB |
Output is correct |
3 |
Correct |
556 ms |
46376 KB |
Output is correct |
4 |
Correct |
613 ms |
54048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
54048 KB |
Output is correct |
2 |
Correct |
2 ms |
54048 KB |
Output is correct |
3 |
Correct |
2 ms |
54048 KB |
Output is correct |
4 |
Correct |
2 ms |
54048 KB |
Output is correct |
5 |
Correct |
2 ms |
54048 KB |
Output is correct |
6 |
Correct |
2 ms |
54048 KB |
Output is correct |
7 |
Correct |
2 ms |
54048 KB |
Output is correct |
8 |
Correct |
3 ms |
54048 KB |
Output is correct |
9 |
Correct |
2 ms |
54048 KB |
Output is correct |
10 |
Correct |
2 ms |
54048 KB |
Output is correct |
11 |
Correct |
2 ms |
54048 KB |
Output is correct |
12 |
Correct |
2 ms |
54048 KB |
Output is correct |
13 |
Correct |
2 ms |
54048 KB |
Output is correct |
14 |
Correct |
2 ms |
54048 KB |
Output is correct |
15 |
Correct |
2 ms |
54048 KB |
Output is correct |
16 |
Correct |
2 ms |
54048 KB |
Output is correct |
17 |
Correct |
2 ms |
54048 KB |
Output is correct |
18 |
Correct |
2 ms |
54048 KB |
Output is correct |
19 |
Correct |
2 ms |
54048 KB |
Output is correct |
20 |
Correct |
2 ms |
54048 KB |
Output is correct |
21 |
Correct |
2 ms |
54048 KB |
Output is correct |
22 |
Correct |
2 ms |
54048 KB |
Output is correct |
23 |
Correct |
3 ms |
54048 KB |
Output is correct |
24 |
Correct |
3 ms |
54048 KB |
Output is correct |
25 |
Correct |
4 ms |
54048 KB |
Output is correct |
26 |
Correct |
3 ms |
54048 KB |
Output is correct |
27 |
Correct |
3 ms |
54048 KB |
Output is correct |
28 |
Correct |
4 ms |
54048 KB |
Output is correct |
29 |
Correct |
3 ms |
54048 KB |
Output is correct |
30 |
Correct |
3 ms |
54048 KB |
Output is correct |
31 |
Correct |
3 ms |
54048 KB |
Output is correct |
32 |
Correct |
3 ms |
54048 KB |
Output is correct |
33 |
Correct |
443 ms |
57400 KB |
Output is correct |
34 |
Correct |
438 ms |
61272 KB |
Output is correct |
35 |
Correct |
473 ms |
72180 KB |
Output is correct |
36 |
Correct |
444 ms |
83012 KB |
Output is correct |
37 |
Correct |
425 ms |
84984 KB |
Output is correct |
38 |
Correct |
425 ms |
88032 KB |
Output is correct |
39 |
Correct |
414 ms |
89960 KB |
Output is correct |
40 |
Correct |
450 ms |
95988 KB |
Output is correct |
41 |
Correct |
425 ms |
98256 KB |
Output is correct |
42 |
Correct |
419 ms |
100168 KB |
Output is correct |
43 |
Correct |
431 ms |
106536 KB |
Output is correct |
44 |
Correct |
422 ms |
107264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
107264 KB |
Output is correct |
2 |
Correct |
2 ms |
107264 KB |
Output is correct |
3 |
Correct |
2 ms |
107264 KB |
Output is correct |
4 |
Correct |
2 ms |
107264 KB |
Output is correct |
5 |
Correct |
2 ms |
107264 KB |
Output is correct |
6 |
Correct |
2 ms |
107264 KB |
Output is correct |
7 |
Correct |
2 ms |
107264 KB |
Output is correct |
8 |
Correct |
2 ms |
107264 KB |
Output is correct |
9 |
Correct |
2 ms |
107264 KB |
Output is correct |
10 |
Correct |
2 ms |
107264 KB |
Output is correct |
11 |
Correct |
2 ms |
107264 KB |
Output is correct |
12 |
Correct |
2 ms |
107264 KB |
Output is correct |
13 |
Correct |
2 ms |
107264 KB |
Output is correct |
14 |
Correct |
2 ms |
107264 KB |
Output is correct |
15 |
Correct |
2 ms |
107264 KB |
Output is correct |
16 |
Correct |
3 ms |
107264 KB |
Output is correct |
17 |
Correct |
2 ms |
107264 KB |
Output is correct |
18 |
Correct |
2 ms |
107264 KB |
Output is correct |
19 |
Correct |
2 ms |
107264 KB |
Output is correct |
20 |
Correct |
2 ms |
107264 KB |
Output is correct |
21 |
Correct |
2 ms |
107264 KB |
Output is correct |
22 |
Correct |
2 ms |
107264 KB |
Output is correct |
23 |
Correct |
3 ms |
107264 KB |
Output is correct |
24 |
Correct |
3 ms |
107264 KB |
Output is correct |
25 |
Correct |
3 ms |
107264 KB |
Output is correct |
26 |
Correct |
3 ms |
107264 KB |
Output is correct |
27 |
Correct |
4 ms |
107264 KB |
Output is correct |
28 |
Correct |
3 ms |
107264 KB |
Output is correct |
29 |
Correct |
3 ms |
107264 KB |
Output is correct |
30 |
Correct |
3 ms |
107264 KB |
Output is correct |
31 |
Correct |
4 ms |
107264 KB |
Output is correct |
32 |
Correct |
3 ms |
107264 KB |
Output is correct |
33 |
Correct |
493 ms |
108292 KB |
Output is correct |
34 |
Correct |
574 ms |
108420 KB |
Output is correct |
35 |
Correct |
546 ms |
108424 KB |
Output is correct |
36 |
Correct |
615 ms |
108424 KB |
Output is correct |
37 |
Correct |
446 ms |
108424 KB |
Output is correct |
38 |
Correct |
445 ms |
108424 KB |
Output is correct |
39 |
Correct |
449 ms |
108424 KB |
Output is correct |
40 |
Correct |
453 ms |
108424 KB |
Output is correct |
41 |
Correct |
427 ms |
108424 KB |
Output is correct |
42 |
Correct |
430 ms |
108424 KB |
Output is correct |
43 |
Correct |
425 ms |
108424 KB |
Output is correct |
44 |
Correct |
435 ms |
108424 KB |
Output is correct |
45 |
Correct |
412 ms |
108424 KB |
Output is correct |
46 |
Correct |
413 ms |
108424 KB |
Output is correct |
47 |
Correct |
421 ms |
108424 KB |
Output is correct |
48 |
Correct |
431 ms |
108424 KB |
Output is correct |
49 |
Correct |
635 ms |
108424 KB |
Output is correct |
50 |
Correct |
559 ms |
108424 KB |
Output is correct |
51 |
Correct |
559 ms |
108424 KB |
Output is correct |
52 |
Correct |
532 ms |
108424 KB |
Output is correct |
53 |
Correct |
644 ms |
108424 KB |
Output is correct |
54 |
Correct |
573 ms |
108424 KB |
Output is correct |
55 |
Correct |
561 ms |
108424 KB |
Output is correct |
56 |
Correct |
565 ms |
108504 KB |
Output is correct |
57 |
Correct |
521 ms |
108504 KB |
Output is correct |
58 |
Correct |
528 ms |
108548 KB |
Output is correct |
59 |
Correct |
425 ms |
108548 KB |
Output is correct |