답안 #984212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984212 2024-05-16T11:37:06 Z SmuggingSpun 말 (IOI15_horses) C++14
77 / 100
1500 ms 36460 KB
#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int lim = 5e5 + 5;
int power(int a, int b){
	int ans = 1;
	for(; b > 0; b >>= 1, a = 1LL * a * a % mod){
		if(b & 1){
			ans = 1LL * ans * a % mod;
		}
	}
	return ans;
}
int n, st[lim << 2], x[lim], x_st[lim << 2], y[lim], bit[lim];
int get_bit(int p){
	int ans = 1;
	for(; p > 0; p -= p & -p){
		ans = 1LL * ans * bit[p] % mod;
	}
	return ans;
}
void update_bit(int p, int x){
	for(; p <= n; p += p & -p){
		bit[p] = 1LL * bit[p] * x % mod;
	}
}
int get_x_prod(int id, int l, int r, int u, int v){
	if(l > v || r < u){
		return 1;
	}
	if(u <= l && v >= r){
		return x_st[id];
	}
	int m = (l + r) >> 1, left = get_x_prod(id << 1, l, m, u, v);
	if(left == mod){
		return mod;
	}
	return min(ll(mod), 1LL * left * get_x_prod(id << 1 | 1, m + 1, r, u, v));
}
int merge(int l, int r){
	if(l == 0){
		return r;
	}
	if(r == 0){
		return l;
	}
	return 1LL * get_x_prod(1, 1, n, l + 1, r) * y[r] < ll(y[l]) ? l : r;
}
void update_X(int id, int l, int r, int p, int X){
	if(l == r){
		update_bit(l, 1LL * power(x[l], mod - 2) * X % mod);
		x[st[id] = l] = X;
		x_st[id] = X;
		return;
	}
	int m = (l + r) >> 1;
	if(m < p){
		update_X(id << 1 | 1, m + 1, r, p, X);
	}
	else{
		update_X(id << 1, l, m, p, X);
	}
	st[id] = merge(st[id << 1], st[id << 1 | 1]);
	x_st[id] = min(ll(mod), 1LL * x_st[id << 1] * x_st[id << 1 | 1]);
}
void update_Y(int p, int Y){
	y[p] = Y;
	int id = 1, l = 1, r = n;
	while(l < r){
		int m = (l + r) >> 1;
		id <<= 1;
		if(m < p){
			l = m + 1;
			id |= 1;
		}
		else{
			r = m;
		}
	}
	while((id >>= 1) > 0){
		st[id] = merge(st[id << 1], st[id << 1 | 1]);
	}
}
int init(int N, int X[], int Y[]){
	n = N;
	fill(bit, bit + lim, 1);
	for(int i = 1; i <= n; i++){
		y[i] = Y[i - 1];
		update_bit(i, x[i] = X[i - 1]);
	}
	fill(x_st, x_st + (lim << 2), 1);
	for(int i = 1; i <= n; i++){
		update_X(1, 1, n, i, X[i - 1]);
	}
	return 1LL * get_bit(st[1]) * y[st[1]] % mod;
}
int updateX(int pos, int val){	
	update_X(1, 1, n, pos + 1, val);
	return 1LL * get_bit(st[1]) * y[st[1]] % mod;
}
int updateY(int pos, int val){
	update_Y(pos + 1, val);
	return 1LL * get_bit(st[1]) * y[st[1]] % mod;
}

Compilation message

