답안 #1025237

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025237 2024-07-16T18:08:44 Z YassirSalama 말 (IOI15_horses) C++17
100 / 100
1126 ms 57424 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ll long long
template<typename T> 
void dbg_out(const T& t){
	cout<<t<<endl;
}
template<typename T,typename... Args>
void dbg_out(const T& t,const Args&... args){
	cout<<t<<" , ";
	dbg_out(args...);
}
#define dbg(...) cout<<"("<<#__VA_ARGS__<<"): ";dbg_out(__VA_ARGS__);
const ll mod=1e9+7;
const int maxn=5e5+1;
ll tree[4*maxn];
void update(int node,int l,int r,int ql,ll x){
	if(l==r){
		tree[node]=x;
		return;
	}
	int mid=(l+r)/2;
	if(ql<=mid)
		update(node<<1,l,mid,ql,x);
	if(ql>mid)
		update(node<<1|1,mid+1,r,ql,x);
	tree[node]=max(tree[node<<1],tree[node<<1|1]);
}
ll query(int node,int l,int r,int ql,int qr){
	if(ql>=qr) return 0LL;
	if(ql<=l&&r<=qr) return tree[node];
	int mid=(l+r)/2;
	ll ans=0;
	if(ql<=mid) ans=max(ans,query(node<<1,l,mid,ql,qr));
	if(qr>mid) ans=max(ans,query(node<<1|1,mid+1,r,ql,qr));
	return ans;
}
int n;
vector<ll> x;
vector<ll> y;
set<int> s;
ll ymx=1e9;
ll pref=1;
ll binpow(int a,int b){
	ll ans=1;
	while(b){
		if(b&1) ans=(ans%mod*a%mod)%mod;
		b>>=1;
		a=(a%mod*a%mod)%mod;
	}
	return ans;
}
ll invmod(int a){
	return binpow(a,mod-2);
}
ll solve(){
	ll suff=1;
	ll p=pref;
	int last=n;
    for(auto i:s){
    	i=-i;
    	suff=max(suff,1LL*query(1,0,n,i,last));
    	last=i;
    	if(suff>=ymx){
    		suff%=mod;
    		return (p%mod*suff%mod)%mod;
    	}
    	suff*=x[i];
    	p=(p%mod*invmod(x[i])%mod)%mod;
    }
    return max(suff*p,1LL*query(1,0,n,0,last))%mod;
}
int init(int N, int X[], int Y[]) {
	n=N;
	x.resize(n,0);
	y.resize(n,0);
	for(int i=0;i<n;i++){
		x[i]=X[i];
		if(x[i]>1){
			s.insert(-i);
		}
		pref=pref*x[i]%mod;
	}
	for(int i=0;i<n;i++){
		y[i]=Y[i];
		update(1,0,n,i,y[i]);
	}
	return (int)((ll)solve()%mod);
}
 
int updateX(int pos, int val) {	
	pref=(pref%mod*invmod(x[pos])%mod)%mod;
	if(x[pos]>1){
		s.erase(-pos);
	}
	x[pos]=val;
	x[pos]%=mod;
	if(x[pos]>1) s.insert(-pos);
	pref=(pref%mod*x[pos]%mod)%mod;
	return solve()%mod;
}
 
int updateY(int pos, int val) {
	y[pos]=val;
	y[pos]%=mod;
	update(1,0,n,pos,val);
	return solve()%mod;
}
 
 
#ifdef IOI
 
 
static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;
 
static inline int _read() {
    if (_charsNumber < 0) {
        exit(1);
    }
    if (!_charsNumber || _currentChar == _charsNumber) {
        _charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile);
        _currentChar = 0;
    }
    if (_charsNumber <= 0) {
        return -1;
    }
    return _buffer[_currentChar++];
}
 
