Submission #132514

#TimeUsernameProblemLanguageResultExecution timeMemory
132514antimirageHorses (IOI15_horses)C++14
54 / 100
428 ms62328 KiB
#include "horses.h" #include <bits/stdc++.h> #define fr first #define sc second #define mk make_pair #define pb push_back #define all(s) s.begin(), s.end() using namespace std; const int N = 5e5 + 5, mod = 1e9 + 7; int a[N], b[N], pr[N], n; double pref[N], eps = 0; struct asd { int val, must; double mx, add; asd() { must = 1; } }; asd t[N * 4]; void build (int v = 1, int tl = 0, int tr = n - 1) { if (tl == tr) { t[v].val = pr[tl] * 1ll * b[tl] % mod; t[v].mx = pref[tl] + log10(b[tl] + eps); } else { int tm = (tl + tr) >> 1; build(v + v, tl, tm); build(v + v + 1, tm + 1, tr); if (t[v + v].mx > t[v + v + 1].mx) { t[v].val = t[v + v].val; t[v].mx = t[v + v].mx; } else { t[v].val = t[v + v + 1].val; t[v].mx = t[v + v + 1].mx; } } } 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]; pref[i] = (i == 0 ? 0 : pref[i - 1]) + log10(a[i] + eps); pr[i] = (i == 0 ? 1 : pr[i - 1]) * 1ll * a[i] % mod; } build(); return t[1].val; } int binpow (int a, int b) { if (b == 0) return 1; if (b & 1) return binpow(a, b - 1) * 1ll * a % mod; int res = binpow(a, b >> 1); return res * 1ll * res % mod; } void push (int v, int tl, int tr) { t[v].mx += t[v].add; t[v].val = t[v].val * 1ll * t[v].must % mod; if (tl != tr) { t[v + v].add += t[v].add; t[v + v + 1].add += t[v].add; t[v + v].must = t[v + v].must * 1ll * t[v].must % mod; t[v + v + 1].must = t[v + v + 1].must * 1ll * t[v].must % mod; } t[v].must = 1; t[v].add = 0; } void update (int l, int r, double val, int mult, int v = 1, int tl = 0, int tr = n - 1) { push(v, tl, tr); if (l > tr || tl > r) return; if (l <= tl && tr <= r) { t[v].add += val; t[v].must = t[v].must * 1ll * mult % mod; push(v, tl, tr); return; } int tm = (tl + tr) >> 1; update(l, r, val, mult, v + v, tl, tm); update(l, r, val, mult, v + v + 1, tm + 1, tr); if (t[v + v].mx > t[v + v + 1].mx) { t[v].val = t[v + v].val; t[v].mx = t[v + v].mx; } else { t[v].val = t[v + v + 1].val; t[v].mx = t[v + v + 1].mx; } } int updateX(int pos, int val) { update(pos, n - 1, -log10(a[pos] + eps), binpow(a[pos], mod - 2) ); a[pos] = val; update(pos, n - 1, log10(a[pos] + eps), a[pos]); return t[1].val; } int updateY(int pos, int val) { update(pos, pos, -log10(b[pos] + eps), binpow(b[pos], mod - 2)); b[pos] = val; update(pos, pos, log10(b[pos] + eps), b[pos]); return t[1].val; }

Compilation message (stderr)

horses.cpp: In function 'void build(int, int, int)':
horses.cpp:31:35: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   t[v].val = pr[tl] * 1ll * b[tl] % mod;
              ~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:48:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 int init(int N, int X[], int Y[]) {
                                 ^
horses.cpp:12:11: note: shadowed declaration is here
 const int N = 5e5 + 5, mod = 1e9 + 7;
           ^
horses.cpp:54:49: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   pr[i] = (i == 0 ? 1 : pr[i - 1]) * 1ll * a[i] % mod;
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int binpow(int, int)':
horses.cpp:60:25: warning: declaration of 'b' shadows a global declaration [-Wshadow]
 int binpow (int a, int b) {
                         ^
horses.cpp:14:11: note: shadowed declaration is here
 int a[N], b[N], pr[N], n;
           ^
horses.cpp:60:25: warning: declaration of 'a' shadows a global declaration [-Wshadow]
 int binpow (int a, int b) {
                         ^
horses.cpp:14:5: note: shadowed declaration is here
 int a[N], b[N], pr[N], n;
     ^
horses.cpp:64:37: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   return binpow(a, b - 1) * 1ll * a % mod;
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:67:25: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return res * 1ll * res % mod;
         ~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void push(int, int, int)':
horses.cpp:71:40: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  t[v].val = t[v].val * 1ll * t[v].must % mod;
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:76:51: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   t[v + v].must = t[v + v].must * 1ll * t[v].must % mod;
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:77:59: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   t[v + v + 1].must = t[v + v + 1].must * 1ll * t[v].must % mod;
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void update(int, int, double, int, int, int, int)':
horses.cpp:88:38: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
   t[v].must = t[v].must * 1ll * mult % mod;
               ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
#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...