#include "horses.h"
#include <bits/stdc++.h>
#define pb push_back
#define ET cout << "\n"
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
ll cross(ll a,ll aB,ll b,ll bB,ll &B)
{
if(aB||bB||a*b>MOD) B=1;
else B=0;
return a*b%MOD;
}
ll n,y[500005];
struct node
{
ll crs,mx,L,R,Lb,Rb,B;
node operator+(const node &a)const{
node re;
re.crs=cross(crs,B,a.crs,a.B,re.B);
if(Rb||a.Lb||R*a.L>MOD||R*a.L*y[a.mx]>=y[mx])
{
re.mx=a.mx;
re.L=cross(crs,B,a.L,a.Lb,re.Lb);
re.R=a.R,re.Rb=a.Rb;
}
else
{
re.mx=mx;
re.L=L,re.Lb=Lb;
re.R=cross(a.crs,a.B,R,Rb,re.Rb);
}
return re;
}
}seg[2000000];
void build(ll l,ll r,ll rt,int X[])
{
if(l==r)
return seg[rt]=node{(ll)X[l],l,(ll)X[l],1LL,0LL,0LL,0LL},void();
ll m=l+r>>1;
build(l,m,rt<<1,X),build(m+1,r,rt<<1|1,X);
seg[rt]=seg[rt<<1]+seg[rt<<1|1];
}
void modifyx(ll x,ll l,ll r,ll rt,ll v)
{
if(l==r)
return seg[rt]=node{v,l,v,1LL,0LL,0LL,0LL},void();
ll m=l+r>>1;
if(x<=m) modifyx(x,l,m,rt<<1,v);
else modifyx(x,m+1,r,rt<<1|1,v);
seg[rt]=seg[rt<<1]+seg[rt<<1|1];
}
void modifyy(ll x,ll l,ll r,ll rt,ll v)
{
if(l==r)
return y[x]=v,void();
ll m=l+r>>1;
if(x<=m) modifyy(x,l,m,rt<<1,v);
else modifyy(x,m+1,r,rt<<1|1,v);
seg[rt]=seg[rt<<1]+seg[rt<<1|1];
}
ll query(ll L,ll R,ll l,ll r,ll rt)
{
if(L<=l&&R>=r)
return seg[rt].crs;
ll m=l+r>>1;
if(R<=m) return query(L,R,l,m,rt<<1);
if(L>m) return query(L,R,m+1,r,rt<<1|1);
return query(L,R,l,m,rt<<1)*query(L,R,m+1,r,rt<<1|1)%MOD;
}
int init(int N, int X[], int Y[])
{
n=N;
for(int i=0;i<N;++i)
y[i]=Y[i];
build(0,n-1,1,X);
return y[seg[1].mx]*query(0,seg[1].mx,0,n-1,1)%MOD;
}
int updateX(int pos, int val)
{
modifyx(pos,0,n-1,1,val);
return y[seg[1].mx]*query(0,seg[1].mx,0,n-1,1)%MOD;
}
int updateY(int pos, int val)
{
modifyy(pos,0,n-1,1,val);
return y[seg[1].mx]*query(0,seg[1].mx,0,n-1,1)%MOD;
}
Compilation message
horses.cpp: In function 'void build(ll, ll, ll, int*)':
horses.cpp:53:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll m=l+r>>1;
~^~
horses.cpp: In function 'void modifyx(ll, ll, ll, ll, ll)':
horses.cpp:62:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll m=l+r>>1;
~^~
horses.cpp: In function 'void modifyy(ll, ll, ll, ll, ll)':
horses.cpp:72:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll m=l+r>>1;
~^~
horses.cpp: In function 'll query(ll, ll, ll, ll, ll)':
horses.cpp:82:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll m=l+r>>1;
~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:94:48: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return y[seg[1].mx]*query(0,seg[1].mx,0,n-1,1)%MOD;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:100:48: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return y[seg[1].mx]*query(0,seg[1].mx,0,n-1,1)%MOD;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:106:48: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return y[seg[1].mx]*query(0,seg[1].mx,0,n-1,1)%MOD;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
424 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
3 ms |
504 KB |
Output is correct |
24 |
Correct |
3 ms |
508 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
504 KB |
Output is correct |
30 |
Correct |
3 ms |
504 KB |
Output is correct |
31 |
Correct |
3 ms |
504 KB |
Output is correct |
32 |
Correct |
2 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
66548 KB |
Output is correct |
2 |
Correct |
208 ms |
79220 KB |
Output is correct |
3 |
Correct |
185 ms |
70584 KB |
Output is correct |
4 |
Correct |
198 ms |
74360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
504 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
504 KB |
Output is correct |
30 |
Correct |
3 ms |
504 KB |
Output is correct |
31 |
Correct |
2 ms |
504 KB |
Output is correct |
32 |
Correct |
2 ms |
504 KB |
Output is correct |
33 |
Correct |
95 ms |
69624 KB |
Output is correct |
34 |
Correct |
93 ms |
69624 KB |
Output is correct |
35 |
Correct |
109 ms |
76536 KB |
Output is correct |
36 |
Correct |
108 ms |
76596 KB |
Output is correct |
37 |
Correct |
80 ms |
67832 KB |
Output is correct |
38 |
Correct |
81 ms |
68728 KB |
Output is correct |
39 |
Correct |
72 ms |
67704 KB |
Output is correct |
40 |
Correct |
88 ms |
71672 KB |
Output is correct |
41 |
Correct |
77 ms |
67704 KB |
Output is correct |
42 |
Correct |
73 ms |
67772 KB |
Output is correct |
43 |
Correct |
87 ms |
72028 KB |
Output is correct |
44 |
Correct |
87 ms |
71928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
380 KB |
Output is correct |
23 |
Correct |
3 ms |
504 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
504 KB |
Output is correct |
31 |
Correct |
3 ms |
516 KB |
Output is correct |
32 |
Correct |
2 ms |
504 KB |
Output is correct |
33 |
Correct |
139 ms |
70392 KB |
Output is correct |
34 |
Correct |
206 ms |
79224 KB |
Output is correct |
35 |
Correct |
177 ms |
70392 KB |
Output is correct |
36 |
Correct |
192 ms |
74348 KB |
Output is correct |
37 |
Correct |
94 ms |
69624 KB |
Output is correct |
38 |
Correct |
91 ms |
69596 KB |
Output is correct |
39 |
Correct |
113 ms |
76536 KB |
Output is correct |
40 |
Correct |
109 ms |
76632 KB |
Output is correct |
41 |
Correct |
81 ms |
67932 KB |
Output is correct |
42 |
Correct |
81 ms |
68728 KB |
Output is correct |
43 |
Correct |
74 ms |
67772 KB |
Output is correct |
44 |
Correct |
89 ms |
71652 KB |
Output is correct |
45 |
Correct |
73 ms |
67836 KB |
Output is correct |
46 |
Correct |
74 ms |
67832 KB |
Output is correct |
47 |
Correct |
85 ms |
72028 KB |
Output is correct |
48 |
Correct |
85 ms |
71928 KB |
Output is correct |
49 |
Correct |
234 ms |
71804 KB |
Output is correct |
50 |
Correct |
219 ms |
71712 KB |
Output is correct |
51 |
Correct |
175 ms |
78468 KB |
Output is correct |
52 |
Correct |
153 ms |
78072 KB |
Output is correct |
53 |
Correct |
190 ms |
70012 KB |
Output is correct |
54 |
Correct |
153 ms |
70520 KB |
Output is correct |
55 |
Correct |
119 ms |
68848 KB |
Output is correct |
56 |
Correct |
137 ms |
73464 KB |
Output is correct |
57 |
Correct |
127 ms |
69384 KB |
Output is correct |
58 |
Correct |
130 ms |
69884 KB |
Output is correct |
59 |
Correct |
86 ms |
71932 KB |
Output is correct |