Submission #40283

# Submission time Handle Problem Language Result Execution time Memory
40283 2018-01-30T15:38:12 Z szawinis Horses (IOI15_horses) C++14
100 / 100
329 ms 41912 KB
#include "horses.h"
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;
const int N = 1 << 19;
const ll MOD = 1e9 + 7;

ll modPow(ll b, ll e) {
  if (!e)
    return 1;
  if (e == 1)
    return b;
  return modPow(b * b % MOD, e >> 1) * modPow(b, e & 1) % MOD;
}

struct node {
  double comp;
  ll val;
  void merge(node rhs) {
    comp += rhs.comp;
    val = 1ll * val * rhs.val % MOD;
  }
  bool operator>(const node &rhs) const {
		return make_pair(comp, val) > make_pair(rhs.comp, rhs.val);
  }
} t[2 * N], lz[2 * N];

void build(int i, int l, int r) {
	lz[i] = {0, 1};
  if (l == r)
    return;
  int mid = l + r >> 1;
  build(i << 1, l, mid);
  build(i << 1 | 1, mid + 1, r);
  if (t[i << 1] > t[i << 1 | 1])
    t[i] = t[i << 1];
  else
    t[i] = t[i << 1 | 1];
}

void apply(int i) {
  t[i].merge(lz[i]);
  if (i < N) {
    lz[i << 1].merge(lz[i]);
    lz[i << 1 | 1].merge(lz[i]);
  }
  lz[i].comp = 0, lz[i].val = 1;
}

void update(int i, int l, int r, int tl, int tr, node v) {
  apply(i);
  if (l > tr || r < tl)
    return;
  if (l >= tl && r <= tr) {
    lz[i].merge(v);
    apply(i);
    return;
  }
  int mid = l + r >> 1;
  update(i << 1, l, mid, tl, tr, v);
  update(i << 1 | 1, mid + 1, r, tl, tr, v);
  if (t[i << 1] > t[i << 1 | 1])
    t[i] = t[i << 1];
  else
    t[i] = t[i << 1 | 1];
}

int n, x[N], y[N];
int init(int _n, int _x[], int _y[]) {
  n = _n;
  copy(_x, _x + n, x);
  copy(_y, _y + n, y);
  node curr = {0, 1};
  for (int i = 0; i < n; i++) {
    curr.merge((node){(double)log2(x[i]), x[i]});
    t[N + i] = curr;
    t[N + i].merge((node){(double)log2(y[i]), y[i]});
  }
  build(1, 0, N - 1);
  return t[1].val;
}

int updateX(int pos, int val) {
  double ncomp = (double)log2(val) - (double)log2(x[pos]);
  ll nval = 1ll * val * modPow(x[pos], MOD - 2) % MOD;
	x[pos] = val;
  update(1, 0, N - 1, pos, N - 1, (node){ncomp, nval});
  return t[1].val;
}

int updateY(int pos, int val) {
  double ncomp = (double)log2(val) - (double)log2(y[pos]);
  ll nval = 1ll * val * modPow(y[pos], MOD - 2) % MOD;
	y[pos] = val;
  update(1, 0, N - 1, pos, pos, (node){ncomp, nval});
  return t[1].val;
}

Compilation message

horses.cpp: In function 'void build(int, int, int)':
horses.cpp:33:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1;
               ^
horses.cpp: In function 'void update(int, int, int, int, int, node)':
horses.cpp:60:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1;
               ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:81:15: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
   return t[1].val;
               ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:89:15: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
   return t[1].val;
               ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:97:15: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
   return t[1].val;
               ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 38000 KB Output is correct
