답안 #1025189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025189 2024-07-16T17:15:14 Z YassirSalama 말 (IOI15_horses) C++17
34 / 100
1500 ms 24232 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ll __int128_t
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=2000;
int n;
vector<ll> x;
vector<ll> y;
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);
}
__int128_t ymx=1e18;
__int128_t pref=1;
void print(__int128 x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}
ll solve(){
	__int128_t suff=1;
	__int128_t p=pref;
    for(int i=n-1;i>=0;i--){
    	suff=max(suff*x[i],1LL*x[i]*y[i]);
    	p=p*invmod(x[i])%mod;
    	if(suff>=ymx){
    		return (p*suff%mod)%mod;
    	}
    }
    return (suff%mod)%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];
		pref=pref*x[i]%mod;
	}
	// print(pref);
	for(int i=0;i<n;i++){
		y[i]=Y[i];
	}
	return (int)((ll)solve()%mod);
}

int updateX(int pos, int val) {	
	pref=(pref%mod*invmod(x[pos])%mod)%mod;
	x[pos]=val;
	x[pos]%=mod;
	pref=(pref%mod*x[pos]%mod)%mod;
	return solve()%mod;
}

int updateY(int pos, int val) {
	y[pos]=val;
	y[pos]%=mod;
	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 '__int128 binpow(int, int)':
horses.cpp:27:18: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
   27 |   a=(a%mod*a%mod)%mod;
      |     ~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void print(__int128)':
horses.cpp:36:21: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   36 | void print(__int128 x) {
      |            ~~~~~~~~~^
horses.cpp:20:12: note: shadowed declaration is here
   20 | vector<ll> x;
      |            ^
horses.cpp:42:20: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
   42 |     putchar(x % 10 + '0');
      |             ~~~~~~~^~~~~
horses.cpp: In function '__int128 solve()':
horses.cpp:49:21: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<__int128>, __int128>::value_type' {aka '__int128'} to 'int' may change value [-Wconversion]
   49 |      p=p*invmod(x[i])%mod;
      |                     ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:72:30: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<__int128>, __int128>::value_type' {aka '__int128'} to 'int' may change value [-Wconversion]
   72 |  pref=(pref%mod*invmod(x[pos])%mod)%mod;
      |                              ^
horses.cpp:76:16: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
   76 |  return solve()%mod;
      |         ~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:82:16: warning: conversion from '__int128' to 'int' may change value [-Wconversion]
   82 |  return solve()%mod;
      |         ~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 604 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 344 KB Output is correct
10 Correct 0 ms 436 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 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 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 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 436 KB Output is correct
14 Correct 1 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 348 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 32 ms 472 KB Output is correct
24 Correct 2 ms 344 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 178 ms 348 KB Output is correct
28 Correct 11 ms 348 KB Output is correct
29 Correct 353 ms 348 KB Output is correct
30 Correct 89 ms 344 KB Output is correct
31 Correct 316 ms 348 KB Output is correct
32 Correct 345 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1593 ms 22720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 344 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 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 1 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 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 32 ms 496 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 5 ms 472 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 171 ms 468 KB Output is correct
28 Correct 11 ms 348 KB Output is correct
29 Correct 352 ms 460 KB Output is correct
30 Correct 91 ms 344 KB Output is correct
31 Correct 340 ms 464 KB Output is correct
32 Correct 353 ms 472 KB Output is correct
33 Execution timed out 1556 ms 23896 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 344 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 1 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 436 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 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 32 ms 348 KB Output is correct
24 Correct 2 ms 448 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 177 ms 348 KB Output is correct
28 Correct 11 ms 348 KB Output is correct
29 Correct 361 ms 464 KB Output is correct
30 Correct 89 ms 476 KB Output is correct
31 Correct 330 ms 464 KB Output is correct
32 Correct 351 ms 464 KB Output is correct
33 Execution timed out 1535 ms 24232 KB Time limit exceeded
34 Halted 0 ms 0 KB -