# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
746134 |
2023-05-21T13:25:26 Z |
Boomyday |
Horses (IOI15_horses) |
C++17 |
|
336 ms |
57212 KB |
//
// Created by adavy on 2/11/2023.
//
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!
using ii = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vii = vector<ii>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;
// pairs
#define mp make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define len(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
#include <stdio.h>
#include <assert.h>
struct Modular {
int value;
static const int MOD_value = MOD;
Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}
Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}
friend Modular mexp(Modular a, long long e) {
Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
return res;
}
friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }
Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
friend Modular operator+(Modular a, Modular const b) { return a += b; }
friend Modular operator-(Modular a, Modular const b) { return a -= b; }
friend Modular operator-(Modular const a) { return 0 - a; }
friend Modular operator*(Modular a, Modular const b) { return a *= b; }
friend Modular operator/(Modular a, Modular const b) { return a /= b; }
friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};
vl X, Y;
ll sz;
vl seg;
set<int> brks;
Modular totalX = 1;
void update(int i, ll x){
i += sz;
seg[i] = x;
i >>= 1;
//cout << i << endl;
while (i > 0){
seg[i] = max(seg[2*i], seg[2*i+1]);
i >>= 1;
}
}
ll query(int l, int r){
l += sz; r += sz;
ll ans = 0;
while(l<=r){
if (l&1) ans = max(ans, seg[l++]);
if (!(r&1)) ans = max(ans, seg[r--]);
l>>=1;
r>>=1;
}
return ans;
}
ll solve(){
//cout << totalX << endl;
ll neg_amount = 1;
ll pos_amount = 1;
ll best = 0;
auto ptr = brks.end();
ptr--; ptr--;
int dist = 0;
//cout << *ptr << endl;
while(ptr != brks.begin() && neg_amount*X[*ptr] <= 1e9+3){
neg_amount *= X[*ptr];
ptr--; dist++;
}
//cout << dist << endl;
//cout << *ptr << " " << *next(ptr)-1 << endl;
//cout << sz << " "<< query(0, 4) << endl;
best = max(best, pos_amount*query(*ptr, *next(ptr)-1));
//cout << best << endl;
F0R(_, dist){
ptr++;
pos_amount*= X[*ptr];
best = max(best, pos_amount*query(*ptr, *next(ptr)-1));
}
//cout << best%MOD << endl;
//cout << totalX << endl;
//cout << neg_amount << " "<< pos_amount << endl;
return (totalX*best/neg_amount).value;
}
int init(int N, int Xi[], int Yi[]) {
sz = 1<<(ll)(log2(N)+1);
seg.rsz(2*sz);
fill(all(seg),0);
/*
ll myHorses = 1;
ll bestScr = 0;*/
brks.insert(N);
brks.insert(0);
X = vl(Xi, Xi+N);
Y = vl(Yi, Yi+N);
F0R(i, N){
totalX *= X[i];
update(i, Y[i]);
if (X[i] > 1) brks.insert(i);
}
/*
F0R(i, N){
myHorses *= X[i];
bestScr = max(bestScr, myHorses*Y[i]);
}*/
return solve();
}
int updateX(int pos, int val) {
totalX /= X[pos];
if (pos==0){
X[pos] = val;
totalX *= X[pos];
return solve();
}
if (val==1){
if (X[pos]!=1) brks.erase(pos);
X[pos] = val;
}
else {
brks.insert(pos);
X[pos] = val;
}
totalX *= X[pos];
return solve();
}
int updateY(int pos, int val) {
Y[pos] = val;
update(pos, Y[pos]);
return solve();
}
/*
int main(){
int n; cin >> n;
int x[n], y[n];
F0R(i, n) cin >> x[i];
F0R(i, n) cin >> y[i];
cout << init(n, x, y) << endl;
//cout << updateX(2, 5) << endl;
//cout << updateY(2, 2) << endl;
}
*/
Compilation message
horses.cpp: In constructor 'Modular::Modular(long long int)':
horses.cpp:71:42: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
71 | Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
| ~~^~~~~
horses.cpp: In member function 'Modular& Modular::operator*=(const Modular&)':
horses.cpp:76:79: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
76 | Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void update(int, ll)':
horses.cpp:103:7: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
103 | i += sz;
| ~~^~~~~
horses.cpp: In function 'll query(int, int)':
horses.cpp:114:7: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
114 | l += sz; r += sz;
| ~~^~~~~
horses.cpp:114:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
114 | l += sz; r += sz;
| ~~^~~~~
horses.cpp: In function 'll solve()':
horses.cpp:137:44: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
137 | while(ptr != brks.begin() && neg_amount*X[*ptr] <= 1e9+3){
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:188:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
188 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:196:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
196 | return solve();
| ~~~~~^~
horses.cpp:209:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
209 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:216:17: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
216 | return solve();
| ~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
240 ms |
44748 KB |
Output is correct |
2 |
Correct |
295 ms |
44716 KB |
Output is correct |
3 |
Correct |
271 ms |
44748 KB |
Output is correct |
4 |
Correct |
336 ms |
44616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 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 |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
312 KB |
Output is correct |
28 |
Correct |
1 ms |
312 KB |
Output is correct |
29 |
Correct |
1 ms |
308 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
312 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
57 ms |
24380 KB |
Output is correct |
34 |
Correct |
57 ms |
24376 KB |
Output is correct |
35 |
Correct |
194 ms |
54592 KB |
Output is correct |
36 |
Correct |
192 ms |
54564 KB |
Output is correct |
37 |
Correct |
55 ms |
22476 KB |
Output is correct |
38 |
Correct |
109 ms |
35388 KB |
Output is correct |
39 |
Correct |
47 ms |
22332 KB |
Output is correct |
40 |
Correct |
182 ms |
49740 KB |
Output is correct |
41 |
Correct |
50 ms |
22384 KB |
Output is correct |
42 |
Correct |
49 ms |
22396 KB |
Output is correct |
43 |
Correct |
176 ms |
50096 KB |
Output is correct |
44 |
Correct |
179 ms |
50000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
308 KB |
Output is correct |
32 |
Correct |
2 ms |
312 KB |
Output is correct |
33 |
Correct |
234 ms |
48568 KB |
Output is correct |
34 |
Correct |
305 ms |
57212 KB |
Output is correct |
35 |
Correct |
268 ms |
48468 KB |
Output is correct |
36 |
Correct |
336 ms |
52456 KB |
Output is correct |
37 |
Correct |
56 ms |
24368 KB |
Output is correct |
38 |
Correct |
55 ms |
24324 KB |
Output is correct |
39 |
Correct |
217 ms |
54612 KB |
Output is correct |
40 |
Correct |
228 ms |
54528 KB |
Output is correct |
41 |
Correct |
57 ms |
22544 KB |
Output is correct |
42 |
Correct |
115 ms |
35268 KB |
Output is correct |
43 |
Correct |
46 ms |
22220 KB |
Output is correct |
44 |
Correct |
196 ms |
49756 KB |
Output is correct |
45 |
Correct |
48 ms |
22288 KB |
Output is correct |
46 |
Correct |
51 ms |
22388 KB |
Output is correct |
47 |
Correct |
183 ms |
50092 KB |
Output is correct |
48 |
Correct |
181 ms |
50012 KB |
Output is correct |
49 |
Correct |
116 ms |
27472 KB |
Output is correct |
50 |
Correct |
108 ms |
27300 KB |
Output is correct |
51 |
Correct |
253 ms |
56484 KB |
Output is correct |
52 |
Correct |
239 ms |
56164 KB |
Output is correct |
53 |
Correct |
159 ms |
25620 KB |
Output is correct |
54 |
Correct |
178 ms |
39244 KB |
Output is correct |
55 |
Correct |
117 ms |
23332 KB |
Output is correct |
56 |
Correct |
238 ms |
51516 KB |
Output is correct |
57 |
Correct |
107 ms |
23940 KB |
Output is correct |
58 |
Correct |
134 ms |
24524 KB |
Output is correct |
59 |
Correct |
176 ms |
50112 KB |
Output is correct |