Submission #28071

#TimeUsernameProblemLanguageResultExecution timeMemory
28071top34051Horses (IOI15_horses)C++14
100 / 100
1153 ms146576 KiB
#include "horses.h" #include<bits/stdc++.h> using namespace std; #define maxn 1000005 #define pdl pair<double,long long> #define mod (long long)1000000007 int n; long long a[maxn]; long long b[maxn]; pdl tree[maxn*4]; pdl lazy[maxn*4]; pdl fus(pdl x,pdl y) { return {x.first+y.first,(x.second*y.second+mod)%mod}; } long long inv(long long value){ if(value == 1) return 1; long long tmp = (inv(mod%value)*((-mod)/value)); tmp %= mod; if(tmp < 0) tmp += mod; return tmp; } void upd(int now) { tree[now] = fus(tree[now],lazy[now]); lazy[now<<1] = fus(lazy[now<<1],lazy[now]); lazy[now<<1|1] = fus(lazy[now<<1|1],lazy[now]); lazy[now] = {0,1}; } void update(int now,int l,int r,int x,int y,double val1,long long val2) { upd(now); if(l>r || l>y || r<x) return ; if(x<=l && r<=y) { lazy[now] = {val1,val2}; upd(now); return ; } int mid = (l+r)/2; update(now<<1,l,mid,x,y,val1,val2); update(now<<1|1,mid+1,r,x,y,val1,val2); tree[now] = max(tree[now<<1],tree[now<<1|1]); } void build(int now,int l,int r) { if(l==r) { tree[now] = lazy[now] = {0,1}; return ; } int mid = (l+r)/2; build(now<<1,l,mid); build(now<<1|1,mid+1,r); tree[now] = lazy[now] = {0,1}; } 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]; build(1,0,n-1); for(int i=0;i<n;i++) update(1,0,n-1,i,n-1,(double)log2(a[i]),a[i]); for(int i=0;i<n;i++) update(1,0,n-1,i,i,(double)log2(b[i]),b[i]); upd(1); return tree[1].second; } int updateX(int pos, int val) { update(1,0,n-1,pos,n-1,-(double)log2(a[pos]),inv(a[pos])); a[pos] = val; update(1,0,n-1,pos,n-1,(double)log2(a[pos]),a[pos]); upd(1); return tree[1].second; } int updateY(int pos, int val) { update(1,0,n-1,pos,pos,-(double)log2(b[pos]),inv(b[pos])); b[pos] = val; update(1,0,n-1,pos,pos,(double)log2(b[pos]),b[pos]); upd(1); return tree[1].second; }

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:63:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return tree[1].second;
                 ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:71:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return tree[1].second;
                 ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:79:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return tree[1].second;
                 ^
#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...