답안 #720436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
720436 2023-04-08T09:27:04 Z abczz 말 (IOI15_horses) C++14
100 / 100
633 ms 73292 KB
#include <iostream>
#include <map>
#include <horses.h>
#define ll long long
int init(int N, int X[], int Y[]);
int updateX(int pos, int val);
int updateY(int pos, int val);

using namespace std;

const ll M = 1e9 + 7;
map <ll, ll> mp;
ll n, st[2000000], st2[2000000], A[500000], B[500000];

void build(ll id, ll l, ll r) {
  if (l == r) {
    st[id] = A[l];
    return;
  }
  ll mid = (l+r)/2;
  build(id*2, l, mid);
  build(id*2+1, mid+1, r);
  st[id] = (st[id*2]*st[id*2+1])%M;
}

void build2(ll id, ll l, ll r) {
  if (l == r) {
    st2[id] = B[l];
    return;
  }
  ll mid = (l+r)/2;
  build2(id*2, l, mid);
  build2(id*2+1, mid+1, r);
  st2[id] = max(st2[id*2], st2[id*2+1]);
}

void update(ll id, ll l, ll r, ll q, ll v) {
  if (l == r) {
    st[id] = v;
    return;
  }
  ll mid = (l+r)/2;
  if (q <= mid) update(id*2, l, mid, q, v);
  else update(id*2+1, mid+1, r, q, v);
  st[id] = (st[id*2]*st[id*2+1])%M;
}

void update2(ll id, ll l, ll r, ll q, ll v) {
  if (l == r) {
    st2[id] = v;
    return;
  }
  ll mid = (l+r)/2;
  if (q <= mid) update2(id*2, l, mid, q, v);
  else update2(id*2+1, mid+1, r, q, v);
  st2[id] = max(st2[id*2], st2[id*2+1]);
}

ll query(ll id, ll l, ll r, ll ql, ll qr) {
  if (qr < l || r < ql) return 1;
  else if (ql <= l && r <= qr) return st[id];
  ll mid = (l+r)/2;
  return (query(id*2, l, mid, ql, qr)*query(id*2+1, mid+1, r, ql, qr))%M;
}

ll query2(ll id, ll l, ll r, ll ql, ll qr) {
  if (qr < l || r < ql) return -1;
  else if (ql <= l && r <= qr) return st2[id];
  ll mid = (l+r)/2;
  return max(query2(id*2, l, mid, ql, qr),query2(id*2+1, mid+1, r, ql, qr));
}

ll solve() {
  ll f = -1, j, p = n-1, res, z;
  if (mp.empty()) return query2(1, 0, n-1, 0, n-1); 
  auto itr = prev(mp.end());
  while (true) {
    if (itr->first != p) {
      res = query2(1, 0, n-1, itr->first, p);
      if (f < res) {
        f = z = res;
        j = itr->first;
      }
    }
    else if (f < B[itr->first]) {
      f = z = B[itr->first];
      j = itr->first;
    }
    f *= A[itr->first];
    p = itr->first-1;
    if (f >= M) break;
    else if (itr == mp.begin()) {
      if (p) {
        res = query2(1, 0, n-1, 0, p);
        if (f < res) return res;
      }
      break;
    }
    itr = prev(itr);
  }
  return (query(1, 0, n-1, 0, j)*z)%M;
}

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];
    if (A[i] != 1) ++mp[i];
  }
  build(1, 0, n-1);
  build2(1, 0, n-1);
  return solve();
}

int updateX(int pos, int val) {
  if (A[pos] != 1 && val == 1) mp.erase(pos);
  else if (A[pos] == 1 && val != 1) ++mp[pos];
  A[pos] = val;
  update(1, 0, n-1, pos, val);
  return solve();
}

int updateY(int pos, int val) {
  B[pos] = val;
  update2(1, 0, n-1, pos, val);
  return solve();
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:113:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  113 |   return solve();
      |          ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:121:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  121 |   return solve();
      |          ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:127:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  127 |   return solve();
      |          ~~~~~^~
horses.cpp: In function 'long long int solve()':
horses.cpp:101:33: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
  101 |   return (query(1, 0, n-1, 0, j)*z)%M;
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~
horses.cpp:101:16: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
  101 |   return (query(1, 0, n-1, 0, j)*z)%M;
      |           ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 308 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 244 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 2 ms 424 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 452 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 64632 KB Output is correct
2 Correct 241 ms 73292 KB Output is correct
3 Correct 199 ms 64684 KB Output is correct
4 Correct 232 ms 68400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 4 ms 320 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 324 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 3 ms 328 KB Output is correct
33 Correct 42 ms 32576 KB Output is correct
34 Correct 44 ms 32768 KB Output is correct
35 Correct 201 ms 70652 KB Output is correct
36 Correct 194 ms 70668 KB Output is correct
37 Correct 90 ms 30756 KB Output is correct
38 Correct 98 ms 47432 KB Output is correct
39 Correct 37 ms 30464 KB Output is correct
40 Correct 181 ms 65792 KB Output is correct
41 Correct 28 ms 30540 KB Output is correct
42 Correct 74 ms 30600 KB Output is correct
43 Correct 179 ms 66108 KB Output is correct
44 Correct 172 ms 66200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 452 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 5 ms 340 KB Output is correct
33 Correct 195 ms 64568 KB Output is correct
34 Correct 237 ms 73276 KB Output is correct
35 Correct 205 ms 64440 KB Output is correct
36 Correct 213 ms 68352 KB Output is correct
37 Correct 54 ms 32608 KB Output is correct
38 Correct 44 ms 32644 KB Output is correct
39 Correct 194 ms 70652 KB Output is correct
40 Correct 205 ms 70592 KB Output is correct
41 Correct 94 ms 30768 KB Output is correct
42 Correct 102 ms 47436 KB Output is correct
43 Correct 35 ms 30548 KB Output is correct
44 Correct 196 ms 65676 KB Output is correct
45 Correct 32 ms 30540 KB Output is correct
46 Correct 78 ms 30592 KB Output is correct
47 Correct 197 ms 66112 KB Output is correct
48 Correct 210 ms 66140 KB Output is correct
49 Correct 146 ms 36052 KB Output is correct
50 Correct 103 ms 35996 KB Output is correct
51 Correct 323 ms 72584 KB Output is correct
52 Correct 225 ms 72004 KB Output is correct
53 Correct 633 ms 34396 KB Output is correct
54 Correct 244 ms 52100 KB Output is correct
55 Correct 156 ms 31564 KB Output is correct
56 Correct 288 ms 67540 KB Output is correct
57 Correct 75 ms 32152 KB Output is correct
58 Correct 552 ms 32748 KB Output is correct
59 Correct 167 ms 66048 KB Output is correct