Submission #320373

#TimeUsernameProblemLanguageResultExecution timeMemory
320373nikatamlianiHorses (IOI15_horses)C++14
0 / 100
1580 ms31688 KiB
#include <bits/stdc++.h> #include "horses.h" #define ll long long using namespace std; const ll MOD = 1e9 + 7, MAXN = 5e5 + 10; set < int > s; int X[MAXN], Y[MAXN], N; int solve() { vector < int > v; for(int x : s) { v.push_back(-x); if(v.size() == 30) break; } reverse(v.begin(), v.end()); v.push_back(N); ll product = 1, answer = 0; for(int i = 0; i < (int) v.size() - 1; ++i) { product *= X[v[i]]; ll maximum = 0; for(int j = v[i]; j < v[i + 1]; ++j) { maximum = max(maximum, (ll)Y[j]); } answer = max(answer, maximum * product); } answer %= MOD; if(!v.empty()) { for(int i = 0; i < v[0]; ++i) { answer *= X[i]; answer %= MOD; } } return answer; } int updateX(int pos, int val) { if(X[pos] > 1) s.erase(s.find(-pos)); X[pos] = val; if(X[pos] > 1) s.insert(-pos); return solve(); } int updateY(int pos, int val) { Y[pos] = val; return solve(); } int init(int _N, int _X[], int _Y[]) { N = _N; for(int i = 0; i < N; ++i) { X[i] = _X[i]; Y[i] = _Y[i]; if(X[i] > 1) s.insert(-i); } return solve(); } // int main() { // int X[] = {2, 1, 3}; // int Y[] = {3, 4, 1}; // cout << init(3, X, Y) << '\n'; // cout << updateY(1, 2) << '\n'; // }

Compilation message (stderr)

horses.cpp: In function 'int solve()':
horses.cpp:32:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   32 |     return answer;
      |            ^~~~~~
#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...