Submission #139868

#TimeUsernameProblemLanguageResultExecution timeMemory
139868PlurmHorses (IOI15_horses)C++11
17 / 100
1583 ms58224 KiB
#include "horses.h" #include <bits/stdc++.h> using namespace std; multimap<long double, int> mm; const int MOD = 1e9+7; long double FT1[500005]; int FT2[500005]; int modpow(int base, int expo){ if(expo == 0) return 1; int res = modpow(base, expo/2); if(expo % 2 == 0){ return (1ll * res * res) % MOD; }else{ return 1ll * ((1ll * res * res) % MOD) * base % MOD; } } int invmod(int x){ return modpow(x, MOD-2); } void sub(int idx, int amt){ idx++; while(idx < 500005){ FT1[idx] -= log2l(amt); FT2[idx] = (1ll * FT2[idx] * invmod(amt)) % MOD; idx += idx & -idx; } } void add(int idx, int amt){ idx++; while(idx < 500005){ FT1[idx] += log2l(amt); FT2[idx] = (1ll * FT2[idx] * amt) % MOD; idx += idx & -idx; } } long double sum1(int idx){ idx++; long double ret = 0; while(idx > 0){ ret += FT1[idx]; idx -= idx & -idx; } return ret; } int sum2(int idx){ idx++; int ret = 1; while(idx > 0){ ret = (1ll * ret * FT2[idx]) % MOD; idx -= idx & -idx; } return ret; } int rx[500005]; int ry[500005]; int answer(){ return mm.rbegin()->second; } int init(int N, int X[], int Y[]) { for(int i = 0; i < N; i++){ rx[i] = X[i]; ry[i] = Y[i]; } for(int i = 0; i < 500005; i++) FT2[i] = 1; for(int i = 0; i < N; i++){ add(i, X[i]); } for(int i = 0; i < N; i++){ mm.insert(make_pair(sum1(i) + log2l(Y[i]), (int)((1ll * sum2(i) * Y[i]) % MOD))); } return answer(); } int updateX(int pos, int val) { if(mm.find(sum1(pos) + log2l(ry[pos])) == mm.end()) while(true); mm.erase(mm.find(sum1(pos) + log2l(ry[pos]))); sub(pos, rx[pos]); add(pos, val); rx[pos] = val; mm.insert(make_pair(sum1(pos) + log2l(ry[pos]), (int)((1ll * sum2(pos) * ry[pos]) % MOD))); return answer(); } int updateY(int pos, int val) { if(mm.find(sum1(pos) + log2l(ry[pos])) == mm.end()) while(true); mm.erase(mm.find(sum1(pos) + log2l(ry[pos]))); ry[pos] = val; mm.insert(make_pair(sum1(pos) + log2l(ry[pos]), (int)((1ll * sum2(pos) * ry[pos]) % MOD))); return answer(); }

Compilation message (stderr)

horses.cpp: In function 'int modpow(int, int)':
horses.cpp:13:34: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         return (1ll * res * res) % MOD;
                ~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:15:55: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         return 1ll * ((1ll * res * res) % MOD) * base % MOD;
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void sub(int, int)':
horses.cpp:25:51: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         FT2[idx] = (1ll * FT2[idx] * invmod(amt)) % MOD;
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void add(int, int)':
horses.cpp:33:43: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         FT2[idx] = (1ll * FT2[idx] * amt) % MOD;
                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int sum2(int)':
horses.cpp:50:38: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         ret = (1ll * ret * FT2[idx]) % MOD;
               ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:78:55: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   if(mm.find(sum1(pos) + log2l(ry[pos])) == mm.end()) while(true);
                                                       ^~~~~
horses.cpp:79:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
     mm.erase(mm.find(sum1(pos) + log2l(ry[pos])));
     ^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:88:55: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   if(mm.find(sum1(pos) + log2l(ry[pos])) == mm.end()) while(true);
                                                       ^~~~~
horses.cpp:89:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
     mm.erase(mm.find(sum1(pos) + log2l(ry[pos])));
     ^~
#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...