Submission #795308

# Submission time Handle Problem Language Result Execution time Memory
795308 2023-07-27T08:16:49 Z Cauchico Horses (IOI15_horses) C++17
0 / 100
1500 ms 66752 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
set<pair<int,int>> s;
vector<ll> x,y,tx,ty;
int MOD = 1e9 + 7;

void Xupdate(int v, int tl, int tr, ll pos, ll val) {
	if (tl > pos or tr < pos) return;
	if (tl == tr) tx[v] = val;
	else {
		int tm = (tr+tl)/2;
		Xupdate(2*v,tl,tm,pos,val);
		Xupdate(2*v+1,tm+1,tr,pos,val);
		tx[v] = (tx[2*v]*tx[2*v+1])%MOD;
	}
}
void Yupdate(int v, int tl, int tr, ll pos, ll val) {
	if (tl > pos or tr < pos) return;
	if (tl == tr) ty[v] = val;
	else {
		int tm = (tr+tl)/2;
		Yupdate(2*v,tl,tm,pos,val);
		Yupdate(2*v+1,tm+1,tr,pos,val);
		ty[v] = max(ty[2*v],ty[2*v+1]);
	}
}
ll Xquery(int v, int tl, int tr, ll l, ll r) {
	if (tl > r or tr < l) return 0;
	else if (tl >= l and tr >= r) return tx[v];
	else {
		int tm = (tr+tl)/2;
		return (Xquery(2*v,tl,tm,l,r)*Xquery(2*v,tm+1,tr,l,r))%MOD;
	}
}
ll Yquery(int v, int tl, int tr, ll l, ll r) {
	if (tl > r or tr < l) return 0;
	else if (tl >= l and tr >= r) return ty[v];
	else {
		int tm = (tr+tl)/2;
		return max(Yquery(2*v,tl,tm,l,r), Yquery(2*v,tm+1,tr,l,r));
	}
}

int update() {
	auto can = s.end();
	for (int i=0;i<=32 and can != s.begin();i++) can--;
	ll ans = can->second, mxy=y[ans];
	ll px = 1;
	can++;
	while (can != s.end()) {
		int i = can->first;
		auto nxt = can; nxt++;
		int nx;
		if (nxt == s.end()) {
			nx = n-1;
		} else {
			nx = nxt->first-1;
		}
		ll xi = x[i], yi = Yquery(1,0,n-1,i,nx); 
		if (mxy < px*yi) {
			ans = i; px = 1; mxy = yi;
		} else {
			px *= xi;
		}
	}
	return (int) (mxy*Xquery(1,0,n-1,0,ans))%MOD;
}



int init(int N, int X[], int Y[]) {
	//return 42; 
	n = N; x.resize(n); y.resize(n);
	tx.resize(4*n); ty.resize(4*n);
	for (int i=0;i<n;i++) {
		x[i] = X[i]; y[i] = Y[i];
		s.insert({x[i]>1,i});
		Xupdate(1,0,n-1,i,x[i]);
		Yupdate(1,0,n-1,i,y[i]);
	}
	return update();
}

int updateX(int pos, int val) {	
	//return 43;
	s.erase({x[pos]>1,pos});
	s.insert({val>1,pos});
	x[pos] = val;
	Xupdate(1,0,n-1,pos,val);
	return update();
	
}

int updateY(int pos, int val) {
	//return 44;
	y[pos] = val;
	Yupdate(1,0,n-1,pos,val);
	return update();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1570 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1555 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1571 ms 66752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1577 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1570 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -