# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1010260 |
2024-06-28T15:37:46 Z |
hotboy2703 |
Horses (IOI15_horses) |
C++17 |
|
484 ms |
68220 KB |
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
set <ll> bigX;
const ll MAXN = 5e5+100;
const ll MOD = 1e9 + 7;
ll n;
set <ll> s;
namespace X{
ll tree[MAXN*4];
ll a[MAXN];
void build(ll id,ll l,ll r){
if (l==r)tree[id] = a[l];
else{
ll mid = (l + r) >> 1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
tree[id] = tree[id<<1] * tree[id<<1|1] % MOD;
}
}
void update(ll id,ll l,ll r,ll i){
if (l > i || r < i)return;
if (l == r){
tree[id] = a[l];
return;
}
ll mid = (l + r) >> 1;
update(id<<1,l,mid,i);
update(id<<1|1,mid+1,r,i);
tree[id] = tree[id<<1] * tree[id<<1|1] % MOD;
}
ll get(ll id,ll l,ll r,ll i){
if (l > i)return 1;
if (r <= i)return tree[id];
ll mid = (l + r) >> 1;
return get(id<<1,l,mid,i)*get(id<<1|1,mid+1,r,i)%MOD;
}
void init(int X[]){
for (ll i = 0;i < n;i ++)a[i] = X[i];
for (ll i = 0;i < n;i ++){
if (a[i] > 1)s.insert(i);
}
build(1,0,n-1);
}
void update(ll pos,ll val){
s.erase(pos);
a[pos]=val;
if (val > 1)s.insert(pos);
update(1,0,n-1,pos);
}
ll get(ll x){
return get(1,0,n-1,x);
}
}
namespace Y{
ll a[MAXN];
ll tree[MAXN*4];
ll better(ll x,ll y){
if (x==-1)return y;
if (y==-1)return x;
if (a[x] > a[y])return x;
return y;
}
void build(ll id,ll l,ll r){
if (l==r)tree[id] = l;
else{
ll mid = (l + r) >> 1;
build(id<<1,l,mid);
build(id<<1|1,mid+1,r);
tree[id] = better(tree[id<<1],tree[id<<1|1]);
}
}
void update(ll id,ll l,ll r,ll i){
if (l > i || r < i)return;
if (l == r){
return;
}
ll mid = (l + r) >> 1;
update(id<<1,l,mid,i);
update(id<<1|1,mid+1,r,i);
tree[id] = better(tree[id<<1],tree[id<<1|1]);
}
ll get(ll id,ll l,ll r,ll l1,ll r1){
if (l > r1 || l1 > r)return -1;
if (l1 <= l && r <= r1)return tree[id];
ll mid = (l + r) >> 1;
return better(get(id<<1,l,mid,l1,r1),get(id<<1|1,mid+1,r,l1,r1));
}
void init(int Y[]){
for (ll i = 0;i < n;i ++)a[i] = Y[i];
build(1,0,n-1);
}
void update(ll pos,ll val){
a[pos] = val;
update(1,0,n-1,pos);
}
ll get(ll l,ll r){
return get(1,0,n-1,l,r);
}
}
ll solve(){
ll best = 0;
ll best_id = -1;
ll last = n;
s.insert(0);
for (auto it = s.rbegin();it != s.rend();it ++){
ll tmp = Y::get(*it,last-1);
if (Y::a[tmp] > best){
best = Y::a[tmp];
best_id = tmp;
}
best *= X::a[*it];
const static ll INF = 1e9;
if (best > INF){
break;
}
last = *it;
}
if (X::a[0]==1)s.erase(0);
// cout<<best_id<<'\n';
return Y::a[best_id] * X::get(best_id) % MOD;
}
int init(int N, int X[], int Y[]) {
n=N;
X::init(X);
Y::init(Y);
return solve();
}
int updateX(int pos, int val) {
X::update(pos,val);
return solve();
}
int updateY(int pos, int val) {
Y::update(pos,val);
return solve();
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:136:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
136 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:141:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
141 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:146:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
146 | return solve();
| ~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6504 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6488 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
3 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
2 ms |
6620 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
2 ms |
6492 KB |
Output is correct |
32 |
Correct |
3 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
454 ms |
55560 KB |
Output is correct |
2 |
Correct |
254 ms |
68220 KB |
Output is correct |
3 |
Correct |
259 ms |
59220 KB |
Output is correct |
4 |
Correct |
248 ms |
63220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6608 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6488 KB |
Output is correct |
27 |
Correct |
3 ms |
6488 KB |
Output is correct |
28 |
Correct |
3 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6608 KB |
Output is correct |
31 |
Correct |
2 ms |
6488 KB |
Output is correct |
32 |
Correct |
3 ms |
6492 KB |
Output is correct |
33 |
Correct |
30 ms |
31324 KB |
Output is correct |
34 |
Correct |
30 ms |
35284 KB |
Output is correct |
35 |
Correct |
152 ms |
65648 KB |
Output is correct |
36 |
Correct |
138 ms |
65488 KB |
Output is correct |
37 |
Correct |
64 ms |
33364 KB |
Output is correct |
38 |
Correct |
80 ms |
46264 KB |
Output is correct |
39 |
Correct |
23 ms |
33060 KB |
Output is correct |
40 |
Correct |
131 ms |
60652 KB |
Output is correct |
41 |
Correct |
41 ms |
33124 KB |
Output is correct |
42 |
Correct |
53 ms |
33344 KB |
Output is correct |
43 |
Correct |
123 ms |
61000 KB |
Output is correct |
44 |
Correct |
133 ms |
61016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6592 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6740 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
3 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
2 ms |
6488 KB |
Output is correct |
32 |
Correct |
3 ms |
6492 KB |
Output is correct |
33 |
Correct |
484 ms |
55472 KB |
Output is correct |
34 |
Correct |
264 ms |
68100 KB |
Output is correct |
35 |
Correct |
214 ms |
59476 KB |
Output is correct |
36 |
Correct |
229 ms |
63200 KB |
Output is correct |
37 |
Correct |
30 ms |
35152 KB |
Output is correct |
38 |
Correct |
31 ms |
35152 KB |
Output is correct |
39 |
Correct |
149 ms |
65584 KB |
Output is correct |
40 |
Correct |
140 ms |
65528 KB |
Output is correct |
41 |
Correct |
76 ms |
33332 KB |
Output is correct |
42 |
Correct |
81 ms |
46164 KB |
Output is correct |
43 |
Correct |
23 ms |
33252 KB |
Output is correct |
44 |
Correct |
147 ms |
60568 KB |
Output is correct |
45 |
Correct |
43 ms |
33244 KB |
Output is correct |
46 |
Correct |
53 ms |
33360 KB |
Output is correct |
47 |
Correct |
119 ms |
60988 KB |
Output is correct |
48 |
Correct |
128 ms |
60964 KB |
Output is correct |
49 |
Correct |
112 ms |
38376 KB |
Output is correct |
50 |
Correct |
90 ms |
38216 KB |
Output is correct |
51 |
Correct |
268 ms |
67500 KB |
Output is correct |
52 |
Correct |
173 ms |
66924 KB |
Output is correct |
53 |
Correct |
413 ms |
36464 KB |
Output is correct |
54 |
Correct |
180 ms |
50000 KB |
Output is correct |
55 |
Correct |
91 ms |
34156 KB |
Output is correct |
56 |
Correct |
201 ms |
62292 KB |
Output is correct |
57 |
Correct |
246 ms |
34900 KB |
Output is correct |
58 |
Correct |
366 ms |
35360 KB |
Output is correct |
59 |
Correct |
151 ms |
61064 KB |
Output is correct |