#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
const int mod=1e9+7;
int mul(long long x,int y){
return 1ll*(x%mod)*y%mod;
}
struct ST{
vector<pair<int,int> > st;
void init(int n){
st.resize(4*n);
}
void pull(int v){
st[v].fs=mul(st[2*v+1].fs,st[2*v+2].fs);
st[v].sc=max(st[2*v+1].sc,st[2*v+2].sc);
}
void update(int v,int L,int R,int p,int t,int x){
if(L==R){
if(t==1){
st[v].fs=x;
}
else{
st[v].sc=x;
}
return;
}
int m=(L+R)/2;
if(p<=m){
update(2*v+1,L,m,p,t,x);
}
else{
update(2*v+2,m+1,R,p,t,x);
}
pull(v);
}
int q1(int v,int L,int R,int l,int r){
if(r<l){
return 1;
}
if(L==l && r==R){
return st[v].fs;
}
int m=(L+R)/2;
if(r<=m){
return q1(2*v+1,L,m,l,r);
}
else if(l>m){
return q1(2*v+2,m+1,R,l,r);
}
else{
return mul(q1(2*v+1,L,m,l,m),q1(2*v+2,m+1,R,m+1,r));
}
}
int q2(int v,int L,int R,int l,int r){
if(L==l && r==R){
return st[v].sc;
}
int m=(L+R)/2;
if(r<=m){
return q2(2*v+1,L,m,l,r);
}
else if(l>m){
return q2(2*v+2,m+1,R,l,r);
}
else{
return max(q2(2*v+1,L,m,l,m),q2(2*v+2,m+1,R,m+1,r));
}
}
}st;
set<pair<int,int> > s;
vector<int> x;
const long long inf=2e9;
int n;
int cal(){
long long nw=1;
int lst=n;
for(auto h:s){
nw=max(nw,(long long)st.q2(0,0,n-1,-h.fs,lst-1));
nw*=h.sc;
if(nw>=inf){
return mul(nw,st.q1(0,0,n-1,0,-h.fs-1));
}
lst=-h.fs;
}
return nw%mod;
}
int init(int N,int X[],int Y[]){
st.init(N);
n=N;
for(int i=0;i<n;i++){
st.update(0,0,n-1,i,1,X[i]);
x.push_back(X[i]);
st.update(0,0,n-1,i,2,Y[i]);
if(X[i]>=2 || i==0){
s.insert({-i,X[i]});
}
}
return cal();
}
int updateX(int pos,int val){
st.update(0,0,n-1,pos,1,val);
if(x[pos]>=2 || pos==0){
assert(s.find(pair<int,int>(-pos,x[pos]))!=s.end());
s.erase({-pos,x[pos]});
}
x[pos]=val;
if(x[pos]>=2 || pos==0){
s.insert({-pos,x[pos]});
}
return cal();
}
int updateY(int pos,int val){
st.update(0,0,n-1,pos,2,val);
return cal();
}
/*
int main() {
int n;
cin >> n;
int u[n]={0},v[n]={0};
for(int i=0;i<n;i++){
cin >> u[i];
}
for(int i=0;i<n;i++){
cin >> v[i];
}
cout << init(n,u,v) << "\n";
int q;
cin >> q;
while(q--){
int t;
cin >> t;
int x,y;
cin >> x >> y;
if(t==1){
cout << updateX(x,y) << "\n";
}
else{
cout << updateY(x,y) << "\n";
}
}
return 0;
}
*/
Compilation message
horses.cpp: In function 'int mul(long long int, int)':
horses.cpp:11:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
11 | return 1ll*(x%mod)*y%mod;
| ~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int cal()':
horses.cpp:92:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
92 | return nw%mod;
| ~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
216 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
312 KB |
Output is correct |
26 |
Correct |
2 ms |
308 KB |
Output is correct |
27 |
Correct |
2 ms |
308 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
503 ms |
46268 KB |
Output is correct |
2 |
Correct |
469 ms |
48012 KB |
Output is correct |
3 |
Correct |
458 ms |
48304 KB |
Output is correct |
4 |
Correct |
505 ms |
48280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
308 KB |
Output is correct |
25 |
Correct |
1 ms |
308 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
320 KB |
Output is correct |
33 |
Correct |
229 ms |
24060 KB |
Output is correct |
34 |
Correct |
222 ms |
24000 KB |
Output is correct |
35 |
Correct |
342 ms |
47200 KB |
Output is correct |
36 |
Correct |
333 ms |
47108 KB |
Output is correct |
37 |
Correct |
239 ms |
24000 KB |
Output is correct |
38 |
Correct |
270 ms |
35984 KB |
Output is correct |
39 |
Correct |
212 ms |
23984 KB |
Output is correct |
40 |
Correct |
318 ms |
47380 KB |
Output is correct |
41 |
Correct |
224 ms |
24104 KB |
Output is correct |
42 |
Correct |
226 ms |
24064 KB |
Output is correct |
43 |
Correct |
309 ms |
47368 KB |
Output is correct |
44 |
Correct |
312 ms |
47296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
308 KB |
Output is correct |
26 |
Correct |
1 ms |
308 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
312 KB |
Output is correct |
29 |
Correct |
1 ms |
328 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
503 ms |
48324 KB |
Output is correct |
34 |
Correct |
462 ms |
48140 KB |
Output is correct |
35 |
Correct |
452 ms |
48316 KB |
Output is correct |
36 |
Correct |
499 ms |
48312 KB |
Output is correct |
37 |
Correct |
235 ms |
24184 KB |
Output is correct |
38 |
Correct |
228 ms |
24032 KB |
Output is correct |
39 |
Correct |
344 ms |
47232 KB |
Output is correct |
40 |
Correct |
330 ms |
47208 KB |
Output is correct |
41 |
Correct |
234 ms |
24036 KB |
Output is correct |
42 |
Correct |
268 ms |
35880 KB |
Output is correct |
43 |
Correct |
213 ms |
24000 KB |
Output is correct |
44 |
Correct |
324 ms |
47440 KB |
Output is correct |
45 |
Correct |
219 ms |
24060 KB |
Output is correct |
46 |
Correct |
226 ms |
24068 KB |
Output is correct |
47 |
Correct |
320 ms |
47296 KB |
Output is correct |
48 |
Correct |
313 ms |
47264 KB |
Output is correct |
49 |
Correct |
309 ms |
25932 KB |
Output is correct |
50 |
Correct |
288 ms |
25916 KB |
Output is correct |
51 |
Correct |
423 ms |
48076 KB |
Output is correct |
52 |
Correct |
390 ms |
47800 KB |
Output is correct |
53 |
Correct |
493 ms |
25292 KB |
Output is correct |
54 |
Correct |
349 ms |
37604 KB |
Output is correct |
55 |
Correct |
273 ms |
22900 KB |
Output is correct |
56 |
Correct |
382 ms |
47012 KB |
Output is correct |
57 |
Correct |
360 ms |
23748 KB |
Output is correct |
58 |
Correct |
426 ms |
23712 KB |
Output is correct |
59 |
Correct |
320 ms |
46136 KB |
Output is correct |