답안 #819975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
819975 2023-08-10T16:43:13 Z Kerim 말 (IOI15_horses) C++17
100 / 100
296 ms 101028 KB
#include "horses.h"
#include "bits/stdc++.h"
using namespace std;

const int MAXN = 5e5+5;
const int INF = 1e9+7;
int a[MAXN], b[MAXN], n;
long double pref[MAXN];

struct node{
	int mul;
	int ans;
	long double p;
	node(){
		mul = ans = 0;
		p = 0;
	}
	node(int _mul, int _ans){
		mul = _mul;
		ans = _ans;
	}
}s[MAXN<<2];

node merge(node x, node y){
	node z = node(0, 0);
	if (x.p < y.p)
		z.ans = y.ans, z.p = y.p;
	else
		z.ans = x.ans, z.p = x.p;
	z.mul = (x.mul * 1LL * y.mul) % INF;
	return z;
}

void build(int nd, int x, int y){
	if (x == y){
		s[nd].ans = x;
		s[nd].mul = a[x];
		s[nd].p = pref[x];
		return;
	}
	int mid = (x+y) >> 1;
	build(nd<<1, x, mid);
	build(nd<<1|1, mid+1, y);
	s[nd] = merge(s[nd<<1], s[nd<<1|1]);
}
long double lazy[MAXN<<2];
void shift(int nd){
	long double &ret = lazy[nd];
	lazy[nd<<1] += ret; s[nd<<1].p += ret;
	lazy[nd<<1|1] += ret; s[nd<<1|1].p += ret;
	ret = 0;
}
void inc(int l, int r, long double val, int nd, int x, int y){
	if (l > y or x > r)
		return;
	if (l <= x and y <= r){
		s[nd].p += val;
		lazy[nd] += val;
		return;
	}
	shift(nd);
	int mid = (x+y) >> 1;
	inc(l, r, val, nd<<1, x, mid);
	inc(l, r, val, nd<<1|1, mid+1, y);
	s[nd] = merge(s[nd<<1], s[nd<<1|1]);
}

void upd(int p, long double val, int nd, int x, int y){
	if (x == y){
		s[nd].mul = a[p];
		s[nd].p += val;
		return;
	}
	shift(nd);
	int mid = (x+y) >> 1;
	if (p <= mid)
		upd(p, val, nd<<1, x, mid);
	else	
		upd(p, val, nd<<1|1, mid+1, y);
	s[nd] = merge(s[nd<<1], s[nd<<1|1]);
}

int get(int l, int r, int nd, int x, int y){
	if (l > y or x > r)
		return 1;
	if (l <= x and y <= r)
		return s[nd].mul;
	int mid = (x+y) >> 1;
	return (get(l, r, nd<<1, x, mid) *1LL* get(l, r, nd<<1|1, mid+1, y)) % INF;
}

int ask(int pos){
	return (get(0, pos, 1, 0, n-1) *1LL* b[pos]) % INF;
}

int init(int N, int X[], int Y[]) {
	n = N;
	long double sum = 0;
	for (int i = 0; i < n; i++){
		a[i] = X[i], b[i] = Y[i];
		sum += log(a[i]);
		pref[i] = sum + log(b[i]);
	}
	build(1, 0, n-1);
	return ask(s[1].ans);
}

int updateX(int pos, int val) {	
	inc(pos, n-1, -log(a[pos]) + log(val), 1, 0, n-1);
	a[pos] = val;
	upd(pos, 0, 1, 0, n-1);
	return ask(s[1].ans);
}

int updateY(int pos, int val) {
	upd(pos, log(val) - log(b[pos]), 1, 0, n-1);
	b[pos] = val;
	return ask(s[1].ans);
}

Compilation message

horses.cpp: In function 'node merge(node, node)':
horses.cpp:30:32: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   30 |  z.mul = (x.mul * 1LL * y.mul) % INF;
      |          ~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get(int, int, int, int, int)':
