Submission #174667

#TimeUsernameProblemLanguageResultExecution timeMemory
174667mat_vHorses (IOI15_horses)C++14
54 / 100
389 ms70028 KiB
#include <bits/stdc++.h> #include "horses.h" #define mod 1000000007 #define maxn 5000005 #define xx first #define yy second using namespace std; typedef long long ll; typedef pair<double,ll>pdl; ll add(ll x, ll y){ return (x + y)%mod; } bool preso = 0; ll mul(ll x, ll y){ if(x * y >= mod)preso = 1; return (x * y)%mod; } ll power(ll x, ll y){ if(y == 0)return 1; ll pola = power(x, y / 2); pola = mul(pola, pola); if(y%2 == 1)pola = mul(pola, x); return pola; } ll inverz(ll x){ return power(x, mod - 2); } int n; ll x[maxn]; ll y[maxn]; double lgx[maxn]; double lgy[maxn]; double niz[maxn]; ll pro[4 * maxn]; /// struct cvor{ double lg; ll pref; int poz; double lazylg; ll lazy; }seg[4 * maxn]; void seginit(int node, int l, int r){ seg[node].lazy = 1; if(l == r){ seg[node].lg = niz[l]; seg[node].poz = l; seg[node].pref = pro[l]; return; } int mid = (l + r) / 2; seginit(node * 2, l, mid); seginit(node * 2 + 1, mid + 1, r); if(seg[node * 2].lg > seg[node * 2 + 1].lg)seg[node].pref = seg[node * 2].pref; else seg[node].pref = seg[node * 2 + 1].pref; seg[node].lg = max(seg[node * 2].lg, seg[node * 2 + 1].lg); } void propagate(int node, int l, int r){ seg[node].lg += seg[node].lazylg; seg[node].pref = mul(seg[node].pref, seg[node].lazy); if(l != r){ seg[node * 2].lazylg += seg[node].lazylg; seg[node * 2 + 1].lazylg += seg[node].lazylg; seg[node * 2].lazy = mul(seg[node * 2].lazy, seg[node].lazy); seg[node * 2 + 1].lazy = mul(seg[node * 2 + 1].lazy, seg[node].lazy); } seg[node].lazylg = 0; seg[node].lazy = 1; } void update(int node, int l, int r, int levo, int desno, double lgval, ll val){ propagate(node, l, r); if(r < levo || desno < l)return; if(r <= desno && l >= levo){ seg[node].lazylg += lgval; seg[node].lazy = mul(seg[node].lazy, val); propagate(node, l, r); return; } int mid = (l + r) / 2; update(node * 2, l, mid, levo, desno, lgval, val); update(node * 2 + 1, mid + 1, r, levo, desno, lgval, val); if(seg[node * 2].lg > seg[node * 2 + 1].lg)seg[node].pref = seg[node * 2].pref; else seg[node].pref = seg[node * 2 + 1].pref; seg[node].lg = max(seg[node * 2].lg, seg[node * 2 + 1].lg); } pdl query(int node, int l, int r, int levo, int desno){ propagate(node, l, r); if(desno < l || levo > r)return {0, 0}; if(l >= levo && r <= desno){ return {seg[node].lg, seg[node].pref}; } int mid = (l + r) / 2; pdl levi = query(node * 2, l, mid, levo, desno); pdl desni = query(node * 2 + 1, mid + 1, r, levo, desno); return max(levi, desni); } int init(int N, int X[], int Y[]) { n = N; y[0] = 1; for(int i=1; i<=n; i++){ x[i] = X[i - 1]; y[i] = Y[i - 1]; lgx[i] = log(1.0 * x[i]); lgy[i] = log(1.0 * y[i]); } ll p = 1; for(int i=1; i<=n; i++){ niz[i] = niz[i - 1] - lgy[i - 1] + lgx[i] + lgy[i]; p = mul(p, x[i]); pro[i] = mul(p, y[i]); } seginit(1,1,n); return query(1,1,n,1,n).yy; } int updateX(int pos, int val){ pos++; update(1,1,n,pos,n,log(val) - lgx[pos], mul(val, inverz(x[pos]))); lgx[pos] = log(val); x[pos] = val; return query(1,1,n,1,n).yy; } int updateY(int pos, int val) { pos++; update(1,1,n,pos,pos,log(val) - lgy[pos], mul(val, inverz(y[pos]))); lgy[pos] = log(val); y[pos] = val; return query(1,1,n,1,n).yy; }

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:110:31: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
         lgx[i] = log(1.0 * x[i]);
                            ~~~^
horses.cpp:111:31: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
         lgy[i] = log(1.0 * y[i]);
                            ~~~^
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
 #define yy second
            ^
horses.cpp:120:29: note: in expansion of macro 'yy'
     return query(1,1,n,1,n).yy;
                             ^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
 #define yy second
            ^
horses.cpp:128:26: note: in expansion of macro 'yy'
  return query(1,1,n,1,n).yy;
                          ^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
 #define yy second
            ^
horses.cpp:136:26: note: in expansion of macro 'yy'
  return query(1,1,n,1,n).yy;
                          ^~
#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...