Submission #1039820

#TimeUsernameProblemLanguageResultExecution timeMemory
1039820ZicrusHorses (IOI15_horses)C++17
17 / 100
46 ms23128 KiB
#include <bits/stdc++.h> #include "horses.h" using namespace std; typedef long long ll; ll n, pow2; vector<ll> segMul; vector<bool> segOF; vector<ll> x, y; #define OF (1ll << 30ll) #define MOD (1000000007) void setX(int pos, int val) { x[pos] = val; pos += pow2; segMul[pos] = val; pos /= 2; while (pos) { segMul[pos] = segMul[2*pos] * segMul[2*pos+1]; if (segOF[2*pos] || segOF[2*pos+1] || segMul[pos] > OF) { segMul[pos] %= MOD; segOF[pos] = true; } pos /= 2; } } int getOFId(int i = 1, ll prod = 1) { if (i >= pow2) return i-pow2; if (segOF[2*i+1] || segMul[2*i+1] * prod >= OF) return getOFId(2*i+1, prod); return getOFId(2*i, prod * segMul[2*i+1]); } int getMulMod(int i) { int low = pow2, high = pow2+i; ll res = 1; while (low <= high) { if (low & 1) res = (res * segMul[low++]) % MOD; if (!(high & 1)) res = (res * segMul[high--]) % MOD; low /= 2; high /= 2; } return res % MOD; } int calc() { ll ofId = getOFId(); ll mx = 0; ll mxRes = 0; ll offCnt = getMulMod(ofId++); ll tCnt = 1; if (!segOF[1]) { offCnt = 1; ofId = 0; } for (int i = ofId; i < n; i++) { offCnt *= x[i]; offCnt %= MOD; tCnt *= x[i]; ll val = tCnt * y[i]; if (val > mx) { mx = val; mxRes = (offCnt * y[i]) % MOD; } } return mxRes; } int init(int N, int X[], int Y[]) { n = N; pow2 = 1ll << (ll)ceil(log2(n)); x = vector<ll>(n); y = vector<ll>(n); for (int i = 0; i < n; i++) { x[i] = X[i]; y[i] = Y[i]; } segMul = vector<ll>(2*pow2, 1); segOF = vector<bool>(2*pow2); for (int i = 0; i < n; i++) { segMul[pow2+i] = X[i]; } for (int i = pow2-1; i > 0; i--) { segMul[i] = segMul[2*i] * segMul[2*i+1]; if (segOF[2*i] || segOF[2*i+1] || segMul[i] >= OF) { segMul[i] %= MOD; segOF[i] = true; } } return calc(); } int updateX(int pos, int val) { setX(pos, val); return calc(); } int updateY(int pos, int val) { y[pos] = val; return calc(); }

Compilation message (stderr)

horses.cpp: In function 'void setX(int, int)':
horses.cpp:17:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   17 |     pos += pow2;
      |     ~~~~^~~~~~~
horses.cpp: In function 'int getOFId(int, ll)':
horses.cpp:31:28: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   31 |     if (i >= pow2) return i-pow2;
      |                           ~^~~~~
horses.cpp: In function 'int getMulMod(int)':
horses.cpp:37:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   37 |     int low = pow2, high = pow2+i;
      |               ^~~~
horses.cpp:37:32: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   37 |     int low = pow2, high = pow2+i;
      |                            ~~~~^~
horses.cpp:44:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   44 |     return res % MOD;
      |                ^
horses.cpp: In function 'int calc()':
horses.cpp:51:31: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   51 |     ll offCnt = getMulMod(ofId++);
      |                           ~~~~^~
horses.cpp:57:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   57 |     for (int i = ofId; i < n; i++) {
      |                  ^~~~
horses.cpp:67:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   67 |     return mxRes;
      |            ^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:83:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   83 |     for (int i = pow2-1; i > 0; i--) {
      |                  ~~~~^~
#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...