# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1014617 | MarwenElarbi | Horses (IOI15_horses) | C++17 | 16 ms | 10588 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
#define ll long long
#define pb push_back
#define se second
#define fi first
const int MOD=1e9+7;
pair<int,int> tab[1005];
int n;
int init(int N, int X[], int Y[]){
n=N;
for (int i = 0; i < N; ++i)
{
tab[i]={X[i],Y[i]};
}
ll cur=0;
ll pos;
for (int i = N-1; i >= 0; --i)
{
if(cur<Y[i]){
pos=i;
cur=Y[i];
}
if(cur<=1e9) cur*=X[i];
}
ll res=1;
for (int i = 0; i < pos; ++i)
{
res*=X[i];
res%=MOD;
}
res*=X[pos]*Y[pos]%MOD;
res%=MOD;
return res;
}
int updateX(int pos, int val){
tab[pos].fi=val;
ll cur=0;
ll ps;
for (int i = n-1; i >= 0; --i)
{
if(cur<tab[i].se){
ps=i;
cur=tab[i].se;
}
if(cur<=1e9) cur*=tab[i].fi;
}
ll res=1;
for (int i = 0; i < ps; ++i)
{
res*=tab[i].fi;
res%=MOD;
}
res*=tab[ps].fi*tab[ps].se%MOD;
res%=MOD;
return res;
}
int updateY(int pos, int val) {
tab[pos].se=val;
ll cur=0;
ll ps;
for (int i = n-1; i >= 0; --i)
{
if(cur<tab[i].se){
ps=i;
cur=tab[i].se;
}
if(cur<=1e9) cur*=tab[i].fi;
}
ll res=1;
for (int i = 0; i < ps; ++i)
{
res*=tab[i].fi;
res%=MOD;
}
res*=tab[ps].fi*tab[ps].se%MOD;
res%=MOD;
return res;
}
/*
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
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)<<" ";
int M; cin>>M;
for (int i = 0; i < M; i++) {
int type; cin>>type;
int pos; cin>>pos;
int val; cin>>val;
if (type == 1) {
cout <<updateX(pos,val)<<" ";
} else if (type == 2) {
cout <<updateY(pos,val)<<" ";
}
}
return 0;
}*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |