답안 #219985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
219985 2020-04-06T18:58:23 Z youssefbou62 말 (IOI15_horses) C++14
0 / 100
19 ms 8448 KB
	#include  <bits/stdc++.h>

	using namespace std;

	#define mp make_pair
	#define fi first
	#define se second
	#define all(v) v.begin(),v.end()
	#define allarr(a) a , a + n
	#define ll long long
	#define ull unsigned long long 
	#define pb push_back
	#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
	typedef pair<int, int> pi;
	typedef pair<ll,ll> pll; 
	typedef pair<int,pi> trp ;
	typedef vector<pi> vpi;
	typedef vector<pll> vpll ;
	// int ab  (int  x ) { return (x>0?x:-x); }

	const int MAXN = 1e3+5; 
	const ll MOD = 1e9+7 ; 
	ll suf[MAXN],X[MAXN],Y[MAXN],N; 
	ll answer(){
		ll ans = 0 , ans1 =0 ; 
		ll prod = 1 ; 
		for(int i = 0 ; i < N ; i++ ){
			prod *= X[i] ;
			if( Y[i] == suf[i] ){
				ans += (prod-1) * Y[i] ; 
				ans1 = max( ans1 , ans + Y[i] ) ; 
				ans %= MOD ; 
				prod = 1 ;
			}   
		}
		return max(ans,ans1); 
	}

	void constructSuffix(){
		for(int i = N-1 ; i >= 0 ; i-- ){
			suf[i] = max(suf[i+1],Y[i]) ; 
		}
	}
	void init(int n,int x[],int y[]){
		N = n ; 
		for(int i = 0 ; i < n ; i++ ){
			X[i] = x[i] ; 
			Y[i] = y[i] ; 
		}
	}

	ll updateX(int pos , int val ){
		X[pos]=val ; 
		// constructSuffix();
		return answer() ;  
	}

	ll updateY(int pos , int val ){
		Y[pos] = val ; 
		constructSuffix();
		return answer() ; 
	}

	// int main(){
	// 	int m ; 
	// 	cin >> m ; 
	// 	cin >> N ; 
	// 	for(int i = 0; i < N ; i++ ){
	// 		cin >> X[i] ; 
	// 	}
	// 	for(int i = 0; i < N ; i++ ){
	// 		cin >> Y[i] ; 
	// 	}

	// 	while ( m-- ){
	// 		char c ; 
	// 		cin >> c ; 
	// 		int p , v ; cin >> p >> v ; 
	// 		cout << answer <<" = " << (( c == 'Y' )?updateY(p,v):updateX(p,v)) <<endl;  
	// 	}
		
	// }

Compilation message

horses.cpp: In function 'void constructSuffix()':
horses.cpp:40:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   for(int i = N-1 ; i >= 0 ; i-- ){
               ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 19 ms 8448 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -