답안 #730125

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730125 2023-04-25T10:02:33 Z sentheta 말 (IOI15_horses) C++17
100 / 100
749 ms 52936 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;
	Int ans = 0, ansmod = 0;
	for(auto it=prev(sx.end()); ; it--){
		int l = *it;

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

		if(1.*x[l]*(double)ans > MOD) break;
		ans *= x[l];
		// ratio *= x[l];
		// if(ratio > MOD) break;
		r = l-1;
		if(it==sx.begin()) break;
	}

	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);
	}
	sx.insert(0);

	// 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);
	sx.insert(0);

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

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

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

	// dbg(n);
	return solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 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 1 ms 212 KB Output is correct
9 Correct 0 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 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 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 1 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 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 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 2 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 320 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 324 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 554 ms 40416 KB Output is correct
2 Correct 441 ms 40344 KB Output is correct
3 Correct 418 ms 40304 KB Output is correct
4 Correct 431 ms 40408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 1 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 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 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 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 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 Correct 3 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 2 ms 340 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 157 ms 20188 KB Output is correct
34 Correct 154 ms 20108 KB Output is correct
35 Correct 305 ms 50388 KB Output is correct
36 Correct 288 ms 50360 KB Output is correct
37 Correct 173 ms 18260 KB Output is correct
38 Correct 210 ms 31052 KB Output is correct
39 Correct 145 ms 18024 KB Output is correct
40 Correct 274 ms 45376 KB Output is correct
41 Correct 156 ms 18140 KB Output is correct
42 Correct 187 ms 18052 KB Output is correct
43 Correct 260 ms 45788 KB Output is correct
44 Correct 278 ms 45876 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 212 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 1 ms 212 KB Output is correct
13 Correct 1 ms 288 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 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 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 3 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 2 ms 320 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 532 ms 44212 KB Output is correct
34 Correct 436 ms 52936 KB Output is correct
35 Correct 414 ms 44168 KB Output is correct
36 Correct 445 ms 48000 KB Output is correct
37 Correct 163 ms 20044 KB Output is correct
38 Correct 146 ms 20036 KB Output is correct
39 Correct 278 ms 50288 KB Output is correct
40 Correct 287 ms 50356 KB Output is correct
41 Correct 169 ms 18280 KB Output is correct
42 Correct 220 ms 30952 KB Output is correct
43 Correct 147 ms 18000 KB Output is correct
44 Correct 269 ms 45460 KB Output is correct
45 Correct 164 ms 18112 KB Output is correct
46 Correct 165 ms 18104 KB Output is correct
47 Correct 259 ms 45796 KB Output is correct
48 Correct 264 ms 45748 KB Output is correct
49 Correct 244 ms 23112 KB Output is correct
50 Correct 218 ms 23076 KB Output is correct
51 Correct 436 ms 52228 KB Output is correct
52 Correct 333 ms 51784 KB Output is correct
53 Correct 749 ms 21408 KB Output is correct
54 Correct 385 ms 34936 KB Output is correct
55 Correct 269 ms 19028 KB Output is correct
56 Correct 403 ms 47240 KB Output is correct
57 Correct 405 ms 19712 KB Output is correct
58 Correct 563 ms 20172 KB Output is correct
59 Correct 301 ms 45812 KB Output is correct