horses.cpp:89:71: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   89 |  return (get(l, r, nd<<1, x, mid) *1LL* get(l, r, nd<<1|1, mid+1, y)) % INF;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int ask(int)':
horses.cpp:93:47: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   93 |  return (get(0, pos, 1, 0, n-1) *1LL* b[pos]) % INF;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 62904 KB Output is correct
2 Correct 26 ms 62836 KB Output is correct
3 Correct 26 ms 62952 KB Output is correct
4 Correct 26 ms 62860 KB Output is correct
5 Correct 26 ms 62884 KB Output is correct
6 Correct 26 ms 62896 KB Output is correct
7 Correct 26 ms 62948 KB Output is correct
8 Correct 28 ms 62896 KB Output is correct
9 Correct 29 ms 62864 KB Output is correct
10 Correct 27 ms 62932 KB Output is correct
11 Correct 26 ms 62844 KB Output is correct
12 Correct 28 ms 62864 KB Output is correct
13 Correct 28 ms 62948 KB Output is correct
14 Correct 26 ms 62908 KB Output is correct
15 Correct 26 ms 62932 KB Output is correct
16 Correct 26 ms 62904 KB Output is correct
17 Correct 26 ms 62864 KB Output is correct
18 Correct 26 ms 62848 KB Output is correct
19 Correct 29 ms 62900 KB Output is correct
20 Correct 27 ms 62888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 62924 KB Output is correct
2 Correct 28 ms 62880 KB Output is correct
3 Correct 28 ms 62864 KB Output is correct
4 Correct 28 ms 62956 KB Output is correct
5 Correct 28 ms 62836 KB Output is correct
6 Correct 32 ms 62840 KB Output is correct
7 Correct 28 ms 62832 KB Output is correct
8 Correct 27 ms 62864 KB Output is correct
9 Correct 30 ms 62932 KB Output is correct
10 Correct 29 ms 62900 KB Output is correct
11 Correct 35 ms 62944 KB Output is correct
12 Correct 35 ms 62868 KB Output is correct
13 Correct 37 ms 62880 KB Output is correct
14 Correct 29 ms 62852 KB Output is correct
15 Correct 28 ms 62844 KB Output is correct
16 Correct 27 ms 62896 KB Output is correct
17 Correct 34 ms 62872 KB Output is correct
18 Correct 27 ms 62872 KB Output is correct
19 Correct 32 ms 62904 KB Output is correct
20 Correct 27 ms 62932 KB Output is correct
21 Correct 28 ms 62832 KB Output is correct
22 Correct 27 ms 62880 KB Output is correct
23 Correct 27 ms 62988 KB Output is correct
24 Correct 34 ms 62928 KB Output is correct
25 Correct 29 ms 62908 KB Output is correct
26 Correct 31 ms 62972 KB Output is correct
27 Correct 27 ms 62924 KB Output is correct
28 Correct 27 ms 63004 KB Output is correct
29 Correct 27 ms 62888 KB Output is correct
30 Correct 33 ms 62936 KB Output is correct
31 Correct 34 ms 62948 KB Output is correct
32 Correct 31 ms 62992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 79596 KB Output is correct
2 Correct 288 ms 95936 KB Output is correct
3 Correct 216 ms 95904 KB Output is correct
4 Correct 293 ms 95948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 62932 KB Output is correct
2 Correct 27 ms 62820 KB Output is correct
3 Correct 28 ms 62932 KB Output is correct
4 Correct 33 ms 62948 KB Output is correct
5 Correct 36 ms 62900 KB Output is correct
6 Correct 27 ms 62868 KB Output is correct
7 Correct 32 ms 62852 KB Output is correct
8 Correct 35 ms 62824 KB Output is correct
9 Correct 32 ms 62836 KB Output is correct
10 Correct 28 ms 62868 KB Output is correct
11 Correct 30 ms 62868 KB Output is correct
12 Correct 28 ms 62908 KB Output is correct
13 Correct 27 ms 62892 KB Output is correct
14 Correct 27 ms 62936 KB Output is correct
15 Correct 27 ms 62908 KB Output is correct
16 Correct 35 ms 62852 KB Output is correct
17 Correct 34 ms 62940 KB Output is correct
18 Correct 28 ms 62872 KB Output is correct
19 Correct 28 ms 62912 KB Output is correct
20 Correct 28 ms 62944 KB Output is correct
21 Correct 34 ms 62852 KB Output is correct
22 Correct 28 ms 62932 KB Output is correct
23 Correct 28 ms 62928 KB Output is correct
24 Correct 28 ms 62984 KB Output is correct
25 Correct 29 ms 62992 KB Output is correct
26 Correct 28 ms 62916 KB Output is correct
27 Correct 29 ms 62904 KB Output is correct
28 Correct 39 ms 62940 KB Output is correct
29 Correct 31 ms 62904 KB Output is correct
30 Correct 33 ms 62940 KB Output is correct
31 Correct 31 ms 62956 KB Output is correct
32 Correct 28 ms 62932 KB Output is correct
33 Correct 87 ms 95036 KB Output is correct
34 Correct 91 ms 94936 KB Output is correct
35 Correct 97 ms 78708 KB Output is correct
36 Correct 93 ms 78684 KB Output is correct
37 Correct 88 ms 94932 KB Output is correct
38 Correct 77 ms 79052 KB Output is correct
39 Correct 81 ms 78748 KB Output is correct
40 Correct 84 ms 79012 KB Output is correct
41 Correct 59 ms 79724 KB Output is correct
42 Correct 61 ms 78712 KB Output is correct
43 Correct 67 ms 78576 KB Output is correct
44 Correct 73 ms 84940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 62836 KB Output is correct
2 Correct 28 ms 62884 KB Output is correct
3 Correct 35 ms 62924 KB Output is correct
4 Correct 34 ms 62924 KB Output is correct
5 Correct 35 ms 62924 KB Output is correct
6 Correct 28 ms 62832 KB Output is correct
7 Correct 36 ms 62884 KB Output is correct
8 Correct 30 ms 62816 KB Output is correct
9 Correct 29 ms 62900 KB Output is correct
10 Correct 28 ms 62836 KB Output is correct
11 Correct 35 ms 62824 KB Output is correct
12 Correct 34 ms 62820 KB Output is correct
13 Correct 28 ms 62932 KB Output is correct
14 Correct 34 ms 62888 KB Output is correct
15 Correct 28 ms 62876 KB Output is correct
16 Correct 30 ms 62896 KB Output is correct
17 Correct 28 ms 62820 KB Output is correct
18 Correct 27 ms 62932 KB Output is correct
19 Correct 32 ms 62864 KB Output is correct
20 Correct 34 ms 62848 KB Output is correct
21 Correct 33 ms 62828 KB Output is correct
22 Correct 27 ms 62924 KB Output is correct
23 Correct 35 ms 62920 KB Output is correct
24 Correct 34 ms 62992 KB Output is correct
25 Correct 29 ms 62916 KB Output is correct
26 Correct 32 ms 62960 KB Output is correct
27 Correct 31 ms 63008 KB Output is correct
28 Correct 27 ms 62964 KB Output is correct
29 Correct 29 ms 62932 KB Output is correct
30 Correct 32 ms 62928 KB Output is correct
31 Correct 34 ms 62912 KB Output is correct
32 Correct 35 ms 62964 KB Output is correct
33 Correct 143 ms 79644 KB Output is correct
34 Correct 255 ms 95872 KB Output is correct
35 Correct 251 ms 95948 KB Output is correct
36 Correct 296 ms 95964 KB Output is correct
37 Correct 102 ms 94968 KB Output is correct
38 Correct 96 ms 94916 KB Output is correct
39 Correct 110 ms 78680 KB Output is correct
40 Correct 109 ms 78676 KB Output is correct
41 Correct 93 ms 94960 KB Output is correct
42 Correct 103 ms 79060 KB Output is correct
43 Correct 68 ms 78844 KB Output is correct
44 Correct 96 ms 78964 KB Output is correct
45 Correct 63 ms 79780 KB Output is correct
46 Correct 64 ms 78688 KB Output is correct
47 Correct 86 ms 78596 KB Output is correct
48 Correct 76 ms 84952 KB Output is correct
49 Correct 265 ms 100932 KB Output is correct
50 Correct 286 ms 101028 KB Output is correct
51 Correct 190 ms 91452 KB Output is correct
52 Correct 179 ms 90912 KB Output is correct
53 Correct 234 ms 99384 KB Output is correct
54 Correct 255 ms 86836 KB Output is correct
55 Correct 195 ms 81940 KB Output is correct
56 Correct 211 ms 89636 KB Output is correct
57 Correct 127 ms 83416 KB Output is correct
58 Correct 157 ms 82876 KB Output is correct
59 Correct 73 ms 84916 KB Output is correct