#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define P push
#define I insert
#define F first
#define S second
typedef long long ll;
const ll mod=1e9+7;
const int maxn=500000;
int n;
ll segx[4*maxn],segy[4*maxn];
ll co[maxn],pr[maxn];
set<int> notone;
void updx(ll a,ll b,int c,ll x,int y){
if(a==b){
segx[c]=x;
return;
}
ll m=(a+b)/2;
if(y<=m)updx(a,m,2*c,x,y);
else updx(m+1,b,2*c+1,x,y);
segx[c]=(segx[2*c]*segx[2*c+1])%mod;
}
ll findx(ll a,ll b,ll c,ll x,ll y){
if(a==x && b==y)return segx[c];
ll m=(a+b)/2;
if(y<=m)return findx(a,m,2*c,x,y);
if(x>=m+1)return findx(m+1,b,2*c+1,x,y);
return (findx(a,m,2*c,x,m)*findx(m+1,b,2*c+1,m+1,y))%mod;
}
void updy(ll a,ll b,int c,ll x,int y){
if(a==b){
segy[c]=x;
return;
}
ll m=(a+b)/2;
if(y<=m)updy(a,m,2*c,x,y);
else updy(m+1,b,2*c+1,x,y);
segy[c]=max(segy[2*c],segy[2*c+1]);
}
ll findy(ll a,ll b,ll c,ll x,ll y){
if(a==x && b==y)return segy[c];
ll m=(a+b)/2;
if(y<=m)return findy(a,m,2*c,x,y);
if(x>=m+1)return findy(m+1,b,2*c+1,x,y);
return max(findy(a,m,2*c,x,m),findy(m+1,b,2*c+1,m+1,y));
}
int func(){
auto itr=notone.end();itr--;
int last=*itr;itr--;
vector<pair<ll,ll> > v;
while(true){
if(v.size()>=80)break;
int cur=*itr;
if(cur+1!=last)v.PB(MP(last-1,findy(0,n-1,1,cur+1,last-1)));
if(cur==-1)break;
v.PB(MP(cur,pr[cur]));
last=cur;
itr--;
}
reverse(v.begin(),v.end());
int cmax=0;
ll mul=1;
for(int i=1;i<v.size();i++){
mul*=co[v[i].F];
if(mul*v[i].S>v[cmax].S){
cmax=i;
mul=1;
}
}
ll ans=v[cmax].S;
ans=v[cmax].S*findx(0,n-1,1,0,v[cmax].F);
ans%=mod;
return ans;
}
int init(int N, int X[], int Y[]) {
n=N;
for(int i=0;i<4*n;i++){segx[i]=1;segy[i]=0;}
for(int i=0;i<n;i++){
co[i]=X[i];
pr[i]=Y[i];
updy(0,n-1,1,Y[i],i);
updx(0,n-1,1,X[i],i);
}
notone.I(-1);notone.I(n);
for(int i=0;i<n;i++)if(X[i]!=1)notone.I(i);
return func();
}
int updateX(int pos, int val) {
updx(0,n-1,1,val,pos);
co[pos]=val;
if(val==1)notone.erase(pos);
else notone.I(pos);
return func();
}
int updateY(int pos, int val) {
updy(0,n-1,1,val,pos);
pr[pos]=val;
return func();
}
Compilation message
horses.cpp: In function 'int func()':
horses.cpp:67:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i=1;i<v.size();i++){
| ~^~~~~~~~~
horses.cpp:77:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
77 | return ans;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
452 KB |
Output is correct |
24 |
Correct |
3 ms |
448 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
488 KB |
Output is correct |
31 |
Correct |
2 ms |
448 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
451 ms |
71308 KB |
Output is correct |
2 |
Correct |
596 ms |
80304 KB |
Output is correct |
3 |
Correct |
517 ms |
71684 KB |
Output is correct |
4 |
Correct |
609 ms |
75476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
452 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
4 ms |
444 KB |
Output is correct |
33 |
Correct |
251 ms |
47384 KB |
Output is correct |
34 |
Correct |
204 ms |
47376 KB |
Output is correct |
35 |
Correct |
380 ms |
77716 KB |
Output is correct |
36 |
Correct |
362 ms |
77672 KB |
Output is correct |
37 |
Correct |
218 ms |
45644 KB |
Output is correct |
38 |
Correct |
253 ms |
58368 KB |
Output is correct |
39 |
Correct |
179 ms |
45400 KB |
Output is correct |
40 |
Correct |
407 ms |
72768 KB |
Output is correct |
41 |
Correct |
182 ms |
45404 KB |
Output is correct |
42 |
Correct |
197 ms |
45432 KB |
Output is correct |
43 |
Correct |
354 ms |
73240 KB |
Output is correct |
44 |
Correct |
329 ms |
73144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
4 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
448 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
513 ms |
71608 KB |
Output is correct |
34 |
Correct |
606 ms |
80400 KB |
Output is correct |
35 |
Correct |
562 ms |
71588 KB |
Output is correct |
36 |
Correct |
599 ms |
75444 KB |
Output is correct |
37 |
Correct |
236 ms |
47480 KB |
Output is correct |
38 |
Correct |
214 ms |
47512 KB |
Output is correct |
39 |
Correct |
358 ms |
77788 KB |
Output is correct |
40 |
Correct |
379 ms |
77716 KB |
Output is correct |
41 |
Correct |
269 ms |
45624 KB |
Output is correct |
42 |
Correct |
262 ms |
58336 KB |
Output is correct |
43 |
Correct |
183 ms |
45360 KB |
Output is correct |
44 |
Correct |
369 ms |
72880 KB |
Output is correct |
45 |
Correct |
181 ms |
45520 KB |
Output is correct |
46 |
Correct |
192 ms |
45528 KB |
Output is correct |
47 |
Correct |
364 ms |
73204 KB |
Output is correct |
48 |
Correct |
306 ms |
73196 KB |
Output is correct |
49 |
Correct |
596 ms |
50608 KB |
Output is correct |
50 |
Correct |
450 ms |
50380 KB |
Output is correct |
51 |
Correct |
529 ms |
79564 KB |
Output is correct |
52 |
Correct |
508 ms |
79160 KB |
Output is correct |
53 |
Correct |
586 ms |
48820 KB |
Output is correct |
54 |
Correct |
457 ms |
62440 KB |
Output is correct |
55 |
Correct |
271 ms |
46416 KB |
Output is correct |
56 |
Correct |
555 ms |
74588 KB |
Output is correct |
57 |
Correct |
275 ms |
47076 KB |
Output is correct |
58 |
Correct |
390 ms |
47552 KB |
Output is correct |
59 |
Correct |
326 ms |
73140 KB |
Output is correct |