2 Correct 6 ms 38000 KB Output is correct
3 Correct 18 ms 38000 KB Output is correct
4 Correct 21 ms 38000 KB Output is correct
5 Correct 16 ms 38000 KB Output is correct
6 Correct 14 ms 38000 KB Output is correct
7 Correct 7 ms 38000 KB Output is correct
8 Correct 6 ms 38000 KB Output is correct
9 Correct 4 ms 38000 KB Output is correct
10 Correct 13 ms 38000 KB Output is correct
11 Correct 18 ms 38000 KB Output is correct
12 Correct 14 ms 38000 KB Output is correct
13 Correct 16 ms 38000 KB Output is correct
14 Correct 14 ms 38000 KB Output is correct
15 Correct 7 ms 38000 KB Output is correct
16 Correct 10 ms 38000 KB Output is correct
17 Correct 10 ms 38000 KB Output is correct
18 Correct 9 ms 38000 KB Output is correct
19 Correct 7 ms 38000 KB Output is correct
20 Correct 6 ms 38000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 38000 KB Output is correct
2 Correct 16 ms 38000 KB Output is correct
3 Correct 9 ms 38000 KB Output is correct
4 Correct 6 ms 38000 KB Output is correct
5 Correct 6 ms 38000 KB Output is correct
6 Correct 19 ms 38000 KB Output is correct
7 Correct 15 ms 38000 KB Output is correct
8 Correct 3 ms 38000 KB Output is correct
9 Correct 17 ms 38000 KB Output is correct
10 Correct 16 ms 38000 KB Output is correct
11 Correct 6 ms 38000 KB Output is correct
12 Correct 7 ms 38000 KB Output is correct
13 Correct 3 ms 38000 KB Output is correct
14 Correct 7 ms 38000 KB Output is correct
15 Correct 6 ms 38000 KB Output is correct
16 Correct 9 ms 38000 KB Output is correct
17 Correct 6 ms 38000 KB Output is correct
18 Correct 20 ms 38000 KB Output is correct
19 Correct 11 ms 38000 KB Output is correct
20 Correct 7 ms 38000 KB Output is correct
21 Correct 3 ms 38000 KB Output is correct
22 Correct 0 ms 38000 KB Output is correct
23 Correct 16 ms 38000 KB Output is correct
24 Correct 20 ms 38000 KB Output is correct
25 Correct 6 ms 38000 KB Output is correct
26 Correct 10 ms 38000 KB Output is correct
27 Correct 0 ms 38000 KB Output is correct
28 Correct 5 ms 38000 KB Output is correct
29 Correct 13 ms 38000 KB Output is correct
30 Correct 10 ms 38000 KB Output is correct
31 Correct 9 ms 38000 KB Output is correct
32 Correct 10 ms 38000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 41912 KB Output is correct
2 Correct 272 ms 41912 KB Output is correct
3 Correct 276 ms 41912 KB Output is correct
4 Correct 271 ms 41912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 38000 KB Output is correct
2 Correct 11 ms 38000 KB Output is correct
3 Correct 3 ms 38000 KB Output is correct
4 Correct 13 ms 38000 KB Output is correct
5 Correct 6 ms 38000 KB Output is correct
6 Correct 11 ms 38000 KB Output is correct
7 Correct 18 ms 38000 KB Output is correct
8 Correct 0 ms 38000 KB Output is correct
9 Correct 3 ms 38000 KB Output is correct
10 Correct 10 ms 38000 KB Output is correct
11 Correct 10 ms 38000 KB Output is correct
12 Correct 12 ms 38000 KB Output is correct
13 Correct 19 ms 38000 KB Output is correct
14 Correct 6 ms 38000 KB Output is correct
15 Correct 6 ms 38000 KB Output is correct
16 Correct 11 ms 38000 KB Output is correct
17 Correct 7 ms 38000 KB Output is correct
18 Correct 8 ms 38000 KB Output is correct
19 Correct 3 ms 38000 KB Output is correct
20 Correct 10 ms 38000 KB Output is correct
21 Correct 10 ms 38000 KB Output is correct
22 Correct 7 ms 38000 KB Output is correct
23 Correct 12 ms 38000 KB Output is correct
24 Correct 18 ms 38000 KB Output is correct
25 Correct 21 ms 38000 KB Output is correct
26 Correct 13 ms 38000 KB Output is correct
27 Correct 9 ms 38000 KB Output is correct
28 Correct 23 ms 38000 KB Output is correct
29 Correct 13 ms 38000 KB Output is correct
30 Correct 15 ms 38000 KB Output is correct
31 Correct 3 ms 38000 KB Output is correct
32 Correct 11 ms 38000 KB Output is correct
33 Correct 72 ms 41912 KB Output is correct
34 Correct 64 ms 41912 KB Output is correct
35 Correct 89 ms 41912 KB Output is correct
36 Correct 83 ms 41912 KB Output is correct
37 Correct 45 ms 41912 KB Output is correct
38 Correct 53 ms 41912 KB Output is correct
39 Correct 37 ms 41912 KB Output is correct
40 Correct 59 ms 41912 KB Output is correct
41 Correct 48 ms 41912 KB Output is correct
42 Correct 44 ms 41912 KB Output is correct
43 Correct 59 ms 41912 KB Output is correct
44 Correct 59 ms 41912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 38000 KB Output is correct
2 Correct 11 ms 38000 KB Output is correct
3 Correct 7 ms 38000 KB Output is correct
4 Correct 13 ms 38000 KB Output is correct
5 Correct 13 ms 38000 KB Output is correct
6 Correct 10 ms 38000 KB Output is correct
7 Correct 6 ms 38000 KB Output is correct
8 Correct 10 ms 38000 KB Output is correct
9 Correct 22 ms 38000 KB Output is correct
10 Correct 13 ms 38000 KB Output is correct
11 Correct 13 ms 38000 KB Output is correct
12 Correct 12 ms 38000 KB Output is correct
13 Correct 7 ms 38000 KB Output is correct
14 Correct 6 ms 38000 KB Output is correct
15 Correct 14 ms 38000 KB Output is correct
16 Correct 3 ms 38000 KB Output is correct
17 Correct 11 ms 38000 KB Output is correct
18 Correct 14 ms 38000 KB Output is correct
19 Correct 17 ms 38000 KB Output is correct
20 Correct 3 ms 38000 KB Output is correct
21 Correct 3 ms 38000 KB Output is correct
22 Correct 13 ms 38000 KB Output is correct
23 Correct 6 ms 38000 KB Output is correct
24 Correct 15 ms 38000 KB Output is correct
25 Correct 15 ms 38000 KB Output is correct
26 Correct 17 ms 38000 KB Output is correct
27 Correct 13 ms 38000 KB Output is correct
28 Correct 11 ms 38000 KB Output is correct
29 Correct 18 ms 38000 KB Output is correct
30 Correct 13 ms 38000 KB Output is correct
31 Correct 10 ms 38000 KB Output is correct
32 Correct 5 ms 38000 KB Output is correct
33 Correct 158 ms 41912 KB Output is correct
34 Correct 329 ms 41912 KB Output is correct
35 Correct 257 ms 41912 KB Output is correct
36 Correct 266 ms 41912 KB Output is correct
37 Correct 66 ms 41912 KB Output is correct
38 Correct 75 ms 41912 KB Output is correct
39 Correct 80 ms 41912 KB Output is correct
40 Correct 64 ms 41912 KB Output is correct
41 Correct 50 ms 41912 KB Output is correct
42 Correct 52 ms 41912 KB Output is correct
43 Correct 61 ms 41912 KB Output is correct
44 Correct 56 ms 41912 KB Output is correct
45 Correct 39 ms 41912 KB Output is correct
46 Correct 45 ms 41912 KB Output is correct
47 Correct 44 ms 41912 KB Output is correct
48 Correct 60 ms 41912 KB Output is correct
49 Correct 264 ms 41912 KB Output is correct
50 Correct 295 ms 41912 KB Output is correct
51 Correct 220 ms 41912 KB Output is correct
52 Correct 227 ms 41912 KB Output is correct
53 Correct 239 ms 41912 KB Output is correct
54 Correct 183 ms 41912 KB Output is correct
55 Correct 123 ms 41912 KB Output is correct
56 Correct 186 ms 41912 KB Output is correct
57 Correct 175 ms 41912 KB Output is correct
58 Correct 154 ms 41912 KB Output is correct
59 Correct 62 ms 41912 KB Output is correct