# include "horses.h"
//# pragma GCC optimize("Ofast,no-stack-protector")
//# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
/*
# include <ext/pb_ds/tree_policy.hpp>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/rope>
*/
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;
const int mod = 1e9 + 7;
set<int>s,S;
int fen[1 << 19],x[1 << 19],y[1 << 19],t[1 << 21],n,b[1 << 19];
void upd(int nod,int l,int r,int pos,int val)
{
if(l == r)
{
t[nod] = val;
return ;
}
int mid = l + r >> 1;
if(pos <= mid) upd(nod << 1,l,mid,pos,val);
else upd(nod << 1 | 1,mid + 1,r,pos,val);
t[nod] = max(t[nod << 1],t[nod << 1 | 1]);
}
int qry(int nod,int tl,int tr,int l,int r)
{
if(l > r) return 0;
if(tl == l && tr == r) return t[nod];
int mid = tl + tr >> 1;
return max(qry(nod << 1,tl,mid,l,min(mid,r)),qry(nod << 1 | 1,mid + 1,tr,max(mid + 1,l),r));
}
void UPD(int pos,int val)
{
pos++;
for(int i = pos;i <= n;i += (i & (-i)))
{
fen[i] *= val;
fen[i] %= mod;
}
}
int QRY(int pos)
{
pos++;
int ans = 1;
for(int i = pos;i;i -= (i & (-i)))
{
ans *= fen[i];
ans %= mod;
}
return ans;
}
int f()
{
auto it = --(S.end());
for(int i = 0;i <= 35;i++)
{
if(it != S.begin()) it--;
}
int pos = (*it) + 1;
vector<pair<int,int>>vec;
vector<int>hm;
int i = pos;
while(i < n)
{
if(x[i] == 1)
{
int r = *(S.upper_bound(i)) - 1;
vec.pb(mp(x[i],qry(1,0,n - 1,i,r)));
hm.pb(i);
i = r + 1;
}
else
{
vec.pb(mp(x[i],y[i]));
hm.pb(i);
i++;
}
}
for(int i = 0;i < sz(vec);i++) b[i] = 1;
for(int i = 0;i < sz(vec);i++)
{
int j = i + 1;
int prod = 1;
while(j < sz(vec))
{
prod *= vec[j].first;
if(prod >= vec[i].second)
{
b[i] = 0;
break;
}
else if(prod * vec[j].second >= vec[i].second)
{
b[i] = 0;
}
else b[j] = 0;
j++;
}
}
int f = 0;
for(int i = 0;i < sz(vec);i++)
{
if(b[i]) f = i;
}
return ((vec[f].second * QRY(hm[f])) % mod);
}
# undef int
int init(int N, int X[], int Y[])
{
# define int ll
n = N;
S.insert(n);S.insert(-1);
for(int i = 1;i <= n;i++) fen[i] = 1;
for(int i = 0;i < n;i++)
{
x[i] = X[i];
y[i] = Y[i];
UPD(i,x[i]);
if(X[i] > 1) S.insert(i);
upd(1,0,n - 1,i,Y[i]);
}
//cout << f() << '\n';
return f();
}
int pw(int val,int p)
{
int ans = 1;
for(int i = 0;(1LL << i) <= p;i++)
{
if(p & (1LL << i))
{
ans *= val;
ans %= mod;
}
val *= val;
val %= mod;
}
return ans;
}
# undef int
int updateX(int pos, int val)
{
# define int ll
if(x[pos] > 1) S.erase(S.find(pos));
if(val > 1) S.insert(pos);
UPD(pos,(val * pw(x[pos],mod - 2)) % mod);
x[pos] = val;
//cout << f() << '\n';
return f();
}
# undef int
int updateY(int pos, int val)
{
# define int ll
upd(1,0,n - 1,pos,val);
y[pos] = val;
//cout << f() << '\n';
return f();
}
Compilation message
horses.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
# pragma GCC optimization ("unroll-loops")
horses.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:38:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
horses.cpp: In function 'long long int qry(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:48:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
horses.cpp: In function 'long long int f()':
horses.cpp:102:10: warning: declaration of 'i' shadows a previous local [-Wshadow]
for(int i = 0;i < sz(vec);i++) b[i] = 1;
^
horses.cpp:85:6: note: shadowed declaration is here
int i = pos;
^
horses.cpp:103:10: warning: declaration of 'i' shadows a previous local [-Wshadow]
for(int i = 0;i < sz(vec);i++)
^
horses.cpp:85:6: note: shadowed declaration is here
int i = pos;
^
horses.cpp:124:10: warning: declaration of 'i' shadows a previous local [-Wshadow]
for(int i = 0;i < sz(vec);i++)
^
horses.cpp:85:6: note: shadowed declaration is here
int i = pos;
^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:147:10: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return f();
~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:175:10: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return f();
~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:185:10: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return f();
~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
368 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 |
380 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 |
376 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 |
408 KB |
Output is correct |
20 |
Correct |
2 ms |
376 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 |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 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 |
376 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 |
380 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 |
376 KB |
Output is correct |
23 |
Correct |
8 ms |
504 KB |
Output is correct |
24 |
Correct |
5 ms |
504 KB |
Output is correct |
25 |
Correct |
5 ms |
504 KB |
Output is correct |
26 |
Correct |
5 ms |
504 KB |
Output is correct |
27 |
Correct |
7 ms |
504 KB |
Output is correct |
28 |
Correct |
7 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
504 KB |
Output is correct |
31 |
Correct |
4 ms |
376 KB |
Output is correct |
32 |
Correct |
6 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
496 ms |
49788 KB |
Output is correct |
2 |
Correct |
622 ms |
50236 KB |
Output is correct |
3 |
Correct |
580 ms |
49732 KB |
Output is correct |
4 |
Correct |
729 ms |
49692 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 |
380 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 |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
3 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 |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
380 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 |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
7 ms |
504 KB |
Output is correct |
24 |
Correct |
5 ms |
504 KB |
Output is correct |
25 |
Correct |
5 ms |
504 KB |
Output is correct |
26 |
Correct |
4 ms |
504 KB |
Output is correct |
27 |
Correct |
6 ms |
412 KB |
Output is correct |
28 |
Correct |
6 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
504 KB |
Output is correct |
31 |
Correct |
4 ms |
504 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
33 |
Correct |
179 ms |
25296 KB |
Output is correct |
34 |
Correct |
119 ms |
25336 KB |
Output is correct |
35 |
Correct |
352 ms |
49080 KB |
Output is correct |
36 |
Correct |
347 ms |
49160 KB |
Output is correct |
37 |
Correct |
167 ms |
25420 KB |
Output is correct |
38 |
Correct |
273 ms |
37312 KB |
Output is correct |
39 |
Correct |
102 ms |
25080 KB |
Output is correct |
40 |
Correct |
344 ms |
48888 KB |
Output is correct |
41 |
Correct |
112 ms |
25176 KB |
Output is correct |
42 |
Correct |
150 ms |
25300 KB |
Output is correct |
43 |
Correct |
305 ms |
48632 KB |
Output is correct |
44 |
Correct |
303 ms |
48732 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 |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
356 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 |
376 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 |
368 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
7 ms |
508 KB |
Output is correct |
24 |
Correct |
5 ms |
504 KB |
Output is correct |
25 |
Correct |
5 ms |
504 KB |
Output is correct |
26 |
Correct |
4 ms |
504 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
504 KB |
Output is correct |
29 |
Correct |
4 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
416 KB |
Output is correct |
31 |
Correct |
4 ms |
504 KB |
Output is correct |
32 |
Correct |
6 ms |
504 KB |
Output is correct |
33 |
Correct |
501 ms |
49888 KB |
Output is correct |
34 |
Correct |
622 ms |
50056 KB |
Output is correct |
35 |
Correct |
598 ms |
49656 KB |
Output is correct |
36 |
Correct |
826 ms |
49648 KB |
Output is correct |
37 |
Correct |
179 ms |
25336 KB |
Output is correct |
38 |
Correct |
120 ms |
25336 KB |
Output is correct |
39 |
Correct |
354 ms |
49120 KB |
Output is correct |
40 |
Correct |
338 ms |
49040 KB |
Output is correct |
41 |
Correct |
165 ms |
25336 KB |
Output is correct |
42 |
Correct |
274 ms |
37240 KB |
Output is correct |
43 |
Correct |
103 ms |
25208 KB |
Output is correct |
44 |
Correct |
334 ms |
48840 KB |
Output is correct |
45 |
Correct |
102 ms |
25180 KB |
Output is correct |
46 |
Correct |
142 ms |
25208 KB |
Output is correct |
47 |
Correct |
304 ms |
48632 KB |
Output is correct |
48 |
Correct |
307 ms |
48648 KB |
Output is correct |
49 |
Correct |
898 ms |
27476 KB |
Output is correct |
50 |
Correct |
351 ms |
27260 KB |
Output is correct |
51 |
Correct |
670 ms |
50168 KB |
Output is correct |
52 |
Correct |
533 ms |
50288 KB |
Output is correct |
53 |
Correct |
873 ms |
27336 KB |
Output is correct |
54 |
Correct |
1059 ms |
40324 KB |
Output is correct |
55 |
Correct |
241 ms |
25336 KB |
Output is correct |
56 |
Correct |
572 ms |
49780 KB |
Output is correct |
57 |
Correct |
232 ms |
26164 KB |
Output is correct |
58 |
Correct |
633 ms |
26204 KB |
Output is correct |
59 |
Correct |
317 ms |
48760 KB |
Output is correct |