답안 #514861

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
514861 2022-01-18T16:21:42 Z thiago_bastos 말 (IOI15_horses) C++17
100 / 100
200 ms 50400 KB
#include "horses.h"
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>

const int mod = 1e9 + 7;

using value = std :: pair<double, int>;
using i64 = long long;

std :: vector<value> maxlg;
std :: vector<double> lg;
std :: vector<int> prod, X, Y;
int N;

value op(value a, double b, int c) {
	a.first += b;
	a.second = (i64)a.second * c % mod;
	return a;
}

void load(int lo, int hi, int no = 1) {
	if(lo == hi) {
		maxlg[no] = std :: make_pair(log(X[lo]) + log(Y[lo]), (i64)X[lo] * Y[lo] % mod);
		lg[no] = log(X[lo]);
		prod[no] = X[lo];
	} else {
		int mid = (lo + hi) / 2;
		load(lo, mid, 2 * no);
		load(mid + 1, hi, 2 * no + 1);
		lg[no] = lg[2 * no] + lg[2 * no + 1];
		maxlg[no] = std :: max(maxlg[2 * no], op(maxlg[2 * no + 1], lg[2 * no], prod[2 * no]));
		prod[no] = (i64)prod[2 * no] * prod[2 * no + 1] % mod;
	}
}

void upd(int k, int x, int y, int lo, int hi, int no = 1) {
	if(lo == hi) {
		X[lo] = x, Y[lo] = y;
		maxlg[no] = std :: make_pair(log(X[lo]) + log(Y[lo]), (i64)X[lo] * Y[lo] % mod);
		lg[no] = log(X[lo]);
		prod[no] = X[lo];	
	} else {
		int mid = (lo + hi) / 2;
		if(k <= mid) upd(k, x, y, lo, mid, 2 * no);
		else upd(k, x, y, mid + 1, hi, 2 * no + 1);
		lg[no] = lg[2 * no] + lg[2 * no + 1];
		maxlg[no] = std :: max(maxlg[2 * no], op(maxlg[2 * no + 1], lg[2 * no], prod[2 * no]));
		prod[no] = (i64)prod[2 * no] * prod[2 * no + 1] % mod;		 
	}
}

int init(int N, int X[], int Y[]) {
	int lg = 31 - __builtin_clz(N);
	maxlg.resize(4 << lg);
	prod.resize(4 << lg);
	:: lg.resize(4 << lg);
	:: X.resize(N);
	:: Y.resize(N);
	:: N = N;
	for(int i = 0; i < N; ++i) :: X[i] = X[i], :: Y[i] = Y[i];
	load(0, N - 1);
	return maxlg[1].second;
}

int updateX(int pos, int val) {
	upd(pos, val, Y[pos], 0, N - 1);
	return maxlg[1].second;
}

int updateY(int pos, int val) {
	upd(pos, X[pos], val, 0, N - 1);
	return maxlg[1].second;
}

Compilation message

horses.cpp: In function 'value op(value, double, int)':
horses.cpp:19:31: warning: conversion from 'i64' {aka 'long long int'} to 'int' may change value [-Wconversion]
   19 |  a.second = (i64)a.second * c % mod;
      |             ~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void load(int, int, int)':
horses.cpp:34:51: warning: conversion from 'i64' {aka 'long long int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   34 |   prod[no] = (i64)prod[2 * no] * prod[2 * no + 1] % mod;
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void upd(int, int, int, int, int, int)':
horses.cpp:50:51: warning: conversion from 'i64' {aka 'long long int'} to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
   50 |   prod[no] = (i64)prod[2 * no] * prod[2 * no + 1] % mod;
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:54:30: warning: declaration of 'Y' shadows a global declaration [-Wshadow]
   54 | int init(int N, int X[], int Y[]) {
      |                          ~~~~^~~
horses.cpp:14:29: note: shadowed declaration is here
   14 | std :: vector<int> prod, X, Y;
      |                             ^
horses.cpp:54:21: warning: declaration of 'X' shadows a global declaration [-Wshadow]
   54 | int init(int N, int X[], int Y[]) {
      |                 ~~~~^~~
horses.cpp:14:26: note: shadowed declaration is here
   14 | std :: vector<int> prod, X, Y;
      |                          ^
horses.cpp:54:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   54 | int init(int N, int X[], int Y[]) {
      |          ~~~~^
horses.cpp:15:5: note: shadowed declaration is here
   15 | int N;
      |     ^
horses.cpp:55:6: warning: declaration of 'lg' shadows a global declaration [-Wshadow]
   55 |  int lg = 31 - __builtin_clz(N);
      |      ^~
horses.cpp:13:23: note: shadowed declaration is here
   13 | std :: vector<double> lg;
      |                       ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 280 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 276 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 260 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 280 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 284 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 284 KB Output is correct
2 Correct 0 ms 280 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 280 KB Output is correct
11 Correct 1 ms 280 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 284 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 356 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 272 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 416 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 276 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 41524 KB Output is correct
2 Correct 179 ms 50396 KB Output is correct
3 Correct 128 ms 41596 KB Output is correct
4 Correct 161 ms 45408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 276 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 260 KB Output is correct
8 Correct 0 ms 280 KB Output is correct
9 Correct 0 ms 276 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 276 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 288 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 292 KB Output is correct
32 Correct 1 ms 292 KB Output is correct
33 Correct 58 ms 40860 KB Output is correct
34 Correct 77 ms 40844 KB Output is correct
35 Correct 88 ms 47764 KB Output is correct
36 Correct 84 ms 47812 KB Output is correct
37 Correct 46 ms 39000 KB Output is correct
38 Correct 56 ms 39876 KB Output is correct
39 Correct 39 ms 38852 KB Output is correct
40 Correct 62 ms 42748 KB Output is correct
41 Correct 44 ms 38980 KB Output is correct
42 Correct 39 ms 39024 KB Output is correct
43 Correct 59 ms 43244 KB Output is correct
44 Correct 67 ms 43204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 276 KB Output is correct
3 Correct 1 ms 276 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 272 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 276 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 268 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 99 ms 41596 KB Output is correct
34 Correct 200 ms 50400 KB Output is correct
35 Correct 126 ms 41612 KB Output is correct
36 Correct 148 ms 45352 KB Output is correct
37 Correct 61 ms 40960 KB Output is correct
38 Correct 72 ms 40848 KB Output is correct
39 Correct 83 ms 47760 KB Output is correct
40 Correct 85 ms 47684 KB Output is correct
41 Correct 44 ms 38996 KB Output is correct
42 Correct 49 ms 39900 KB Output is correct
43 Correct 40 ms 38884 KB Output is correct
44 Correct 60 ms 42760 KB Output is correct
45 Correct 41 ms 38884 KB Output is correct
46 Correct 41 ms 38932 KB Output is correct
47 Correct 68 ms 43148 KB Output is correct
48 Correct 57 ms 43300 KB Output is correct
49 Correct 151 ms 42976 KB Output is correct
50 Correct 141 ms 42824 KB Output is correct
51 Correct 134 ms 49692 KB Output is correct
52 Correct 132 ms 49100 KB Output is correct
53 Correct 123 ms 41156 KB Output is correct
54 Correct 91 ms 41780 KB Output is correct
55 Correct 85 ms 39996 KB Output is correct
56 Correct 102 ms 44568 KB Output is correct
57 Correct 87 ms 40644 KB Output is correct
58 Correct 85 ms 41056 KB Output is correct
59 Correct 61 ms 43212 KB Output is correct