Submission #929086

#TimeUsernameProblemLanguageResultExecution timeMemory
929086OAleksaHorses (IOI15_horses)C++14
34 / 100
1577 ms13916 KiB
#include "horses.h" #include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int inf = 1e9 + 69; const int N = 5e5 + 69; int n, a[N], b[N], c[N]; int mul(int a, int b) { long long r = 1ll * a * b; if (r >= mod) r %= mod; return r; } int Solve() { /* int ptr = n - 1, s = a[n - 1]; c[n - 1] = n - 1; for (int i = n - 2;i >= 0;i--) { if (a[i] > inf / s) { while (a[i] > inf / s) { s /= a[ptr]; ptr--; } c[i] = ptr; } else { c[i] = c[i + 1]; s *= a[i]; } }*/ long long ans = 1, x = a[0]; int bst = 0; for (int i = 1;i < n;i++) { if (x > inf / a[i]) { x = 1; bst = i; } else { x *= a[i]; if (b[i] > b[bst] / x) { x = 1; bst = i; } } } for (int i = 0;i <= bst;i++) ans = mul(ans, a[i]); return mul(ans, b[bst]); } int init(int N, int X[], int Y[]) { n = N; for (int i = 0;i < n;i++) a[i] = X[i], b[i] = Y[i]; return Solve(); } int updateX(int pos, int val) { a[pos] = val; return Solve(); } int updateY(int pos, int val) { b[pos] = val; return Solve(); } /* 3 2 1 3 3 4 1 1 2 1 2 */

Compilation message (stderr)

horses.cpp: In function 'int mul(int, int)':
horses.cpp:8:20: warning: declaration of 'b' shadows a global declaration [-Wshadow]
    8 | int mul(int a, int b) {
      |                ~~~~^
horses.cpp:7:14: note: shadowed declaration is here
    7 | int n, a[N], b[N], c[N];
      |              ^
horses.cpp:8:13: warning: declaration of 'a' shadows a global declaration [-Wshadow]
    8 | int mul(int a, int b) {
      |         ~~~~^
horses.cpp:7:8: note: shadowed declaration is here
    7 | int n, a[N], b[N], c[N];
      |        ^
horses.cpp:12:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   12 |    return r;
      |           ^
horses.cpp: In function 'int Solve()':
horses.cpp:47:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   47 |       ans = mul(ans, a[i]);
      |                 ^~~
horses.cpp:48:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   48 |    return mul(ans, b[bst]);
      |               ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:50:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   50 | int init(int N, int X[], int Y[]) {
      |          ~~~~^
horses.cpp:6:11: note: shadowed declaration is here
    6 | const int N = 5e5 + 69;
      |           ^
#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...