답안 #1077815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077815 2024-08-27T09:21:07 Z juicy 말 (IOI15_horses) C++17
17 / 100
409 ms 44772 KB
#include "horses.h"

#include <bits/stdc++.h>

const int N = 5e5, MD = 1e9 + 7;

int n;
int a[N], prv[N], ma[4 * N], s[4 * N];
std::set<int> st;

void upd(int i, int x, int *s, int pul(int, int), int id = 1, int l = 0, int r = n - 1) {
  if (l == r) {
    s[id] = x;
    return;
  }
  int md = (l + r) / 2;
  if (i <= md) {
    upd(i, x, s, pul, id * 2, l, md);
  } else {
    upd(i, x, s, pul, id * 2 + 1, md + 1, r);
  }
  s[id] = pul(s[id * 2], s[id * 2 + 1]);
} 

int qry(int u, int v, int *s, int pul(int, int), int id = 1, int l = 0, int r = n - 1) {
  if (u <= l && r <= v) {
    return s[id];
  }
  int md = (l + r) / 2;
  if (v <= md) {
    return qry(u, v, s, pul, id * 2, l, md);
  }
  if (md < u) {
    return qry(u, v, s, pul, id * 2 + 1, md + 1, r);
  }
  return pul(qry(u, v, s, pul, id * 2, l, md), qry(u, v, s, pul, id * 2 + 1, md + 1, r));
}

int mul(int a, int b) {
  return (long long) a * b % MD;
}

int max(int a, int b) {
  return std::max(a, b);
}

int get() {
  if (!st.size()) {
    return ma[1];
  }
  int p = *st.rbegin(), prod = 1;
  std::vector<int> cands;
  while (~p) {
    if (a[p] > MD / prod) {
      break;
    }
    prod *= a[p];
    cands.push_back(p);
    p = prv[p];
  } 
  if (cands.back() && prv[cands.back()] + 1 != cands.back()) {
    cands.push_back(prv[cands.back()] + 1);
  } 
  reverse(cands.begin(), cands.end());
  prod = 1;
  int base = cands[0] ? qry(0, cands[0] - 1, s, mul) : 1;
  long long best = 0;
  for (int i = 0; i < cands.size(); ++i) {
    prod *= a[cands[i]];
    int j = i + 1 == cands.size() ? n - 1 : cands[i + 1] - 1;
    best = std::max(best, (long long) qry(cands[i], j, ma, max) * prod);
  }
  return best % MD * base % MD;
}

int init(int n, int *x, int *y) {
  ::n = n;
  for (int i = 0; i < n; ++i) {
    if (x[i] > 1) {
      prv[i] = !st.size() ? -1 : *st.rbegin();
      st.insert(i);
    }
    upd(i, x[i], s, mul);
    upd(i, y[i], ma, max);
  }
  for (int i = 0; i < n; ++i) {
    a[i] = x[i];
  }
  return get();
}

void ers(int i) {
  auto it = st.find(i);
  it = st.erase(it);
  if (it != st.end()) {
    prv[*it] = it == st.begin() ? -1 : *prev(it);
  }
}

void add(int i) {
  auto it = st.insert(i).first;
  prv[*it] = it == st.begin() ? -1 : *prev(it);
  ++it;
  if (it != st.end()) {
    prv[*it] = i;
  }
}

int updateX(int i, int x) {	
  if (x == 1 && a[i] > 1) {
    ers(i);
  } 
  if (x > 1 && a[i] == 1) {
    add(i);
  }
  upd(i, a[i] = x, s, mul);
  return get();
}

int updateY(int i, int x) {
  upd(i, x, ma, max);
  return get();
}

Compilation message

horses.cpp: In function 'void upd(int, int, int*, int (*)(int, int), int, int, int)':
horses.cpp:11:29: warning: declaration of 's' shadows a global declaration [-Wshadow]
   11 | void upd(int i, int x, int *s, int pul(int, int), int id = 1, int l = 0, int r = n - 1) {
      |                        ~~~~~^
horses.cpp:8:30: note: shadowed declaration is here
    8 | int a[N], prv[N], ma[4 * N], s[4 * N];
      |                              ^
horses.cpp: In function 'int qry(int, int, int*, int (*)(int, int), int, int, int)':
horses.cpp:25:28: warning: declaration of 's' shadows a global declaration [-Wshadow]
   25 | int qry(int u, int v, int *s, int pul(int, int), int id = 1, int l = 0, int r = n - 1) {
      |                       ~~~~~^
horses.cpp:8:30: note: shadowed declaration is here
    8 | int a[N], prv[N], ma[4 * N], s[4 * N];
      |                              ^
horses.cpp: In function 'int mul(int, int)':
horses.cpp:39:13: warning: declaration of 'a' shadows a global declaration [-Wshadow]
   39 | int mul(int a, int b) {
      |         ~~~~^
horses.cpp:8:5: note: shadowed declaration is here
    8 | int a[N], prv[N], ma[4 * N], s[4 * N];
      |     ^
horses.cpp:40:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   40 |   return (long long) a * b % MD;
      |          ~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int max(int, int)':
horses.cpp:43:13: warning: declaration of 'a' shadows a global declaration [-Wshadow]
   43 | int max(int a, int b) {
      |         ~~~~^
horses.cpp:8:5: note: shadowed declaration is here
    8 | int a[N], prv[N], ma[4 * N], s[4 * N];
      |     ^
horses.cpp: In function 'int get()':
horses.cpp:68:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for (int i = 0; i < cands.size(); ++i) {
      |                   ~~^~~~~~~~~~~~~~
horses.cpp:70:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     int j = i + 1 == cands.size() ? n - 1 : cands[i + 1] - 1;
      |             ~~~~~~^~~~~~~~~~~~~~~
horses.cpp:73:27: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   73 |   return best % MD * base % MD;
      |          ~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:76:14: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   76 | int init(int n, int *x, int *y) {
      |          ~~~~^
horses.cpp:7:5: note: shadowed declaration is here
    7 | int n;
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 448 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 448 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 444 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 600 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 409 ms 44772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 440 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 392 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Halted 0 ms 0 KB -