# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
560958 |
2022-05-12T05:45:05 Z |
AriaH |
Horses (IOI15_horses) |
C++17 |
|
433 ms |
37516 KB |
#include "horses.h"
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define Mp make_pair
#define endl "\n"
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 5e5 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;
int n, A[N], B[N];
struct node
{
ll z, mx, my;
void init(int a, int b)
{
z = a;
mx = a;
my = b;
}
friend node operator | (node a, node b)
{
a.z = a.z * b.z % mod;
a.mx = max(a.mx, b.mx);
a.my = max(a.my, b.my);
return a;
}
} seg[N << 2];
void build(int v = 1, int tl = 0, int tr = n - 1)
{
if(tl == tr)
{
seg[v].init(A[tl], B[tl]);
return;
}
int mid = (tl + tr) >> 1;
build(v << 1, tl, mid), build(v << 1 | 1, mid + 1, tr);
seg[v] = seg[v << 1] | seg[v << 1 | 1];
}
void Change(int p, int v = 1, int tl = 0, int tr = n - 1)
{
if(tl == tr)
{
seg[v].init(A[p], B[p]);
return;
}
int mid = (tl + tr) >> 1;
if(p <= mid) Change(p, v << 1, tl, mid);
else Change(p, v << 1 | 1, mid + 1, tr);
}
pii get(int pos, int v = 1, int tl = 0, int tr = n - 1)
{
if(tl > pos) return Mp(-1, -1);
if(seg[v].mx == 1) return Mp(tl, seg[v].my);
if(tl == tr) return Mp(tl, B[tl]);
int mid = (tl + tr) >> 1;
pii cu = get(pos, v << 1 | 1, mid + 1, tr);
if(A[cu.F] > 1)
{
return cu;
}
pii now = get(pos, v << 1, tl, mid);
return Mp(now.F, max(now.S, cu.S));
}
ll ask(int l, int r, int v = 1, int tl = 0, int tr = n - 1)
{
if(r == -1) return 1;
if(l > tr || r < tl || l > r) return 1;
if(l <= tl && tr <= r) return seg[v].z;
int mid = (tl + tr) >> 1;
return ask(l, r, v << 1, tl, mid) * ask(l, r, v << 1 | 1, mid + 1, tr) % mod;
}
int solve()
{
int id = n - 1;
ll zarb = 1, best = 0;
while(id >= 0)
{
pii now = get(id);
zarb *= A[now.F];
best = max(best, (ll)now.S);
id = now.F - 1;
///printf("id = %d best = %lld zarb = %lld\n", id, best, zarb);
if(zarb >= 1e9) break;
best *= A[now.F];
}
best %= mod;
return best * ask(0, id) % mod;
}
int init(int _N, int X[], int Y[])
{
n = _N;
for(int i = 0; i < n; i ++) A[i] = X[i], B[i] = Y[i];
build();
return solve();
}
int updateX(int pos, int val)
{
A[pos] = val;
Change(pos);
return solve();
}
int updateY(int pos, int val)
{
B[pos] = val;
Change(pos);
return solve();
}
Compilation message
horses.cpp: In function 'int solve()':
horses.cpp:105:6: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
105 | if(zarb >= 1e9) break;
| ^~~~
horses.cpp:109:27: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
109 | return best * ask(0, id) % mod;
| ~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
308 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 |
292 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 |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
0 ms |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 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 |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
308 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 |
316 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 |
212 KB |
Output is correct |
21 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
433 ms |
37516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
308 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 |
212 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 |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 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 |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
340 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 |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
212 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 |
312 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |