Submission #380059

#TimeUsernameProblemLanguageResultExecution timeMemory
380059idk321Horses (IOI15_horses)C++11
34 / 100
1582 ms16380 KiB
#include "horses.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1000000007; const int N = 500000; const int R = 710; int n; int* x; int* y; int best[R]; ll left1[R][R]; ll right1[R][R]; void spMod(ll& num) { if (num >= mod) { num %= mod; num += mod; } } ll getBest() { ll cbest = left1[0][best[0]] % mod; cbest *= y[best[0]]; cbest %= mod; int ci = best[0]; ll fac = 1; if (ci != min(R - 1, n - 1)) fac *= right1[0][ci + 1]; spMod(fac); ll facAll = left1[0][R - 1]; facAll %= mod; for (int a = R; a < n; a += R) { int i = best[a / R]; fac *= left1[a / R][i % R]; spMod(fac); facAll *= left1[a / R][i % R]; facAll %= mod; if (fac * y[i] > y[ci]) { cbest = facAll * y[i]; cbest %= mod; ci = i; fac = 1; } if (i + 1 != min(n - 1, a + R - 1)) { fac *= right1[a / R][(i + 1) % R]; spMod(fac); facAll *= right1[a / R][(i + 1) % R]; facAll %= mod; } } return cbest; } void makeBlock(int block) { int ci = block * R; ll fac = 1; for (int i = block * R + 1; i < min(n, (block + 1) * R); i++) { fac *= x[i]; spMod(fac); if (fac > y[ci] || fac * y[i] > y[ci]) { ci = i; fac = 1; } } fac = 1; for (int i = 0; i < R; i++) { if (i + block * R >= n) continue; fac *= x[i + block * R]; if (fac >= mod) { fac %= mod; fac += mod; } left1[block][i] = fac; } fac = 1; for (int i = R - 1; i >= 0; i--) { if (i + block * R >= n) continue; fac *= x[i + block * R]; if (fac >= mod) { fac %= mod; fac += mod; } right1[block][i] = fac; } best[block] = ci; } int init(int N, int X[], int Y[]) { n = N; x = X; y = Y; for (int a = 0; a < R && a * R < n; a++) { makeBlock(a); } //cout << best[0] << endl; return getBest(); } int updateX(int pos, int val) { x[pos] = val; makeBlock(pos / R); return getBest(); } int updateY(int pos, int val) { y[pos] = val; makeBlock(pos / R); return getBest(); }

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:124:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
  124 | int init(int N, int X[], int Y[]) {
      |                                 ^
horses.cpp:9:11: note: shadowed declaration is here
    9 | const int N = 500000;
      |           ^
horses.cpp:135:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  135 |  return getBest();
      |         ~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:145:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  145 |  return getBest();
      |         ~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:154:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  154 |  return getBest();
      |         ~~~~~~~^~
#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...