#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (ll)1000000005//biggest than max Y
#define MOD (ll)1000000007//modulo for evaluation
#define MAXN 500005
ll x[MAXN],y[MAXN];
int mxst[4*MAXN];
pair<ll,ll> prst[4*MAXN];//(real,mod);
int n;
ll pr(ll a,ll b){
return ((a*b)>=INF)?INF:(a*b);
}
ll prmod(ll a,ll b){
return (a*b)%MOD;
}
pair<ll,ll> pr(pair<ll,ll> a,pair<ll,ll> b){
return {pr(a.first,b.first),prmod(a.second,b.second)};
}
void prbuild(int v=1,int start=0,int end=n-1){
if(start==end){
prst[v]={x[start],x[start]};
return;
}
int mid=(start+end)/2;
prbuild(2*v,start,mid);
prbuild(2*v+1,mid+1,end);
prst[v]=pr(prst[2*v],prst[2*v+1]);
}
void prupdate(int pos,int v=1,int start=0,int end=n-1){
if(start==end){
prst[v]={x[start],x[start]};
return;
}
int mid=(start+end)/2;
if(pos<=mid){
prupdate(pos,2*v,start,mid);
}else{
prupdate(pos,2*v+1,mid+1,end);
}
prst[v]=pr(prst[2*v],prst[2*v+1]);
}
pair<ll,ll> prquery(int from,int to,int v=1,int start=0,int end=n-1){
if(start==from&&end==to){
return prst[v];
}
int mid=(start+end)/2;
if(to<=mid){
return prquery(from,to,2*v,start,mid);
}else if(from>mid){
return prquery(from,to,2*v+1,mid+1,end);
}else{
return pr(prquery(from,mid,2*v,start,mid),prquery(mid+1,to,2*v+1,mid+1,end));
}
}
int mx(int i,int j){//i<j
return (y[i]>pr(prquery(i+1,j).first,y[j]))?i:j;
}
void mxbuild(int v=1,int start=0,int end=n-1){
if(start==end){
mxst[v]=start;
return;
}
int mid=(start+end)/2;
mxbuild(2*v,start,mid);
mxbuild(2*v+1,mid+1,end);
mxst[v]=mx(mxst[2*v],mxst[2*v+1]);
}
void mxupdate(int pos,int v=1,int start=0,int end=n-1){
if(start==end){
mxst[v]=start;
return;
}
int mid=(start+end)/2;
if(pos<=mid){
mxupdate(pos,2*v,start,mid);
}else{
mxupdate(pos,2*v+1,mid+1,end);
}
mxst[v]=mx(mxst[2*v],mxst[2*v+1]);
}
int evaluate(){
int i=mxst[1];
return prmod(prquery(0,i).second,y[i]);
}
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];
}
prbuild();
mxbuild();
return evaluate();
}
int updateX(int pos, int val) {
x[pos]=val;
prupdate(pos);
mxupdate(pos);
return evaluate();
}
int updateY(int pos, int val) {
y[pos]=val;
mxupdate(pos);
return evaluate();
}
Compilation message
horses.cpp: In function 'int evaluate()':
horses.cpp:96:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
96 | return prmod(prquery(0,i).second,y[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
3 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
3 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
303 ms |
35216 KB |
Output is correct |
2 |
Correct |
371 ms |
46060 KB |
Output is correct |
3 |
Correct |
484 ms |
37236 KB |
Output is correct |
4 |
Correct |
488 ms |
41172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
248 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
3 ms |
332 KB |
Output is correct |
24 |
Correct |
3 ms |
388 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
178 ms |
32576 KB |
Output is correct |
34 |
Correct |
147 ms |
36516 KB |
Output is correct |
35 |
Correct |
138 ms |
43540 KB |
Output is correct |
36 |
Correct |
122 ms |
43372 KB |
Output is correct |
37 |
Correct |
110 ms |
34720 KB |
Output is correct |
38 |
Correct |
104 ms |
35668 KB |
Output is correct |
39 |
Correct |
82 ms |
34596 KB |
Output is correct |
40 |
Correct |
99 ms |
38468 KB |
Output is correct |
41 |
Correct |
118 ms |
34644 KB |
Output is correct |
42 |
Correct |
87 ms |
34708 KB |
Output is correct |
43 |
Correct |
102 ms |
38856 KB |
Output is correct |
44 |
Correct |
112 ms |
38896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 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 |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
312 ms |
35232 KB |
Output is correct |
34 |
Correct |
360 ms |
46128 KB |
Output is correct |
35 |
Correct |
445 ms |
37224 KB |
Output is correct |
36 |
Correct |
456 ms |
41164 KB |
Output is correct |
37 |
Correct |
163 ms |
36496 KB |
Output is correct |
38 |
Correct |
147 ms |
36480 KB |
Output is correct |
39 |
Correct |
132 ms |
43460 KB |
Output is correct |
40 |
Correct |
121 ms |
43568 KB |
Output is correct |
41 |
Correct |
121 ms |
34756 KB |
Output is correct |
42 |
Correct |
110 ms |
35652 KB |
Output is correct |
43 |
Correct |
83 ms |
34580 KB |
Output is correct |
44 |
Correct |
101 ms |
38508 KB |
Output is correct |
45 |
Correct |
105 ms |
34828 KB |
Output is correct |
46 |
Correct |
91 ms |
34728 KB |
Output is correct |
47 |
Correct |
93 ms |
38840 KB |
Output is correct |
48 |
Correct |
93 ms |
38916 KB |
Output is correct |
49 |
Correct |
765 ms |
38592 KB |
Output is correct |
50 |
Correct |
707 ms |
38588 KB |
Output is correct |
51 |
Correct |
379 ms |
45472 KB |
Output is correct |
52 |
Correct |
217 ms |
44888 KB |
Output is correct |
53 |
Correct |
504 ms |
37020 KB |
Output is correct |
54 |
Correct |
331 ms |
37456 KB |
Output is correct |
55 |
Correct |
197 ms |
35796 KB |
Output is correct |
56 |
Correct |
214 ms |
40376 KB |
Output is correct |
57 |
Correct |
359 ms |
36276 KB |
Output is correct |
58 |
Correct |
265 ms |
36804 KB |
Output is correct |
59 |
Correct |
91 ms |
38856 KB |
Output is correct |