답안 #387158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387158 2021-04-08T05:24:34 Z alireza_kaviani 말 (IOI15_horses) C++11
100 / 100
371 ms 65132 KB
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;

typedef long long ll;

const ll MAXN = 5e5 + 10;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

ll n , x[MAXN] , y[MAXN] , mul[MAXN * 2] , mx[MAXN * 2];
set<int , greater<int>> st;

void reBuild(int pos){
	for(mul[pos + n] = x[pos] , mx[pos + n] = y[pos] , pos += n ; pos /= 2 ;){
		mul[pos] = mul[pos * 2] * mul[pos * 2 + 1] % MOD;
		mx[pos] = max(mx[pos * 2] , mx[pos * 2 + 1]); 
	}
}

ll getMul(int ql , int qr){
	ll ans = 1;
	for(ql += n , qr += n ; ql < qr ; ql >>= 1 , qr >>= 1){
		if(ql & 1)	ans = ans * mul[ql++] % MOD;
		if(qr & 1)	ans = ans * mul[--qr] % MOD;
	}
	return ans;
}

ll getMax(int ql , int qr){
	ll ans = 0;
	for(ql += n , qr += n ; ql < qr ; ql >>= 1 , qr >>= 1){
		if(ql & 1)	ans = max(ans , mx[ql++]);
		if(qr & 1)	ans = max(ans , mx[--qr]);
	}
	return ans;
}

ll solve(){
	ll ans = 0 , cur = n , prv;
	for(auto it = st.begin() ; it != st.end() ; it++){
		if(ans > INF)	break;
		prv = cur; cur = (*it);
		ans = max(ans , getMax(cur , prv)) * x[cur];
//		cout << cur << ' ' << getMax(cur , prv) << endl;
	}
//	cout << endl;
	return ans % MOD * getMul(0 , cur) % MOD;
}

int init(int N, int X[], int Y[]) {
	n = N;
	for(int i = 0 ; i < N ; i++){
		mul[i + N] = X[i]; x[i] = X[i];
		mx[i + N] = Y[i];  y[i] = Y[i];
		if(X[i] >= 2 || i == 0)	st.insert(i);
	}
	for(int i = N - 1 ; i >= 1 ; i--){
		mul[i] = mul[i * 2] * mul[i * 2 + 1] % MOD;
		mx[i] = max(mx[i * 2] , mx[i * 2 + 1]);
	}
	return solve();
}

int updateX(int pos, int val) {	
	x[pos] = val; st.erase(pos);
	reBuild(pos);
	if(val >= 2 || pos == 0)	st.insert(pos);
	return solve();
}

int updateY(int pos, int val) {
	y[pos] = val;
	reBuild(pos);
	return solve();
}

Compilation message

horses.cpp: In function 'void reBuild(int)':
horses.cpp:15:57: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   15 |  for(mul[pos + n] = x[pos] , mx[pos + n] = y[pos] , pos += n ; pos /= 2 ;){
      |                                                     ~~~~^~~~
horses.cpp: In function 'll getMul(int, int)':
horses.cpp:23:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   23 |  for(ql += n , qr += n ; ql < qr ; ql >>= 1 , qr >>= 1){
      |      ~~~^~~~
horses.cpp:23:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   23 |  for(ql += n , qr += n ; ql < qr ; ql >>= 1 , qr >>= 1){
      |                ~~~^~~~
horses.cpp: In function 'll getMax(int, int)':
horses.cpp:32:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   32 |  for(ql += n , qr += n ; ql < qr ; ql >>= 1 , qr >>= 1){
      |      ~~~^~~~
horses.cpp:32:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   32 |  for(ql += n , qr += n ; ql < qr ; ql >>= 1 , qr >>= 1){
      |                ~~~^~~~
horses.cpp: In function 'll solve()':
horses.cpp:44:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   44 |   ans = max(ans , getMax(cur , prv)) * x[cur];
      |                          ^~~
horses.cpp:44:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   44 |   ans = max(ans , getMax(cur , prv)) * x[cur];
      |                                ^~~
horses.cpp:48:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   48 |  return ans % MOD * getMul(0 , cur) % MOD;
      |                                ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:62:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   62 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:69:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   69 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:75:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   75 |  return solve();
      |         ~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 3 ms 364 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 52204 KB Output is correct
2 Correct 320 ms 52460 KB Output is correct
3 Correct 291 ms 52240 KB Output is correct
4 Correct 371 ms 52332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 2 ms 364 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 48 ms 32108 KB Output is correct
34 Correct 46 ms 31852 KB Output is correct
35 Correct 194 ms 62188 KB Output is correct
36 Correct 189 ms 62188 KB Output is correct
37 Correct 52 ms 30060 KB Output is correct
38 Correct 98 ms 42904 KB Output is correct
39 Correct 34 ms 29804 KB Output is correct
40 Correct 172 ms 57324 KB Output is correct
41 Correct 34 ms 29932 KB Output is correct
42 Correct 36 ms 29932 KB Output is correct
43 Correct 182 ms 57580 KB Output is correct
44 Correct 174 ms 57580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 215 ms 56172 KB Output is correct
34 Correct 329 ms 65132 KB Output is correct
35 Correct 291 ms 56044 KB Output is correct
36 Correct 366 ms 59884 KB Output is correct
37 Correct 45 ms 31852 KB Output is correct
38 Correct 45 ms 31908 KB Output is correct
39 Correct 213 ms 62188 KB Output is correct
40 Correct 191 ms 62188 KB Output is correct
41 Correct 43 ms 30060 KB Output is correct
42 Correct 97 ms 43116 KB Output is correct
43 Correct 40 ms 29932 KB Output is correct
44 Correct 177 ms 57324 KB Output is correct
45 Correct 36 ms 29932 KB Output is correct
46 Correct 42 ms 29932 KB Output is correct
47 Correct 168 ms 57580 KB Output is correct
48 Correct 172 ms 57580 KB Output is correct
49 Correct 133 ms 35012 KB Output is correct
50 Correct 123 ms 34924 KB Output is correct
51 Correct 266 ms 64108 KB Output is correct
52 Correct 237 ms 63596 KB Output is correct
53 Correct 167 ms 33132 KB Output is correct
54 Correct 165 ms 46828 KB Output is correct
55 Correct 80 ms 30828 KB Output is correct
56 Correct 232 ms 58988 KB Output is correct
57 Correct 96 ms 31596 KB Output is correct
58 Correct 106 ms 32048 KB Output is correct
59 Correct 171 ms 57836 KB Output is correct