#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using lint=long long;
const lint mod=1e9+7;
const int lim=5e5+100;
const int inf=1e9;
int mul(lint i,lint j){
return i*j%mod;
}
int n,*x,*y;
struct{
int tree[4*lim];
int P,VAL;
int update(int l,int r,int node){
if(l==r){
return tree[node]=VAL;
}
int mid=(l+r)>>1,child=node<<1;
if(P<=mid)return tree[node]=mul(update(l,mid,child),tree[child|1]);
return tree[node]=mul(tree[child],update(mid+1,r,child|1));
}
void update(int p,int val){
P=p,VAL=val;
update(0,n-1,1);
}
int query(int l,int r,int node){
if(r<=P){
return tree[node];
}
int mid=(l+r)>>1,child=node<<1;
if(P<=mid)return query(l,mid,child);
return mul(tree[child],query(mid+1,r,child|1));
}
int query(int p){
P=p;
return query(0,n-1,1);
}
}stmul;
struct{
int tree[4*lim];
int P,VAL;
int update(int l,int r,int node){
if(l==r)return tree[node]=VAL;
int mid=(l+r)>>1,child=node<<1;
if(P<=mid)return tree[node]=max(update(l,mid,child),tree[child|1]);
return tree[node]=max(tree[child],update(mid+1,r,child|1));
}
void update(int p,int val){
P=p,VAL=val;
update(0,n-1,1);
}
int L,R;
int query(int l,int r,int node){
if(L<=l&&r<=R)return tree[node];
if(r<L||R<l)return 0;
int mid=(l+r)>>1,child=node<<1;
return max(query(l,mid,child),query(mid+1,r,child|1));
}
int query(int l,int r){
L=l,R=r;
return query(0,n-1,1);
}
}stmax;
set<int,greater<int>>nonones;
int findmax(){
if(*nonones.begin()==-1)return stmax.query(0,n-1);
lint past=*nonones.begin(),aa=stmax.query(past,n-1),bb=stmul.query(past);
lint curbest=mul(aa,bb),temp=aa*x[past];
if(inf<temp)return curbest;
for(auto p=next(nonones.begin());p!=nonones.end();p++){
int pp=*p;
if(pp==-1){
if(past==0)break;
pp=0;
}
aa=stmax.query(pp,past-1);
if(temp<aa){
bb=stmul.query(pp);
curbest=mul(aa,bb);
temp=aa;
}
temp*=x[pp];
if(inf<temp)return curbest;
past=pp;
}
return curbest;
}
int init(int N, int X[], int Y[]) {
n=N,x=X,y=Y;
nonones.insert(-1);
for(int i=0;i<n;i++){
stmul.update(i,x[i]);
stmax.update(i,y[i]);
if(X[i]!=1)nonones.insert(i);
}
return findmax();
}
int updateX(int pos, int val) {
if(x[pos]!=1)nonones.erase(pos);
x[pos]=val;
stmul.update(pos,val);
if(x[pos]!=1)nonones.insert(pos);
return findmax();
}
int updateY(int pos, int val) {
stmax.update(pos,val);
return findmax();
}
Compilation message
horses.cpp: In function 'int mul(lint, lint)':
horses.cpp:13:12: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
13 | return i*j%mod;
| ~~~^~~~
horses.cpp: In function 'int findmax()':
horses.cpp:77:44: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
77 | lint past=*nonones.begin(),aa=stmax.query(past,n-1),bb=stmul.query(past);
| ^~~~
horses.cpp:77:69: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
77 | lint past=*nonones.begin(),aa=stmax.query(past,n-1),bb=stmul.query(past);
| ^~~~
horses.cpp:79:21: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
79 | if(inf<temp)return curbest;
| ^~~~~~~
horses.cpp:86:25: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
86 | aa=stmax.query(pp,past-1);
| ~~~~^~
horses.cpp:93:22: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
93 | if(inf<temp)return curbest;
| ^~~~~~~
horses.cpp:96:9: warning: conversion from 'lint' {aka 'long long int'} to 'int' may change value [-Wconversion]
96 | return curbest;
| ^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
400 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
556 KB |
Output is correct |
31 |
Correct |
1 ms |
500 KB |
Output is correct |
32 |
Correct |
2 ms |
488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
382 ms |
37204 KB |
Output is correct |
2 |
Correct |
330 ms |
37148 KB |
Output is correct |
3 |
Correct |
274 ms |
40788 KB |
Output is correct |
4 |
Correct |
341 ms |
44624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
520 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
103 ms |
16688 KB |
Output is correct |
34 |
Correct |
102 ms |
16784 KB |
Output is correct |
35 |
Correct |
209 ms |
46928 KB |
Output is correct |
36 |
Correct |
218 ms |
46924 KB |
Output is correct |
37 |
Correct |
151 ms |
14932 KB |
Output is correct |
38 |
Correct |
149 ms |
27732 KB |
Output is correct |
39 |
Correct |
96 ms |
14672 KB |
Output is correct |
40 |
Correct |
214 ms |
42200 KB |
Output is correct |
41 |
Correct |
106 ms |
14676 KB |
Output is correct |
42 |
Correct |
115 ms |
14672 KB |
Output is correct |
43 |
Correct |
211 ms |
42380 KB |
Output is correct |
44 |
Correct |
195 ms |
42588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
389 ms |
41040 KB |
Output is correct |
34 |
Correct |
289 ms |
49668 KB |
Output is correct |
35 |
Correct |
329 ms |
40824 KB |
Output is correct |
36 |
Correct |
326 ms |
44816 KB |
Output is correct |
37 |
Correct |
111 ms |
16704 KB |
Output is correct |
38 |
Correct |
109 ms |
16724 KB |
Output is correct |
39 |
Correct |
237 ms |
46996 KB |
Output is correct |
40 |
Correct |
225 ms |
47088 KB |
Output is correct |
41 |
Correct |
135 ms |
14964 KB |
Output is correct |
42 |
Correct |
187 ms |
27660 KB |
Output is correct |
43 |
Correct |
103 ms |
14768 KB |
Output is correct |
44 |
Correct |
213 ms |
42000 KB |
Output is correct |
45 |
Correct |
109 ms |
14684 KB |
Output is correct |
46 |
Correct |
120 ms |
14680 KB |
Output is correct |
47 |
Correct |
204 ms |
42300 KB |
Output is correct |
48 |
Correct |
203 ms |
42416 KB |
Output is correct |
49 |
Correct |
167 ms |
19868 KB |
Output is correct |
50 |
Correct |
146 ms |
19824 KB |
Output is correct |
51 |
Correct |
314 ms |
48832 KB |
Output is correct |
52 |
Correct |
247 ms |
48468 KB |
Output is correct |
53 |
Correct |
436 ms |
17824 KB |
Output is correct |
54 |
Correct |
234 ms |
31572 KB |
Output is correct |
55 |
Correct |
149 ms |
15700 KB |
Output is correct |
56 |
Correct |
280 ms |
44016 KB |
Output is correct |
57 |
Correct |
264 ms |
16308 KB |
Output is correct |
58 |
Correct |
334 ms |
16868 KB |
Output is correct |
59 |
Correct |
201 ms |
42204 KB |
Output is correct |