Submission #219983

#TimeUsernameProblemLanguageResultExecution timeMemory
219983youssefbou62Horses (IOI15_horses)C++14
0 / 100
20 ms10616 KiB
#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 + prod ) ; 
			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 (stderr)

horses.cpp: In function 'void constructSuffix()':
horses.cpp:40:15: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  for(int i = N-1 ; i >= 0 ; i-- ){
              ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...