#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using lint=__int128_t;
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.size())return stmax.query(0,n-1);
int past=*nonones.begin(),aa=stmax.query(past,n-1),bb=stmul.query(past);
int curbest=mul(aa,bb),temp=mul(aa,x[past]);
if(inf<temp)return curbest;
for(auto p=next(nonones.begin());p!=nonones.end();p++){
aa=stmax.query(*p,past-1);
if(temp<aa){
bb=stmul.query(*p);
curbest=mul(aa,bb);
temp=mul(aa,x[*p]);
}else{
temp=mul(temp,x[*p]);
}
if(inf<temp)return curbest;
past=*p;
}
return curbest;
}
int init(int N, int X[], int Y[]) {
n=N,x=X,y=Y;
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 '__int128'} to 'int' may change value [-Wconversion]
13 | return i*j%mod;
| ~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 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 |
448 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 |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
396 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
452 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 |
1 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1545 ms |
37988 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
344 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 |
360 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 |
1 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 |
440 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 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 |
448 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 |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |