답안 #1018566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1018566 2024-07-10T06:55:53 Z AmirAli_H1 말 (IOI15_horses) C++17
100 / 100
1354 ms 50120 KB
// In the name of Allah

#include <bits/stdc++.h>
#include "horses.h"
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct node {
	ll mul, mx; int ind;
};

const int maxn = (1 << 19) + 4;
const int maxlg = 20;
const int mod = 1e9 + 7;

int n; pll A[maxn];
node t[2 * maxn], ca;

node f(node a, node b) {
	node res;
	res.mul = a.mul * b.mul % mod;
	res.mx = max(a.mx, b.mx);
	res.ind = max(a.ind, b.ind);
	return res;
}

void build(int v, int tl, int tr) {
	if (tr - tl == 1) {
		t[v].mul = A[tl].F; t[v].mx = A[tl].S;
		if (A[tl].F == 1) t[v].ind = -1;
		else t[v].ind = tl;
		return ;
	}
	int mid = (tl + tr) / 2;
	build(2 * v + 1, tl, mid); build(2 * v + 2, mid, tr);
	t[v] = f(t[2 * v + 1], t[2 * v + 2]);
}

void upd(int v, int tl, int tr, int i) {
	if (i >= tr || i < tl) return ;
	if (tr - tl == 1) {
		t[v].mul = A[tl].F; t[v].mx = A[tl].S;
		if (A[tl].F == 1) t[v].ind = -1;
		else t[v].ind = tl;
		return ;
	}
	int mid = (tl + tr) / 2;
	upd(2 * v + 1, tl, mid, i); upd(2 * v + 2, mid, tr, i);
	t[v] = f(t[2 * v + 1], t[2 * v + 2]);
}

node get_res(int v, int tl, int tr, int l, int r) {
	l = max(l, tl); r = min(r, tr);
	if (l >= tr || r <= tl) return ca;
	if (l == tl && r == tr) return t[v];
	int mid = (tl + tr) / 2;
	return f(get_res(2 * v + 1, tl, mid, l, r), get_res(2 * v + 2, mid, tr, l, r));
}

ll get_ans() {
	ll mx = 1; int j = n;
	while (j > 0) {
		node res = get_res(0, 0, n, 0, j);
		int k = res.ind;
		if (k == -1) {
			mx = max(mx, res.mx); j = 0;
		}
		else {
			res = get_res(0, 0, n, k, j);
			mx = max(mx, res.mx) * A[k].F; j = k;
			if (mx >= mod) break;
		}
	}
	return (mx % mod) * get_res(0, 0, n, 0, j).mul % mod;
}

int init(int N, int X[], int Y[]) {
	n = N;
	for (int i = 0; i < n; i++) A[i] = Mp(X[i], Y[i]);
	ca.mul = 1; ca.mx = 0; ca.ind = -1;
	build(0, 0, n);
	return get_ans();
}

int updateX(int i, int val) {
	A[i].F = val;
	upd(0, 0, n, i);
	return get_ans();
}

int updateY(int i, int val) {
	A[i].S = val;
	upd(0, 0, n, i);
	return get_ans();
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:100:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  100 |  return get_ans();
      |         ~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:106:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  106 |  return get_ans();
      |         ~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:112:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  112 |  return get_ans();
      |         ~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2496 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2512 KB Output is correct
24 Correct 1 ms 2508 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 1 ms 2536 KB Output is correct
27 Correct 7 ms 2576 KB Output is correct
28 Correct 3 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 5 ms 2396 KB Output is correct
32 Correct 6 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1075 ms 37760 KB Output is correct
2 Correct 156 ms 37712 KB Output is correct
3 Correct 257 ms 37712 KB Output is correct
4 Correct 136 ms 45392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2440 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2500 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 2 ms 2392 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 10 ms 2576 KB Output is correct
28 Correct 3 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 5 ms 2396 KB Output is correct
32 Correct 8 ms 2392 KB Output is correct
33 Correct 42 ms 40764 KB Output is correct
34 Correct 50 ms 40680 KB Output is correct
35 Correct 91 ms 47584 KB Output is correct
36 Correct 57 ms 47620 KB Output is correct
37 Correct 183 ms 38996 KB Output is correct
38 Correct 51 ms 39784 KB Output is correct
39 Correct 32 ms 38876 KB Output is correct
40 Correct 47 ms 42612 KB Output is correct
41 Correct 121 ms 38744 KB Output is correct
42 Correct 146 ms 38992 KB Output is correct
43 Correct 33 ms 43088 KB Output is correct
44 Correct 36 ms 43140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 3 ms 2396 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 7 ms 2396 KB Output is correct
28 Correct 2 ms 2576 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 1 ms 2508 KB Output is correct
31 Correct 4 ms 2576 KB Output is correct
32 Correct 6 ms 2392 KB Output is correct
33 Correct 1087 ms 41396 KB Output is correct
34 Correct 143 ms 50120 KB Output is correct
35 Correct 257 ms 41552 KB Output is correct
36 Correct 130 ms 45376 KB Output is correct
37 Correct 36 ms 40740 KB Output is correct
38 Correct 39 ms 40784 KB Output is correct
39 Correct 76 ms 47696 KB Output is correct
40 Correct 57 ms 47684 KB Output is correct
41 Correct 162 ms 38796 KB Output is correct
42 Correct 49 ms 39764 KB Output is correct
43 Correct 29 ms 38744 KB Output is correct
44 Correct 43 ms 42580 KB Output is correct
45 Correct 96 ms 38740 KB Output is correct
46 Correct 132 ms 38904 KB Output is correct
47 Correct 33 ms 43088 KB Output is correct
48 Correct 33 ms 43164 KB Output is correct
49 Correct 146 ms 42816 KB Output is correct
50 Correct 118 ms 42836 KB Output is correct
51 Correct 344 ms 49420 KB Output is correct
52 Correct 109 ms 48932 KB Output is correct
53 Correct 1354 ms 40976 KB Output is correct
54 Correct 289 ms 41680 KB Output is correct
55 Correct 152 ms 39756 KB Output is correct
56 Correct 138 ms 44464 KB Output is correct
57 Correct 760 ms 40532 KB Output is correct
58 Correct 1178 ms 40936 KB Output is correct
59 Correct 36 ms 43092 KB Output is correct