답안 #758419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758419 2023-06-14T15:21:18 Z joelgun14 말 (IOI15_horses) C++17
100 / 100
645 ms 57428 KB
#include "horses.h"
#include <bits/stdc++.h>
#define ll long long
#define lll __int128_t
using namespace std;
const int lim = 1 << 19;
int mod = 1e9 + 7;
struct max_segment_tree {
	int a[2 * lim];
	max_segment_tree() {
		memset(a, 0, sizeof(a));
	}
	void update(int idx, int val) {
		idx += lim;
		a[idx] = val;
		while(idx) {
			idx >>= 1;
			a[idx] = max(a[2 * idx], a[2 * idx + 1]);
		}
	}
	int query(int nd, int cl, int cr, int l, int r) {
		if(cl >= l && cr <= r) 
			return a[nd];
		else if(cl > r || cr < l)
			return 0;
		else {
			int mid = (cl + cr) / 2;
			return max(query(2 * nd, cl, mid, l, r), query(2 * nd + 1, mid + 1, cr, l, r));
		}
	}
};
struct mul_segment_tree {
	int a[2 * lim];
	mul_segment_tree() {
		fill(a, a + 2 * lim, 1);
	}
	void update(int idx, int val) {
		idx += lim;
		a[idx] = val;
		while(idx) {
			idx >>= 1;
			a[idx] = (1ll * a[2 * idx] * a[2 * idx + 1]) % mod;
		}
	}
	int query(int nd, int cl, int cr, int l, int r) {
		if(cl >= l && cr <= r) {
			return a[nd];
		}
		else if(cl > r || cr < l)
			return 1;
		else {
			int mid = (cl + cr) / 2;
			return (1ll * query(2 * nd, cl, mid, l, r) * query(2 * nd + 1, mid + 1, cr, l, r)) % mod;
		}
	}
};
max_segment_tree mxx, mxy;
mul_segment_tree valx;
set<int> nz;
vector<int> x, y;
int n;
int recalc() {
	vector<int> v;
	if(nz.empty()) {
		return mxy.query(1, 0, lim - 1, 0, n - 1);
	}
	auto it = --nz.end();
	ll prmul = 1;
	while(true) {
		v.push_back(*it);
		prmul *= x[v.back()];
		if(prmul >= 1e9)
			break;
		if(it == nz.begin())
			break;
		--it;
	}
	// jadi sekarang isinya v itu indices tp inverted
	reverse(v.begin(), v.end());
	prmul = 1;
	lll res = mxy.query(1, 0, lim - 1, 0, n - 1);
	for(int i = 0; i < v.size(); ++i) {
		prmul = (1ll * prmul * x[v[i]]);
		//cout << i << " " << prmul << " " << mxy.query(1, 0, lim - 1, v[i], (i == v.size() - 1 ? n - 1 : v[i + 1] - 1)) << endl;
		// nanti di sini kita "upgrade" ke next nya
		res = max(res, (lll)prmul * mxy.query(1, 0, lim - 1, v[i], (i == v.size() - 1 ? n - 1 : v[i + 1] - 1)));
	}
	res %= mod;
	return (valx.query(1, 0, lim - 1, 0, v.front() - 1) * res) % mod;
}
int init(int N, int X[], int Y[]) {
	x.resize(N), y.resize(N);
	n = N;
	for(int i = 0; i < N; ++i) {
		mxx.update(i, X[i]), mxy.update(i, Y[i]);
		valx.update(i, X[i]);
		x[i] = X[i];
		y[i] = Y[i];
		if(X[i] != 1)
			nz.insert(i);
	}
	// simpan index yg bukan 1
	// nanti di iterate dr belakang isinya
	// simpan iterator current last element?
	// pakai lower_bound aja, terus dikurangin terus iteratornya
	// maximum per operasi update cmn log (karena sekali panggil lower_bound, sisanya -- O(1))
	return recalc();
}
int updateX(int pos, int val) {	
	// nanti re calculate ulang nilainya :))
	// cmn count lastzero sampe nilai nya > int_mx aja :D
	x[pos] = val;
	int tmp = mxx.query(1, 0, lim - 1, pos, pos);
	if(tmp != 1)
		nz.erase(nz.lower_bound(pos));
	mxx.update(pos, val);
	valx.update(pos, val);
	if(val != 1)
		nz.insert(pos);
	return recalc();
}

int updateY(int pos, int val) {
	y[pos] = val;
	mxy.update(pos, val);
	return recalc();
}

Compilation message

