Submission #1121844

#TimeUsernameProblemLanguageResultExecution timeMemory
1121844SalihSahinHorses (IOI15_horses)C++14
0 / 100
39 ms25804 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; #include "horses.h" const long long mod = 1e9 + 7; const long long inf = 1e18 + 20; vector<array<long long, 2> > arr; int n; array<long long, 2> comp(array<long long, 2> a, array<long long, 2> b){ if(inf / a[0] >= a[1] && inf / b[0] >= b[1]){ if(a[0] * a[1] > b[0] * b[1]) return a; else return b; } if(inf / a[0] < a[1] && inf / b[0] < b[1]){ return a; } if(inf / a[0] < a[1]) return a; else return b; } int init(int N, int X[], int Y[]) { arr.resize(N); n = N; for(int i = 0; i < N; i++){ arr[i] = {X[i], Y[i]}; } long long vl = 1; int ind = 0; for(int i = N-1; i >= 0; i--){ vl *= arr[i][0]; if(vl > mod){ ind = i; break; } } vl = 1; long long precarp = 1; for(int i = 0; i < ind; i++){ precarp = (precarp * arr[i][0])%mod; } array<long long, 2> ans = {0LL, 0LL}; for(int i = ind; i < N; i++){ vl *= arr[i][0]; ans = comp(ans, {vl, arr[i][1]}); } long long calc = (ans[0]%mod) * (ans[1]%mod); calc %= mod; calc *= precarp; calc %= mod; int res = calc; return res; } int updateX(int pos, int val) { int N = n; arr[pos][0] = val; long long vl = 1; int ind = 0; for(int i = N-1; i >= 0; i--){ vl *= arr[i][0]; if(vl > mod){ ind = i; break; } } vl = 1; long long precarp = 1; for(int i = 0; i < ind; i++){ precarp = (precarp * arr[i][0])%mod; } array<long long, 2> ans = {0LL, 0LL}; for(int i = ind; i < N; i++){ vl *= arr[i][0]; ans = comp(ans, {vl, arr[i][1]}); } long long calc = (ans[0]%mod) * (ans[1]%mod); calc %= mod; calc *= precarp; calc %= mod; int res = calc; return res; } int updateY(int pos, int val){ int N = n; arr[pos][1] = val; long long vl = 1; int ind = 0; for(int i = N-1; i >= 0; i--){ vl *= arr[i][0]; if(vl > mod){ ind = i; break; } } vl = 1; long long precarp = 1; for(int i = 0; i < ind; i++){ precarp = (precarp * arr[i][0])%mod; } array<long long, 2> ans = {0LL, 0LL}; for(int i = ind; i < N; i++){ vl *= arr[i][0]; ans = comp(ans, {vl, arr[i][1]}); } long long calc = (ans[0]%mod) * (ans[1]%mod); calc %= mod; calc *= precarp; calc %= mod; int res = calc; return res; }

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:55:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   55 |     int res = calc;
      |               ^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:86:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   86 |     int res = calc;
      |               ^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:117:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  117 |     int res = calc;
      |               ^~~~
#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...