horses.cpp: In function 'int power(int, int)':
horses.cpp:9:40: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
    9 |  for(; b > 0; b >>= 1, a = 1LL * a * a % mod){
      |                            ~~~~~~~~~~~~^~~~~
horses.cpp:11:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   11 |    ans = 1LL * ans * a % mod;
      |          ~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get_bit(int)':
horses.cpp:20:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   20 |   ans = 1LL * ans * bit[p] % mod;
      |         ~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void update_bit(int, int)':
horses.cpp:24:28: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   24 | void update_bit(int p, int x){
      |                        ~~~~^
horses.cpp:16:22: note: shadowed declaration is here
   16 | int n, st[lim << 2], x[lim], x_st[lim << 2], y[lim], bit[lim];
      |                      ^
horses.cpp:26:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   26 |   bit[p] = 1LL * bit[p] * x % mod;
      |            ~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int get_x_prod(int, int, int, int, int)':
horses.cpp:40:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   40 |  return min(ll(mod), 1LL * left * get_x_prod(id << 1 | 1, m + 1, r, u, v));
      |         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'void update_X(int, int, int, int, int)':
horses.cpp:53:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   53 |   update_bit(l, 1LL * power(x[l], mod - 2) * X % mod);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:66:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   66 |  x_st[id] = min(ll(mod), 1LL * x_st[id << 1] * x_st[id << 1 | 1]);
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:97:41: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   97 |  return 1LL * get_bit(st[1]) * y[st[1]] % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:101:41: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  101 |  return 1LL * get_bit(st[1]) * y[st[1]] % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:105:41: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  105 |  return 1LL * get_bit(st[1]) * y[st[1]] % mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14952 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 3 ms 14940 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 3 ms 14936 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14940 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 3 ms 14940 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 3 ms 14940 KB Output is correct
22 Correct 3 ms 14936 KB Output is correct
23 Correct 5 ms 14940 KB Output is correct
24 Correct 5 ms 14996 KB Output is correct
25 Correct 5 ms 14940 KB Output is correct
26 Correct 6 ms 14796 KB Output is correct
27 Correct 5 ms 15012 KB Output is correct
28 Correct 5 ms 14940 KB Output is correct
29 Correct 5 ms 14940 KB Output is correct
30 Correct 4 ms 15136 KB Output is correct
31 Correct 5 ms 14792 KB Output is correct
32 Correct 5 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 759 ms 23768 KB Output is correct
2 Correct 785 ms 24044 KB Output is correct
3 Correct 885 ms 23888 KB Output is correct
4 Correct 989 ms 31436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14976 KB Output is correct
5 Correct 3 ms 14940 KB Output is correct
6 Correct 3 ms 14940 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14940 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14936 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14936 KB Output is correct
16 Correct 3 ms 14936 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 4 ms 15192 KB Output is correct
22 Correct 3 ms 14940 KB Output is correct
23 Correct 5 ms 14936 KB Output is correct
24 Correct 5 ms 14940 KB Output is correct
25 Correct 4 ms 14940 KB Output is correct
26 Correct 4 ms 15028 KB Output is correct
27 Correct 5 ms 14940 KB Output is correct
28 Correct 5 ms 14940 KB Output is correct
29 Correct 5 ms 14940 KB Output is correct
30 Correct 4 ms 14936 KB Output is correct
31 Correct 4 ms 14940 KB Output is correct
32 Correct 6 ms 15060 KB Output is correct
33 Correct 1191 ms 27172 KB Output is correct
34 Correct 1161 ms 27056 KB Output is correct
35 Correct 604 ms 33852 KB Output is correct
36 Correct 599 ms 33804 KB Output is correct
37 Correct 905 ms 25092 KB Output is correct
38 Correct 722 ms 26008 KB Output is correct
39 Correct 896 ms 25052 KB Output is correct
40 Correct 569 ms 28900 KB Output is correct
41 Correct 897 ms 24916 KB Output is correct
42 Correct 998 ms 25328 KB Output is correct
43 Correct 581 ms 29248 KB Output is correct
44 Correct 582 ms 29368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14964 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 3 ms 14940 KB Output is correct
5 Correct 4 ms 14972 KB Output is correct
6 Correct 3 ms 14968 KB Output is correct
7 Correct 3 ms 14940 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 3 ms 14940 KB Output is correct
10 Correct 3 ms 14968 KB Output is correct
11 Correct 3 ms 14980 KB Output is correct
12 Correct 3 ms 14940 KB Output is correct
13 Correct 3 ms 14940 KB Output is correct
14 Correct 3 ms 14940 KB Output is correct
15 Correct 3 ms 14940 KB Output is correct
16 Correct 4 ms 14940 KB Output is correct
17 Correct 3 ms 14940 KB Output is correct
18 Correct 3 ms 14940 KB Output is correct
19 Correct 3 ms 14940 KB Output is correct
20 Correct 3 ms 14940 KB Output is correct
21 Correct 4 ms 14940 KB Output is correct
22 Correct 4 ms 14960 KB Output is correct
23 Correct 5 ms 14940 KB Output is correct
24 Correct 5 ms 15024 KB Output is correct
25 Correct 5 ms 14940 KB Output is correct
26 Correct 5 ms 14940 KB Output is correct
27 Correct 5 ms 14936 KB Output is correct
28 Correct 5 ms 14940 KB Output is correct
29 Correct 4 ms 14940 KB Output is correct
30 Correct 4 ms 15024 KB Output is correct
31 Correct 4 ms 14940 KB Output is correct
32 Correct 5 ms 14940 KB Output is correct
33 Correct 781 ms 27724 KB Output is correct
34 Correct 781 ms 36460 KB Output is correct
35 Correct 889 ms 27708 KB Output is correct
36 Correct 969 ms 31804 KB Output is correct
37 Correct 1156 ms 26920 KB Output is correct
38 Correct 1165 ms 26920 KB Output is correct
39 Correct 587 ms 33876 KB Output is correct
40 Correct 594 ms 34036 KB Output is correct
41 Correct 909 ms 25096 KB Output is correct
42 Correct 682 ms 26272 KB Output is correct
43 Correct 918 ms 25044 KB Output is correct
44 Correct 565 ms 28892 KB Output is correct
45 Correct 900 ms 25428 KB Output is correct
46 Correct 951 ms 25380 KB Output is correct
47 Correct 554 ms 29188 KB Output is correct
48 Correct 558 ms 29604 KB Output is correct
49 Execution timed out 1516 ms 29140 KB Time limit exceeded
50 Halted 0 ms 0 KB -