static inline int _readInt() {
    int c, x, s;
    c = _read();
    while (c <= 32) c = _read();
    x = 0;
    s = 1;
    if (c == '-') {
        s = -1;
        c = _read();
    }
    while (c > 32) {
        x *= 10;
        x += c - '0';
        c = _read();
    }
    if (s < 0) x = -x;
    return x;
}
 
 
int main() {
	// _inputFile = fopen("horses.in", "rb");
	// _outputFile = fopen("horses.out", "w");
	
	int N; 
	cin>>N;
 
	int *X = (int*)malloc(sizeof(int)*(unsigned int)N);
	int *Y = (int*)malloc(sizeof(int)*(unsigned int)N);
 
	for (int i = 0; i < N; i++) {
		cin>>X[i];
	}
 
	for (int i = 0; i < N; i++) {
		cin>>Y[i];
	}	
	cout<<init(N,X,Y)<<endl;
 
 
	int M; 
	// M = _readInt();
	cin>>M;
 
	for (int i = 0; i < M; i++) {
		int type; 
		int pos; 
		int val; 
		cin>>type>>pos>>val;
		if (type == 1) {
			cout<<updateX(pos,val)<<endl;
			// fprintf(_outputFile,"%d\n",updateX(pos,val));
		} else if (type == 2) {
			cout<<updateY(pos,val)<<endl;
			// fprintf(_outputFile,"%d\n",updateY(pos,val));
		}
	}
 
	return 0;
}
 
#endif 

Compilation message

horses.cpp: In function 'long long int binpow(int, int)':
horses.cpp:52:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   52 |   a=(a%mod*a%mod)%mod;
      |     ~~~~~~~~~~~~~^~~~
horses.cpp: In function 'long long int solve()':
horses.cpp:72:26: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   72 |      p=(p%mod*invmod(x[i])%mod)%mod;
      |                          ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:95:30: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   95 |  pref=(pref%mod*invmod(x[pos])%mod)%mod;
      |                              ^
horses.cpp:103:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  103 |  return solve()%mod;
      |         ~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:110:16: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  110 |  return solve()%mod;
      |         ~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 612 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 352 KB Output is correct
20 Correct 0 ms 356 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 448 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 9 ms 512 KB Output is correct
28 Correct 3 ms 344 KB Output is correct
29 Correct 1 ms 352 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 6 ms 396 KB Output is correct
32 Correct 9 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1058 ms 48480 KB Output is correct
2 Correct 298 ms 57424 KB Output is correct
3 Correct 422 ms 48724 KB Output is correct
4 Correct 327 ms 52368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 448 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 452 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 9 ms 512 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 6 ms 348 KB Output is correct
32 Correct 9 ms 508 KB Output is correct
33 Correct 86 ms 24348 KB Output is correct
34 Correct 81 ms 24304 KB Output is correct
35 Correct 217 ms 54636 KB Output is correct
36 Correct 187 ms 54584 KB Output is correct
37 Correct 178 ms 22608 KB Output is correct
38 Correct 131 ms 35412 KB Output is correct
39 Correct 78 ms 22356 KB Output is correct
40 Correct 178 ms 49832 KB Output is correct
41 Correct 133 ms 22280 KB Output is correct
42 Correct 158 ms 22344 KB Output is correct
43 Correct 169 ms 50020 KB Output is correct
44 Correct 175 ms 50164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 436 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 11 ms 344 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 7 ms 348 KB Output is correct
32 Correct 10 ms 348 KB Output is correct
33 Correct 1036 ms 48540 KB Output is correct
34 Correct 285 ms 57420 KB Output is correct
35 Correct 395 ms 48472 KB Output is correct
36 Correct 311 ms 52268 KB Output is correct
37 Correct 84 ms 24404 KB Output is correct
38 Correct 92 ms 24312 KB Output is correct
39 Correct 218 ms 54720 KB Output is correct
40 Correct 187 ms 54568 KB Output is correct
41 Correct 181 ms 22512 KB Output is correct
42 Correct 132 ms 35360 KB Output is correct
43 Correct 90 ms 22580 KB Output is correct
44 Correct 182 ms 49744 KB Output is correct
45 Correct 139 ms 22320 KB Output is correct
46 Correct 165 ms 22612 KB Output is correct
47 Correct 166 ms 50016 KB Output is correct
48 Correct 166 ms 50236 KB Output is correct
49 Correct 188 ms 27408 KB Output is correct
50 Correct 152 ms 27404 KB Output is correct
51 Correct 415 ms 56656 KB Output is correct
52 Correct 220 ms 56176 KB Output is correct
53 Correct 1126 ms 25620 KB Output is correct
54 Correct 369 ms 39416 KB Output is correct
55 Correct 194 ms 23376 KB Output is correct
56 Correct 300 ms 51456 KB Output is correct
57 Correct 749 ms 24152 KB Output is correct
58 Correct 1018 ms 24808 KB Output is correct
59 Correct 185 ms 50256 KB Output is correct