답안 #876082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876082 2023-11-21T08:24:19 Z Elvin_Fritl 말 (IOI15_horses) C++17
100 / 100
458 ms 55036 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 5e5 + 545 , inf = 1e9 + 12 , mod = 1e9 + 7;

    #include "horses.h"

 
struct segtree {
	int tree[N*4];
	void update(int v,int l,int r,int pos,int val) {
		if(l == r) {
			tree[v] = val; 
			return;
		}
		int mid = (l+r)/2;
		if(pos <= mid) {
			update((v*2), l, mid, pos, val);
		}
		else {
			update((v*2 + 1), mid + 1, r, pos, val);
		}
		tree[v] = max(tree[(v*2)], tree[(v*2 + 1)]);
	}
	int get(int v,int l,int r,int ml,int mr) {
		if(mr < l || r < ml || l > r){
			return 0LL;
		}
		if(ml <= l && r <= mr){
			return tree[v];
		}
		int mid = (l+r)/2;
		return max(get((v*2), l, mid, ml, mr), get((v*2 + 1), mid + 1, r, ml, mr));
	}
	
};
int n;
ll x[N] , y[N];
set<int> s;
ll tmp = 1;
 
ll bp(ll x,ll m){
    if(m == 0){
        return 1LL;
    }
    if(m == 1){
        return x%mod;
    }
    if(m%2==0){
        return bp(x*x%mod,m/2)%mod;
    }
    return x*bp(x,m-1)%mod;
}

segtree S;


int calc() {
	ll res = 1 , ind = -1;
	assert((int)s.size() >= 2);
	auto it = next(s.rbegin());
	while(it != s.rend()) {
		res *= x[*it];
		ind = *it;
		if(res > inf){
			break;
		}
		it = next(it);
	}
	auto it2 = s.lower_bound(ind);
	ll mx = 0; 
	res = 1;
	while(next(it2) != s.end()) {
		int i = *it2;
		int j = *(next(it2));
		if(i != ind){
			res = res*x[i];
		}
		ll ans = S.get(1, 0, n-1, i, j-1);
		mx = max(mx, res*ans);
		it2 = next(it2);
	}
	mx %= mod;
	return tmp*bp(res,mod-2)%mod*mx%mod;
}


int init(int nn, int X[], int Y[]) {
	n = nn;
	for(int i=0;i<n;i++) {
		x[i] = X[i];
		y[i] = Y[i];
	}
	for(int i=0;i<n;i++) {
		S.update(1, 0, n - 1, i, y[i]);
	}
	s.insert(0);
	s.insert(n);
	for(int i=n-1;i>=0;i--) {
		if(x[i] > 1) {
			tmp = (tmp * x[i])%mod;
			s.insert(i); 
		}
	}
	return calc();
}
 
 
int updateX(int pos, int val) {
	tmp = (tmp * bp(x[pos], mod-2))%mod;
	x[pos] = val;
	tmp = (tmp*val)%mod;
	if(val > 1 || pos == 0){
		s.insert(pos);
	}
	else if(s.find(pos) != s.end()){
		s.erase(pos);
	}
	return calc();
}
 
int updateY(int pos, int val) {
	S.update(1, 0, n-1, pos, val);
	return calc();
}

Compilation message

horses.cpp: In function 'll bp(ll, ll)':
horses.cpp:44:10: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   44 | ll bp(ll x,ll m){
      |       ~~~^
horses.cpp:40:4: note: shadowed declaration is here
   40 | ll x[N] , y[N];
      |    ^
horses.cpp: In function 'int calc()':
horses.cpp:72:27: warning: conversion from 'll' {aka 'long long int'} to 'std::set<int>::key_type' {aka 'int'} may change value [-Wconversion]
   72 |  auto it2 = s.lower_bound(ind);
      |                           ^~~
horses.cpp:86:33: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   86 |  return tmp*bp(res,mod-2)%mod*mx%mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:97:31: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   97 |   S.update(1, 0, n - 1, i, y[i]);
      |                            ~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4440 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 3 ms 4444 KB Output is correct
26 Correct 2 ms 4700 KB Output is correct
27 Correct 3 ms 4444 KB Output is correct
28 Correct 2 ms 4556 KB Output is correct
29 Correct 2 ms 4628 KB Output is correct
30 Correct 2 ms 4588 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 3 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 417 ms 42280 KB Output is correct
2 Correct 296 ms 42440 KB Output is correct
3 Correct 297 ms 42372 KB Output is correct
4 Correct 340 ms 42444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 2 ms 4564 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 2 ms 4552 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
27 Correct 3 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 2 ms 4560 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 3 ms 4444 KB Output is correct
33 Correct 64 ms 20308 KB Output is correct
34 Correct 63 ms 22100 KB Output is correct
35 Correct 178 ms 52304 KB Output is correct
36 Correct 207 ms 52564 KB Output is correct
37 Correct 93 ms 20056 KB Output is correct
38 Correct 108 ms 32852 KB Output is correct
39 Correct 58 ms 19944 KB Output is correct
40 Correct 189 ms 47368 KB Output is correct
41 Correct 68 ms 20048 KB Output is correct
42 Correct 78 ms 20052 KB Output is correct
43 Correct 169 ms 47684 KB Output is correct
44 Correct 170 ms 47840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
27 Correct 4 ms 4444 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 2 ms 4572 KB Output is correct
30 Correct 2 ms 4564 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 3 ms 4444 KB Output is correct
33 Correct 431 ms 45544 KB Output is correct
34 Correct 304 ms 55036 KB Output is correct
35 Correct 300 ms 46272 KB Output is correct
36 Correct 353 ms 50000 KB Output is correct
37 Correct 64 ms 22008 KB Output is correct
38 Correct 62 ms 21980 KB Output is correct
39 Correct 210 ms 52308 KB Output is correct
40 Correct 197 ms 52260 KB Output is correct
41 Correct 92 ms 20272 KB Output is correct
42 Correct 118 ms 32852 KB Output is correct
43 Correct 58 ms 20024 KB Output is correct
44 Correct 196 ms 47484 KB Output is correct
45 Correct 70 ms 20052 KB Output is correct
46 Correct 79 ms 20012 KB Output is correct
47 Correct 174 ms 48088 KB Output is correct
48 Correct 161 ms 47832 KB Output is correct
49 Correct 166 ms 25148 KB Output is correct
50 Correct 142 ms 24916 KB Output is correct
51 Correct 315 ms 54336 KB Output is correct
52 Correct 275 ms 53712 KB Output is correct
53 Correct 458 ms 23184 KB Output is correct
54 Correct 270 ms 36804 KB Output is correct
55 Correct 155 ms 21164 KB Output is correct
56 Correct 267 ms 49232 KB Output is correct
57 Correct 259 ms 21664 KB Output is correct
58 Correct 362 ms 22100 KB Output is correct
59 Correct 167 ms 47700 KB Output is correct