Submission #730119

# Submission time Handle Problem Language Result Execution time Memory
730119 2023-04-25T09:47:11 Z sentheta Horses (IOI15_horses) C++17
17 / 100
543 ms 44136 KB
#include "horses.h"
// author : sentheta aka vanwij
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<random>
#include<chrono>
#include<cmath>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;

#define Int long long
#define V vector
#define pii pair<int,int>
#define ff first
#define ss second

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))

#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define dbg(x) if(1) cout << "?" << #x << " : " << (x) << endl << flush;

const Int MOD = 1e9+7;
const int N = 5e5+5;

int n;
int *x, *y;

#define mid (tl+tr)/2
#define lc (v+1)
#define rc (v+2*(mid-tl+1))
struct Maxsegtree{
	int mx[2*N];
	void upd(int i,int val,int v=0,int tl=0,int tr=n-1){
		if(tl==tr){
			mx[v] = val; return;
		}
		if(i<=mid) upd(i,val, lc,tl,mid);
		else upd(i,val, rc,mid+1,tr);
		mx[v] = max(mx[lc], mx[rc]);
	}
	int qry(int l,int r,int v=0,int tl=0,int tr=n-1){
		if(r<tl || tr<l) return 0;
		if(l<=tl && tr<=r) return mx[v];
		return max(qry(l,r, lc,tl,mid), qry(l,r, rc,mid+1,tr));
	}
} maxtree;
struct Mulsegtree{
	Int prod[2*N];
	void upd(int i,Int val,int v=0,int tl=0,int tr=n-1){
		if(tl==tr){
			prod[v] = val; return;
		}
		if(i<=mid) upd(i,val, lc,tl,mid);
		else upd(i,val, rc,mid+1,tr);
		prod[v] = prod[lc] * prod[rc] % MOD;
	}
	Int qry(int l,int r,int v=0,int tl=0,int tr=n-1){
		if(r<tl || tr<l) return 1;
		if(l<=tl && tr<=r) return prod[v];
		return qry(l,r, lc,tl,mid) * qry(l,r, rc,mid+1,tr) % MOD;
	}
} multree;
#undef mid

set<int> sx;

int solve(){
	if(sx.empty()){
		return (int)maxtree.qry(0,n-1);
	}

	int r = n-1;
	Int ratio = 1, ans = 0, ansmod = 0;
	for(auto it=sx.end(); it!=sx.begin(); ){
		it = prev(it);
		int l = *it;

		Int mxy = maxtree.qry(l,r);
		// dbg(mxy);
		if(mxy > (Int)ans*ratio){
			ans = mxy;
			ansmod = multree.qry(0,l) *1LL *mxy%MOD;
		}

		ratio *= x[l];
		if(ratio > MOD) break;
		r = l-1;
	}

	return (int)ansmod;
}

int init(int _n,int _x[], int _y[]){
	n = _n; x = _x; y = _y;

	rep(i,0,n){
		maxtree.upd(i,y[i]);

		multree.upd(i,x[i]);
		if(x[i]!=1) sx.insert(i);
	}

	// dbg(n);
	return solve();
}

int updateX(int i,int val){
	// assert(0);

	if(x[i]!=1) sx.erase(i);
	x[i] = val;
	multree.upd(i,x[i]);
	if(x[i]!=1) sx.insert(i);

	// dbg(n);
	return solve();
}

int updateY(int i,int val){
	// assert(0);

	y[i] = val;
	maxtree.upd(i,y[i]);

	// dbg(n);
	return solve();
}
# 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 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 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 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 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 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 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 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 0 ms 212 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 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 1 ms 212 KB Output is correct
23 Correct 2 ms 324 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 Incorrect 3 ms 340 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 543 ms 44136 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 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 308 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 1 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 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 1 ms 212 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 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 288 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 328 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Incorrect 3 ms 328 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 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 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 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 312 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 0 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 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 0 ms 212 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 1 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 1 ms 212 KB Output is correct
23 Correct 2 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 Incorrect 2 ms 340 KB Output isn't correct
28 Halted 0 ms 0 KB -