# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
341047 |
2020-12-28T23:57:35 Z |
12tqian |
Horses (IOI15_horses) |
C++17 |
|
1025 ms |
49772 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
template <int MOD, int RT> struct Mint {
static const int mod = MOD;
static constexpr Mint rt() { return RT; } // primitive root for FFT
int v;
explicit operator int() const { return v; } // explicit -> don't silently convert to int
Mint() { v = 0; }
Mint(long long _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD); if (v < 0) v += MOD; }
friend bool operator == (const Mint& a, const Mint& b) { return a.v == b.v; }
friend bool operator != (const Mint& a, const Mint& b) { return !(a == b); }
friend bool operator < (const Mint& a, const Mint& b) { return a.v < b.v; }
friend bool operator > (const Mint& a, const Mint& b) { return a.v > b.v; }
friend bool operator <= (const Mint& a, const Mint& b) { return a.v <= b.v; }
friend bool operator >= (const Mint& a, const Mint& b) { return a.v >= b.v; }
friend std::istream& operator >> (std::istream& in, Mint& a) {
long long x; std::cin >> x; a = Mint(x); return in; }
friend std::ostream& operator << (std::ostream& os, const Mint& a) { return os << a.v; }
Mint& operator += (const Mint& m) {
if ((v += m.v) >= MOD) v -= MOD;
return *this; }
Mint& operator -= (const Mint& m) {
if ((v -= m.v) < 0) v += MOD;
return *this; }
Mint& operator *= (const Mint& m) {
v = (long long ) v * m.v % MOD; return *this; }
Mint& operator /= (const Mint& m) { return (*this) *= inv(m); }
friend Mint pow(Mint a, long long p) {
Mint ans = 1; assert(p >= 0);
for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
return ans;
}
friend Mint inv(const Mint& a) { assert(a.v != 0); return pow(a, MOD - 2); }
Mint operator - () const { return Mint(-v); }
Mint& operator ++ () { return *this += 1; }
Mint& operator -- () { return *this -= 1; }
friend Mint operator + (Mint a, const Mint& b) { return a += b; }
friend Mint operator - (Mint a, const Mint& b) { return a -= b; }
friend Mint operator * (Mint a, const Mint& b) { return a *= b; }
friend Mint operator / (Mint a, const Mint& b) { return a /= b; }
};
using mi = Mint<MOD, 5>;
typedef double db;
template <class T> struct LazySeg {
std::vector<T> mn, lazy;
vector<int> id;
int sz;
void init(int sz_) {
sz = 1;
while (sz < sz_) sz *= 2;
mn.assign(2 * sz, 0);
lazy.assign(2 * sz, 0);
id.assign(2 * sz, 0);
for (int i = 0; i < sz; i++)
id[i + sz] = i;
build();
}
void push(int ind, int L, int R) {
mn[ind] += lazy[ind];
if (L != R) {
lazy[2 * ind] += lazy[ind];
lazy[2 * ind + 1] += lazy[ind];
}
lazy[ind] = 0;
}
void pull(int ind) {
if (mn[2 * ind] >= mn[2 * ind + 1]) {
mn[ind] = mn[2 * ind];
id[ind] = id[2 * ind];
} else {
mn[ind] = mn[2 *ind + 1];
id[ind] = id[2 * ind + 1];
}
}
void build() {
for (int i = sz - 1; i >= 1; i--) {
pull(i);
}
}
void upd(int lo, int hi, T inc, int ind = 1, int L = 0, int R = -1) {
if (R == -1) R += sz;
push(ind, L, R);
if (hi < L || R < lo) return;
if (lo <= L && R <= hi) {
lazy[ind] = inc;
push(ind, L, R);
return;
}
int M = (L + R) / 2;
upd(lo, hi, inc, 2 * ind, L, M);
upd(lo, hi, inc, 2 * ind + 1, M + 1, R);
pull(ind);
}
pair<T, int> qmin(int lo, int hi, int ind = 1, int L = 0, int R = -1) {
if (R == -1) R += sz;
push(ind, L, R);
if (lo > R || L > hi) return {0, id[ind]};
if (lo <= L && R <= hi) return {mn[ind], id[ind]};
int M = (L + R) / 2;
return max(qmin(lo, hi, 2 * ind, L, M), qmin(lo, hi, 2 * ind + 1, M + 1, R));
}
};
template <class T> struct LazySegProd {
std::vector<T> mn, lazy;
int sz;
void init(int sz_) {
sz = 1;
while (sz < sz_) sz *= 2;
mn.assign(2 * sz, 1);
lazy.assign(2 * sz, 1);
}
void push(int ind, int L, int R) {
mn[ind] *= lazy[ind];
if (L != R) {
lazy[2 * ind] *= lazy[ind];
lazy[2 * ind + 1] *= lazy[ind];
}
lazy[ind] = 1;
}
void upd(int lo, int hi, T inc, int ind = 1, int L = 0, int R = -1) {
if (R == -1) R += sz;
push(ind, L, R);
if (hi < L || R < lo) return;
if (lo <= L && R <= hi) {
lazy[ind] = inc;
push(ind, L, R);
return;
}
int M = (L + R) / 2;
upd(lo, hi, inc, 2 * ind, L, M);
upd(lo, hi, inc, 2 * ind + 1, M + 1, R);
}
T qmin(int lo, int hi, int ind = 1, int L = 0, int R = -1) {
if (R == -1) R += sz;
push(ind, L, R);
if (lo > R || L > hi) return MOD - 1;
if (lo <= L && R <= hi) return mn[ind];
int M = (L + R) / 2;
return min(qmin(lo, hi, 2 * ind, L, M), qmin(lo, hi, 2 * ind + 1, M + 1, R));
}
};
int n;
LazySegProd<mi> seg_compute;
LazySeg<db> seg;
vector<int> x, y;
mi ask() {
int id = seg.qmin(0, n-1).second;
return seg_compute.qmin(id, id);
}
int init(int N, int X[], int Y[]) {
n = N;
seg_compute.init(n);
seg.init(n);
x.reserve(n), y.reserve(n);
mi run = 1;
db sum = 0;
for (int i = 0; i < n; i++) {
x[i] = X[i], y[i] = Y[i];
run *= x[i];
sum += log2(x[i]);
seg_compute.upd(i, i, run * y[i]);
seg.upd(i, i, sum + log2(y[i]));
}
return ask().v;
}
int updateX(int pos, int val) {
db diff = log2(val) - log2(x[pos]);
mi change = val / mi(x[pos]);
seg.upd(pos, n-1, diff);
seg_compute.upd(pos, n-1, change);
x[pos] = val;
return ask().v;
}
int updateY(int pos, int val) {
db diff = log2(val) - log2(y[pos]);
mi change = val / mi(y[pos]);
seg.upd(pos, pos, diff);
seg_compute.upd(pos, pos, change);
y[pos] = val;
return ask().v;
}
Compilation message
horses.cpp: In instantiation of 'Mint<MOD, RT>& Mint<MOD, RT>::operator*=(const Mint<MOD, RT>&) [with int MOD = 1000000007; int RT = 5]':
horses.cpp:167:19: required from here
horses.cpp:29:34: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
29 | v = (long long ) v * m.v % MOD; return *this; }
| ~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
2 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
3 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
758 ms |
38072 KB |
Output is correct |
2 |
Correct |
1025 ms |
38124 KB |
Output is correct |
3 |
Correct |
990 ms |
41712 KB |
Output is correct |
4 |
Correct |
1012 ms |
44524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
0 ms |
364 KB |
Output is correct |
20 |
Correct |
0 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
2 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
3 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
600 ms |
37100 KB |
Output is correct |
34 |
Correct |
613 ms |
37228 KB |
Output is correct |
35 |
Correct |
617 ms |
37100 KB |
Output is correct |
36 |
Correct |
624 ms |
37100 KB |
Output is correct |
37 |
Correct |
572 ms |
37056 KB |
Output is correct |
38 |
Correct |
599 ms |
37100 KB |
Output is correct |
39 |
Correct |
560 ms |
36972 KB |
Output is correct |
40 |
Correct |
597 ms |
37356 KB |
Output is correct |
41 |
Correct |
553 ms |
37228 KB |
Output is correct |
42 |
Correct |
550 ms |
37100 KB |
Output is correct |
43 |
Correct |
571 ms |
36972 KB |
Output is correct |
44 |
Correct |
567 ms |
36972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
0 ms |
364 KB |
Output is correct |
15 |
Correct |
0 ms |
364 KB |
Output is correct |
16 |
Correct |
0 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
2 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
3 ms |
364 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
3 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
3 ms |
364 KB |
Output is correct |
33 |
Correct |
769 ms |
38020 KB |
Output is correct |
34 |
Correct |
1010 ms |
38124 KB |
Output is correct |
35 |
Correct |
951 ms |
41836 KB |
Output is correct |
36 |
Correct |
1014 ms |
44240 KB |
Output is correct |
37 |
Correct |
610 ms |
40940 KB |
Output is correct |
38 |
Correct |
606 ms |
41052 KB |
Output is correct |
39 |
Correct |
622 ms |
41868 KB |
Output is correct |
40 |
Correct |
624 ms |
41964 KB |
Output is correct |
41 |
Correct |
574 ms |
39276 KB |
Output is correct |
42 |
Correct |
593 ms |
40156 KB |
Output is correct |
43 |
Correct |
551 ms |
39020 KB |
Output is correct |
44 |
Correct |
600 ms |
42860 KB |
Output is correct |
45 |
Correct |
549 ms |
39020 KB |
Output is correct |
46 |
Correct |
550 ms |
39156 KB |
Output is correct |
47 |
Correct |
573 ms |
43492 KB |
Output is correct |
48 |
Correct |
569 ms |
43244 KB |
Output is correct |
49 |
Correct |
971 ms |
43100 KB |
Output is correct |
50 |
Correct |
970 ms |
43204 KB |
Output is correct |
51 |
Correct |
819 ms |
49772 KB |
Output is correct |
52 |
Correct |
876 ms |
49516 KB |
Output is correct |
53 |
Correct |
959 ms |
41572 KB |
Output is correct |
54 |
Correct |
917 ms |
41864 KB |
Output is correct |
55 |
Correct |
787 ms |
40300 KB |
Output is correct |
56 |
Correct |
870 ms |
44956 KB |
Output is correct |
57 |
Correct |
756 ms |
40812 KB |
Output is correct |
58 |
Correct |
762 ms |
41324 KB |
Output is correct |
59 |
Correct |
577 ms |
43244 KB |
Output is correct |