Submission #1014618

#TimeUsernameProblemLanguageResultExecution timeMemory
1014618MarwenElarbi말 (IOI15_horses)C++17
34 / 100
19 ms12320 KiB
#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<ll,ll> 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*=1ll*X[i];
    }
    ll res=1;
    for (int i = 0; i < pos; ++i)
    {
        res*=1ll*X[i];
        res%=MOD;
    }
    res*=1ll*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*=1ll*tab[i].fi;
    }
    ll res=1;
    for (int i = 0; i < ps; ++i)
    {
        res*=tab[i].fi;
        res%=MOD;
    }
    res*=1ll*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*=1ll*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)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:25:12: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   25 |         if(cur<=1e9) cur*=1ll*X[i];
      |            ^~~
horses.cpp:35:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   35 |     return res;
      |            ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:48:12: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   48 |         if(cur<=1e9) cur*=1ll*tab[i].fi;
      |            ^~~
horses.cpp:58:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   58 |     return res;
      |            ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:71:12: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   71 |         if(cur<=1e9) cur*=tab[i].fi;
      |            ^~~
horses.cpp:81:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   81 |     return res;
      |            ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:18:8: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   18 |     ll pos;
      |        ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:41:8: warning: 'ps' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |     ll ps;
      |        ^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:64:8: warning: 'ps' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |     ll ps;
      |        ^~
#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...