/* [Author : Hoang Duy Vu] - THPT Chuyen Nguyen Du */
//#pragma GCC optimize(" unroll-loops")
//#pragma gcc optimize("Ofast")
//#pragma GCC optimization("Ofast")
//#pragma optimize(Ofast)
#include "horses.h"
#include <bits/stdc++.h>
#define All(x) (x).begin(),(x).end()
#define ll long long
#define C make_pair
#define fi first
#define se second
#define two second.first
#define thr second.second
#define TASK "txt"
#define ld long double
using namespace std;
template<typename T> bool maximize(T &res, const T &val) {
if (res < val) { res = val; return true; } return false; }
template<typename T> bool minimize(T &res, const T &val) {
if (res > val) { res = val; return true; } return false; }
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const int LOG = 20;
const ll INF = 1e9;
const ll LNF = 1e18 + 7;
const ll mod = 1e9 + 7;
const int N = 5e5 + 100;
struct SegmentTree
{
vector <ll> f;
int n;
SegmentTree(int _n = 0)
{
n = _n;
f.assign(n*4,1);
}
void update(int i , int l , int r , int x , ll val)
{
if (l > x || r < x) return ;
if (l == r)
{
f[i] = val;
return ;
}
int m = (l + r) >> 1;
update(i*2,l,m,x,val);
update(i*2+1,m+1,r,x,val);
f[i] = (f[i*2]*f[i*2+1]) % mod;
}
ll get(int i , int l , int r , int c)
{
if (c < l) return 1;
if (r <= c) return f[i];
int m = (l + r) >> 1;
return (get(i*2,l,m,c)*get(i*2+1,m+1,r,c)) % mod;
}
};
struct SegmentTree2
{
vector <ll> f;
int n;
SegmentTree2(int _n = 0)
{
n = _n;
f.assign(n*4,0);
}
void update(int i , int l , int r , int x , ll val)
{
if (l > x || r < x) return ;
if (l == r)
{
f[i] = val;
return ;
}
int m = (l + r) >> 1;
update(i*2,l,m,x,val);
update(i*2+1,m+1,r,x,val);
f[i] = max(f[i*2],f[i*2+1]);
}
ll get(int i , int l , int r , int d , int c)
{
if (c < l || d > r || d > c) return 0;
if (d <= l && r <= c) return f[i];
int m = (l + r) >> 1;
return max(get(i*2,l,m,d,c),get(i*2+1,m+1,r,d,c));
}
};
SegmentTree2 Mx = 0;
SegmentTree IT = 0;
ll w[N] , val[N];
int n;
set <int> p;
ll calc() {
auto l = p.end();
l--;
l--;
auto r = l;
r++;
ll res = 0;
// cout << (*l) << " " << (*r) << "\n";
while (true)
{
int d = (*l) + 1;
int c = (*r) - 1;
if (d <= c)
{
ll gt = Mx.get(1,1,n,d,c);
maximize(res,gt);
}
if (d == 1) break;
maximize(res,val[(*l)]);
res = res * w[(*l)];
if (res >= 1e9)
{
res = res % mod;
res = (res * IT.get(1,1,n,(*l) - 1)) % mod;
return res;
}
l--;
r--;
}
return res;
}
int init(int Nx, int X[], int Y[]) {
n = Nx;
p.insert(0);
p.insert(n + 1);
IT = n;
Mx = n;
for (int i = 1 ; i <= n ; i++)
{
w[i] = X[i - 1], val[i] = Y[i - 1];
if (w[i] > 1) p.insert(i);
IT.update(1,1,n,i,w[i]);
Mx.update(1,1,n,i,val[i]);
}
return calc();
}
int updateX(int pos, int gt) {
pos++;
if (w[pos] == gt) return calc();
IT.update(1,1,n,pos,gt);
if (w[pos] == 1) p.insert(pos);
else if (gt == 1) p.erase(pos);
w[pos] = gt;
return calc();
}
int updateY(int pos, int gt) {
pos++;
Mx.update(1,1,n,pos,gt);
val[pos] = gt;
return calc();
}
// int main()
// {
// ios_base::sync_with_stdio(0);
// cin.tie(NULL); cout.tie(NULL);
// if(fopen(TASK".inp", "r")){
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
// }
// int x[N] , y[N];
// int t;
// cin >> t;
// for (int i = 0 ; i < t ; i++) cin >> x[i] >> y[i];
// cout << init(t,x,y) << "\n";
// int q;
// cin >> q;
// while (q--)
// {
// int id , g , h;
// cin >> id >> g >> h;
// if (id == 1) cout << updateX(g,h) << "\n";
// else cout << updateY(g,h) << "\n";
// }
// return 0;
// }
Compilation message
horses.cpp: In function 'long long int calc()':
horses.cpp:140:13: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
140 | if (res >= 1e9)
| ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:169:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
169 | return calc();
| ~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:174:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
174 | if (w[pos] == gt) return calc();
| ~~~~^~
horses.cpp:179:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
179 | return calc();
| ~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:186:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
186 | return calc();
| ~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 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 |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 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 |
308 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 |
308 KB |
Output is correct |
15 |
Correct |
1 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 |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
312 KB |
Output is correct |
18 |
Correct |
1 ms |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
320 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
452 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
320 KB |
Output is correct |
32 |
Correct |
2 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
366 ms |
68512 KB |
Output is correct |
2 |
Correct |
415 ms |
80436 KB |
Output is correct |
3 |
Correct |
372 ms |
71496 KB |
Output is correct |
4 |
Correct |
369 ms |
75400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
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 |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
388 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 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 |
0 ms |
312 KB |
Output is correct |
22 |
Correct |
0 ms |
312 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
448 KB |
Output is correct |
26 |
Correct |
1 ms |
448 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
456 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
181 ms |
47488 KB |
Output is correct |
34 |
Correct |
179 ms |
47468 KB |
Output is correct |
35 |
Correct |
379 ms |
77708 KB |
Output is correct |
36 |
Correct |
352 ms |
77640 KB |
Output is correct |
37 |
Correct |
213 ms |
45640 KB |
Output is correct |
38 |
Correct |
244 ms |
58368 KB |
Output is correct |
39 |
Correct |
183 ms |
45388 KB |
Output is correct |
40 |
Correct |
336 ms |
72796 KB |
Output is correct |
41 |
Correct |
176 ms |
45452 KB |
Output is correct |
42 |
Correct |
198 ms |
45484 KB |
Output is correct |
43 |
Correct |
336 ms |
73164 KB |
Output is correct |
44 |
Correct |
334 ms |
73188 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
312 KB |
Output is correct |
6 |
Correct |
0 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
312 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 |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
312 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 |
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 |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
320 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
369 ms |
71560 KB |
Output is correct |
34 |
Correct |
409 ms |
80380 KB |
Output is correct |
35 |
Correct |
380 ms |
71528 KB |
Output is correct |
36 |
Correct |
392 ms |
75352 KB |
Output is correct |
37 |
Correct |
185 ms |
47476 KB |
Output is correct |
38 |
Correct |
181 ms |
47436 KB |
Output is correct |
39 |
Correct |
333 ms |
77708 KB |
Output is correct |
40 |
Correct |
334 ms |
77792 KB |
Output is correct |
41 |
Correct |
216 ms |
45568 KB |
Output is correct |
42 |
Correct |
245 ms |
58368 KB |
Output is correct |
43 |
Correct |
181 ms |
45460 KB |
Output is correct |
44 |
Correct |
344 ms |
72884 KB |
Output is correct |
45 |
Correct |
173 ms |
45392 KB |
Output is correct |
46 |
Correct |
205 ms |
45568 KB |
Output is correct |
47 |
Correct |
347 ms |
73236 KB |
Output is correct |
48 |
Correct |
357 ms |
73200 KB |
Output is correct |
49 |
Correct |
261 ms |
50584 KB |
Output is correct |
50 |
Correct |
233 ms |
50500 KB |
Output is correct |
51 |
Correct |
429 ms |
79668 KB |
Output is correct |
52 |
Correct |
397 ms |
79092 KB |
Output is correct |
53 |
Correct |
579 ms |
48776 KB |
Output is correct |
54 |
Correct |
337 ms |
62324 KB |
Output is correct |
55 |
Correct |
231 ms |
46520 KB |
Output is correct |
56 |
Correct |
418 ms |
74588 KB |
Output is correct |
57 |
Correct |
215 ms |
47180 KB |
Output is correct |
58 |
Correct |
507 ms |
47520 KB |
Output is correct |
59 |
Correct |
333 ms |
73152 KB |
Output is correct |