Submission #130358

#TimeUsernameProblemLanguageResultExecution timeMemory
130358jovan_bHorses (IOI15_horses)C++17
17 / 100
197 ms61636 KiB
#include "horses.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; struct drvo{ double val; double lazy; ll prod; ll lazyprod; } seg[4000000]; double x[1000005]; double y[1000005]; double xpref[1000005]; ll u1[1000005]; ll xprod[1000005]; ll x1[1000005]; ll n; const int MOD = 1000000007; ll mul(ll a, ll b){ return (1LL*a*b)%MOD; } ll pw(ll a, ll b){ if(b == 0) return 1; ll res = pw(a, b/2); res = (res*res)%MOD; if(b%2) res = (res*a)%MOD; return res; } /* ll pww(double x){ ll y = x; x -= y; double res = pw(2, y); double jos = pow(2, x); res *= jos; return round(res); }*/ void seginit(ll node, ll l, ll r){ seg[node].lazyprod = 1; if(l == r){ seg[node].val = xpref[l] + y[l]; seg[node].prod = mul(xprod[l], u1[l]); return; } ll mid = (l+r)/2; seginit(node*2, l, mid); seginit(node*2+1, mid+1, r); if(seg[node*2].val > seg[node*2+1].val){ seg[node].val = seg[node*2].val; seg[node].prod = seg[node*2].prod; } else{ seg[node].val = seg[node*2+1].val; seg[node].prod = seg[node*2+1].prod; } } void propagate(ll node, ll l, ll r){ seg[node].val += seg[node].lazy; seg[node].prod = mul(seg[node].prod, seg[node].lazyprod); if(l == r){ seg[node].lazy = 0; seg[node].lazyprod = 1; return; } seg[node*2].lazy += seg[node].lazy; seg[node*2].lazyprod = mul(seg[node*2].lazyprod, seg[node].lazyprod); seg[node*2+1].lazy += seg[node].lazy; seg[node*2+1].lazyprod = mul(seg[node*2+1].lazyprod, seg[node].lazyprod); seg[node].lazy = 0; seg[node].lazyprod = 1; } void upd(ll node, ll l, ll r, ll tl, ll tr, double val, ll prod){ propagate(node, l, r); if(l > tr || tl > r) return; if(tl <= l && r <= tr){ seg[node].lazy += val; seg[node].lazyprod = mul(seg[node].lazyprod, prod); propagate(node, l, r); return; } ll mid = (l+r)/2; upd(node*2, l, mid, tl, tr, val, prod); upd(node*2+1, mid+1, r, tl, tr, val, prod); if(seg[node*2].val > seg[node*2+1].val){ seg[node].val = seg[node*2].val; seg[node].prod = seg[node*2].prod; } else{ seg[node].val = seg[node*2+1].val; seg[node].prod = seg[node*2+1].prod; } } int init(int N, int X[], int Y[]) { n = N; xprod[0] = 1; for(ll i=0; i<N; i++){ x[i+1] = log(X[i]); x1[i+1] = X[i]; xpref[i+1] = x[i+1] + xpref[i]; xprod[i+1] = mul(xprod[i], X[i]); y[i+1] = log(Y[i]); u1[i+1] = Y[i]; //cout << xpref[i] << " " << y[i+1] << endl; } seginit(1, 1, n); //cout << seg[1].val << endl; return seg[1].prod; } int updateX(int pos, int val){ pos++; double g = x[pos]; x[pos] = log(val); ll f = x1[pos]; x1[pos] = val; upd(1, 1, n, pos, n, x[pos]-g, mul(x1[pos], pw(f, MOD-2))); return seg[1].prod; } int updateY(int pos, int val) { pos++; double g = y[pos]; y[pos] = log(val); ll f = u1[pos]; u1[pos] = val; upd(1, 1, n, pos, pos, y[pos]-g, pw(f, MOD-2)); return seg[1].prod; }

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:120:19: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
     return seg[1].prod;
            ~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:130:16: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return seg[1].prod;
         ~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:140:16: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return seg[1].prod;
         ~~~~~~~^~~~
#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...