horses.cpp: In member function 'void mul_segment_tree::update(int, int)':
horses.cpp:42:49: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   42 |    a[idx] = (1ll * a[2 * idx] * a[2 * idx + 1]) % mod;
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In member function 'int mul_segment_tree::query(int, int, int, int, int)':
horses.cpp:53:87: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   53 |    return (1ll * query(2 * nd, cl, mid, l, r) * query(2 * nd + 1, mid + 1, cr, l, r)) % mod;
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int recalc()':
horses.cpp:72:6: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   72 |   if(prmul >= 1e9)
      |      ^~~~~
horses.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |  for(int i = 0; i < v.size(); ++i) {
      |                 ~~^~~~~~~~~~
horses.cpp:86:65: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |   res = max(res, (lll)prmul * mxy.query(1, 0, lim - 1, v[i], (i == v.size() - 1 ? n - 1 : v[i + 1] - 1)));
      |                                                               ~~^~~~~~~~~~~~~~~
horses.cpp:89:61: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
   89 |  return (valx.query(1, 0, lim - 1, 0, v.front() - 1) * res) % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12500 KB Output is correct
2 Correct 6 ms 12500 KB Output is correct
3 Correct 5 ms 12500 KB Output is correct
4 Correct 6 ms 12500 KB Output is correct
5 Correct 6 ms 12500 KB Output is correct
6 Correct 7 ms 12500 KB Output is correct
7 Correct 6 ms 12500 KB Output is correct
8 Correct 7 ms 12500 KB Output is correct
9 Correct 6 ms 12500 KB Output is correct
10 Correct 6 ms 12500 KB Output is correct
11 Correct 6 ms 12504 KB Output is correct
12 Correct 5 ms 12500 KB Output is correct
13 Correct 6 ms 12500 KB Output is correct
14 Correct 6 ms 12500 KB Output is correct
15 Correct 6 ms 12500 KB Output is correct
16 Correct 6 ms 12500 KB Output is correct
17 Correct 6 ms 12500 KB Output is correct
18 Correct 6 ms 12500 KB Output is correct
19 Correct 6 ms 12500 KB Output is correct
20 Correct 6 ms 12500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12500 KB Output is correct
2 Correct 7 ms 12500 KB Output is correct
3 Correct 6 ms 12560 KB Output is correct
4 Correct 6 ms 12500 KB Output is correct
5 Correct 7 ms 12544 KB Output is correct
6 Correct 6 ms 12500 KB Output is correct
7 Correct 7 ms 12500 KB Output is correct
8 Correct 6 ms 12500 KB Output is correct
9 Correct 7 ms 12500 KB Output is correct
10 Correct 6 ms 12500 KB Output is correct
11 Correct 6 ms 12500 KB Output is correct
12 Correct 8 ms 12500 KB Output is correct
13 Correct 8 ms 12500 KB Output is correct
14 Correct 6 ms 12500 KB Output is correct
15 Correct 6 ms 12500 KB Output is correct
16 Correct 6 ms 12500 KB Output is correct
17 Correct 6 ms 12500 KB Output is correct
18 Correct 6 ms 12612 KB Output is correct
19 Correct 7 ms 12500 KB Output is correct
20 Correct 6 ms 12564 KB Output is correct
21 Correct 7 ms 12500 KB Output is correct
22 Correct 6 ms 12500 KB Output is correct
23 Correct 7 ms 12628 KB Output is correct
24 Correct 7 ms 12628 KB Output is correct
25 Correct 9 ms 12628 KB Output is correct
26 Correct 9 ms 12704 KB Output is correct
27 Correct 10 ms 12620 KB Output is correct
28 Correct 8 ms 12672 KB Output is correct
29 Correct 8 ms 12628 KB Output is correct
30 Correct 7 ms 12628 KB Output is correct
31 Correct 10 ms 12628 KB Output is correct
32 Correct 10 ms 12628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 639 ms 44880 KB Output is correct
2 Correct 445 ms 44900 KB Output is correct
3 Correct 437 ms 44880 KB Output is correct
4 Correct 563 ms 44968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12628 KB Output is correct
2 Correct 6 ms 12600 KB Output is correct
3 Correct 6 ms 12500 KB Output is correct
4 Correct 6 ms 12500 KB Output is correct
5 Correct 6 ms 12492 KB Output is correct
6 Correct 6 ms 12500 KB Output is correct
7 Correct 7 ms 12520 KB Output is correct
8 Correct 6 ms 12500 KB Output is correct
9 Correct 6 ms 12500 KB Output is correct
10 Correct 6 ms 12500 KB Output is correct
11 Correct 6 ms 12596 KB Output is correct
12 Correct 6 ms 12500 KB Output is correct
13 Correct 6 ms 12500 KB Output is correct
14 Correct 5 ms 12500 KB Output is correct
15 Correct 7 ms 12496 KB Output is correct
16 Correct 5 ms 12500 KB Output is correct
17 Correct 6 ms 12500 KB Output is correct
18 Correct 6 ms 12500 KB Output is correct
19 Correct 8 ms 12628 KB Output is correct
20 Correct 5 ms 12500 KB Output is correct
21 Correct 6 ms 12500 KB Output is correct
22 Correct 6 ms 12500 KB Output is correct
23 Correct 7 ms 12612 KB Output is correct
24 Correct 9 ms 12620 KB Output is correct
25 Correct 8 ms 12624 KB Output is correct
26 Correct 9 ms 12648 KB Output is correct
27 Correct 11 ms 12660 KB Output is correct
28 Correct 9 ms 12620 KB Output is correct
29 Correct 8 ms 12628 KB Output is correct
30 Correct 8 ms 12628 KB Output is correct
31 Correct 10 ms 12628 KB Output is correct
32 Correct 11 ms 12628 KB Output is correct
33 Correct 152 ms 24524 KB Output is correct
34 Correct 145 ms 24488 KB Output is correct
35 Correct 292 ms 54928 KB Output is correct
36 Correct 281 ms 54824 KB Output is correct
37 Correct 173 ms 22668 KB Output is correct
38 Correct 205 ms 35452 KB Output is correct
39 Correct 145 ms 22496 KB Output is correct
40 Correct 274 ms 49868 KB Output is correct
41 Correct 149 ms 22516 KB Output is correct
42 Correct 164 ms 22608 KB Output is correct
43 Correct 262 ms 50240 KB Output is correct
44 Correct 248 ms 50252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12500 KB Output is correct
2 Correct 5 ms 12500 KB Output is correct
3 Correct 5 ms 12500 KB Output is correct
4 Correct 6 ms 12500 KB Output is correct
5 Correct 6 ms 12540 KB Output is correct
6 Correct 6 ms 12500 KB Output is correct
7 Correct 6 ms 12500 KB Output is correct
8 Correct 6 ms 12500 KB Output is correct
9 Correct 6 ms 12500 KB Output is correct
10 Correct 6 ms 12500 KB Output is correct
11 Correct 6 ms 12500 KB Output is correct
12 Correct 6 ms 12500 KB Output is correct
13 Correct 6 ms 12588 KB Output is correct
14 Correct 6 ms 12500 KB Output is correct
15 Correct 6 ms 12500 KB Output is correct
16 Correct 6 ms 12568 KB Output is correct
17 Correct 8 ms 12524 KB Output is correct
18 Correct 6 ms 12500 KB Output is correct
19 Correct 6 ms 12500 KB Output is correct
20 Correct 6 ms 12500 KB Output is correct
21 Correct 6 ms 12500 KB Output is correct
22 Correct 6 ms 12500 KB Output is correct
23 Correct 7 ms 12628 KB Output is correct
24 Correct 8 ms 12628 KB Output is correct
25 Correct 8 ms 12624 KB Output is correct
26 Correct 7 ms 12628 KB Output is correct
27 Correct 11 ms 12628 KB Output is correct
28 Correct 10 ms 12604 KB Output is correct
29 Correct 7 ms 12628 KB Output is correct
30 Correct 7 ms 12628 KB Output is correct
31 Correct 9 ms 12628 KB Output is correct
32 Correct 9 ms 12620 KB Output is correct
33 Correct 645 ms 48664 KB Output is correct
34 Correct 465 ms 57428 KB Output is correct
35 Correct 455 ms 48604 KB Output is correct
36 Correct 553 ms 52436 KB Output is correct
37 Correct 142 ms 24492 KB Output is correct
38 Correct 143 ms 24492 KB Output is correct
39 Correct 292 ms 54764 KB Output is correct
40 Correct 295 ms 54772 KB Output is correct
41 Correct 180 ms 22788 KB Output is correct
42 Correct 212 ms 35404 KB Output is correct
43 Correct 130 ms 22492 KB Output is correct
44 Correct 268 ms 49916 KB Output is correct
45 Correct 150 ms 22480 KB Output is correct
46 Correct 161 ms 22524 KB Output is correct
47 Correct 256 ms 50200 KB Output is correct
48 Correct 263 ms 50260 KB Output is correct
49 Correct 274 ms 27600 KB Output is correct
50 Correct 256 ms 27592 KB Output is correct
51 Correct 432 ms 56664 KB Output is correct
52 Correct 360 ms 56140 KB Output is correct
53 Correct 638 ms 25956 KB Output is correct
54 Correct 401 ms 39372 KB Output is correct
55 Correct 228 ms 23492 KB Output is correct
56 Correct 390 ms 51612 KB Output is correct
57 Correct 405 ms 24160 KB Output is correct
58 Correct 508 ms 24676 KB Output is correct
59 Correct 259 ms 50252 KB Output is correct