# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
416311 |
2021-06-02T10:01:01 Z |
Theo830 |
Horses (IOI15_horses) |
C++17 |
|
961 ms |
73396 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<ll> distr;
ll rnd(ll a, ll b){return distr(rng)%(b-a+1)+a;}
#include "horses.h"
/*
int init(int N, int X[], int Y[]);
int updateX(int pos, int val);
int updateY(int pos, int val);
int main() {
int N;
cin>>N;
int *X = (int*)malloc(sizeof(int)*(unsigned int)N);
int *Y = (int*)malloc(sizeof(int)*(unsigned int)N);
for (int i = 0; i < N; i++) {
cin>>X[i];
}
for (int i = 0; i < N; i++) {
cin>>Y[i];
}
printf("%d\n",init(N,X,Y));
int M;
cin>>M;
for (int i = 0; i < M; i++) {
int type;
cin>>type;
int pos;
int val;
cin>>pos>>val;
if (type == 1) {
printf("%d\n",updateX(pos,val));
} else if (type == 2) {
printf("%d\n",updateY(pos,val));
}
}
return 0;
}
*/
ll seg[2000005]={0},se[2000005]={0};
ll y[500000];
ll n;
void build(ll s,ll e,ll idx){
if(s == e){
seg[idx] = y[s-1];
return;
}
ll mid = (s+e)/2;
build(s,mid,idx*2);
build(mid+1,e,idx*2+1);
seg[idx] = max(seg[idx*2],seg[idx*2+1]);
}
void update(ll s,ll e,ll qs,ll qe,ll idx,ll k){
if(s == e && s == qs){
seg[idx] = k;
return;
}
if(qs > e || qe < s){
return;
}
ll mid = (s+e)/2;
update(s,mid,qs,qe,idx*2,k);
update(mid+1,e,qs,qe,idx*2+1,k);
seg[idx] = max(seg[idx*2],seg[idx*2+1]);
}
ll query(ll s,ll e,ll qs,ll qe,ll idx){
if(qs <= s && e <= qe){
return seg[idx];
}
if(qs > e || qe < s){
return 0;
}
ll mid = (s+e)/2;
ll a = query(s,mid,qs,qe,idx*2);
ll b = query(mid+1,e,qs,qe,idx*2+1);
return max(a,b);
}
ll x[500000];
void build2(ll s,ll e,ll idx){
if(s == e){
se[idx] = x[s-1];
return;
}
ll mid = (s+e)/2;
build2(s,mid,idx*2);
build2(mid+1,e,idx*2+1);
se[idx] = (se[idx*2] * se[idx*2+1]) % INF;
}
void update2(ll s,ll e,ll qs,ll qe,ll idx,ll k){
if(s == e && s == qs){
se[idx] = k;
return;
}
if(qs > e || qe < s){
return;
}
ll mid = (s+e)/2;
update2(s,mid,qs,qe,idx*2,k);
update2(mid+1,e,qs,qe,idx*2+1,k);
se[idx] = (se[idx*2] * se[idx*2+1]) % INF;
}
ll query2(ll s,ll e,ll qs,ll qe,ll idx){
if(qs <= s && e <= qe){
return se[idx];
}
if(qs > e || qe < s){
return 1;
}
ll mid = (s+e)/2;
ll a = query2(s,mid,qs,qe,idx*2);
ll b = query2(mid+1,e,qs,qe,idx*2+1);
return (a * b) % INF;
}
set<ii>ar;
ll power(ll a,ll b){
if(b == 0){
return 1;
}
if(b == 1){
return a;
}
ll ans = power(a,b/2);
ans *= ans;
ans %= INF;
if(b % 2){
ans *= a;
}
return ans % INF;
}
ll inv(ll a){
return power(a,INF-2);
}
int solve(void){
ll num = 1;
ll p = 0;
ll product = query2(1,n,1,n,1);
ll num2 = 1,y2 = y[n-1];
auto it = ar.begin();
ll last = n;
while(num <= 1e9 && p != ar.size()){
ll y1 = query(1,n,-(*it).F+1,last,1);
if(y1 * num2 > y2 * num){
y2 = y1;
num2 = num;
}
last = -(*it).F;
num *= (*it).S;
it++;
p++;
}
if(num <= 1e9){
ll y1 = query(1,n,1,last,1);
if(y1 * num2 > y2 * num){
y2 = y1;
num2 = num;
}
}
ll ans = (((product * inv(num2)) % INF) * y2) % INF;
return ans;
}
int init(int N, int X[], int Y[]) {
n = N;
f(i,0,N){
y[i] = Y[i];
x[i] = X[i];
}
build(1,N,1);
build2(1,N,1);
ll pos = N - 1;
while(pos >= 0){
if(x[pos] > 1){
ar.insert(ii(-pos,x[pos]));
}
pos--;
}
return solve();
}
int updateX(int pos, int val){
if(ar.count(ii(-pos,x[pos]))){
ar.erase(ii(-pos,x[pos]));
}
x[pos] = val;
update2(1,n,pos+1,pos+1,1,val);
if(val != 1){
ar.insert(ii(-pos,x[pos]));
}
return solve();
}
int updateY(int pos, int val){
y[pos] = val;
update(1,n,pos+1,pos+1,1,val);
return solve();
}
/*
3
2 1 3
3 4 1
1
2 1 2
*/
Compilation message
horses.cpp: In function 'int solve()':
horses.cpp:170:11: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
170 | while(num <= 1e9 && p != ar.size()){
| ^~~
horses.cpp:170:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::set<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
170 | while(num <= 1e9 && p != ar.size()){
| ~~^~~~~~~~~~~~
horses.cpp:181:8: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
181 | if(num <= 1e9){
| ^~~
horses.cpp:189:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
189 | return ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
308 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
420 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
448 KB |
Output is correct |
27 |
Correct |
5 ms |
332 KB |
Output is correct |
28 |
Correct |
3 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
891 ms |
60672 KB |
Output is correct |
2 |
Correct |
527 ms |
73396 KB |
Output is correct |
3 |
Correct |
533 ms |
64540 KB |
Output is correct |
4 |
Correct |
679 ms |
68420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
304 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
3 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
440 KB |
Output is correct |
27 |
Correct |
5 ms |
424 KB |
Output is correct |
28 |
Correct |
3 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
5 ms |
332 KB |
Output is correct |
33 |
Correct |
67 ms |
32564 KB |
Output is correct |
34 |
Correct |
64 ms |
32648 KB |
Output is correct |
35 |
Correct |
249 ms |
70720 KB |
Output is correct |
36 |
Correct |
249 ms |
70828 KB |
Output is correct |
37 |
Correct |
148 ms |
30896 KB |
Output is correct |
38 |
Correct |
144 ms |
47484 KB |
Output is correct |
39 |
Correct |
52 ms |
30532 KB |
Output is correct |
40 |
Correct |
233 ms |
65844 KB |
Output is correct |
41 |
Correct |
87 ms |
30528 KB |
Output is correct |
42 |
Correct |
108 ms |
30652 KB |
Output is correct |
43 |
Correct |
213 ms |
66084 KB |
Output is correct |
44 |
Correct |
224 ms |
66172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
5 ms |
332 KB |
Output is correct |
28 |
Correct |
3 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
440 KB |
Output is correct |
31 |
Correct |
4 ms |
332 KB |
Output is correct |
32 |
Correct |
5 ms |
332 KB |
Output is correct |
33 |
Correct |
917 ms |
64556 KB |
Output is correct |
34 |
Correct |
518 ms |
73356 KB |
Output is correct |
35 |
Correct |
548 ms |
64592 KB |
Output is correct |
36 |
Correct |
728 ms |
68628 KB |
Output is correct |
37 |
Correct |
65 ms |
32564 KB |
Output is correct |
38 |
Correct |
61 ms |
32584 KB |
Output is correct |
39 |
Correct |
312 ms |
70720 KB |
Output is correct |
40 |
Correct |
287 ms |
70724 KB |
Output is correct |
41 |
Correct |
145 ms |
30728 KB |
Output is correct |
42 |
Correct |
155 ms |
47448 KB |
Output is correct |
43 |
Correct |
52 ms |
30540 KB |
Output is correct |
44 |
Correct |
237 ms |
65680 KB |
Output is correct |
45 |
Correct |
87 ms |
30548 KB |
Output is correct |
46 |
Correct |
108 ms |
30636 KB |
Output is correct |
47 |
Correct |
256 ms |
66224 KB |
Output is correct |
48 |
Correct |
251 ms |
66160 KB |
Output is correct |
49 |
Correct |
262 ms |
35976 KB |
Output is correct |
50 |
Correct |
230 ms |
35976 KB |
Output is correct |
51 |
Correct |
519 ms |
72604 KB |
Output is correct |
52 |
Correct |
401 ms |
72132 KB |
Output is correct |
53 |
Correct |
961 ms |
34228 KB |
Output is correct |
54 |
Correct |
441 ms |
52084 KB |
Output is correct |
55 |
Correct |
212 ms |
31552 KB |
Output is correct |
56 |
Correct |
424 ms |
67524 KB |
Output is correct |
57 |
Correct |
568 ms |
32324 KB |
Output is correct |
58 |
Correct |
786 ms |
32716 KB |
Output is correct |
59 |
Correct |
249 ms |
66116 KB |
Output is correct |