problem_id
stringlengths 6
6
| language
stringclasses 2
values | original_status
stringclasses 3
values | original_src
stringlengths 19
243k
| changed_src
stringlengths 19
243k
| change
stringclasses 3
values | i1
int64 0
8.44k
| i2
int64 0
8.44k
| j1
int64 0
8.44k
| j2
int64 0
8.44k
| error
stringclasses 270
values | stderr
stringlengths 0
226k
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03201 | C++ | Runtime Error | // #define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>
using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;
template <class T = usize> class rep {
const T f, l;
public:
class itr {
friend rep;
T i;
constexpr itr(T x) noexcept : i(x) {}
public:
void operator++() noexcept { ++i; }
constexpr T operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
constexpr itr begin() const noexcept { return itr(f); }
constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
const T f, l;
public:
class itr {
friend revrep;
T i;
constexpr itr(T x) noexcept : i(x) {}
public:
void operator++() noexcept { --i; }
constexpr T operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
constexpr itr begin() const noexcept { return itr(l - 1); }
constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
return b <= a ? (a = b, 1) : 0;
}
template <class T> bool samax(T &a, const T &b) {
return b <= a ? 0 : (a = b, 1);
}
template <class T> bool samin(T &a, const T &b) {
return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
return a <= b ? b - a : a - b;
}
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include <utility>
int main() {
usize n;
::std::cin >> n;
::std::multiset<u32, ::std::greater<u32>> st;
while (n--) {
u32 a;
::std::cin >> a;
st.insert(a);
}
usize ans{0};
u32 ht{~static_cast<u32>(0)};
for (auto itr = st.begin(); itr != st.end(); ++itr) {
const u32 v = *itr;
while (ht > v * 2)
ht >>= 1;
const u32 p = ~v + 1 & ht;
if (v == p) {
const usize c = st.count(v);
itr = st.upper_bound(v);
ans += c / 2;
} else {
auto pi = st.find(p);
if (pi != st.end()) {
st.erase(pi);
++ans;
}
}
}
::std::cout << ans << ::std::endl;
return 0;
}
| // #define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>
using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;
template <class T = usize> class rep {
const T f, l;
public:
class itr {
friend rep;
T i;
constexpr itr(T x) noexcept : i(x) {}
public:
void operator++() noexcept { ++i; }
constexpr T operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
constexpr itr begin() const noexcept { return itr(f); }
constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
const T f, l;
public:
class itr {
friend revrep;
T i;
constexpr itr(T x) noexcept : i(x) {}
public:
void operator++() noexcept { --i; }
constexpr T operator*() const noexcept { return i; }
constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
};
constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
constexpr itr begin() const noexcept { return itr(l - 1); }
constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
return b <= a ? (a = b, 1) : 0;
}
template <class T> bool samax(T &a, const T &b) {
return b <= a ? 0 : (a = b, 1);
}
template <class T> bool samin(T &a, const T &b) {
return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
return a <= b ? b - a : a - b;
}
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include <utility>
int main() {
usize n;
::std::cin >> n;
::std::multiset<u32, ::std::greater<u32>> st;
while (n--) {
u32 a;
::std::cin >> a;
st.insert(a);
}
usize ans{0};
u32 ht{~static_cast<u32>(0)};
for (auto itr = st.begin(); itr != st.end(); ++itr) {
const u32 v = *itr;
while (ht > v * 2)
ht >>= 1;
const u32 p = ~v + 1 & ht;
if (v == p) {
const usize c = st.count(v);
itr = ::std::prev(st.upper_bound(v));
ans += c / 2;
} else {
auto pi = st.find(p);
if (pi != st.end()) {
st.erase(pi);
++ans;
}
}
}
::std::cout << ans << ::std::endl;
return 0;
}
| replace | 99 | 100 | 99 | 100 | TLE | |
p03201 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
std::map<int, int> mp;
int n, a[200005];
void init() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
mp[a[i]] ? (++mp[a[i]]) : mp[a[i]] = 1;
}
std::map<int, int>::iterator it = mp.end();
--it;
int ans = 0, nw;
while (1) {
if (it->second == 0) {
goto loop;
}
nw = it->first;
for (int i = 30; i >= 1; --i) {
while (it->second >= 1 && mp[(1 << i) - nw] >= 1 &&
(nw != (1 << (i - 1)))) {
--mp[(1 << i) - nw];
it->second -= 1;
++ans;
}
while (it->second >= 2 && nw == (1 << (i - 1))) {
it->second -= 2;
++ans;
}
}
loop:
if (it == mp.begin()) {
break;
}
--it;
}
printf("%d\n", ans);
}
int main() {
init();
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
std::map<int, int> mp;
int n, a[200005];
void init() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
mp[a[i]] ? (++mp[a[i]]) : mp[a[i]] = 1;
}
std::map<int, int>::iterator it = mp.end();
--it;
int ans = 0, nw;
while (1) {
if (it->second == 0) {
goto loop;
}
nw = it->first;
for (int i = 30; i >= 1; --i) {
while (it->second >= 1 && (1 << i) - nw >= 0 && mp[(1 << i) - nw] >= 1 &&
(nw != (1 << (i - 1)))) {
--mp[(1 << i) - nw];
it->second -= 1;
++ans;
}
while (it->second >= 2 && nw == (1 << (i - 1))) {
it->second -= 2;
++ans;
}
}
loop:
if (it == mp.begin()) {
break;
}
--it;
}
printf("%d\n", ans);
}
int main() {
init();
return 0;
} | replace | 25 | 26 | 25 | 26 | TLE | |
p03201 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (LL i = 0; i < N; ++i)
typedef long long int LL;
int main() {
LL N;
in >> N;
std::vector<LL> A(N);
rep(i, N) in >> A[i];
std::map<LL, LL> cnt;
rep(i, N)++ cnt[A[i]];
LL ans = 0;
for (LL b = 31; b >= 0; --b) {
LL num = (1LL << b);
for (auto &p : cnt) {
if (p.first > 0) {
if (cnt[num - p.first] > 0) {
if (num == p.first * 2) {
ans += p.second / 2;
p.second = 0;
} else {
LL res = std::min(p.second, cnt[num - p.first]);
ans += res;
p.second -= res;
cnt[num - p.first] -= res;
}
}
}
}
}
out << ans << std::endl;
return 0;
}
| #include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (LL i = 0; i < N; ++i)
typedef long long int LL;
int main() {
LL N;
in >> N;
std::vector<LL> A(N);
rep(i, N) in >> A[i];
std::map<LL, LL> cnt;
rep(i, N)++ cnt[A[i]];
LL ans = 0;
for (LL b = 31; b >= 0; --b) {
LL num = (1LL << b);
for (auto &p : cnt) {
if (p.first > 0) {
if (cnt.count(num - p.first) > 0) {
if (num == p.first * 2) {
ans += p.second / 2;
p.second = 0;
} else {
LL res = std::min(p.second, cnt[num - p.first]);
ans += res;
p.second -= res;
cnt[num - p.first] -= res;
}
}
}
}
}
out << ans << std::endl;
return 0;
}
| replace | 20 | 21 | 20 | 21 | TLE | |
p03201 | C++ | Time Limit Exceeded | #include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "
int main() {
int n;
scanf("%d", &n);
multiset<int> st;
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
st.insert(x);
}
vector<int> pw2(1, 1);
while (*st.rbegin() * 2 > pw2.back())
pw2.pb(pw2.back() << 1);
int ans = 0;
while (!st.empty()) {
auto it = --st.end();
int cur = *it;
st.erase(it);
while (!pw2.empty() && 2 * cur < pw2.back())
pw2.pop_back();
assert(!pw2.empty());
int tar = pw2.back() - cur;
it = st.find(tar);
if (it != st.end()) {
++ans;
st.erase(it);
}
}
printf("%d\n", ans);
}
| #include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "
int main() {
int n;
scanf("%d", &n);
multiset<int> st;
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
st.insert(x);
}
const int P = 31;
vector<int> pw2(P);
for (int i = 0; i < P; ++i)
pw2[i] = 1 << i;
int ans = 0;
while (!st.empty()) {
auto it = --st.end();
int cur = *it;
st.erase(it);
while (!pw2.empty() && 2 * cur < pw2.back())
pw2.pop_back();
assert(!pw2.empty());
int tar = pw2.back() - cur;
it = st.find(tar);
if (it != st.end()) {
++ans;
st.erase(it);
}
}
printf("%d\n", ans);
}
| replace | 46 | 49 | 46 | 51 | TLE | |
p03201 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
map<int, int> mapa;
int n, a, f, i, j, res, tab[200005];
int main() {
scanf("%d", &n);
res = 0;
for (i = 0; i < n; i++)
scanf("%d", &tab[i]);
mapa.clear();
sort(tab, tab + n);
for (j = n - 1; j >= 0; j--) {
a = tab[j];
f = 0;
for (i = 1; i <= (1 << 30); i *= 2)
if (i > a && mapa[i - a] > 0) {
mapa[i - a]--;
f = 1;
break;
}
res += f;
if (!f)
mapa[a]++;
}
printf("%d\n", res);
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
map<int, int> mapa;
int n, a, f, i, j, res, tab[200005];
int main() {
scanf("%d", &n);
res = 0;
for (i = 0; i < n; i++)
scanf("%d", &tab[i]);
mapa.clear();
sort(tab, tab + n);
for (j = n - 1; j >= 0; j--) {
a = tab[j];
f = 0;
for (i = 1; i <= (1 << 30); i *= 2)
if (i > a && mapa[i - a] > 0) {
mapa[i - a]--;
f = 1;
break;
} else if (i == (1 << 30))
break;
res += f;
if (!f)
mapa[a]++;
}
printf("%d\n", res);
return 0;
}
| replace | 40 | 41 | 40 | 42 | TLE | |
p03201 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
using vs = vector<string>;
using tll = tuple<ll, ll, ll>;
using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
void in() {}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) {
cerr << " " << h;
if (sizeof...(t) > 0)
cerr << " :";
debug_out(t...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> vec) {
for (size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
ll ctoi(char c) {
switch (c) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
default:
return 0;
}
}
bool pairCompare(const pll firstElof, pll secondElof) {
return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
// rep, vin, all, iteLoop, bitSearch, bitList, nod//
// gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv,
// doubling, digitDP// dfs, bfs, dijkstra, WarshallFloyd, BellmanFord,
// UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l;
ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D;
vpll path;
//***********//
int main() {
cin >> N;
vl A(N);
map<ll, ll> B;
for (i = 0; i < N; i++) {
cin >> A[i];
B[A[i]]++;
}
sort(A.begin(), A.end());
reverse(A.begin(), A.end());
for (i = 0; i < N; i++) {
if (B[A[i]] > 0) {
B[A[i]]--;
for (j = 31; j >= 1; j--) {
ll P = pow(2, j) - A[i];
// debug(P, B[P]);
if (B[P] > 0) {
ans++;
B[P]--;
break;
}
}
}
}
cout << ans;
} | #include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
using vs = vector<string>;
using tll = tuple<ll, ll, ll>;
using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
void in() {}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) {
cerr << " " << h;
if (sizeof...(t) > 0)
cerr << " :";
debug_out(t...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> vec) {
for (size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
ll ctoi(char c) {
switch (c) {
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
default:
return 0;
}
}
bool pairCompare(const pll firstElof, pll secondElof) {
return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
// rep, vin, all, iteLoop, bitSearch, bitList, nod//
// gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv,
// doubling, digitDP// dfs, bfs, dijkstra, WarshallFloyd, BellmanFord,
// UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l;
ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D;
vpll path;
//***********//
int main() {
cin >> N;
vl A(N);
map<ll, ll> B;
for (i = 0; i < N; i++) {
cin >> A[i];
B[A[i]]++;
}
sort(A.begin(), A.end());
reverse(A.begin(), A.end());
for (i = 0; i < N; i++) {
if (B[A[i]] > 0) {
B[A[i]]--;
for (j = 31; j >= 1; j--) {
ll P = pow(2, j) - A[i];
if (P >= 1) {
// debug(P, B[P]);
if (B[P] > 0) {
ans++;
B[P]--;
break;
}
}
}
}
}
cout << ans;
} | replace | 96 | 101 | 96 | 103 | TLE | |
p03201 | C++ | Time Limit Exceeded | /*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Graph = vector<VecP>;
template <typename T> using Vec1 = vector<T>;
template <typename T> using Vec2 = vector<Vec1<T>>;
#define REP(i, m, n) for (ll(i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for (ll(i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for (ll(i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for (ll(i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> void co(const T n) { cout << n << endl; }
template <typename T> void cosp(const T n) { cout << n << ' '; }
void coVec(const Vec &v) {
for (ll i : v)
cosp(i);
cout << endl;
}
ll in() {
ll x;
cin >> x;
return x;
}
void sonic() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void setp(const ll n) { cout << fixed << setprecision(n); }
const ll INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
int main(void) {
ll n;
cin >> n;
Vec a(n);
rep(i, n) cin >> a[i];
sort(all(a));
reverse(all(a));
ll ans = 0;
VecB used(n, false);
rep(i, n) {
if (used[i])
continue;
else
used[i] = true;
ll b = 1;
while (b <= a[i])
b <<= 1;
ll c = b - a[i];
ll p = lower_bound(all(a), c, greater<>()) - a.begin();
while (p != n && a[p] == c) {
if (!used[p]) {
ans++;
used[p] = true;
break;
}
p++;
}
}
co(ans);
return 0;
}
| /*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Graph = vector<VecP>;
template <typename T> using Vec1 = vector<T>;
template <typename T> using Vec2 = vector<Vec1<T>>;
#define REP(i, m, n) for (ll(i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for (ll(i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for (ll(i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for (ll(i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> void co(const T n) { cout << n << endl; }
template <typename T> void cosp(const T n) { cout << n << ' '; }
void coVec(const Vec &v) {
for (ll i : v)
cosp(i);
cout << endl;
}
ll in() {
ll x;
cin >> x;
return x;
}
void sonic() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void setp(const ll n) { cout << fixed << setprecision(n); }
const ll INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
int main(void) {
ll n;
cin >> n;
Vec a(n);
rep(i, n) cin >> a[i];
sort(all(a));
reverse(all(a));
ll ans = 0;
VecB used(n, false);
rep(i, n) {
if (used[i])
continue;
else
used[i] = true;
ll b = 1;
while (b <= a[i])
b <<= 1;
ll c = b - a[i];
if (i != n - 1 && a[i] == a[i + 1] && a[i + 1] == c) {
ans++;
used[i + 1] = true;
continue;
}
ll p = lower_bound(all(a), c, greater<>()) - a.begin();
while (p != n && a[p] == c) {
if (!used[p]) {
ans++;
used[p] = true;
break;
}
p++;
}
}
co(ans);
return 0;
}
| insert | 92 | 92 | 92 | 97 | TLE | |
p03201 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define brep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define cY cout << "Yes" << endl
#define cN cout << "No" << endl
#define ll long long
ll pow2(ll p, ll n) {
long long num = 1;
while (n) {
if (n % 2 == 1) {
num *= p;
}
n /= 2;
p *= p;
}
return num;
}
int main(void) {
ll two[30];
rep(i, 30) two[i] = pow2(2, i + 1);
ll n;
cin >> n;
ll a[n];
ll ans = 0;
rep(i, n) { cin >> a[i]; }
sort(a, a + n);
brep(i, 30) {
int num = 0;
brep(j, n) {
if (a[j] == -INT_MAX || a[j] >= two[i])
continue;
for (int k = num; k < j; k++) {
if (a[k] == -INT_MAX)
continue;
if (a[j] + a[k] == two[i]) {
a[j] = -INT_MAX;
a[k] = -INT_MAX;
ans++;
num = k + 1;
break;
} else if (a[j] + a[k] > two[i]) {
num = k;
break;
}
}
}
}
// rep(i,n)cout <<a[i]<< endl;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define brep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define cY cout << "Yes" << endl
#define cN cout << "No" << endl
#define ll long long
ll pow2(ll p, ll n) {
long long num = 1;
while (n) {
if (n % 2 == 1) {
num *= p;
}
n /= 2;
p *= p;
}
return num;
}
int main(void) {
ll two[30];
rep(i, 30) two[i] = pow2(2, i + 1);
ll n;
cin >> n;
ll a[n];
ll ans = 0;
rep(i, n) { cin >> a[i]; }
sort(a, a + n);
brep(i, 30) {
int num = 0;
brep(j, n) {
if (a[j] == -INT_MAX || a[j] >= two[i])
continue;
if (a[j] < (two[i] + 1) / 2)
break;
for (int k = num; k < j; k++) {
if (a[k] == -INT_MAX)
continue;
if (a[j] + a[k] == two[i]) {
a[j] = -INT_MAX;
a[k] = -INT_MAX;
ans++;
num = k + 1;
break;
} else if (a[j] + a[k] > two[i]) {
num = k;
break;
}
}
}
}
// rep(i,n)cout <<a[i]<< endl;
cout << ans << endl;
}
| insert | 35 | 35 | 35 | 38 | TLE | |
p03201 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long t, n, a[200000 + 10], ans;
multiset<long long> st;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
st.insert(a[i]);
}
for (int i = 0; i < n; i++) {
t = 1;
for (int j = 1; j < 30 && t < 1e9 + 10; j++) {
t *= 2;
if (a[i] > t && st.find(a[i] - t) != st.end()) {
ans++;
st.erase(st.find(a[i] - t));
st.erase(st.find(a[i]));
break;
}
}
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
long long t, n, a[200000 + 10], ans;
multiset<long long> st;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
st.insert(a[i]);
}
sort(a, a + n);
for (int i = n - 1; i >= 0; i--) {
if (st.find(a[i]) != st.end()) {
t = 1;
st.erase(st.find(a[i]));
for (int j = 0; j < 40; j++) {
t *= 2;
if (st.find(t - a[i]) != st.end()) {
st.erase(st.find(t - a[i]));
ans++;
break;
}
}
}
}
cout << ans;
}
| replace | 10 | 19 | 10 | 22 | 0 | |
p03201 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define FOR(i, n) for (long long i = 0; i < (n); ++i)
#define pb push_back
#define int long long
#define debug(x) std::cout << #x << ": " << x << '\n';
typedef long long ll;
const int N = 2e5 + 10;
int a[N];
signed main() {
std::ios::sync_with_stdio(false);
int n;
std::cin >> n;
std::map<int, int> cnt;
FOR(i, n) {
std::cin >> a[i];
cnt[a[i]]++;
}
int answ = 0;
FOR(lg, 31) {
ll x = (1ll << (31 - lg));
FOR(i, n) {
if (cnt[a[i]] != 0 && cnt.find(x - a[i]) != cnt.end()) {
if (x - a[i] == a[i]) {
if (cnt[x - a[i]] >= 2) {
cnt[x - a[i]] -= 2;
answ++;
}
} else if (cnt[x - a[i]] >= 1) {
cnt[a[i]]--;
cnt[x - a[i]]--;
answ++;
}
}
}
}
std::cout << answ;
} | #include <bits/stdc++.h>
#define FOR(i, n) for (long long i = 0; i < (n); ++i)
#define pb push_back
#define int long long
#define debug(x) std::cout << #x << ": " << x << '\n';
typedef long long ll;
const int N = 2e5 + 10;
int a[N];
signed main() {
std::ios::sync_with_stdio(false);
int n;
std::cin >> n;
std::unordered_map<int, int> cnt;
FOR(i, n) {
std::cin >> a[i];
cnt[a[i]]++;
}
int answ = 0;
FOR(lg, 31) {
ll x = (1ll << (31 - lg));
FOR(i, n) {
if (cnt[a[i]] != 0 && cnt.find(x - a[i]) != cnt.end()) {
if (x - a[i] == a[i]) {
if (cnt[x - a[i]] >= 2) {
cnt[x - a[i]] -= 2;
answ++;
}
} else if (cnt[x - a[i]] >= 1) {
cnt[a[i]]--;
cnt[x - a[i]]--;
answ++;
}
}
}
}
std::cout << answ;
} | replace | 13 | 14 | 13 | 14 | TLE | |
p03201 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
map<int, int> mp;
rep(i, 0, n) {
cin >> a[i];
mp[a[i]]++;
}
int ans = 0;
for (int i = 30; i >= 1; i--) {
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it->second == 0)
continue;
int op = (1LL << i) - it->first;
if (mp[op] == 0)
continue;
if (op == it->first) {
ans += mp[op] / 2;
mp[op] %= 2;
} else {
int tmp = min(it->second, mp[op]);
ans += tmp;
it->second -= tmp;
mp[op] -= tmp;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
map<int, int> mp;
rep(i, 0, n) {
cin >> a[i];
mp[a[i]]++;
}
int ans = 0;
for (int i = 30; i >= 1; i--) {
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it->second == 0)
continue;
int op = (1LL << i) - it->first;
if (op < it->first)
break;
if (mp[op] == 0)
continue;
if (op == it->first) {
ans += mp[op] / 2;
mp[op] %= 2;
} else {
int tmp = min(it->second, mp[op]);
ans += tmp;
it->second -= tmp;
mp[op] -= tmp;
}
}
}
cout << ans << endl;
} | insert | 29 | 29 | 29 | 31 | TLE | |
p03201 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, x, count = 0;
long int t;
vector<int> num;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
num.push_back(x);
}
sort(num.begin(), num.end());
while (num.size() > 1) {
t = 1;
x = num[num.size() - 1];
// cout << x << endl;
num.pop_back();
while (t <= x) {
t *= 2;
}
auto it = lower_bound(num.begin(), num.end(), t - x);
if (*it == t - x) {
// cout << "found" << *it <<endl;
num.erase(it);
count++;
} else {
continue;
}
}
cout << count << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, x, count = 0;
long int t;
vector<int> num;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
num.push_back(x);
}
sort(num.begin(), num.end());
while (num.size() > 1) {
t = 1;
x = num[num.size() - 1];
// cout << x << endl;
num.pop_back();
while (t <= x) {
t *= 2;
}
auto it = lower_bound(num.begin(), num.end(), t - x);
if (it == num.end())
continue;
if (*it == t - x) {
// cout << "found" << *it <<endl;
num.erase(it);
count++;
} else {
continue;
}
}
cout << count << endl;
return 0;
} | insert | 21 | 21 | 21 | 23 | 0 | |
p03201 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
unordered_map<int, int> mp;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int A[200010];
rep(i, N) {
cin >> A[i];
mp[A[i]]++;
}
int num = (1 << 30);
int ans = 0;
rep(k, 31) {
rep(i, N) {
int remain = num - A[i];
if (remain != A[i] && mp[remain] > 0 && mp[A[i]] > 0) {
ans++;
mp[remain]--;
mp[A[i]]--;
// cout << remain << " " << A[i] << endl;
} else if (remain == A[i] && mp[A[i]] > 1) {
ans++;
mp[A[i]] -= 2;
// cout << remain << " " << A[i] << " " << mp[A[i]] << endl;
}
}
num >>= 1;
// cout << num << endl;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
unordered_map<int, int> mp;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int A[200010];
rep(i, N) {
cin >> A[i];
mp[A[i]]++;
}
int num = (1 << 30);
int ans = 0;
rep(k, 31) {
rep(i, N) {
int remain = num - A[i];
if (remain <= 0)
continue;
if (remain != A[i] && mp[remain] > 0 && mp[A[i]] > 0) {
ans++;
mp[remain]--;
mp[A[i]]--;
// cout << remain << " " << A[i] << endl;
} else if (remain == A[i] && mp[A[i]] > 1) {
ans++;
mp[A[i]] -= 2;
// cout << remain << " " << A[i] << " " << mp[A[i]] << endl;
}
}
num >>= 1;
// cout << num << endl;
}
cout << ans << endl;
return 0;
}
| insert | 41 | 41 | 41 | 43 | TLE | |
p03201 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <map>
#include <utility>
#include <vector>
using namespace std;
int a[200010];
int main() {
int n;
scanf("%d", &n);
map<int, int> m;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
m[a[i]]++;
}
vector<pair<int, int>> b(m.begin(), m.end());
int ans = 0;
for (int i = n - 1; i >= 0; i--) {
int x = b[i].first;
for (int j = 30; j >= 0; j--) {
if ((1 << j) <= x)
break;
if (b[i].second <= 0)
break;
int l = lower_bound(b.begin(), b.begin() + i + 1,
make_pair((1 << j) - x, -1)) -
b.begin();
if (l > i || b[l].first + x != (1 << j))
continue;
if (l == i) {
ans += b[i].second / 2;
b[i].second %= 2;
} else {
int t = min(b[i].second, b[l].second);
ans += t;
b[i].second -= t;
b[l].second -= t;
}
}
}
printf("%d\n", ans);
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <map>
#include <utility>
#include <vector>
using namespace std;
int a[200010];
int main() {
int n;
scanf("%d", &n);
map<int, int> m;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
m[a[i]]++;
}
vector<pair<int, int>> b(m.begin(), m.end());
int ans = 0;
for (int i = (int)b.size() - 1; i >= 0; i--) {
int x = b[i].first;
for (int j = 30; j >= 0; j--) {
if ((1 << j) <= x)
break;
if (b[i].second <= 0)
break;
int l = lower_bound(b.begin(), b.begin() + i + 1,
make_pair((1 << j) - x, -1)) -
b.begin();
if (l > i || b[l].first + x != (1 << j))
continue;
if (l == i) {
ans += b[i].second / 2;
b[i].second %= 2;
} else {
int t = min(b[i].second, b[l].second);
ans += t;
b[i].second -= t;
b[l].second -= t;
}
}
}
printf("%d\n", ans);
return 0;
}
| replace | 17 | 18 | 17 | 18 | 0 | |
p03201 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
const int MAX = 200010;
int main() {
int N;
int A[MAX];
map<long long, long long> table;
int ans = 0;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
if (table.count(A[i]) == 0)
table[A[i]] = 0;
table[A[i]]++;
}
sort(A, A + N);
for (int i = N - 1; i >= 0; i--) {
long long n = 1;
while (n <= A[i])
n = n * n;
if (A[i] == n * 2 && table[A[i]] >= 2) {
ans++;
table[A[i]] -= 2;
} else if (table[A[i]] >= 1 && table[n - A[i]] >= 1) {
ans++;
table[A[i]]--;
table[n - A[i]]--;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
const int MAX = 200010;
int main() {
int N;
int A[MAX];
map<long long, long long> table;
int ans = 0;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
if (table.count(A[i]) == 0)
table[A[i]] = 0;
table[A[i]]++;
}
sort(A, A + N);
for (int i = N - 1; i >= 0; i--) {
long long n = 1;
while (n <= A[i])
n <<= 1;
if (A[i] * 2 == n) {
if (table[A[i]] >= 2) {
ans++;
table[A[i]] -= 2;
}
} else if (table[A[i]] >= 1 && table[n - A[i]] >= 1) {
ans++;
table[A[i]]--;
table[n - A[i]]--;
}
}
cout << ans << endl;
return 0;
} | replace | 33 | 37 | 33 | 39 | TLE | |
p03201 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, int> P;
// typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010; // 10^18 = 2^60
int INF = 2147483600; // 10^9
ll MOD = 1000000007;
ll r(ll x) {
ll xdash = x;
int cnt = 0;
while (xdash != 0) {
cnt++;
xdash /= 2;
}
return pow(2, cnt) - x;
}
int main(void) {
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
A.push_back(INFL);
sort(A.begin(), A.end());
vector<pair<ll, int>> Apair(0);
ll ad = A.at(0);
int c = 1;
for (int i = 1; i <= N; i++) {
if (A.at(i) != ad) {
Apair.push_back({ad, c});
c = 1;
ad = A.at(i);
} else {
c++;
}
}
ll cnt = 0;
for (int i = Apair.size() - 1; i >= 0; i--) {
while (Apair.at(i).second != 0) {
Apair.at(i).second--;
ll now = Apair.at(i).first;
ll R = r(now);
int left = -1;
int right = N;
int mid;
while (right - left > 1) {
mid = (left + right) / 2;
if (Apair.at(mid).first > R) {
right = mid;
} else {
left = mid;
}
}
if (left != -1 && Apair.at(left).first == R &&
Apair.at(left).second != 0) {
cnt++;
Apair.at(left).second--;
}
}
}
cout << cnt << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, int> P;
// typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010; // 10^18 = 2^60
int INF = 2147483600; // 10^9
ll MOD = 1000000007;
ll r(ll x) {
ll xdash = x;
int cnt = 0;
while (xdash != 0) {
cnt++;
xdash /= 2;
}
return pow(2, cnt) - x;
}
int main(void) {
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
A.push_back(INFL);
sort(A.begin(), A.end());
vector<pair<ll, int>> Apair(0);
ll ad = A.at(0);
int c = 1;
for (int i = 1; i <= N; i++) {
if (A.at(i) != ad) {
Apair.push_back({ad, c});
c = 1;
ad = A.at(i);
} else {
c++;
}
}
ll cnt = 0;
for (int i = Apair.size() - 1; i >= 0; i--) {
while (Apair.at(i).second != 0) {
Apair.at(i).second--;
ll now = Apair.at(i).first;
ll R = r(now);
int left = -1;
int right = Apair.size();
int mid;
while (right - left > 1) {
mid = (left + right) / 2;
if (Apair.at(mid).first > R) {
right = mid;
} else {
left = mid;
}
}
if (left != -1 && Apair.at(left).first == R &&
Apair.at(left).second != 0) {
cnt++;
Apair.at(left).second--;
}
}
}
cout << cnt << endl;
}
| replace | 50 | 51 | 50 | 51 | 0 | |
p03201 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define F(i, a, b) for (int i = a; i <= (b); ++i)
#define F2(i, a, b) for (int i = a; i < (b); ++i)
#define dF(i, a, b) for (int i = a; i >= (b); --i)
#define dF2(i, a, b) for (int i = a; i > (b); --i)
#define eF(i, u) for (int i = h[u]; i; i = nxt[i])
#define SZ(x) ((int)(x).size())
#define prts(x) return puts(x), 0
#define pirtf(x) return printf("%d\n", x), 0
#define re return
typedef long long LL;
const int INF = 0x3f3f3f3f;
map<int, int> mp;
int n, q, m, k, Ans;
int a[200005];
int main() {
scanf("%d", &n);
F(i, 1, n) scanf("%d", a + i), ++mp[a[i]];
for (int j = 1 << 30; j; j >>= 1) {
F(i, 1, n) {
if (mp[a[i]] > 0 && mp[j - a[i]] > 0) {
if (a[i] != j - a[i]) {
++Ans, --mp[a[i]], --mp[j - a[i]];
} else {
if (mp[a[i]] > 1) {
++Ans;
mp[a[i]] -= 2;
}
}
}
}
}
printf("%d\n", Ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define F(i, a, b) for (int i = a; i <= (b); ++i)
#define F2(i, a, b) for (int i = a; i < (b); ++i)
#define dF(i, a, b) for (int i = a; i >= (b); --i)
#define dF2(i, a, b) for (int i = a; i > (b); --i)
#define eF(i, u) for (int i = h[u]; i; i = nxt[i])
#define SZ(x) ((int)(x).size())
#define prts(x) return puts(x), 0
#define pirtf(x) return printf("%d\n", x), 0
#define re return
typedef long long LL;
const int INF = 0x3f3f3f3f;
map<int, int> mp;
int n, q, m, k, Ans;
int a[200005];
int main() {
scanf("%d", &n);
F(i, 1, n) scanf("%d", a + i), ++mp[a[i]];
sort(a + 1, a + n + 1);
dF(i, n, 1) {
if (mp[a[i]] == 0)
continue;
dF(j, 30, 0) {
int v = (1 << j) - a[i], o = 0;
if (v < 0)
break;
if (v == a[i])
o = 1;
if (mp[v] > o) {
++Ans, --mp[v], --mp[a[i]];
break;
}
}
}
printf("%d\n", Ans);
return 0;
} | replace | 22 | 33 | 22 | 35 | TLE | |
p03201 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>
// #include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int, int>
#define qi ios::sync_with_stdio(0)
bool debug = true;
/* *************************************
* Written in New Computer *
* The following code belongs to *
* XiaoGeNintendo of HellHoleStudios *
*************************************
*/
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> ptt) {
os << ptt.first << "," << ptt.second;
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> vt) {
os << "{";
for (int i = 0; i < vt.size(); i++) {
os << vt[i] << " ";
}
os << "}";
return os;
}
int n;
int a[200005];
map<int, int> mp;
int p2[33];
int main(int argc, char *argv[]) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
p2[0] = 1;
for (int i = 1; i <= 30; i++) {
p2[i] = p2[i - 1] * 2;
}
sort(a, a + n);
reverse(a, a + n);
int ans = 0;
for (int i = 0; i < n; i++) {
if (mp[a[i]] == 0) {
continue;
}
for (int j = 30; j >= 1; j--) {
int ano = p2[j] - a[i];
int left = mp[ano];
if (left >= 2 || left == 1 && a[i] != ano) {
mp[ano]--;
mp[a[i]]--;
ans++;
break;
}
}
}
cout << ans;
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>
// #include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int, int>
#define qi ios::sync_with_stdio(0)
bool debug = true;
/* *************************************
* Written in New Computer *
* The following code belongs to *
* XiaoGeNintendo of HellHoleStudios *
*************************************
*/
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> ptt) {
os << ptt.first << "," << ptt.second;
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> vt) {
os << "{";
for (int i = 0; i < vt.size(); i++) {
os << vt[i] << " ";
}
os << "}";
return os;
}
int n;
int a[200005];
map<int, int> mp;
int p2[33];
int main(int argc, char *argv[]) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
p2[0] = 1;
for (int i = 1; i <= 30; i++) {
p2[i] = p2[i - 1] * 2;
}
sort(a, a + n);
reverse(a, a + n);
int ans = 0;
for (int i = 0; i < n; i++) {
if (mp[a[i]] == 0) {
continue;
}
for (int j = 30; j >= 1; j--) {
if (p2[j] <= a[i]) {
continue;
}
int ano = p2[j] - a[i];
int left = mp[ano];
if (left >= 2 || left == 1 && a[i] != ano) {
mp[ano]--;
mp[a[i]]--;
ans++;
break;
}
}
}
cout << ans;
return 0;
}
| replace | 64 | 65 | 64 | 67 | TLE | |
p03201 | C++ | Runtime Error | #include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
const double pi =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod = 1000000007;
int main() {
int n;
int a[101010] = {};
map<int, int> mp;
cin >> n;
FOR(i, 0, n) {
cin >> a[i];
mp[a[i]]++;
}
sort(a, a + n);
int cnt = 0;
FORD(i, n, 0) {
FORD(j, 31, 0) {
int sum = 1 << j;
int rest = sum - a[i];
if (rest <= 0)
continue;
if (mp[a[i]] > 0 && mp[rest] > 0) {
if (rest == a[i]) {
if (mp[rest] >= 2) {
mp[rest] -= 2;
cnt++;
break;
}
} else {
mp[a[i]]--;
mp[rest]--;
cnt++;
break;
}
}
}
}
cout << cnt << endl;
return 0;
}
| #include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
const double pi =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod = 1000000007;
int main() {
int n;
int a[201010] = {};
map<int, int> mp;
cin >> n;
FOR(i, 0, n) {
cin >> a[i];
mp[a[i]]++;
}
sort(a, a + n);
int cnt = 0;
FORD(i, n, 0) {
FORD(j, 31, 0) {
int sum = 1 << j;
int rest = sum - a[i];
if (rest <= 0)
continue;
if (mp[a[i]] > 0 && mp[rest] > 0) {
if (rest == a[i]) {
if (mp[rest] >= 2) {
mp[rest] -= 2;
cnt++;
break;
}
} else {
mp[a[i]]--;
mp[rest]--;
cnt++;
break;
}
}
}
}
cout << cnt << endl;
return 0;
}
| replace | 40 | 41 | 40 | 41 | 0 | |
p03201 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;
vector<ll> G[500005];
vector<P> tree[500010];
priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "RULD";
// ↓,→,↑,←
#define p(x) cout << x << endl;
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << x;
#define re(i, n) \
for (i = 0; i < n; i++) \
;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout << #x << " = " << x << endl
ll rui(ll number1, ll number2) {
if (number2 == 0) {
return 1;
} else {
ll number3 = rui(number1, number2 / 2);
number3 *= number3;
number3 %= mod;
if (number2 % 2 == 1) {
number3 *= number1;
number3 %= mod;
}
return number3;
}
}
ll gcd(ll number1, ll number2) {
if (number1 > number2) {
swap(number1, number2);
}
if (number1 == 0 || number1 == number2) {
return number2;
} else {
return gcd(number2 % number1, number1);
}
}
ll i, j, k, ii, jj;
ll n, m;
ll a, b, c, d, e, g, h, r;
ll l, ans, num;
ll x[500005], y[500005], z[500005];
bool dame, flag;
char s[500005], t[500005];
bool used[500005];
int main() {
cin >> n;
map<ll, ll> kazu;
for (i = 0; i < n; i++) {
cin >> x[i];
kazu[x[i]]++;
}
sort(x, x + n);
reverse(x, x + n);
for (i = 0; i < n; i++) {
// pe(x[i]);p(kazu[x[i]]);
if (kazu[x[i]] <= 0)
continue;
for (j = 32; j >= 0; j--) {
num = (1ll << j);
// p(num);
// if(num < x[i])break;
if (num == x[i] * 2) {
if (kazu[x[i]] >= 2) {
kazu[x[i]] -= 2;
ans++;
break;
}
} else {
if (kazu[num - x[i]] >= 1) {
kazu[x[i]]--;
kazu[num - x[i]]--;
ans++;
break;
}
}
}
}
p(ans);
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;
vector<ll> G[500005];
vector<P> tree[500010];
priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "RULD";
// ↓,→,↑,←
#define p(x) cout << x << endl;
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << x;
#define re(i, n) \
for (i = 0; i < n; i++) \
;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout << #x << " = " << x << endl
ll rui(ll number1, ll number2) {
if (number2 == 0) {
return 1;
} else {
ll number3 = rui(number1, number2 / 2);
number3 *= number3;
number3 %= mod;
if (number2 % 2 == 1) {
number3 *= number1;
number3 %= mod;
}
return number3;
}
}
ll gcd(ll number1, ll number2) {
if (number1 > number2) {
swap(number1, number2);
}
if (number1 == 0 || number1 == number2) {
return number2;
} else {
return gcd(number2 % number1, number1);
}
}
ll i, j, k, ii, jj;
ll n, m;
ll a, b, c, d, e, g, h, r;
ll l, ans, num;
ll x[500005], y[500005], z[500005];
bool dame, flag;
char s[500005], t[500005];
bool used[500005];
int main() {
cin >> n;
map<ll, ll> kazu;
for (i = 0; i < n; i++) {
cin >> x[i];
kazu[x[i]]++;
}
sort(x, x + n);
reverse(x, x + n);
for (i = 0; i < n; i++) {
// pe(x[i]);p(kazu[x[i]]);
if (kazu[x[i]] <= 0)
continue;
for (j = 32; j >= 0; j--) {
num = (1ll << j);
// p(num);
if (num < x[i])
break;
if (num == x[i] * 2) {
if (kazu[x[i]] >= 2) {
kazu[x[i]] -= 2;
ans++;
break;
}
} else {
if (kazu[num - x[i]] >= 1) {
kazu[x[i]]--;
kazu[num - x[i]]--;
ans++;
break;
}
}
}
}
p(ans);
return 0;
} | replace | 104 | 105 | 104 | 106 | TLE | |
p03201 | C++ | Runtime Error | /*************************************************
*************************************************
*************************************************
*** _________________ | | | /***
*** | | | | / ***
*** | | | | / ***
*** | | | | / ***
*** | | | | / ***
*** | |____________| |/ en ***
*** | | | |\ ***
*** | | | | \ ***
*** _____ | | | | \ ***
*** | | | | | \ ***
*** \ / | | | \ ***
*** \___/ | | | \***
*************************************************
*************Written by: JiangHaoKai*************
*************************************************/
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#pragma comment(linker, "/STACK:102400000,102400000")
// #include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <cassert>
#include <ccomplex>
#include <cctype>
#include <cerrno>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <condition_variable>
#include <csetjmp>
#include <csignal>
#include <cstdalign>
#include <cstdarg>
#include <cstdbool>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctgmath>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>
// #include <conio.h>
// #include <windows.h>
using namespace std;
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double ld;
typedef pair<int, int> pii;
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const LL LINF = 4557430888798830399;
#define PI 3.1415926535897932384626433832795028841971
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define MOD 1000000007
#define sz(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define repa(i, a, n) for (int i = a; i < n; i++)
#define repa1(i, a, n) for (int i = a; i <= n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define repd1(i, n) for (int i = n; i >= 1; i--)
#define repda(i, n, a) for (int i = n; i > a; i--)
#define repda1(i, n, a) for (int i = n; i >= a; i--)
#define FOR(i, a, n, step) for (int i = a; i < n; i += step)
#define repv(itr, v) \
for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++)
#define repV(i, v) for (auto i : v)
#define repE(i, v) for (auto &i : v)
#define MS(x, y) memset(x, y, sizeof(x))
#define MC(x) MS(x, 0)
#define MCP(x, y) memcpy(x, y, sizeof(y))
#define sqr(x) ((x) * (x))
#define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end())
#define filein(x) freopen(x, "r", stdin)
#define fileout(x) freopen(x, "w", stdout)
#define fileio(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define filein2(filename, name) ifstream name(filename, ios::in)
#define fileout2(filename, name) ofstream name(filename, ios::out)
#define file(filename, name) fstream name(filename, ios::in | ios::out)
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define PC(x) putchar(x)
#define GC(x) x = getchar()
#define Endl PC('\n')
#define SF scanf
#define PF printf
inline int Read() {
int X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
inline void Write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
Write(x / 10);
putchar(x % 10 + '0');
}
inline LL powmod(LL a, LL b) {
LL res = 1;
a %= MOD;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res;
}
inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; }
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
/**************************************************************Begin***************************************************************/
const int maxn = 100010;
int n, m, a[maxn], ans;
int main() {
SF("%d", &n);
rep(i, n) SF("%d", &a[i]);
sort(a, a + n);
for (int h = (1 << 30); h > 0; h >>= 1)
for (int i = 0, j = n - 1; i < j; i++)
if (a[i] != -1) {
while (j > i && (a[j] == -1 || a[i] + a[j] > h))
j--;
if (j > i && a[j] != -1 && a[i] + a[j] == h) {
ans++;
a[i] = a[j] = -1;
}
}
PF("%d", ans);
return 0;
}
/***************************************************************End****************************************************************/
| /*************************************************
*************************************************
*************************************************
*** _________________ | | | /***
*** | | | | / ***
*** | | | | / ***
*** | | | | / ***
*** | | | | / ***
*** | |____________| |/ en ***
*** | | | |\ ***
*** | | | | \ ***
*** _____ | | | | \ ***
*** | | | | | \ ***
*** \ / | | | \ ***
*** \___/ | | | \***
*************************************************
*************Written by: JiangHaoKai*************
*************************************************/
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#pragma comment(linker, "/STACK:102400000,102400000")
// #include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <cassert>
#include <ccomplex>
#include <cctype>
#include <cerrno>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <condition_variable>
#include <csetjmp>
#include <csignal>
#include <cstdalign>
#include <cstdarg>
#include <cstdbool>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctgmath>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>
// #include <conio.h>
// #include <windows.h>
using namespace std;
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double ld;
typedef pair<int, int> pii;
#define ui(n) ((unsigned int)(n))
#define LL(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const LL LINF = 4557430888798830399;
#define PI 3.1415926535897932384626433832795028841971
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define MOD 1000000007
#define sz(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define repa(i, a, n) for (int i = a; i < n; i++)
#define repa1(i, a, n) for (int i = a; i <= n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define repd1(i, n) for (int i = n; i >= 1; i--)
#define repda(i, n, a) for (int i = n; i > a; i--)
#define repda1(i, n, a) for (int i = n; i >= a; i--)
#define FOR(i, a, n, step) for (int i = a; i < n; i += step)
#define repv(itr, v) \
for (__typeof((v).begin()) itr = (v).begin(); itr != (v).end(); itr++)
#define repV(i, v) for (auto i : v)
#define repE(i, v) for (auto &i : v)
#define MS(x, y) memset(x, y, sizeof(x))
#define MC(x) MS(x, 0)
#define MCP(x, y) memcpy(x, y, sizeof(y))
#define sqr(x) ((x) * (x))
#define UN(v) sort(All(v)), v.erase(unique(All(v)), v.end())
#define filein(x) freopen(x, "r", stdin)
#define fileout(x) freopen(x, "w", stdout)
#define fileio(x) \
freopen(x ".in", "r", stdin); \
freopen(x ".out", "w", stdout)
#define filein2(filename, name) ifstream name(filename, ios::in)
#define fileout2(filename, name) ofstream name(filename, ios::out)
#define file(filename, name) fstream name(filename, ios::in | ios::out)
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define PC(x) putchar(x)
#define GC(x) x = getchar()
#define Endl PC('\n')
#define SF scanf
#define PF printf
inline int Read() {
int X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
inline void Write(int x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
Write(x / 10);
putchar(x % 10 + '0');
}
inline LL powmod(LL a, LL b) {
LL res = 1;
a %= MOD;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
}
return res;
}
inline LL gcdll(LL a, LL b) { return b ? gcdll(b, a % b) : a; }
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};
/**************************************************************Begin***************************************************************/
const int maxn = 200010;
int n, m, a[maxn], ans;
int main() {
SF("%d", &n);
rep(i, n) SF("%d", &a[i]);
sort(a, a + n);
for (int h = (1 << 30); h > 0; h >>= 1)
for (int i = 0, j = n - 1; i < j; i++)
if (a[i] != -1) {
while (j > i && (a[j] == -1 || a[i] + a[j] > h))
j--;
if (j > i && a[j] != -1 && a[i] + a[j] == h) {
ans++;
a[i] = a[j] = -1;
}
}
PF("%d", ans);
return 0;
}
/***************************************************************End****************************************************************/
| replace | 185 | 186 | 185 | 186 | 0 | |
p03201 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for (int i = int(m); i < int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1 << 30;
const ll INFll = 1ll << 62;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
ll N;
cin >> N;
multiset<int> a;
rep(i, N) {
int x;
cin >> x;
a.insert(x);
}
int ans = 0;
while (!a.empty()) {
auto it = max_element(all(a));
int x = *it;
int k = 0;
while (x) {
k++;
x /= 2;
}
int y = (1 << k) - *it;
a.erase(it);
it = a.find(y);
if (it != a.end()) {
a.erase(it);
ans++;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for (int i = int(m); i < int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1 << 30;
const ll INFll = 1ll << 62;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
ll N;
cin >> N;
multiset<int> a;
rep(i, N) {
int x;
cin >> x;
a.insert(x);
}
int ans = 0;
while (!a.empty()) {
auto it = a.end();
it--;
int x = *it;
int k = 0;
while (x) {
k++;
x /= 2;
}
int y = (1 << k) - *it;
a.erase(it);
it = a.find(y);
if (it != a.end()) {
a.erase(it);
ans++;
}
}
cout << ans << endl;
return 0;
}
| replace | 48 | 49 | 48 | 50 | TLE | |
p03201 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define all(a) (a).begin(), (a).end()
#define For(i, a, b) for (auto i = (a); i < (b); i++)
#define FOR(i, b) For(i, 0, b)
#define Rev(i, a, b) for (auto i = (a); i > (b); i--)
#define REV(i, a) Rev(i, a, -1)
#define FORE(i, a) for (auto &&i : a)
#define sz(a) (int((a).size()))
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pill = pair<int, ll>;
using plli = pair<ll, int>;
using pdd = pair<double, double>;
using pld = pair<ld, ld>;
constexpr const char nl = '\n', sp = ' ';
constexpr const int INT_INF = 0x3f3f3f3f;
constexpr const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
constexpr const double D_INF = numeric_limits<double>::infinity();
constexpr const ld LD_INF = numeric_limits<ld>::infinity();
template <class T> constexpr const T &_min(const T &x, const T &y) {
return x < y ? x : y;
}
template <class T> constexpr const T &_max(const T &x, const T &y) {
return x < y ? y : x;
}
template <class T, class... Ts>
constexpr const T &_min(const T &x, const Ts &...xs) {
return _min(x, _min(xs...));
}
template <class T, class... Ts>
constexpr const T &_max(const T &x, const Ts &...xs) {
return _max(x, _max(xs...));
}
template <class T, class... Ts> void MIN(T &x, const Ts &...xs) {
x = _min(x, xs...);
}
template <class T, class... Ts> void MAX(T &x, const Ts &...xs) {
x = _max(x, xs...);
}
template <class T>
constexpr const T &_clamp(const T &v, const T &lo, const T &hi) {
return v < lo ? lo : hi < v ? hi : v;
}
template <class T> void CLAMP(T &v, const T &lo, const T &hi) {
v = _clamp(v, lo, hi);
}
template <class T, class... Args> unique_ptr<T> _make_unique(Args &&...args) {
return unique_ptr<T>(new T(forward<Args>(args)...));
}
template <class T, class... Args> shared_ptr<T> _make_shared(Args &&...args) {
return shared_ptr<T>(new T(forward<Args>(args)...));
}
#define min(...) _min(__VA_ARGS__)
#define max(...) _max(__VA_ARGS__)
#define clamp(...) _clamp(__VA_ARGS__)
#define make_unique _make_unique
#define make_shared _make_shared
template <class... Ts> using uset = unordered_set<Ts...>;
template <class... Ts> using umap = unordered_map<Ts...>;
template <class... Ts> using pq = priority_queue<Ts...>;
template <class T> using minpq = pq<T, vector<T>, greater<T>>;
template <class T> using maxpq = pq<T, vector<T>, less<T>>;
template <class T1, class T2, class H1 = hash<T1>, class H2 = hash<T2>>
struct pair_hash {
size_t operator()(const pair<T1, T2> &p) const {
return 31 * H1{}(p.first) + H2{}(p.second);
}
};
template <class T> struct is_iterator {
template <class U, typename enable_if<!is_convertible<U, const char *>::value,
int>::type = 0>
constexpr static auto has_indirection(int)
-> decltype(*declval<U>(), bool()) {
return true;
}
template <class> constexpr static bool has_indirection(long) { return false; }
constexpr static bool value = has_indirection<T>(0);
};
seed_seq seq{(uint64_t)chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count(),
(uint64_t)__builtin_ia32_rdtsc(),
(uint64_t)(uintptr_t)make_unique<char>().get()};
mt19937 rng(seq);
mt19937_64 rng64(seq);
constexpr const int _bufferSize = 4096, _maxNumLength = 128;
char _inputBuffer[_bufferSize + 1],
*_inputPtr = _inputBuffer, _outputBuffer[_bufferSize], _c, _sign,
*_tempInputBuf = nullptr, _numBuf[_maxNumLength],
_tempOutputBuf[_maxNumLength], _fill = ' ';
FILE *_input = stdin, *_output = stdout, *_error = stderr;
const char *_delimiter = " ";
int _cur, _outputPtr = 0, _numPtr = 0, _precision = 6, _width = 0,
_tempOutputPtr = 0, _cnt;
ull _precisionBase = 1000000;
#define _peekchar() \
(*_inputPtr ? *_inputPtr \
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, _bufferSize, \
_input)] = '\0', \
*_inputPtr))
#define _getchar() \
(*_inputPtr ? *_inputPtr++ \
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, _bufferSize, \
_input)] = '\0', \
*_inputPtr++))
#define _hasNext() (*_inputPtr || !feof(_input))
#define _readSignAndNum(x) \
do { \
(x) = _getchar(); \
} while ((x) <= ' '); \
_sign = (x) == '-'; \
if (_sign) \
(x) = _getchar(); \
for ((x) -= '0'; (_c = _getchar()) >= '0'; (x) = (x)*10 + _c - '0')
#define _readFloatingPoint(x, T) \
for (T _div = 1.0; (_c = _getchar()) >= '0'; (x) += (_c - '0') / (_div *= 10))
#define rc(x) \
do { \
do { \
(x) = _getchar(); \
} while ((x) <= ' '); \
} while (0)
#define ri(x) \
do { \
_readSignAndNum(x); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rd(x) \
do { \
_readSignAndNum(x); \
if (_c == '.') \
_readFloatingPoint(x, double); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rld(x) \
do { \
_readSignAndNum(x); \
if (_c == '.') \
_readFloatingPoint(x, ld); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rcs(x) \
do { \
_cur = 0; \
do { \
_c = _getchar(); \
} while (_c <= ' '); \
do { \
(x)[_cur++] = _c; \
} while ((_c = _getchar()) > ' '); \
(x)[_cur] = '\0'; \
} while (0)
#define rs(x) \
do { \
if (!_tempInputBuf) \
assert(0); \
rcs(_tempInputBuf); \
(x) = string(_tempInputBuf, _cur); \
} while (0)
#define rcln(x) \
do { \
_cur = 0; \
do { \
_c = _getchar(); \
} while (_c <= ' '); \
do { \
(x)[_cur++] = _c; \
} while ((_c = _getchar()) >= ' '); \
(x)[_cur] = '\0'; \
} while (0)
#define rln(x) \
do { \
if (!_tempInputBuf) \
assert(0); \
rcln(_tempInputBuf); \
(x) = string(_tempInputBuf, _cur); \
} while (0)
#define setLength(x) \
do { \
if (_tempInputBuf) \
delete[] (_tempInputBuf); \
_tempInputBuf = new char[(x) + 1]; \
} while (0)
void read(int &x) { ri(x); }
void read(uint &x) { ri(x); }
void read(ll &x) { ri(x); }
void read(ull &x) { ri(x); }
void read(double &x) { rd(x); }
void read(ld &x) { rld(x); }
void read(char &x) { rc(x); }
void read(char *x) { rcs(x); }
void read(string &x) { rs(x); }
void readln(char *x) { rcln(x); }
void readln(string &x) { rln(x); }
template <class T1, class T2> void read(pair<T1, T2> &x) {
read(x.first);
read(x.second);
}
template <class T> void read(complex<T> &x) {
T _re, _im;
read(_re);
read(_im);
x.real(_re);
x.imag(_im);
}
template <class T> void read(T &x);
template <class T, class... Ts> void read(T &x, Ts &&...xs);
template <class It>
typename enable_if<is_iterator<It>::value>::type read(It st, It en) {
for (It _i = st; _i != en; _i++)
read(*_i);
}
template <class It, class... Ts>
typename enable_if<is_iterator<It>::value>::type read(It st, It en,
Ts &&...xs) {
read(st, en);
read(forward<Ts>(xs)...);
}
template <class T> void read(T &x) {
for (auto &&_i : x)
read(_i);
}
template <class T, class... Ts> void read(T &x, Ts &&...xs) {
read(x);
read(forward<Ts>(xs)...);
}
bool hasNext() {
while (_hasNext() && _peekchar() <= ' ')
_getchar();
return _hasNext();
}
void setInput(FILE *file) {
*_inputPtr = '\0';
_input = file;
}
void setInput(const char *s) {
*_inputPtr = '\0';
_input = fopen(s, "r");
}
void setInput(const string &s) {
*_inputPtr = '\0';
_input = fopen(s.c_str(), "r");
}
#define _flush() \
do { \
_flushBuf(); \
fflush(_output); \
} while (0)
#define _flushBuf() \
(fwrite(_outputBuffer, 1, _outputPtr, _output), _outputPtr = 0)
#define _putchar(x) \
(_outputBuffer[_outputPtr == _bufferSize ? _flushBuf() : _outputPtr] = (x), \
_outputPtr++)
#define _writeTempBuf(x) (_tempOutputBuf[_tempOutputPtr++] = (x))
#define _writeOutput() \
for (int _i = 0; _i < _tempOutputPtr; _putchar(_tempOutputBuf[_i++])) \
; \
_tempOutputPtr = 0
#define _writeNum(x, T, digits) \
_cnt = 0; \
for (T _y = (x); _y; _y /= 10, _cnt++) \
_numBuf[_numPtr++] = '0' + _y % 10; \
for (; _cnt < digits; _cnt++) \
_numBuf[_numPtr++] = '0'; \
_flushNumBuf();
#define _writeFloatingPoint(x, T) \
ull _I = (ull)(x); \
ull _F = ((x)-_I) * _precisionBase + (T)(0.5); \
if (_F >= _precisionBase) { \
_I++; \
_F = 0; \
} \
_writeNum(_I, ull, 1); \
_writeTempBuf('.'); \
_writeNum(_F, ull, _precision)
#define _checkFinite(x) \
if (std::isnan(x)) { \
wcs("NaN"); \
} else if (std::isinf(x)) { \
wcs("Inf"); \
}
#define _flushNumBuf() for (; _numPtr; _writeTempBuf(_numBuf[--_numPtr]))
#define _fillBuf(x) \
for (int _i = 0; _i < (x); _i++) \
_putchar(_fill)
#define _flushTempBuf() \
int _tempLen = _tempOutputPtr; \
_fillBuf(_width - _tempLen); \
_writeOutput(); \
_fillBuf(-_width - _tempLen)
#define wb(x) \
do { \
if (x) \
_writeTempBuf('1'); \
else \
_writeTempBuf('0'); \
_flushTempBuf(); \
} while (0)
#define wc(x) \
do { \
_writeTempBuf(x); \
_flushTempBuf(); \
} while (0)
#define wi(x) \
do { \
if ((x) < 0) { \
_writeTempBuf('-'); \
_writeNum(-(x), uint, 1); \
} else { \
_writeNum(x, uint, 1); \
} \
_flushTempBuf(); \
} while (0)
#define wll(x) \
do { \
if ((x) < 0) { \
_writeTempBuf('-'); \
_writeNum(-(x), ull, 1); \
} else { \
_writeNum(x, ull, 1); \
} \
_flushTempBuf(); \
} while (0)
#define wd(x) \
do { \
_checkFinite(x) else if ((x) < 0) { \
_writeTempBuf('-'); \
_writeFloatingPoint(-(x), double); \
} \
else { \
_writeFloatingPoint(x, double); \
} \
_flushTempBuf(); \
} while (0)
#define wld(x) \
do { \
_checkFinite(x) else if ((x) < 0) { \
_writeTempBuf('-'); \
_writeFloatingPoint(-(x), ld); \
} \
else { \
_writeFloatingPoint(x, ld); \
} \
_flushTempBuf(); \
} while (0)
#define wcs(x) \
do { \
int _slen = strlen(x); \
_fillBuf(_width - _slen); \
for (const char *_p = (x); *_p; _putchar(*_p++)) \
; \
_fillBuf(-_width - _slen); \
} while (0)
#define ws(x) \
do { \
_fillBuf(_width - int((x).length())); \
for (int _i = 0; _i < int((x).length()); _putchar(x[_i++])) \
; \
_fillBuf(-_width - int((x).length())); \
} while (0)
#define setPrecision(x) \
do { \
_precision = (x); \
_precisionBase = 1; \
for (int _i = 0; _i < (x); _i++, _precisionBase *= 10) \
; \
} while (0)
#define setDelimiter(x) \
do { \
_delimiter = (x); \
} while (0)
#define setWidth(x) \
do { \
_width = (x); \
} while (0)
#define setFill(x) \
do { \
_fill = (x); \
} while (0)
void writeDelimiter() {
for (const char *_p = _delimiter; *_p; _putchar(*_p++))
;
}
void write(const bool &x) { wb(x); }
void write(const int &x) { wi(x); }
void write(const uint &x) { wi(x); }
void write(const ll &x) { wll(x); }
void write(const ull &x) { wll(x); }
void write(const double &x) { wd(x); }
void write(const ld &x) { wld(x); }
void write(const char &x) { wc(x); }
void write(const char *x) { wcs(x); }
void write(const string &x) { ws(x); }
template <class T1, class T2> void write(const pair<T1, T2> &x) {
write(x.first);
writeDelimiter();
write(x.second);
}
template <class T> void write(const complex<T> &x) {
write(x.real());
writeDelimiter();
write(x.imag());
}
template <class T> void write(const T &x);
template <class T, class... Ts> void write(const T &x, Ts &&...xs);
template <class It>
typename enable_if<is_iterator<It>::value>::type write(It st, It en) {
bool _first = 1;
for (It _i = st; _i != en; _i++) {
if (_first)
_first = 0;
else
writeDelimiter();
write(*_i);
}
}
template <class It, class... Ts>
typename enable_if<is_iterator<It>::value>::type write(It st, It en,
Ts &&...xs) {
write(st, en);
writeDelimiter();
write(forward<Ts>(xs)...);
}
template <class T> void write(const T &x) {
bool _first = 1;
for (auto &&_i : x) {
if (_first)
_first = 0;
else
writeDelimiter();
write(_i);
}
}
template <class T, class... Ts> void write(const T &x, Ts &&...xs) {
write(x);
writeDelimiter();
write(forward<Ts>(xs)...);
}
void writeln() { _putchar('\n'); }
template <class... Ts> void writeln(Ts &&...xs) {
write(forward<Ts>(xs)...);
_putchar('\n');
}
void flush() { _flush(); }
class IOManager {
public:
~IOManager() {
flush();
if (_tempInputBuf)
delete[] (_tempInputBuf);
}
};
unique_ptr<IOManager> iomanager = make_unique<IOManager>();
void setOutput(FILE *file) {
flush();
_output = file;
}
void setOutput(const char *s) {
flush();
_output = fopen(s, "w");
}
void setOutput(const string &s) {
flush();
_output = fopen(s.c_str(), "w");
}
template <class... Ts> void debug(const Ts &...xs) {
FILE *_temp = _output;
setOutput(_error);
write(xs...);
setOutput(_temp);
}
template <class... Ts> void debugln(const Ts &...xs) {
FILE *_temp = _output;
setOutput(_error);
writeln(xs...);
setOutput(_temp);
}
void setError(FILE *file) {
flush();
_error = file;
}
void setError(const char *s) {
flush();
_error = fopen(s, "w");
}
void setError(const string &s) {
flush();
_error = fopen(s.c_str(), "w");
}
const int MAXN = 2e5 + 5;
int N, A[MAXN], ord[MAXN], cnt[MAXN];
umap<int, int> freq;
umap<int, queue<int>> freq2;
int main() {
// setInput("in.txt");
// setOutput("out.txt");
// setError("err.txt");
read(N);
read(A, A + N);
fill(cnt, cnt + N, 0);
FOR(i, N) freq[A[i]]++;
FOR(i, N) {
if (freq[A[i]]-- == 1)
freq.erase(A[i]);
FOR(j, 31) {
int x = 1 << j;
if (freq.count(x - A[i]))
cnt[i] += freq[x - A[i]];
}
freq[A[i]]++;
}
iota(ord, ord + N, 0);
sort(ord, ord + N,
[&](const int &i, const int &j) { return cnt[i] < cnt[j]; });
int ans = 0;
FOR(i, N) freq2[A[i]] = queue<int>();
FOR(i, N) {
int minj = -1, mini = INT_INF;
FOR(j, 31) {
int x = 1 << j;
if (!freq2[x - A[ord[i]]].empty() &&
freq2[x - A[ord[i]]].front() < mini) {
mini = freq2[x - A[ord[i]]].front();
minj = j;
}
}
if (minj == -1)
freq2[A[ord[i]]].push(i);
else {
int x = 1 << minj;
freq2[x - A[ord[i]]].pop();
ans++;
}
}
writeln(ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define all(a) (a).begin(), (a).end()
#define For(i, a, b) for (auto i = (a); i < (b); i++)
#define FOR(i, b) For(i, 0, b)
#define Rev(i, a, b) for (auto i = (a); i > (b); i--)
#define REV(i, a) Rev(i, a, -1)
#define FORE(i, a) for (auto &&i : a)
#define sz(a) (int((a).size()))
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pill = pair<int, ll>;
using plli = pair<ll, int>;
using pdd = pair<double, double>;
using pld = pair<ld, ld>;
constexpr const char nl = '\n', sp = ' ';
constexpr const int INT_INF = 0x3f3f3f3f;
constexpr const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
constexpr const double D_INF = numeric_limits<double>::infinity();
constexpr const ld LD_INF = numeric_limits<ld>::infinity();
template <class T> constexpr const T &_min(const T &x, const T &y) {
return x < y ? x : y;
}
template <class T> constexpr const T &_max(const T &x, const T &y) {
return x < y ? y : x;
}
template <class T, class... Ts>
constexpr const T &_min(const T &x, const Ts &...xs) {
return _min(x, _min(xs...));
}
template <class T, class... Ts>
constexpr const T &_max(const T &x, const Ts &...xs) {
return _max(x, _max(xs...));
}
template <class T, class... Ts> void MIN(T &x, const Ts &...xs) {
x = _min(x, xs...);
}
template <class T, class... Ts> void MAX(T &x, const Ts &...xs) {
x = _max(x, xs...);
}
template <class T>
constexpr const T &_clamp(const T &v, const T &lo, const T &hi) {
return v < lo ? lo : hi < v ? hi : v;
}
template <class T> void CLAMP(T &v, const T &lo, const T &hi) {
v = _clamp(v, lo, hi);
}
template <class T, class... Args> unique_ptr<T> _make_unique(Args &&...args) {
return unique_ptr<T>(new T(forward<Args>(args)...));
}
template <class T, class... Args> shared_ptr<T> _make_shared(Args &&...args) {
return shared_ptr<T>(new T(forward<Args>(args)...));
}
#define min(...) _min(__VA_ARGS__)
#define max(...) _max(__VA_ARGS__)
#define clamp(...) _clamp(__VA_ARGS__)
#define make_unique _make_unique
#define make_shared _make_shared
template <class... Ts> using uset = unordered_set<Ts...>;
template <class... Ts> using umap = unordered_map<Ts...>;
template <class... Ts> using pq = priority_queue<Ts...>;
template <class T> using minpq = pq<T, vector<T>, greater<T>>;
template <class T> using maxpq = pq<T, vector<T>, less<T>>;
template <class T1, class T2, class H1 = hash<T1>, class H2 = hash<T2>>
struct pair_hash {
size_t operator()(const pair<T1, T2> &p) const {
return 31 * H1{}(p.first) + H2{}(p.second);
}
};
template <class T> struct is_iterator {
template <class U, typename enable_if<!is_convertible<U, const char *>::value,
int>::type = 0>
constexpr static auto has_indirection(int)
-> decltype(*declval<U>(), bool()) {
return true;
}
template <class> constexpr static bool has_indirection(long) { return false; }
constexpr static bool value = has_indirection<T>(0);
};
seed_seq seq{(uint64_t)chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count(),
(uint64_t)__builtin_ia32_rdtsc(),
(uint64_t)(uintptr_t)make_unique<char>().get()};
mt19937 rng(seq);
mt19937_64 rng64(seq);
constexpr const int _bufferSize = 4096, _maxNumLength = 128;
char _inputBuffer[_bufferSize + 1],
*_inputPtr = _inputBuffer, _outputBuffer[_bufferSize], _c, _sign,
*_tempInputBuf = nullptr, _numBuf[_maxNumLength],
_tempOutputBuf[_maxNumLength], _fill = ' ';
FILE *_input = stdin, *_output = stdout, *_error = stderr;
const char *_delimiter = " ";
int _cur, _outputPtr = 0, _numPtr = 0, _precision = 6, _width = 0,
_tempOutputPtr = 0, _cnt;
ull _precisionBase = 1000000;
#define _peekchar() \
(*_inputPtr ? *_inputPtr \
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, _bufferSize, \
_input)] = '\0', \
*_inputPtr))
#define _getchar() \
(*_inputPtr ? *_inputPtr++ \
: (_inputBuffer[fread(_inputPtr = _inputBuffer, 1, _bufferSize, \
_input)] = '\0', \
*_inputPtr++))
#define _hasNext() (*_inputPtr || !feof(_input))
#define _readSignAndNum(x) \
do { \
(x) = _getchar(); \
} while ((x) <= ' '); \
_sign = (x) == '-'; \
if (_sign) \
(x) = _getchar(); \
for ((x) -= '0'; (_c = _getchar()) >= '0'; (x) = (x)*10 + _c - '0')
#define _readFloatingPoint(x, T) \
for (T _div = 1.0; (_c = _getchar()) >= '0'; (x) += (_c - '0') / (_div *= 10))
#define rc(x) \
do { \
do { \
(x) = _getchar(); \
} while ((x) <= ' '); \
} while (0)
#define ri(x) \
do { \
_readSignAndNum(x); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rd(x) \
do { \
_readSignAndNum(x); \
if (_c == '.') \
_readFloatingPoint(x, double); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rld(x) \
do { \
_readSignAndNum(x); \
if (_c == '.') \
_readFloatingPoint(x, ld); \
if (_sign) \
(x) = -(x); \
} while (0)
#define rcs(x) \
do { \
_cur = 0; \
do { \
_c = _getchar(); \
} while (_c <= ' '); \
do { \
(x)[_cur++] = _c; \
} while ((_c = _getchar()) > ' '); \
(x)[_cur] = '\0'; \
} while (0)
#define rs(x) \
do { \
if (!_tempInputBuf) \
assert(0); \
rcs(_tempInputBuf); \
(x) = string(_tempInputBuf, _cur); \
} while (0)
#define rcln(x) \
do { \
_cur = 0; \
do { \
_c = _getchar(); \
} while (_c <= ' '); \
do { \
(x)[_cur++] = _c; \
} while ((_c = _getchar()) >= ' '); \
(x)[_cur] = '\0'; \
} while (0)
#define rln(x) \
do { \
if (!_tempInputBuf) \
assert(0); \
rcln(_tempInputBuf); \
(x) = string(_tempInputBuf, _cur); \
} while (0)
#define setLength(x) \
do { \
if (_tempInputBuf) \
delete[] (_tempInputBuf); \
_tempInputBuf = new char[(x) + 1]; \
} while (0)
void read(int &x) { ri(x); }
void read(uint &x) { ri(x); }
void read(ll &x) { ri(x); }
void read(ull &x) { ri(x); }
void read(double &x) { rd(x); }
void read(ld &x) { rld(x); }
void read(char &x) { rc(x); }
void read(char *x) { rcs(x); }
void read(string &x) { rs(x); }
void readln(char *x) { rcln(x); }
void readln(string &x) { rln(x); }
template <class T1, class T2> void read(pair<T1, T2> &x) {
read(x.first);
read(x.second);
}
template <class T> void read(complex<T> &x) {
T _re, _im;
read(_re);
read(_im);
x.real(_re);
x.imag(_im);
}
template <class T> void read(T &x);
template <class T, class... Ts> void read(T &x, Ts &&...xs);
template <class It>
typename enable_if<is_iterator<It>::value>::type read(It st, It en) {
for (It _i = st; _i != en; _i++)
read(*_i);
}
template <class It, class... Ts>
typename enable_if<is_iterator<It>::value>::type read(It st, It en,
Ts &&...xs) {
read(st, en);
read(forward<Ts>(xs)...);
}
template <class T> void read(T &x) {
for (auto &&_i : x)
read(_i);
}
template <class T, class... Ts> void read(T &x, Ts &&...xs) {
read(x);
read(forward<Ts>(xs)...);
}
bool hasNext() {
while (_hasNext() && _peekchar() <= ' ')
_getchar();
return _hasNext();
}
void setInput(FILE *file) {
*_inputPtr = '\0';
_input = file;
}
void setInput(const char *s) {
*_inputPtr = '\0';
_input = fopen(s, "r");
}
void setInput(const string &s) {
*_inputPtr = '\0';
_input = fopen(s.c_str(), "r");
}
#define _flush() \
do { \
_flushBuf(); \
fflush(_output); \
} while (0)
#define _flushBuf() \
(fwrite(_outputBuffer, 1, _outputPtr, _output), _outputPtr = 0)
#define _putchar(x) \
(_outputBuffer[_outputPtr == _bufferSize ? _flushBuf() : _outputPtr] = (x), \
_outputPtr++)
#define _writeTempBuf(x) (_tempOutputBuf[_tempOutputPtr++] = (x))
#define _writeOutput() \
for (int _i = 0; _i < _tempOutputPtr; _putchar(_tempOutputBuf[_i++])) \
; \
_tempOutputPtr = 0
#define _writeNum(x, T, digits) \
_cnt = 0; \
for (T _y = (x); _y; _y /= 10, _cnt++) \
_numBuf[_numPtr++] = '0' + _y % 10; \
for (; _cnt < digits; _cnt++) \
_numBuf[_numPtr++] = '0'; \
_flushNumBuf();
#define _writeFloatingPoint(x, T) \
ull _I = (ull)(x); \
ull _F = ((x)-_I) * _precisionBase + (T)(0.5); \
if (_F >= _precisionBase) { \
_I++; \
_F = 0; \
} \
_writeNum(_I, ull, 1); \
_writeTempBuf('.'); \
_writeNum(_F, ull, _precision)
#define _checkFinite(x) \
if (std::isnan(x)) { \
wcs("NaN"); \
} else if (std::isinf(x)) { \
wcs("Inf"); \
}
#define _flushNumBuf() for (; _numPtr; _writeTempBuf(_numBuf[--_numPtr]))
#define _fillBuf(x) \
for (int _i = 0; _i < (x); _i++) \
_putchar(_fill)
#define _flushTempBuf() \
int _tempLen = _tempOutputPtr; \
_fillBuf(_width - _tempLen); \
_writeOutput(); \
_fillBuf(-_width - _tempLen)
#define wb(x) \
do { \
if (x) \
_writeTempBuf('1'); \
else \
_writeTempBuf('0'); \
_flushTempBuf(); \
} while (0)
#define wc(x) \
do { \
_writeTempBuf(x); \
_flushTempBuf(); \
} while (0)
#define wi(x) \
do { \
if ((x) < 0) { \
_writeTempBuf('-'); \
_writeNum(-(x), uint, 1); \
} else { \
_writeNum(x, uint, 1); \
} \
_flushTempBuf(); \
} while (0)
#define wll(x) \
do { \
if ((x) < 0) { \
_writeTempBuf('-'); \
_writeNum(-(x), ull, 1); \
} else { \
_writeNum(x, ull, 1); \
} \
_flushTempBuf(); \
} while (0)
#define wd(x) \
do { \
_checkFinite(x) else if ((x) < 0) { \
_writeTempBuf('-'); \
_writeFloatingPoint(-(x), double); \
} \
else { \
_writeFloatingPoint(x, double); \
} \
_flushTempBuf(); \
} while (0)
#define wld(x) \
do { \
_checkFinite(x) else if ((x) < 0) { \
_writeTempBuf('-'); \
_writeFloatingPoint(-(x), ld); \
} \
else { \
_writeFloatingPoint(x, ld); \
} \
_flushTempBuf(); \
} while (0)
#define wcs(x) \
do { \
int _slen = strlen(x); \
_fillBuf(_width - _slen); \
for (const char *_p = (x); *_p; _putchar(*_p++)) \
; \
_fillBuf(-_width - _slen); \
} while (0)
#define ws(x) \
do { \
_fillBuf(_width - int((x).length())); \
for (int _i = 0; _i < int((x).length()); _putchar(x[_i++])) \
; \
_fillBuf(-_width - int((x).length())); \
} while (0)
#define setPrecision(x) \
do { \
_precision = (x); \
_precisionBase = 1; \
for (int _i = 0; _i < (x); _i++, _precisionBase *= 10) \
; \
} while (0)
#define setDelimiter(x) \
do { \
_delimiter = (x); \
} while (0)
#define setWidth(x) \
do { \
_width = (x); \
} while (0)
#define setFill(x) \
do { \
_fill = (x); \
} while (0)
void writeDelimiter() {
for (const char *_p = _delimiter; *_p; _putchar(*_p++))
;
}
void write(const bool &x) { wb(x); }
void write(const int &x) { wi(x); }
void write(const uint &x) { wi(x); }
void write(const ll &x) { wll(x); }
void write(const ull &x) { wll(x); }
void write(const double &x) { wd(x); }
void write(const ld &x) { wld(x); }
void write(const char &x) { wc(x); }
void write(const char *x) { wcs(x); }
void write(const string &x) { ws(x); }
template <class T1, class T2> void write(const pair<T1, T2> &x) {
write(x.first);
writeDelimiter();
write(x.second);
}
template <class T> void write(const complex<T> &x) {
write(x.real());
writeDelimiter();
write(x.imag());
}
template <class T> void write(const T &x);
template <class T, class... Ts> void write(const T &x, Ts &&...xs);
template <class It>
typename enable_if<is_iterator<It>::value>::type write(It st, It en) {
bool _first = 1;
for (It _i = st; _i != en; _i++) {
if (_first)
_first = 0;
else
writeDelimiter();
write(*_i);
}
}
template <class It, class... Ts>
typename enable_if<is_iterator<It>::value>::type write(It st, It en,
Ts &&...xs) {
write(st, en);
writeDelimiter();
write(forward<Ts>(xs)...);
}
template <class T> void write(const T &x) {
bool _first = 1;
for (auto &&_i : x) {
if (_first)
_first = 0;
else
writeDelimiter();
write(_i);
}
}
template <class T, class... Ts> void write(const T &x, Ts &&...xs) {
write(x);
writeDelimiter();
write(forward<Ts>(xs)...);
}
void writeln() { _putchar('\n'); }
template <class... Ts> void writeln(Ts &&...xs) {
write(forward<Ts>(xs)...);
_putchar('\n');
}
void flush() { _flush(); }
class IOManager {
public:
~IOManager() {
flush();
if (_tempInputBuf)
delete[] (_tempInputBuf);
}
};
unique_ptr<IOManager> iomanager = make_unique<IOManager>();
void setOutput(FILE *file) {
flush();
_output = file;
}
void setOutput(const char *s) {
flush();
_output = fopen(s, "w");
}
void setOutput(const string &s) {
flush();
_output = fopen(s.c_str(), "w");
}
template <class... Ts> void debug(const Ts &...xs) {
FILE *_temp = _output;
setOutput(_error);
write(xs...);
setOutput(_temp);
}
template <class... Ts> void debugln(const Ts &...xs) {
FILE *_temp = _output;
setOutput(_error);
writeln(xs...);
setOutput(_temp);
}
void setError(FILE *file) {
flush();
_error = file;
}
void setError(const char *s) {
flush();
_error = fopen(s, "w");
}
void setError(const string &s) {
flush();
_error = fopen(s.c_str(), "w");
}
const int MAXN = 2e5 + 5;
int N, A[MAXN], ord[MAXN], cnt[MAXN];
umap<int, int> freq;
umap<int, queue<int>> freq2;
int main() {
// setInput("in.txt");
// setOutput("out.txt");
// setError("err.txt");
read(N);
read(A, A + N);
fill(cnt, cnt + N, 0);
FOR(i, N) freq[A[i]]++;
FOR(i, N) {
if (freq[A[i]]-- == 1)
freq.erase(A[i]);
FOR(j, 31) {
int x = 1 << j;
if (freq.count(x - A[i]))
cnt[i] += freq[x - A[i]];
}
freq[A[i]]++;
}
iota(ord, ord + N, 0);
sort(ord, ord + N,
[&](const int &i, const int &j) { return cnt[i] < cnt[j]; });
int ans = 0;
FOR(i, N) freq2[A[i]] = queue<int>();
FOR(i, N) {
int minj = -1, mini = INT_INF;
FOR(j, 31) {
int x = 1 << j;
if (freq2.count(x - A[ord[i]]) && !freq2[x - A[ord[i]]].empty() &&
freq2[x - A[ord[i]]].front() < mini) {
mini = freq2[x - A[ord[i]]].front();
minj = j;
}
}
if (minj == -1)
freq2[A[ord[i]]].push(i);
else {
int x = 1 << minj;
freq2[x - A[ord[i]]].pop();
ans++;
}
}
writeln(ans);
return 0;
}
| replace | 537 | 538 | 537 | 538 | TLE | |
p03201 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll smallest2(ll a) {
ll rtn = 1;
while (rtn <= a)
rtn *= 2;
return rtn;
}
int main() {
int n;
cin >> n;
map<ll, int> cnt;
for (int i = 0; i < n; i++) {
ll a;
cin >> a;
cnt[a]++;
}
int ans = 0;
for (map<ll, int>::reverse_iterator it = cnt.rbegin();; it++) {
if (it->second == 0)
continue;
if (it == cnt.rend())
break;
ll s = it->first, t = smallest2(s) - s;
if (s == t) {
ll p = cnt[s] / 2;
ans += p;
cnt[s] -= p;
} else {
ll p = min(cnt[s], cnt[t]);
ans += p;
cnt[s] -= p;
cnt[t] -= p;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll smallest2(ll a) {
ll rtn = 1;
while (rtn <= a)
rtn *= 2;
return rtn;
}
int main() {
int n;
cin >> n;
map<ll, int> cnt;
for (int i = 0; i < n; i++) {
ll a;
cin >> a;
cnt[a]++;
}
int ans = 0;
for (map<ll, int>::reverse_iterator it = cnt.rbegin();; it++) {
if (&it == 0)
continue;
if (it == cnt.rend())
break;
ll s = it->first, t = smallest2(s) - s;
if (s == t) {
ll p = cnt[s] / 2;
ans += p;
cnt[s] -= p;
} else {
ll p = min(cnt[s], cnt[t]);
ans += p;
cnt[s] -= p;
cnt[t] -= p;
}
}
cout << ans << endl;
return 0;
} | replace | 26 | 27 | 26 | 27 | TLE | |
p03201 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> a[100001];
int ans;
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i].first;
sort(a, a + n);
for (int i = n; i--;) { // 好聪明啊
if (a[i].second)
continue;
int t = 2 << __lg(a[i].first); // fantastic
int k = upper_bound(a, a + i, make_pair(t - a[i].first, 0)) - a; // wonderful
if (k > 0 && k <= i && a[i].first + a[k - 1].first == t) {
ans++;
a[k - 1].second = 1;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> a[200001];
int ans;
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i].first;
sort(a, a + n);
for (int i = n; i--;) { // 好聪明啊
if (a[i].second)
continue;
int t = 2 << __lg(a[i].first); // fantastic
int k = upper_bound(a, a + i, make_pair(t - a[i].first, 0)) - a; // wonderful
if (k > 0 && k <= i && a[i].first + a[k - 1].first == t) {
ans++;
a[k - 1].second = 1;
}
}
cout << ans << endl;
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) \
sort(all(v)); \
(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
type x; \
cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f) \
if ((f)) { \
cout << (TRUE__) << endl; \
} else { \
cout << FALSE__ << endl; \
}
#define RS(N) resize(N)
#define CINV(v, N) \
do { \
v.RS(N); \
rep(i, N) cin >> v[i]; \
} while (0);
#define RCINV(v, N) \
do { \
v.RS(N); \
rrep(i, N) cin >> v[i]; \
} while (0);
#define MOD 1000000007
void init();
void solve();
signed main() {
init();
solve();
}
int N;
vector<int> A;
void init() {
cin >> N;
CINV(A, N);
}
int X;
inline void add(int x, map<int, int> &m) {
m[x]++;
if (m[x] == X) {
m.erase(x);
add(x - 1, m);
}
}
inline bool isok(int x) {
X = x;
int pre = 0;
map<int, int> m;
rep(i, N) {
if (pre < A[i]) {
pre = A[i];
continue;
}
pre = A[i];
add(A[i], m);
while (1) {
auto itr = --m.end();
if (x > A[i])
m.erase(itr);
else
break;
}
if (m.count(0))
return false;
}
return true;
}
void solve() {
bool f = true;
rep(i, N - 1) { f &= A[i] < A[i + 1]; }
if (f) {
cout << 1 << endl;
return;
}
int ok = 1000000000;
int ng = 1;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid))
ok = mid;
else
ng = mid;
}
cout << ok << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) \
sort(all(v)); \
(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
type x; \
cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f) \
if ((f)) { \
cout << (TRUE__) << endl; \
} else { \
cout << FALSE__ << endl; \
}
#define RS(N) resize(N)
#define CINV(v, N) \
do { \
v.RS(N); \
rep(i, N) cin >> v[i]; \
} while (0);
#define RCINV(v, N) \
do { \
v.RS(N); \
rrep(i, N) cin >> v[i]; \
} while (0);
#define MOD 1000000007
void init();
void solve();
signed main() {
init();
solve();
}
int N;
vector<int> A;
void init() {
cin >> N;
CINV(A, N);
}
int X;
inline void add(int x, map<int, int> &m) {
m[x]++;
if (m[x] == X) {
m.erase(x);
add(x - 1, m);
}
}
inline bool isok(int x) {
X = x;
int pre = 0;
map<int, int> m;
rep(i, N) {
if (pre < A[i]) {
pre = A[i];
continue;
}
pre = A[i];
add(A[i], m);
while (1) {
auto itr = --m.end();
int x = (*itr).first;
if (x > A[i])
m.erase(itr);
else
break;
}
if (m.count(0))
return false;
}
return true;
}
void solve() {
bool f = true;
rep(i, N - 1) { f &= A[i] < A[i + 1]; }
if (f) {
cout << 1 << endl;
return;
}
int ok = 1000000000;
int ng = 1;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid))
ok = mid;
else
ng = mid;
}
cout << ok << endl;
}
| insert | 80 | 80 | 80 | 81 | -11 | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))
const int INF = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1},
{-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
int n;
int a[200010];
bool solve(int m) {
map<int, int> b;
for (int i = 1; i <= n; i++) {
if (a[i - 1] < a[i])
continue;
map<int, int>::iterator itr = b.end();
if (itr == b.begin())
goto f;
itr--;
while (1) {
if (itr->fr <= a[i])
break;
if (itr == b.begin()) {
b.erase(itr);
break;
}
b.erase(itr--);
}
f:;
b[a[i]]++;
int loc = a[i];
while (b[loc] == m) {
if (loc == 1)
return false;
b[loc] = 0;
b[loc - 1]++;
loc--;
}
}
return true;
}
int main() {
scanf("%d", &n);
a[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int l = 1, r = 200000;
while (l < r) {
int m = (l + r) / 2;
if (solve(m))
r = m;
else
l = m + 1;
}
cout << l << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))
const int INF = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1},
{-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
int n;
int a[200010];
bool solve(int m) {
map<int, int> b;
for (int i = 1; i <= n; i++) {
if (a[i - 1] < a[i])
continue;
map<int, int>::iterator itr = b.end();
if (itr == b.begin())
goto f;
itr--;
while (1) {
if (itr->fr <= a[i])
break;
if (itr == b.begin()) {
b.erase(itr);
break;
}
b.erase(itr--);
}
f:;
b[a[i]]++;
int loc = a[i];
while (b[loc] == m) {
if (loc == 1)
return false;
b[loc] = 0;
b[loc - 1]++;
loc--;
}
}
return true;
}
int main() {
scanf("%d", &n);
a[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
bool one = true;
for (int i = 1; i + 1 <= n; i++) {
one &= a[i] < a[i + 1];
}
if (one) {
puts("1");
return 0;
}
int l = 2, r = 200000;
while (l < r) {
int m = (l + r) / 2;
if (solve(m))
r = m;
else
l = m + 1;
}
cout << l << endl;
}
| replace | 79 | 80 | 79 | 89 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
const int N = 200005;
int n;
int arr[N];
bool ok(int x) {
map<int, int> cnt;
for (int i = 1; i < n; i++) {
if (arr[i] <= arr[i - 1]) {
int ce = arr[i];
while (!cnt.empty() && (--cnt.end())->first > ce) {
cnt.erase(--cnt.end());
}
cnt[ce]++;
while (cnt[ce] >= x) {
cnt.erase(ce--);
cnt[ce]++;
if (ce == 0)
return 0;
}
}
}
return 1;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int l = 0, r = 1e9;
while (l + 1 < r) {
int mid = (l + r) >> 1;
if (ok(mid)) {
r = mid;
} else {
l = mid;
}
}
cout << r << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
const int N = 200005;
int n;
int arr[N];
bool ok(int x) {
map<int, int> cnt;
for (int i = 1; i < n; i++) {
if (arr[i] <= arr[i - 1]) {
int ce = arr[i];
while (!cnt.empty() && (--cnt.end())->first > ce) {
cnt.erase(--cnt.end());
}
cnt[ce]++;
while (cnt[ce] >= x) {
cnt.erase(ce--);
cnt[ce]++;
if (ce == 0)
return 0;
}
}
}
return 1;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
bool ww = 1;
for (int i = 1; i < n; i++) {
if (arr[i] <= arr[i - 1]) {
ww = 0;
}
}
if (ww) {
cout << 1 << endl;
return 0;
}
int l = 1, r = 1e9;
while (l + 1 < r) {
int mid = (l + r) >> 1;
if (ok(mid)) {
r = mid;
} else {
l = mid;
}
}
cout << r << endl;
return 0;
}
| replace | 52 | 53 | 52 | 63 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll INF = 1e9 + 10;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1);
const int M = 1e3 + 10;
const int N = 1e6 + 10;
int a[N];
void solve() {
int n;
scanf("%d", &n);
fr(i, n) { scanf("%d", &a[i]); }
vector<int> v;
frab(i, 1, n) {
if (a[i] <= a[i - 1]) {
v.pb(a[i]);
}
}
// sort(v.begin(), v.end());
// reverse(v.begin(), v.end());
// for (auto x: v) cout << x << " ";cout << endl;
ll tl = 0, tr = n + 2;
while (tr - tl > 1) {
ll tm = (tl + tr) / 2;
auto u = v;
map<int, int, std::greater<int>> m;
fr(i, u.size()) {
int x = u[i];
while (m.size() && m.begin()->first > x)
m.erase(m.begin());
m[x]++;
while (m.count(x) && m[x] >= tm && x > 1) {
m[x - 1] += m[x] / tm;
m[x] %= tm;
x--;
}
}
if (u.size())
m[1] = max(1, m[1]);
if (m[1] >= tm)
tl = tm;
else
tr = tm;
}
cout << tr << "\n";
}
int main() {
// freopen("a.in", "r", stdin);
// ios_base::sync_with_stdio(false);
solve();
return 0;
}
| #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll INF = 1e9 + 10;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1);
const int M = 1e3 + 10;
const int N = 1e6 + 10;
int a[N];
void solve() {
int n;
scanf("%d", &n);
fr(i, n) { scanf("%d", &a[i]); }
vector<int> v;
frab(i, 1, n) {
if (a[i] <= a[i - 1]) {
v.pb(a[i]);
}
}
// sort(v.begin(), v.end());
// reverse(v.begin(), v.end());
// for (auto x: v) cout << x << " ";cout << endl;
ll tl = 0, tr = n + 2;
while (tr - tl > 1) {
ll tm = (tl + tr) / 2;
auto u = v;
map<int, int, std::greater<int>> m;
fr(i, u.size()) {
int x = u[i];
while (m.size() && m.begin()->first > x)
m.erase(m.begin());
m[x]++;
if (tm > 1) {
while (m.count(x) && m[x] >= tm && x > 1) {
m[x - 1] += m[x] / tm;
m[x] %= tm;
x--;
}
}
}
if (u.size())
m[1] = max(1, m[1]);
if (m[1] >= tm)
tl = tm;
else
tr = tm;
}
cout << tr << "\n";
}
int main() {
// freopen("a.in", "r", stdin);
// ios_base::sync_with_stdio(false);
solve();
return 0;
}
| replace | 52 | 56 | 52 | 58 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>;
using VII = vector<II>;
using VVII = vector<VII>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T = int> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> ostream &operator<<(ostream &s, const vector<T> &d) {
int n = d.size();
REP(i, n) s << d[i] << " ";
return s;
}
template <class T>
ostream &operator<<(ostream &s, const vector<vector<T>> &dd) {
for (vector<T> d : dd)
s << d << endl;
return s;
}
template <class T, class S>
ostream &operator<<(ostream &s, const pair<T, S> &p) {
s << "{" << p.first << ", " << p.second << "}";
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, const map<T, S> m) {
for (pair<T, S> p : m)
s << p << endl;
return s;
}
#ifdef _MY_DEBUG
#define dump(...) \
cerr << "\t" << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ \
<< "]" << endl \
<< "\t", \
dump_func(__VA_ARGS__);
#else
#define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head &&h, Tail &&...t) {
cerr << h << (sizeof...(Tail) == 0 ? "" : ", "),
dump_func(forward<Tail>(t)...);
}
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
constexpr int MOD = 1e9 + 7;
int N;
bool check(int m, VI &A) {
map<int, int> mp;
REP(i, N) {
if (i == 0 || A[i] > A[i - 1])
continue;
int k = A[i];
mp[k]++;
while (mp[k] >= m) {
if (k == 1) {
return false;
}
mp.erase(mp.find(k));
k--;
mp[k]++;
}
while (!mp.empty() && mp.rbegin()->fi > A[i]) {
mp.erase(prev(mp.end()));
}
}
return true;
}
signed main() {
cin >> N;
VI A = VI(N);
REP(i, N) cin >> A[i];
int l = 0, r = N;
while (r - l > 1) {
int m = (l + r) / 2;
(check(m, A) ? r : l) = m;
}
cout << r << endl;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>;
using VII = vector<II>;
using VVII = vector<VII>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T = int> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> ostream &operator<<(ostream &s, const vector<T> &d) {
int n = d.size();
REP(i, n) s << d[i] << " ";
return s;
}
template <class T>
ostream &operator<<(ostream &s, const vector<vector<T>> &dd) {
for (vector<T> d : dd)
s << d << endl;
return s;
}
template <class T, class S>
ostream &operator<<(ostream &s, const pair<T, S> &p) {
s << "{" << p.first << ", " << p.second << "}";
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, const map<T, S> m) {
for (pair<T, S> p : m)
s << p << endl;
return s;
}
#ifdef _MY_DEBUG
#define dump(...) \
cerr << "\t" << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ \
<< "]" << endl \
<< "\t", \
dump_func(__VA_ARGS__);
#else
#define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head &&h, Tail &&...t) {
cerr << h << (sizeof...(Tail) == 0 ? "" : ", "),
dump_func(forward<Tail>(t)...);
}
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
constexpr int MOD = 1e9 + 7;
int N;
bool check(int m, VI &A) {
if (m == 1) {
// 狭義単調増加かどうか
REP(i, N - 1) {
if (A[i + 1] <= A[i]) {
return false;
}
}
return true;
}
map<int, int> mp;
REP(i, N) {
if (i == 0 || A[i] > A[i - 1])
continue;
int k = A[i];
mp[k]++;
while (mp[k] >= m) {
if (k == 1) {
return false;
}
mp.erase(mp.find(k));
k--;
mp[k]++;
}
while (!mp.empty() && mp.rbegin()->fi > A[i]) {
mp.erase(prev(mp.end()));
}
}
return true;
}
signed main() {
cin >> N;
VI A = VI(N);
REP(i, N) cin >> A[i];
int l = 0, r = N;
while (r - l > 1) {
int m = (l + r) / 2;
(check(m, A) ? r : l) = m;
}
cout << r << endl;
}
| insert | 75 | 75 | 75 | 84 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define fo(i, a, b) for (i = a; i <= b; i++)
#define fd(i, a, b) for (i = a; i >= b; i--)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
using namespace std;
typedef long long ll;
inline int read() {
int n = 0, f = 1;
char c;
for (c = getchar(); c != '-' && (c < '0' || c > '9'); c = getchar())
;
if (c == '-')
f = -1, c = getchar();
for (; c >= '0' && c <= '9'; c = getchar())
n = (n << 3) + (n << 1) + (c & 15);
return n * f;
}
const int maxn = 2e5 + 5;
int i, j, k, s, n, len, a[maxn];
map<int, int> p;
map<int, int>::iterator it;
int main() {
n = read();
fo(i, 1, n) a[i] = read();
int l = 1, r = n;
for (; l < r;) {
int m = (l + r) >> 1;
p.clear();
len = 0;
for (i = 1; i <= n; i++) {
int x = a[i];
if (x > len) {
len = x;
continue;
}
for (;;) {
it = p.end();
if (it != p.begin())
it--;
else
break;
if (it->first > x)
p.erase(it);
else
break;
}
p[x]++, len = x;
for (; x && p[x] == m;)
p.erase(p.find(x)), p[--x]++;
if (x <= 0)
break;
}
if (i > n)
r = m;
else
l = m + 1;
}
printf("%d\n", l);
} | #include <bits/stdc++.h>
#define fo(i, a, b) for (i = a; i <= b; i++)
#define fd(i, a, b) for (i = a; i >= b; i--)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
using namespace std;
typedef long long ll;
inline int read() {
int n = 0, f = 1;
char c;
for (c = getchar(); c != '-' && (c < '0' || c > '9'); c = getchar())
;
if (c == '-')
f = -1, c = getchar();
for (; c >= '0' && c <= '9'; c = getchar())
n = (n << 3) + (n << 1) + (c & 15);
return n * f;
}
const int maxn = 2e5 + 5;
int i, j, k, s, n, len, a[maxn];
map<int, int> p;
map<int, int>::iterator it;
int main() {
n = read();
fo(i, 1, n) a[i] = read();
int l = 1, r = n;
for (; l < r;) {
int m = (l + r) >> 1;
p.clear();
len = 0;
for (i = 1; i <= n; i++) {
int x = a[i];
if (x > len) {
len = x;
continue;
}
for (;;) {
it = p.end();
if (it != p.begin())
it--;
else
break;
if (it->first > x)
p.erase(it);
else
break;
}
if (m == 1)
break;
p[x]++, len = x;
for (; x && p[x] == m;)
p.erase(p.find(x)), p[--x]++;
if (x <= 0)
break;
}
if (i > n)
r = m;
else
l = m + 1;
}
printf("%d\n", l);
} | insert | 47 | 47 | 47 | 49 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define N 200010
using namespace std;
typedef int ll;
ll p[N];
map<ll, ll> mp;
ll a;
bool check(ll k) {
mp.clear();
for (ll i = 2; i <= a; i++)
if (p[i] > p[i - 1])
continue;
else {
while (mp.size()) {
ll u = mp.rbegin()->first;
if (u > p[i])
mp.erase(u);
else
break;
}
ll j = p[i];
while (j && mp[j] + 1 == k) {
mp.erase(j);
j--;
}
if (j == 0)
return false;
mp[j]++;
}
return true;
}
int main() {
cin >> a;
for (ll i = 1; i <= a; i++)
cin >> p[i];
ll l = 1, r = a, mid;
while (l < r) {
mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
}
| #include <bits/stdc++.h>
#define N 200010
using namespace std;
typedef int ll;
ll p[N];
map<ll, ll> mp;
ll a;
bool check(ll k) {
mp.clear();
for (ll i = 2; i <= a; i++)
if (p[i] > p[i - 1])
continue;
else {
if (k == 1)
return false;
while (mp.size()) {
ll u = mp.rbegin()->first;
if (u > p[i])
mp.erase(u);
else
break;
}
ll j = p[i];
while (j && mp[j] + 1 == k) {
mp.erase(j);
j--;
}
if (j == 0)
return false;
mp[j]++;
}
return true;
}
int main() {
cin >> a;
for (ll i = 1; i <= a; i++)
cin >> p[i];
ll l = 1, r = a, mid;
while (l < r) {
mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
}
| insert | 13 | 13 | 13 | 15 | TLE | |
p03202 | C++ | Time Limit Exceeded | #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
// #define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
void accell() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
}
unordered_map<int, int> mp;
set<int> st;
void clr() {
for (auto it : st)
mp[it] = 0;
st.clear();
}
bool check(int sz, vector<int> &a) {
for (int i = 1; i < a.size(); ++i) {
int c = a[i];
if (sz != 1 && c >= 5e5)
continue;
if (a[i - 1] >= a[i]) {
while (st.size() > 0 && *st.rbegin() > c) {
mp[*st.rbegin()] = 0;
st.erase(*st.rbegin());
}
while (c >= 1 && mp[c] + 1 == sz) {
mp[c] = 0;
--c;
}
if (c == 0) {
clr();
return false;
}
mp[c]++;
st.insert(c);
} else {
continue;
}
}
clr();
return true;
}
signed main() {
accell();
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
bool ok = true;
for (int i = 0; i + 1 < n; ++i)
ok &= (a[i] < a[i + 1]);
if (ok) {
cout << 1;
return 0;
}
int l = 0;
int r = n + 1;
while (r - l > 1) {
int m = l + r >> 1;
if (!check(m, a))
l = m;
else
r = m;
}
cout << r << endl;
return 0;
}
| #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
// #define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
void accell() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
}
unordered_map<int, int> mp;
set<int> st;
void clr() {
for (auto it : st)
mp[it] = 0;
st.clear();
}
bool check(int sz, vector<int> &a) {
for (int i = 1; i < a.size(); ++i) {
int c = a[i];
if (c >= 5e5)
continue;
if (a[i - 1] >= a[i]) {
while (st.size() > 0 && *st.rbegin() > c) {
mp[*st.rbegin()] = 0;
st.erase(*st.rbegin());
}
while (c >= 1 && mp[c] + 1 == sz) {
mp[c] = 0;
--c;
}
if (c == 0) {
clr();
return false;
}
mp[c]++;
st.insert(c);
} else {
continue;
}
}
clr();
return true;
}
signed main() {
accell();
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
bool ok = true;
for (int i = 0; i + 1 < n; ++i)
ok &= (a[i] < a[i + 1]);
if (ok) {
cout << 1;
return 0;
}
int l = 0;
int r = n + 1;
while (r - l > 1) {
int m = l + r >> 1;
if (!check(m, a))
l = m;
else
r = m;
}
cout << r << endl;
return 0;
}
| replace | 33 | 34 | 33 | 34 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <iostream>
#include <map>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
int n;
int a[200001];
bool check(int x) {
map<int, int>
str; //(桁の位置(0-indexed), 桁の値(0~x-1)). (pos, 0)以外を記録.
int i;
for (i = 1; i < n; i++) {
if (a[i] > a[i - 1])
continue;
while (!str.empty() && str.rbegin()->first >= a[i])
str.erase(str.rbegin()->first);
str[a[i] - 1]++;
int cur = a[i] - 1;
while (str[cur] >= x) {
str.erase(cur);
cur--;
str[cur]++;
if (cur < 0) {
return false;
}
}
}
return true;
}
int main() {
int i;
cin >> n;
a[0] = 0;
rep(i, n) cin >> a[i + 1];
n++;
int st = 0, ed = n, mid; // xxxooo, (st, ed]
while (ed - st >= 2) {
mid = (st + ed) / 2;
if (check(mid))
ed = mid;
else
st = mid;
}
cout << ed << endl;
return 0;
} | #include <iostream>
#include <map>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;
int n;
int a[200001];
bool check(int x) {
map<int, int>
str; //(桁の位置(0-indexed), 桁の値(0~x-1)). (pos, 0)以外を記録.
int i;
for (i = 1; i < n; i++) {
if (a[i] > a[i - 1])
continue;
while (!str.empty() && str.rbegin()->first >= a[i])
str.erase(str.rbegin()->first);
str[a[i] - 1]++;
int cur = a[i] - 1;
while (str[cur] >= x) {
str.erase(cur);
cur--;
str[cur]++;
if (cur < 0) {
return false;
}
}
}
return true;
}
int main() {
int i;
cin >> n;
a[0] = 0;
rep(i, n) cin >> a[i + 1];
n++;
// check(1)を呼び出すと,桁上がりの処理がO(A_i)回行われる可能性があるので、答え=1かの判定は先にやる
bool ok1 = true;
for (i = 1; i < n; i++)
if (a[i] <= a[i - 1])
ok1 = false;
if (ok1) {
cout << 1 << endl;
return 0;
}
// 2分探索
int st = 1, ed = n, mid; // xxxooo, (st, ed]
while (ed - st >= 2) {
mid = (st + ed) / 2;
if (check(mid))
ed = mid;
else
st = mid;
}
cout << ed << endl;
return 0;
} | replace | 42 | 43 | 42 | 54 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define int long long int
using namespace std;
template <typename T, typename U> using P = pair<T, U>;
template <typename T> using V = vector<T>;
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> auto &operator<<(ostream &s, const vector<T> &v) {
s << "[";
bool a = 1;
for (auto e : v) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "]";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const pair<T, U> &p) {
s << "(" << p.first << "," << p.second << ")";
return s;
}
template <typename T> auto &operator<<(ostream &s, const set<T> &st) {
s << "{";
bool a = 1;
for (auto e : st) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "}";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const map<T, U> &m) {
s << "{";
bool a = 1;
for (auto e : m) {
s << (a ? "" : " ") << e.first << ":" << e.second;
a = 0;
}
s << "}";
return s;
}
#define DUMP(x) cerr << #x << " = " << (x) << endl;
struct edge {
int to, cost;
};
const int INF = 1e18;
const int MOD = 1e9 + 7;
bool is_possible(const V<int> &a, int k) {
int n = a.size();
stack<P<int, int>> st;
for (int i = 1; i < n; i++) {
if (a[i - 1] < a[i])
continue;
while (!st.empty() && st.top().first > a[i]) {
st.pop();
}
if (!st.empty() && st.top().first == a[i]) {
st.top().second++;
} else {
st.push(make_pair(a[i], 1));
}
while (st.top().second == k) {
int id = st.top().first;
if (id == 1) {
return false;
}
st.pop();
if (!st.empty() && st.top().first == id - 1) {
st.top().second++;
} else {
st.push(make_pair(id - 1, 1));
}
}
}
return true;
}
signed main() {
int n;
cin >> n;
V<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int l = 0, r = n;
while (r - l > 1) {
int m = (l + r) / 2;
if (is_possible(a, m)) {
r = m;
} else {
l = m;
}
}
cout << r << endl;
return 0;
}
| #include <bits/stdc++.h>
#define int long long int
using namespace std;
template <typename T, typename U> using P = pair<T, U>;
template <typename T> using V = vector<T>;
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> auto &operator<<(ostream &s, const vector<T> &v) {
s << "[";
bool a = 1;
for (auto e : v) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "]";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const pair<T, U> &p) {
s << "(" << p.first << "," << p.second << ")";
return s;
}
template <typename T> auto &operator<<(ostream &s, const set<T> &st) {
s << "{";
bool a = 1;
for (auto e : st) {
s << (a ? "" : " ") << e;
a = 0;
}
s << "}";
return s;
}
template <typename T, typename U>
auto &operator<<(ostream &s, const map<T, U> &m) {
s << "{";
bool a = 1;
for (auto e : m) {
s << (a ? "" : " ") << e.first << ":" << e.second;
a = 0;
}
s << "}";
return s;
}
#define DUMP(x) cerr << #x << " = " << (x) << endl;
struct edge {
int to, cost;
};
const int INF = 1e18;
const int MOD = 1e9 + 7;
bool is_possible(const V<int> &a, int k) {
int n = a.size();
stack<P<int, int>> st;
for (int i = 1; i < n; i++) {
if (a[i - 1] < a[i])
continue;
while (!st.empty() && st.top().first > a[i]) {
st.pop();
}
if (!st.empty() && st.top().first == a[i]) {
st.top().second++;
} else {
st.push(make_pair(a[i], 1));
}
while (st.top().second == k) {
int id = st.top().first;
if (id == 1) {
return false;
}
st.pop();
if (!st.empty() && st.top().first == id - 1) {
st.top().second++;
} else {
st.push(make_pair(id - 1, 1));
}
}
}
return true;
}
signed main() {
int n;
cin >> n;
V<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
bool all_increacing = true;
for (int i = 1; i < n; i++) {
if (a[i] <= a[i - 1]) {
all_increacing = false;
break;
}
}
if (all_increacing) {
cout << 1 << endl;
return 0;
}
int l = 1, r = n;
while (r - l > 1) {
int m = (l + r) / 2;
if (is_possible(a, m)) {
r = m;
} else {
l = m;
}
}
cout << r << endl;
return 0;
}
| replace | 104 | 105 | 104 | 117 | TLE | |
p03202 | C++ | Time Limit Exceeded | #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// need
#include <algorithm>
#include <iostream>
// data structure
#include <bitset>
#include <complex>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// #include <deque>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
// stream
// #include <istream>
#include <sstream>
// #include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <chrono>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <random>
// input
#define INIT \
std::ios::sync_with_stdio(false); \
std::cin.tie(0);
#define VAR(type, ...) \
type __VA_ARGS__; \
MACRO_VAR_Scan(__VA_ARGS__);
template <typename T> void MACRO_VAR_Scan(T &t) { std::cin >> t; }
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &...rest) {
std::cin >> first;
MACRO_VAR_Scan(rest...);
}
#define VEC_ROW(type, n, ...) \
std::vector<type> __VA_ARGS__; \
MACRO_VEC_ROW_Init(n, __VA_ARGS__); \
for (int w_ = 0; w_ < n; ++w_) { \
MACRO_VEC_ROW_Scan(w_, __VA_ARGS__); \
}
template <typename T> void MACRO_VEC_ROW_Init(int n, T &t) { t.resize(n); }
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Init(int n, First &first, Rest &...rest) {
first.resize(n);
MACRO_VEC_ROW_Init(n, rest...);
}
template <typename T> void MACRO_VEC_ROW_Scan(int p, T &t) { std::cin >> t[p]; }
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Scan(int p, First &first, Rest &...rest) {
std::cin >> first[p];
MACRO_VEC_ROW_Scan(p, rest...);
}
#define VEC(type, c, n) \
std::vector<type> c(n); \
for (auto &i : c) \
std::cin >> i;
#define MAT(type, c, m, n) \
std::vector<std::vector<type>> c(m, std::vector<type>(n)); \
for (auto &R : c) \
for (auto &w : R) \
std::cin >> w;
// output
#define OUT(dist) std::cout << (dist);
#define FOUT(n, dist) std::cout << std::fixed << std::setprecision(n) << (dist);
#define SOUT(n, c, dist) std::cout << std::setw(n) << std::setfill(c) << (dist);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' ');
#define ENDL std::cout << std::endl;
#define FLUSH std::cout << std::flush;
#define SHOW(dist) \
{ std::cerr << #dist << "\t:" << (dist) << "\n"; }
#define SHOWVECTOR(v) \
{ \
std::cerr << #v << "\t:"; \
for (const auto &xxx : v) { \
std::cerr << xxx << " "; \
} \
std::cerr << "\n"; \
}
#define SHOWVECTOR2(v) \
{ \
std::cerr << #v << "\t:\n"; \
for (const auto &xxx : v) { \
for (const auto &yyy : xxx) { \
std::cerr << yyy << " "; \
} \
std::cerr << "\n"; \
} \
}
#define SHOWQUEUE(a) \
{ \
auto tmp(a); \
std::cerr << #a << "\t:"; \
while (!tmp.empty()) { \
std::cerr << tmp.front() << " "; \
tmp.pop(); \
} \
std::cerr << "\n"; \
}
// utility
#define ALL(a) (a).begin(), (a).end()
#define FOR(w, a, n) for (int w = (a); w < (n); ++w)
#define RFOR(w, a, n) for (int w = (n)-1; w >= (a); --w)
#define REP(w, n) for (int w = 0; w < int(n); ++w)
#define RREP(w, n) for (int w = int(n) - 1; w >= 0; --w)
#define IN(a, x, b) (a <= x && x < b)
template <class T> inline T CHMAX(T &a, const T b) {
return a = (a < b) ? b : a;
}
template <class T> inline T CHMIN(T &a, const T b) {
return a = (a > b) ? b : a;
}
#define EXCEPTION(msg) \
throw std::string("Exception : " msg " [ in ") + __func__ + " : " + \
std::to_string(__LINE__) + " lines ]"
#define TRY(cond, msg) \
try { \
if (cond) \
EXCEPTION(msg); \
} catch (std::string s) { \
std::cerr << s << std::endl; \
}
// void CHECKTIME(std::function<void()> f) { auto start =
// std::chrono::system_clock::now(); f(); auto end =
// std::chrono::system_clock::now(); auto res =
// std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count();
// std::cerr << "[Time:" << res << "ns (" << res / (1.0e9) << "s)]\n"; }
// test
template <class T> using V = std::vector<T>;
template <class T> using VV = V<V<T>>;
template <typename S, typename T>
std::ostream &operator<<(std::ostream &os, std::pair<S, T> p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
#define random_shuffle "USE std::shuffle!";
// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = (1 << 30) - 1; // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60; // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18
constexpr double EPS = 1e-10;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template <class T, size_t N> void FILL(T (&a)[N], const T &val) {
for (auto &x : a)
x = val;
}
template <class ARY, size_t N, size_t M, class T>
void FILL(ARY (&a)[N][M], const T &val) {
for (auto &b : a)
FILL(b, val);
}
template <class T> void FILL(std::vector<T> &a, const T &val) {
for (auto &x : a)
x = val;
}
template <class ARY, class T>
void FILL(std::vector<std::vector<ARY>> &a, const T &val) {
for (auto &b : a)
FILL(b, val);
}
// ------------>8------------------------------------->8------------
signed main() {
INIT;
VAR(int, n);
VEC(int, a, n);
auto check = [&](int d) {
std::map<int, int> map;
int pre = 0;
for (int i = 0; i < n; pre = a[i], ++i) {
if (pre < a[i])
continue;
int p = a[i];
while (p) {
if (++map[p] == d) {
map.erase(p);
--p;
} else
break;
}
if (p == 0)
return false;
while (!map.empty() && map.rbegin()->first > a[i])
map.erase(map.rbegin()->first);
}
return true;
};
int ok = 200005, ng = 0;
while (ok - ng > 1) {
int me = (ok + ng) / 2;
if (check(me))
ok = me;
else
ng = me;
}
OUT(ok) BR;
return 0;
} | #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// need
#include <algorithm>
#include <iostream>
// data structure
#include <bitset>
#include <complex>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// #include <deque>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
// stream
// #include <istream>
#include <sstream>
// #include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <chrono>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <random>
// input
#define INIT \
std::ios::sync_with_stdio(false); \
std::cin.tie(0);
#define VAR(type, ...) \
type __VA_ARGS__; \
MACRO_VAR_Scan(__VA_ARGS__);
template <typename T> void MACRO_VAR_Scan(T &t) { std::cin >> t; }
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &...rest) {
std::cin >> first;
MACRO_VAR_Scan(rest...);
}
#define VEC_ROW(type, n, ...) \
std::vector<type> __VA_ARGS__; \
MACRO_VEC_ROW_Init(n, __VA_ARGS__); \
for (int w_ = 0; w_ < n; ++w_) { \
MACRO_VEC_ROW_Scan(w_, __VA_ARGS__); \
}
template <typename T> void MACRO_VEC_ROW_Init(int n, T &t) { t.resize(n); }
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Init(int n, First &first, Rest &...rest) {
first.resize(n);
MACRO_VEC_ROW_Init(n, rest...);
}
template <typename T> void MACRO_VEC_ROW_Scan(int p, T &t) { std::cin >> t[p]; }
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Scan(int p, First &first, Rest &...rest) {
std::cin >> first[p];
MACRO_VEC_ROW_Scan(p, rest...);
}
#define VEC(type, c, n) \
std::vector<type> c(n); \
for (auto &i : c) \
std::cin >> i;
#define MAT(type, c, m, n) \
std::vector<std::vector<type>> c(m, std::vector<type>(n)); \
for (auto &R : c) \
for (auto &w : R) \
std::cin >> w;
// output
#define OUT(dist) std::cout << (dist);
#define FOUT(n, dist) std::cout << std::fixed << std::setprecision(n) << (dist);
#define SOUT(n, c, dist) std::cout << std::setw(n) << std::setfill(c) << (dist);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' ');
#define ENDL std::cout << std::endl;
#define FLUSH std::cout << std::flush;
#define SHOW(dist) \
{ std::cerr << #dist << "\t:" << (dist) << "\n"; }
#define SHOWVECTOR(v) \
{ \
std::cerr << #v << "\t:"; \
for (const auto &xxx : v) { \
std::cerr << xxx << " "; \
} \
std::cerr << "\n"; \
}
#define SHOWVECTOR2(v) \
{ \
std::cerr << #v << "\t:\n"; \
for (const auto &xxx : v) { \
for (const auto &yyy : xxx) { \
std::cerr << yyy << " "; \
} \
std::cerr << "\n"; \
} \
}
#define SHOWQUEUE(a) \
{ \
auto tmp(a); \
std::cerr << #a << "\t:"; \
while (!tmp.empty()) { \
std::cerr << tmp.front() << " "; \
tmp.pop(); \
} \
std::cerr << "\n"; \
}
// utility
#define ALL(a) (a).begin(), (a).end()
#define FOR(w, a, n) for (int w = (a); w < (n); ++w)
#define RFOR(w, a, n) for (int w = (n)-1; w >= (a); --w)
#define REP(w, n) for (int w = 0; w < int(n); ++w)
#define RREP(w, n) for (int w = int(n) - 1; w >= 0; --w)
#define IN(a, x, b) (a <= x && x < b)
template <class T> inline T CHMAX(T &a, const T b) {
return a = (a < b) ? b : a;
}
template <class T> inline T CHMIN(T &a, const T b) {
return a = (a > b) ? b : a;
}
#define EXCEPTION(msg) \
throw std::string("Exception : " msg " [ in ") + __func__ + " : " + \
std::to_string(__LINE__) + " lines ]"
#define TRY(cond, msg) \
try { \
if (cond) \
EXCEPTION(msg); \
} catch (std::string s) { \
std::cerr << s << std::endl; \
}
// void CHECKTIME(std::function<void()> f) { auto start =
// std::chrono::system_clock::now(); f(); auto end =
// std::chrono::system_clock::now(); auto res =
// std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count();
// std::cerr << "[Time:" << res << "ns (" << res / (1.0e9) << "s)]\n"; }
// test
template <class T> using V = std::vector<T>;
template <class T> using VV = V<V<T>>;
template <typename S, typename T>
std::ostream &operator<<(std::ostream &os, std::pair<S, T> p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
#define random_shuffle "USE std::shuffle!";
// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = (1 << 30) - 1; // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60; // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18
constexpr double EPS = 1e-10;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template <class T, size_t N> void FILL(T (&a)[N], const T &val) {
for (auto &x : a)
x = val;
}
template <class ARY, size_t N, size_t M, class T>
void FILL(ARY (&a)[N][M], const T &val) {
for (auto &b : a)
FILL(b, val);
}
template <class T> void FILL(std::vector<T> &a, const T &val) {
for (auto &x : a)
x = val;
}
template <class ARY, class T>
void FILL(std::vector<std::vector<ARY>> &a, const T &val) {
for (auto &b : a)
FILL(b, val);
}
// ------------>8------------------------------------->8------------
signed main() {
INIT;
VAR(int, n);
VEC(int, a, n);
REP(i, n) CHMIN(a[i], 300005LL);
auto check = [&](int d) {
std::map<int, int> map;
int pre = 0;
for (int i = 0; i < n; pre = a[i], ++i) {
if (pre < a[i])
continue;
int p = a[i];
while (p) {
if (++map[p] == d) {
map.erase(p);
--p;
} else
break;
}
if (p == 0)
return false;
while (!map.empty() && map.rbegin()->first > a[i])
map.erase(map.rbegin()->first);
}
return true;
};
int ok = 200005, ng = 0;
while (ok - ng > 1) {
int me = (ok + ng) / 2;
if (check(me))
ok = me;
else
ng = me;
}
OUT(ok) BR;
return 0;
} | insert | 196 | 196 | 196 | 198 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
const int INF = 1e9;
template <class T> T Next() {
T buf;
cin >> buf;
return buf;
}
int n;
int a[200000];
bool ok(int kind) {
map<int, int> mp;
for (int i = 1; i < n; ++i) {
if (a[i - 1] < a[i])
continue;
int idx = a[i];
while (idx > 0 && mp[idx] == kind - 1) {
mp[idx] = 0;
--idx;
}
if (idx == 0)
return false;
++mp[idx];
mp.erase(mp.upper_bound(idx), mp.end());
}
return true;
}
int sub() {
int lo = 0;
int hi = 200001;
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
if (ok(mid)) {
hi = mid;
} else {
lo = mid;
}
}
return hi;
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
cout << sub() << endl;
} | #include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
const int INF = 1e9;
template <class T> T Next() {
T buf;
cin >> buf;
return buf;
}
int n;
int a[200000];
bool ok(int kind) {
map<int, int> mp;
for (int i = 1; i < n; ++i) {
if (a[i - 1] < a[i])
continue;
if (kind == 1)
return false;
int idx = a[i];
while (idx > 0 && mp[idx] == kind - 1) {
mp[idx] = 0;
--idx;
}
if (idx == 0)
return false;
++mp[idx];
mp.erase(mp.upper_bound(idx), mp.end());
}
return true;
}
int sub() {
int lo = 0;
int hi = 200001;
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
if (ok(mid)) {
hi = mid;
} else {
lo = mid;
}
}
return hi;
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
cout << sub() << endl;
} | insert | 18 | 18 | 18 | 20 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, a[N];
bool check(int mid) {
map<int, int> b;
for (int i = 2; i <= n; ++i) {
while (!b.empty() && b.rbegin()->first >= a[i])
b.erase(--b.end());
if (a[i] <= a[i - 1]) {
++b[a[i] - 1];
for (int j = a[i] - 1; b.count(j) && b[j] == mid; --j) {
b.erase(j);
if (j == 0)
return false;
++b[j - 1];
}
}
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", a + i);
int l = 1, r = n;
while (l < r) {
int mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%d\n", r);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, a[N];
bool check(int mid) {
map<int, int> b;
for (int i = 2; i <= n; ++i) {
while (!b.empty() && b.rbegin()->first >= a[i])
b.erase(--b.end());
if (a[i] <= a[i - 1]) {
++b[a[i] - 1];
for (int j = a[i] - 1; b.count(j) && b[j] == mid; --j) {
b.erase(j);
if (j == 0)
return false;
++b[j - 1];
}
}
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", a + i);
bool flag = true;
for (int i = 2; i <= n; ++i)
flag &= a[i] > a[i - 1];
if (flag)
return puts("1"), 0;
int l = 2, r = n;
while (l < r) {
int mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%d\n", r);
return 0;
}
| replace | 28 | 29 | 28 | 34 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T> using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for (ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for (ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for (ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for (ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2> bool chmax(T1 &a, const T2 b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T1, class T2> bool chmin(T1 &a, const T2 b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll pow2(const int n) { return (1LL << n); }
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (const T &i : v)
os << i << ' ';
return os;
}
void co() { cout << '\n'; }
template <class Head, class... Tail> void co(Head &&head, Tail &&...tail) {
cout << head << ' ';
co(forward<Tail>(tail)...);
}
void ce() { cerr << '\n'; }
template <class Head, class... Tail> void ce(Head &&head, Tail &&...tail) {
cerr << head << ' ';
ce(forward<Tail>(tail)...);
}
void sonic() {
ios::sync_with_stdio(false);
cin.tie(0);
}
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);
template <class T> struct BIT {
ll N;
vector<T> data;
BIT(int64_t n) { init(n); }
void init(int64_t n) {
N = 1;
while (N <= n)
N <<= 1;
data.assign(N, 0);
}
void build(vector<T> v) {
data.assign(N, 0);
for (size_t i = 0; i < v.size(); ++i) {
if (i == 0)
trans(i, v[i]);
else
trans(i, v[i] - v[i - 1]);
}
trans(v.size(), -v.back());
}
void trans(int64_t k, T x) {
++k;
while (k <= N) {
data[k] += x;
k += k & -k;
}
}
void update(int64_t k, T x) { add(k, k + 1, x - at(k)); }
void add(int64_t k, T x) { add(k, k + 1, x); }
void add(int64_t a, int64_t b, T x) {
trans(a, x);
trans(b, -x);
}
T at(int64_t k) {
++k;
T res = 0;
while (k > 0) {
res += data[k];
k -= k & -k;
}
return res;
}
};
int main(void) {
ll n;
cin >> n;
Vec a(n);
rep(i, n) cin >> a[i];
rep(i, n) chmin(a[i], 3e5);
ll l = 0, r = 3e5;
while (r - l > 1) {
ll m = (l + r) / 2;
BIT<ll> bit(3e5);
ll len = 0;
rep(i, n) {
if (a[i] > len) {
len = a[i];
continue;
}
len = a[i];
if (a[i] == 3e5)
continue;
if (bit.at(a[i]) < 0)
bit.update(a[i], 0);
bit.add(a[i], 1);
bit.add(a[i] + 1, 3e5, -INF);
ll p = a[i];
while (p >= 1 && bit.at(p) >= m) {
bit.update(p, 0);
--p;
if (bit.at(p) < 0)
bit.update(p, 0);
bit.add(p, 1);
}
}
if (bit.at(0) == 0)
r = m;
else
l = m;
}
co(r);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T> using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for (ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for (ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for (ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for (ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2> bool chmax(T1 &a, const T2 b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T1, class T2> bool chmin(T1 &a, const T2 b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll pow2(const int n) { return (1LL << n); }
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (const T &i : v)
os << i << ' ';
return os;
}
void co() { cout << '\n'; }
template <class Head, class... Tail> void co(Head &&head, Tail &&...tail) {
cout << head << ' ';
co(forward<Tail>(tail)...);
}
void ce() { cerr << '\n'; }
template <class Head, class... Tail> void ce(Head &&head, Tail &&...tail) {
cerr << head << ' ';
ce(forward<Tail>(tail)...);
}
void sonic() {
ios::sync_with_stdio(false);
cin.tie(0);
}
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);
template <class T> struct BIT {
ll N;
vector<T> data;
BIT(int64_t n) { init(n); }
void init(int64_t n) {
N = 1;
while (N <= n)
N <<= 1;
data.assign(N, 0);
}
void build(vector<T> v) {
data.assign(N, 0);
for (size_t i = 0; i < v.size(); ++i) {
if (i == 0)
trans(i, v[i]);
else
trans(i, v[i] - v[i - 1]);
}
trans(v.size(), -v.back());
}
void trans(int64_t k, T x) {
++k;
while (k <= N) {
data[k] += x;
k += k & -k;
}
}
void update(int64_t k, T x) { add(k, k + 1, x - at(k)); }
void add(int64_t k, T x) { add(k, k + 1, x); }
void add(int64_t a, int64_t b, T x) {
trans(a, x);
trans(b, -x);
}
T at(int64_t k) {
++k;
T res = 0;
while (k > 0) {
res += data[k];
k -= k & -k;
}
return res;
}
};
int main(void) {
ll n;
cin >> n;
Vec a(n);
rep(i, n) cin >> a[i];
rep(i, n) chmin(a[i], 3e5);
ll l = 0, r = 3e5;
while (r - l > 1) {
ll m = (l + r) / 2;
BIT<ll> bit(3e5);
ll len = 0;
rep(i, n) {
if (a[i] > len) {
len = a[i];
continue;
}
len = a[i];
if (a[i] == 3e5)
continue;
if (bit.at(a[i]) < 0)
bit.update(a[i], 0);
bit.add(a[i], 1);
bit.add(a[i] + 1, 3e5, -INF);
ll p = a[i];
while (p >= 1 && bit.at(p) >= m) {
bit.update(p, 0);
--p;
if (bit.at(p) < 0)
bit.update(p, 0);
bit.add(p, 1);
}
if (bit.at(0) != 0)
break;
}
if (bit.at(0) == 0)
r = m;
else
l = m;
}
co(r);
return 0;
}
| insert | 150 | 150 | 150 | 152 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T> using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for (ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for (ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for (ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for (ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2> bool chmax(T1 &a, const T2 b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T1, class T2> bool chmin(T1 &a, const T2 b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll pow2(const int n) { return (1LL << n); }
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (const T &i : v)
os << i << ' ';
return os;
}
void co() { cout << '\n'; }
template <class Head, class... Tail> void co(Head &&head, Tail &&...tail) {
cout << head << ' ';
co(forward<Tail>(tail)...);
}
void ce() { cerr << '\n'; }
template <class Head, class... Tail> void ce(Head &&head, Tail &&...tail) {
cerr << head << ' ';
ce(forward<Tail>(tail)...);
}
void sonic() {
ios::sync_with_stdio(false);
cin.tie(0);
}
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);
int main(void) {
ll n;
cin >> n;
Vec a(n);
rep(i, n) cin >> a[i];
ce(a[144650]);
ce(a[144651]);
ll l = 0, r = 3e5;
while (r - l > 1) {
ll m = (l + r) / 2;
map<ll, ll> mp;
ll len = 0;
rep(i, n) {
if (a[i] > len) {
len = a[i];
continue;
}
if (m == 1) {
mp[0]++;
break;
}
len = a[i];
ll p = len;
while (p >= 1 && mp[p] >= m - 1) {
--p;
}
mp.erase(mp.upper_bound(p), mp.end());
mp[p]++;
if (mp[0] != 0)
break;
}
if (mp[0] == 0)
r = m;
else
l = m;
}
co(r);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T> using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for (ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for (ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for (ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for (ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2> bool chmax(T1 &a, const T2 b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T1, class T2> bool chmin(T1 &a, const T2 b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll pow2(const int n) { return (1LL << n); }
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (const T &i : v)
os << i << ' ';
return os;
}
void co() { cout << '\n'; }
template <class Head, class... Tail> void co(Head &&head, Tail &&...tail) {
cout << head << ' ';
co(forward<Tail>(tail)...);
}
void ce() { cerr << '\n'; }
template <class Head, class... Tail> void ce(Head &&head, Tail &&...tail) {
cerr << head << ' ';
ce(forward<Tail>(tail)...);
}
void sonic() {
ios::sync_with_stdio(false);
cin.tie(0);
}
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);
int main(void) {
ll n;
cin >> n;
Vec a(n);
rep(i, n) cin >> a[i];
ll l = 0, r = 3e5;
while (r - l > 1) {
ll m = (l + r) / 2;
map<ll, ll> mp;
ll len = 0;
rep(i, n) {
if (a[i] > len) {
len = a[i];
continue;
}
if (m == 1) {
mp[0]++;
break;
}
len = a[i];
ll p = len;
while (p >= 1 && mp[p] >= m - 1) {
--p;
}
mp.erase(mp.upper_bound(p), mp.end());
mp[p]++;
if (mp[0] != 0)
break;
}
if (mp[0] == 0)
r = m;
else
l = m;
}
co(r);
return 0;
} | delete | 72 | 74 | 72 | 72 | -11 | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
bool add(map<int, int> &a, int d, int b) {
for (int j = d; j >= 0; j--) {
a[j]++;
if (a[j] == b) {
if (j == 0)
return false;
a[j] = 0;
} else {
break;
}
}
return true;
}
int n;
int a[200010];
bool ok(int X) {
map<int, int> crt;
repl(i, 1, n) {
if (a[i - 1] >= a[i]) {
while (crt.lower_bound(a[i]) != crt.end()) {
crt.erase(crt.lower_bound(a[i]));
}
if (!add(crt, a[i] - 1, X))
return false;
}
}
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
rep(i, n) { cin >> a[i]; }
int lb = 0, ub = n + 1;
while (ub - lb > 1) {
int mid = (lb + ub) / 2;
if (ok(mid))
ub = mid;
else
lb = mid;
}
cout << ub << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
bool add(map<int, int> &a, int d, int b) {
for (int j = d; j >= 0; j--) {
a[j]++;
if (a[j] == b) {
if (j == 0)
return false;
a[j] = 0;
} else {
break;
}
}
return true;
}
int n;
int a[200010];
bool ok(int X) {
if (X == 1) {
rep(i, n - 1) {
if (a[i] >= a[i + 1])
return false;
}
return true;
}
map<int, int> crt;
repl(i, 1, n) {
if (a[i - 1] >= a[i]) {
while (crt.lower_bound(a[i]) != crt.end()) {
crt.erase(crt.lower_bound(a[i]));
}
if (!add(crt, a[i] - 1, X))
return false;
}
}
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
rep(i, n) { cin >> a[i]; }
int lb = 0, ub = n + 1;
while (ub - lb > 1) {
int mid = (lb + ub) / 2;
if (ok(mid))
ub = mid;
else
lb = mid;
}
cout << ub << endl;
return 0;
}
| insert | 42 | 42 | 42 | 49 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (i64 i = (s); (i) < (e); (i)++)
#define all(x) x.begin(), x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ std::cout << PREFIX << #x << " = " << x << std::endl; }
std::ostream &output_indent(std::ostream &os, int ind) {
for (int i = 0; i < ind; i++)
os << " ";
return os;
}
template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p);
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v);
template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) {
return (os << "(" << p.first << ", " << p.second << ")");
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
os << "[";
for (int i = 0; i < v.size(); i++)
os << v[i] << ", ";
return (os << "]");
}
template <class T, class V>
std::ostream &operator<<(std::ostream &os, const std::map<T, V> &v) {
os << "{";
for (auto p : v)
os << p << ", ";
return (os << "}");
}
template <class T> static inline std::vector<T> ndvec(size_t &&n, T val) {
return std::vector<T>(n, std::forward<T>(val));
}
template <class... Tail> static inline auto ndvec(size_t &&n, Tail &&...tail) {
return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(
n, ndvec(std::forward<Tail>(tail)...));
}
template <class Cond> struct chain {
Cond cond;
chain(Cond cond) : cond(cond) {}
template <class T> bool operator()(T &a, const T &b) const {
if (cond(a, b)) {
a = b;
return true;
}
return false;
}
};
template <class Cond> chain<Cond> make_chain(Cond cond) {
return chain<Cond>(cond);
}
int main() {
i64 N;
cin >> N;
vector<i64> A(N);
rep(i, 0, N) cin >> A[i];
auto func = [&](i64 K) {
map<i64, i64> mp;
mp[0] = 0;
rep(i, 1, N) {
i64 b = A[i - 1];
i64 a = A[i];
if (b < a) {
auto iter = mp.end();
--iter;
if (iter->second > 0) {
mp[b] = 0;
}
} else {
i64 j = a - 1;
while (j >= 0) {
auto iter = mp.upper_bound(j);
--iter;
i64 x = iter->second;
if (x + 1 == K) {
j = iter->second - 1;
mp.erase(iter);
} else {
mp[j] = x + 1;
mp[j + 1] = 0;
break;
}
}
if (j <= -1) {
return false;
}
auto iter = mp.lower_bound(a);
while (iter != mp.end()) {
mp.erase(iter++);
}
}
}
return true;
};
i64 ok = N;
i64 ng = 0;
while (abs(ng - ok) > 1) {
i64 m = (ok + ng) >> 1;
if (func(m)) {
ok = m;
} else {
ng = m;
}
}
cout << ok << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, s, e) for (i64 i = (s); (i) < (e); (i)++)
#define all(x) x.begin(), x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ std::cout << PREFIX << #x << " = " << x << std::endl; }
std::ostream &output_indent(std::ostream &os, int ind) {
for (int i = 0; i < ind; i++)
os << " ";
return os;
}
template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p);
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v);
template <class S, class T>
std::ostream &operator<<(std::ostream &os, const std::pair<S, T> &p) {
return (os << "(" << p.first << ", " << p.second << ")");
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
os << "[";
for (int i = 0; i < v.size(); i++)
os << v[i] << ", ";
return (os << "]");
}
template <class T, class V>
std::ostream &operator<<(std::ostream &os, const std::map<T, V> &v) {
os << "{";
for (auto p : v)
os << p << ", ";
return (os << "}");
}
template <class T> static inline std::vector<T> ndvec(size_t &&n, T val) {
return std::vector<T>(n, std::forward<T>(val));
}
template <class... Tail> static inline auto ndvec(size_t &&n, Tail &&...tail) {
return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(
n, ndvec(std::forward<Tail>(tail)...));
}
template <class Cond> struct chain {
Cond cond;
chain(Cond cond) : cond(cond) {}
template <class T> bool operator()(T &a, const T &b) const {
if (cond(a, b)) {
a = b;
return true;
}
return false;
}
};
template <class Cond> chain<Cond> make_chain(Cond cond) {
return chain<Cond>(cond);
}
int main() {
i64 N;
cin >> N;
vector<i64> A(N);
rep(i, 0, N) cin >> A[i];
auto func = [&](i64 K) {
map<i64, i64> mp;
mp[0] = 0;
rep(i, 1, N) {
i64 b = A[i - 1];
i64 a = A[i];
if (b < a) {
auto iter = mp.end();
--iter;
if (iter->second > 0) {
mp[b] = 0;
}
} else {
i64 j = a - 1;
while (j >= 0) {
auto iter = mp.upper_bound(j);
--iter;
i64 x = iter->second;
if (x + 1 == K) {
j = iter->first - 1;
mp.erase(iter);
} else {
mp[j] = x + 1;
mp[j + 1] = 0;
break;
}
}
if (j <= -1) {
return false;
}
auto iter = mp.lower_bound(a);
while (iter != mp.end()) {
mp.erase(iter++);
}
}
}
return true;
};
i64 ok = N;
i64 ng = 0;
while (abs(ng - ok) > 1) {
i64 m = (ok + ng) >> 1;
if (func(m)) {
ok = m;
} else {
ng = m;
}
}
cout << ok << endl;
}
| replace | 88 | 89 | 88 | 89 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
bool ispossible(vector<int> &A, ll d) {
int N = A.size();
map<ll, ll> digit;
for (int i = 1; i < N; i++) {
if (A[i] <= A[i - 1]) {
bool cont = true;
int now = A[i];
while (cont && now != 0) {
cont = false;
digit[now]++;
if (digit[now] == d) {
digit.erase(now);
now--;
cont = true;
}
}
if (now == 0)
return false;
for (auto it = digit.lower_bound(A[i] + 1); it != digit.end();
it = digit.erase(it))
;
}
}
return true;
}
void solve() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll ok = 200000;
ll ng = 0;
while (ok - ng > 1) {
ll c = (ok + ng) / 2;
if (ispossible(A, c)) {
ok = c;
} else {
ng = c;
}
}
cout << ok << endl;
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
bool ispossible(vector<int> &A, ll d) {
int N = A.size();
if (d == 1) {
for (int i = 0; i + 1 < N; i++) {
if (A[i + 1] <= A[i]) {
return false;
}
}
return true;
}
map<ll, ll> digit;
for (int i = 1; i < N; i++) {
if (A[i] <= A[i - 1]) {
bool cont = true;
int now = A[i];
while (cont && now != 0) {
cont = false;
digit[now]++;
if (digit[now] == d) {
digit.erase(now);
now--;
cont = true;
}
}
if (now == 0)
return false;
for (auto it = digit.lower_bound(A[i] + 1); it != digit.end();
it = digit.erase(it))
;
}
}
return true;
}
void solve() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
ll ok = 200000;
ll ng = 0;
while (ok - ng > 1) {
ll c = (ok + ng) / 2;
if (ispossible(A, c)) {
ok = c;
} else {
ng = c;
}
}
cout << ok << endl;
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| insert | 29 | 29 | 29 | 37 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i, u) for (register int i = head[u]; i; i = nxt[i])
#define rep(i, a, b) for (register int i = (a); i <= (b); i++)
#define per(i, a, b) for (register int i = (a); i >= (b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
x = 0;
char c = getchar();
int f = 1;
while (!isdigit(c)) {
if (c == '-')
f = -1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
x *= f;
}
inline ui R() {
static ui seed = 416;
return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
const int N = 666666;
int n, a[N]; //,b[N];
void ls() {
static int v[N];
rep(i, 1, n) v[i] = a[i];
sort(v + 1, v + n + 1);
rep(i, 1, n) a[i] = lower_bound(v + 1, v + n + 1, a[i]) - v;
}
int main() {
read(n);
rep(i, 1, n) read(a[i]); // ls();
// rep(i,1,n)printf("qaq %d\n",a[i]);
int l = 1, r = n, res = n;
while (l <= r) {
int mid = (l + r) >> 1; // memset(b,0,sizeof(b));
bool gg = 0;
priority_queue<int> heap;
map<int, int> b;
rep(i, 1, n) {
/*if(a[i-1]<a[i]){
assert(heap.empty()||heap.top()<=a[i-1]);
//
while(!heap.empty()&&heap.top()>a[i-1])b[heap.top()]=0,heap.pop(); }else*/
if (a[i - 1] >= a[i]) {
if (mid == 1) {
gg = 1;
break;
}
int j;
for (j = a[i]; j >= 1; j--)
if (b[j] < mid - 1)
break;
if (!j) {
gg = 1;
break;
}
// printf("find %d <%d>\n",j,a[i]);
b[j]++;
heap.push(j); // erase(j+1..a[i])
while (!heap.empty() && heap.top() > j)
b[heap.top()] = 0, heap.pop();
}
// rep(j,1,(heap.empty()?0:heap.top()))printf("%d ",b[j]);puts("");
}
if (!gg)
res = mid, r = mid - 1;
else
l = mid + 1;
}
cout << res;
return 0;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i, u) for (register int i = head[u]; i; i = nxt[i])
#define rep(i, a, b) for (register int i = (a); i <= (b); i++)
#define per(i, a, b) for (register int i = (a); i >= (b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
x = 0;
char c = getchar();
int f = 1;
while (!isdigit(c)) {
if (c == '-')
f = -1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
x *= f;
}
inline ui R() {
static ui seed = 416;
return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
const int N = 666666;
int n, a[N]; //,b[N];
void ls() {
static int v[N];
rep(i, 1, n) v[i] = a[i];
sort(v + 1, v + n + 1);
rep(i, 1, n) a[i] = lower_bound(v + 1, v + n + 1, a[i]) - v;
}
int main() {
read(n);
rep(i, 1, n) read(a[i]); // ls();
// rep(i,1,n)printf("qaq %d\n",a[i]);
int l = 1, r = n, res = n;
while (l <= r) {
int mid = (l + r) >> 1; // memset(b,0,sizeof(b));
bool gg = 0;
priority_queue<int> heap;
map<int, int> b;
rep(i, 1, n) {
/*if(a[i-1]<a[i]){
assert(heap.empty()||heap.top()<=a[i-1]);
//
while(!heap.empty()&&heap.top()>a[i-1])b[heap.top()]=0,heap.pop(); }else*/
if (a[i - 1] >= a[i]) {
if (mid == 1) {
gg = 1;
break;
}
int j;
for (j = a[i]; j >= 1; j--)
if (b[j] < mid - 1)
break;
if (!j) {
gg = 1;
break;
}
// printf("find %d <%d>\n",j,a[i]);
b[j]++;
rep(k, j + 1, a[i]) b.erase(k);
heap.push(j); // erase(j+1..a[i])
while (!heap.empty() && heap.top() > j)
b[heap.top()] = 0, heap.pop();
}
// rep(j,1,(heap.empty()?0:heap.top()))printf("%d ",b[j]);puts("");
}
if (!gg)
res = mid, r = mid - 1;
else
l = mid + 1;
}
cout << res;
return 0;
}
| insert | 70 | 70 | 70 | 71 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define pdi pair<db, int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
// #define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template <class T> void read(T &res) {
res = 0;
char c = getchar();
T f = 1;
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template <class T> void out(T x) {
if (x < 0) {
x = -x;
putchar('-');
}
if (x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int A[MAXN];
int pw[MAXN][25], cnt[MAXN], ans;
vector<pii> v;
void Init() {
read(N);
for (int i = 1; i <= N; ++i)
read(A[i]);
cnt[1] = 1000000000;
for (int i = 1; i <= N; ++i) {
pw[i][0] = 1;
for (int j = 1; j <= 20; ++j) {
if (pw[i][j - 1] > N / i) {
cnt[i] = j - 1;
break;
}
pw[i][j] = pw[i][j - 1] * i;
}
}
}
bool check(int mid) {
v.clear();
v.pb(mp(A[1], 0));
int sum = A[1];
for (int i = 2; i <= N; ++i) {
if (A[i] <= A[i - 1]) {
if (sum < A[i - 1]) {
v.pb(mp(A[i - 1] - sum, 0));
sum = A[i - 1];
}
int s = v.size() - 1;
for (int k = s; k >= 0; --k) {
if (sum - v[k].fi >= A[i]) {
sum -= v[k].fi;
v.pop_back();
} else {
int t = sum - A[i];
if (t > cnt[mid])
v[k].se = 0;
else
v[k].se /= pw[mid][t];
v[k].fi -= t;
sum = A[i];
}
if (sum == A[i])
break;
}
s = v.size() - 1;
for (int k = s; k >= 0; --k) {
if (v[k].fi <= cnt[mid]) {
if (v[k].se + 1 < pw[mid][v[k].fi]) {
++v[k].se;
break;
} else {
v[k].se = 0;
if (k == 0)
return false;
}
} else {
++v[k].se;
break;
}
}
}
}
return true;
}
void Solve() {
int l = 1, r = N;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
out(l);
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in", "r", stdin);
#endif
Init();
Solve();
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define pdi pair<db, int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
// #define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template <class T> void read(T &res) {
res = 0;
char c = getchar();
T f = 1;
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template <class T> void out(T x) {
if (x < 0) {
x = -x;
putchar('-');
}
if (x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int A[MAXN];
int pw[MAXN][25], cnt[MAXN], ans;
vector<pii> v;
void Init() {
read(N);
for (int i = 1; i <= N; ++i)
read(A[i]);
cnt[1] = 1000000000;
for (int i = 1; i <= N; ++i) {
pw[i][0] = 1;
for (int j = 1; j <= 20; ++j) {
if (pw[i][j - 1] > N / i) {
cnt[i] = j - 1;
break;
}
pw[i][j] = pw[i][j - 1] * i;
}
}
}
bool check(int mid) {
v.clear();
v.pb(mp(A[1], 0));
int sum = A[1];
for (int i = 2; i <= N; ++i) {
if (A[i] <= A[i - 1]) {
if (mid == 1)
return false;
if (sum < A[i - 1]) {
v.pb(mp(A[i - 1] - sum, 0));
sum = A[i - 1];
}
int s = v.size() - 1;
for (int k = s; k >= 0; --k) {
if (sum - v[k].fi >= A[i]) {
sum -= v[k].fi;
v.pop_back();
} else {
int t = sum - A[i];
if (t > cnt[mid])
v[k].se = 0;
else
v[k].se /= pw[mid][t];
v[k].fi -= t;
sum = A[i];
}
if (sum == A[i])
break;
}
s = v.size() - 1;
for (int k = s; k >= 0; --k) {
if (v[k].fi <= cnt[mid]) {
if (v[k].se + 1 < pw[mid][v[k].fi]) {
++v[k].se;
break;
} else {
v[k].se = 0;
if (k == 0)
return false;
}
} else {
++v[k].se;
break;
}
}
}
}
return true;
}
void Solve() {
int l = 1, r = N;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
out(l);
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in", "r", stdin);
#endif
Init();
Solve();
}
| insert | 67 | 67 | 67 | 69 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
typedef complex<double> C;
#define cx real()
#define cy imag()
const ll INF = 1LL << 60;
const double DINF = 1e30;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const C I = C(0, 1);
const double EPS = 1e-10;
const ll NCK_MAX = 510000;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
ll q = a / b, g = extgcd(b, a - q * b, x, y);
ll z = x - q * y;
x = y;
y = z;
return g;
}
ll invmod(ll a, ll m) { // a^-1 mod m
ll x, y;
extgcd(a, m, x, y);
x %= m;
if (x < 0)
x += m;
return x;
}
ll *fac, *finv, *inv;
void nCk_init(ll mod) {
fac = new ll[NCK_MAX];
finv = new ll[NCK_MAX];
inv = new ll[NCK_MAX];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < NCK_MAX; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
ll nCk(ll n, ll k, ll mod) {
if (fac == NULL)
nCk_init(mod);
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
template <typename T> class Zip {
vector<T> d;
bool flag;
void init() {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
public:
Zip() { flag = false; }
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) {
if (flag)
init();
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag)
init();
return (ll)d.size();
}
};
class UnionFind {
vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
UnionFind(ll n) : par(n, 1), rank(n, 0) {}
ll getSize(ll x) { return par[find(x)]; }
ll find(ll x) {
if (par[x] > 0)
return x;
return -(par[x] = -find(-par[x]));
}
void merge(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = -y;
} else {
par[x] += par[y];
par[y] = -x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool isSame(ll x, ll y) { return find(x) == find(y); }
};
template <typename T> class SegmentTree {
ll n;
vector<T> node;
function<T(T, T)> fun, fun2;
bool customChange;
T outValue, initValue;
public:
void init(ll num, function<T(T, T)> resultFunction, T init, T out,
function<T(T, T)> changeFunction = NULL) {
// changeFunction: (input, beforevalue) => newvalue
fun = resultFunction;
fun2 = changeFunction;
customChange = changeFunction != NULL;
n = 1;
while (n < num)
n *= 2;
node.resize(2 * n - 1);
fill(node.begin(), node.end(), init);
outValue = out;
initValue = init;
}
void valueChange(ll num, T value) {
num += n - 1;
if (customChange)
node[num] = fun2(value, node[num]);
else
node[num] = value;
while (num > 0)
num = (num - 1) / 2,
node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]);
}
T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
if (r == -1)
r = n;
if (a <= l && r <= b)
return node[k];
if (b <= l || r <= a)
return outValue;
ll mid = (l + r) / 2;
return fun(rangeQuery(a, b, l, mid, 2 * k + 1),
rangeQuery(a, b, mid, r, 2 * k + 2));
}
};
template <typename T> class Graph {
struct edge {
ll to;
T cost;
};
struct edge_data {
ll from, to;
T cost;
};
ll v;
vector<vector<edge>> e, re;
vector<edge_data> ed;
vector<bool> used;
vector<ll> vs, cmp;
bool isDirected, isMinasEdge;
public:
Graph(ll _v, bool _isDirected = true, ll range_add = 0) {
// range_add 0:no / 1:in / 2:out / 3:in+out
//_v++;
v = _v, isDirected = _isDirected;
isMinasEdge = false;
e.resize(v), re.resize(v);
}
void add_edge(ll s, ll t, T cost = 1) {
e[s].push_back((edge){t, cost});
if (!isDirected)
e[t].push_back((edge){s, cost});
else
re[t].push_back((edge){s, cost});
ed.push_back((edge_data){s, t, cost});
if (cost < 0)
isMinasEdge = true;
}
vector<T> dijkstra(ll s) {
vector<T> d(v, INF);
d[s] = 0;
auto edge_cmp = [](const edge &a, const edge &b) {
return a.cost > b.cost;
};
priority_queue<edge, vector<edge>, decltype(edge_cmp)> pq(edge_cmp);
pq.push((edge){s, 0});
while (!pq.empty()) {
edge temp = pq.top();
pq.pop();
if (d[temp.to] < temp.cost)
continue;
for (const edge &next : e[temp.to]) {
T cost = temp.cost + next.cost;
if (d[next.to] > cost) {
d[next.to] = cost;
pq.push((edge){next.to, cost});
}
}
}
return d;
}
vector<T> bellmanford(ll s) {
vector<T> d(v, INF);
d[s] = 0;
for (ll i = 0; i < v; i++) {
for (const edge_data &temp : ed) {
if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost)
d[temp.to] = d[temp.from] + temp.cost;
if (!isDirected && d[temp.to] != INF &&
d[temp.from] > d[temp.to] + temp.cost)
d[temp.from] = d[temp.to] + temp.cost;
}
}
for (ll i = 0; i < v; i++) {
for (const edge_data &temp : ed) {
if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost)
d[temp.to] = -INF;
if (!isDirected && d[temp.to] != INF &&
d[temp.from] > d[temp.to] + temp.cost)
d[temp.from] = -INF;
}
}
return d;
}
vector<T> shortest_path(ll s) {
if (isMinasEdge)
return bellmanford(s);
else
return dijkstra(s);
}
T kruskal() {
// if (isDirected)
UnionFind uf(v);
auto edge_data_cmp = [](const edge_data &a, const edge_data &b) {
return a.cost < b.cost;
};
sort(ed.begin(), ed.end(), edge_data_cmp);
T ans = 0;
for (const edge_data &temp : ed) {
if (uf.isSame(temp.from, temp.to))
continue;
uf.merge(temp.from, temp.to);
ans += temp.cost;
}
return ans;
}
void scc_dfs(ll s) {
used[s] = true;
for (const edge &i : e[s])
if (!used[i.to])
scc_dfs(i.to);
vs.push_back(s);
}
void scc_rdfs(ll s, ll k) {
used[s] = true;
cmp[s] = k;
for (const edge &i : re[s])
if (!used[i.to])
scc_rdfs(i.to, k);
}
vector<ll> scc() {
used.resize(v);
fill(used.begin(), used.end(), false);
cmp.resize(v);
vs.clear();
for (ll i = 0; i < v; i++)
if (!used[i])
scc_dfs(i);
used.resize(v);
fill(used.begin(), used.end(), false);
ll k = 0;
for (ll i = vs.size() - 1; i >= 0; i--)
if (!used[vs[i]])
scc_rdfs(vs[i], k++);
return cmp;
}
};
class RollingHash {
int base;
vector<__int128> hash;
vector<__int128> pw;
const __int128 hashmod = (1ull << 61) - 1;
public:
RollingHash(string s, int base = 10007)
: base(base), hash(s.length() + 1, 0), pw(s.length() + 1, 1) {
for (int i = 0; i < (int)s.length(); i++) {
hash[i + 1] = (hash[i] * base + s[i]) % hashmod;
pw[i + 1] = pw[i] * base % hashmod;
}
}
ll get(ll a, ll b) { // [a, b)
__int128 tmp = hashmod + hash[b] - hash[a] * pw[b - a] % hashmod;
if (tmp >= hashmod)
tmp -= hashmod;
return (ll)tmp;
}
};
ll n, a[200000];
ll small(map<ll, ll> &mp, ll before, ll x) {
while (mp[before] > x) {
mp.erase(before);
before--;
if (before == 0)
return 0;
if (mp[before] == 0)
mp[before] = 1;
mp[before]++;
}
return before;
}
bool check(ll x) {
map<ll, ll> mp;
mp[a[0]] = 1;
ll before = a[0];
for (ll i = 1; i < n; i++) {
if (before < a[i]) {
before = a[i];
mp[a[i]] = 1;
} else if (before == a[i]) {
mp[a[i]]++;
before = small(mp, a[i], x);
if (before <= 0)
return false;
} else {
before = a[i];
ll tmp;
while (!mp.empty() && ((tmp = mp.rbegin()->first) > a[i]))
mp.erase(tmp);
if (mp[a[i]] == 0)
mp[a[i]] = 1;
mp[a[i]]++;
before = small(mp, a[i], x);
if (before <= 0)
return false;
}
// for (auto it = mp.begin(); it != mp.end(); it++) printf("%lld %lld\n",
// it->first, it->second); printf("\n");
}
return true;
}
int main() {
scanf("%lld", &n);
for (ll i = 0; i < n; i++)
scanf("%lld", &a[i]);
ll lb = 0, ub = n;
while (lb + 1 < ub) {
ll mid = (lb + ub) / 2;
if (check(mid))
ub = mid;
else
lb = mid;
}
printf("%lld\n", ub);
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
typedef complex<double> C;
#define cx real()
#define cy imag()
const ll INF = 1LL << 60;
const double DINF = 1e30;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const C I = C(0, 1);
const double EPS = 1e-10;
const ll NCK_MAX = 510000;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
ll q = a / b, g = extgcd(b, a - q * b, x, y);
ll z = x - q * y;
x = y;
y = z;
return g;
}
ll invmod(ll a, ll m) { // a^-1 mod m
ll x, y;
extgcd(a, m, x, y);
x %= m;
if (x < 0)
x += m;
return x;
}
ll *fac, *finv, *inv;
void nCk_init(ll mod) {
fac = new ll[NCK_MAX];
finv = new ll[NCK_MAX];
inv = new ll[NCK_MAX];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < NCK_MAX; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
ll nCk(ll n, ll k, ll mod) {
if (fac == NULL)
nCk_init(mod);
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
template <typename T> class Zip {
vector<T> d;
bool flag;
void init() {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
public:
Zip() { flag = false; }
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) {
if (flag)
init();
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag)
init();
return (ll)d.size();
}
};
class UnionFind {
vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
UnionFind(ll n) : par(n, 1), rank(n, 0) {}
ll getSize(ll x) { return par[find(x)]; }
ll find(ll x) {
if (par[x] > 0)
return x;
return -(par[x] = -find(-par[x]));
}
void merge(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = -y;
} else {
par[x] += par[y];
par[y] = -x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool isSame(ll x, ll y) { return find(x) == find(y); }
};
template <typename T> class SegmentTree {
ll n;
vector<T> node;
function<T(T, T)> fun, fun2;
bool customChange;
T outValue, initValue;
public:
void init(ll num, function<T(T, T)> resultFunction, T init, T out,
function<T(T, T)> changeFunction = NULL) {
// changeFunction: (input, beforevalue) => newvalue
fun = resultFunction;
fun2 = changeFunction;
customChange = changeFunction != NULL;
n = 1;
while (n < num)
n *= 2;
node.resize(2 * n - 1);
fill(node.begin(), node.end(), init);
outValue = out;
initValue = init;
}
void valueChange(ll num, T value) {
num += n - 1;
if (customChange)
node[num] = fun2(value, node[num]);
else
node[num] = value;
while (num > 0)
num = (num - 1) / 2,
node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]);
}
T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b)
if (r == -1)
r = n;
if (a <= l && r <= b)
return node[k];
if (b <= l || r <= a)
return outValue;
ll mid = (l + r) / 2;
return fun(rangeQuery(a, b, l, mid, 2 * k + 1),
rangeQuery(a, b, mid, r, 2 * k + 2));
}
};
template <typename T> class Graph {
struct edge {
ll to;
T cost;
};
struct edge_data {
ll from, to;
T cost;
};
ll v;
vector<vector<edge>> e, re;
vector<edge_data> ed;
vector<bool> used;
vector<ll> vs, cmp;
bool isDirected, isMinasEdge;
public:
Graph(ll _v, bool _isDirected = true, ll range_add = 0) {
// range_add 0:no / 1:in / 2:out / 3:in+out
//_v++;
v = _v, isDirected = _isDirected;
isMinasEdge = false;
e.resize(v), re.resize(v);
}
void add_edge(ll s, ll t, T cost = 1) {
e[s].push_back((edge){t, cost});
if (!isDirected)
e[t].push_back((edge){s, cost});
else
re[t].push_back((edge){s, cost});
ed.push_back((edge_data){s, t, cost});
if (cost < 0)
isMinasEdge = true;
}
vector<T> dijkstra(ll s) {
vector<T> d(v, INF);
d[s] = 0;
auto edge_cmp = [](const edge &a, const edge &b) {
return a.cost > b.cost;
};
priority_queue<edge, vector<edge>, decltype(edge_cmp)> pq(edge_cmp);
pq.push((edge){s, 0});
while (!pq.empty()) {
edge temp = pq.top();
pq.pop();
if (d[temp.to] < temp.cost)
continue;
for (const edge &next : e[temp.to]) {
T cost = temp.cost + next.cost;
if (d[next.to] > cost) {
d[next.to] = cost;
pq.push((edge){next.to, cost});
}
}
}
return d;
}
vector<T> bellmanford(ll s) {
vector<T> d(v, INF);
d[s] = 0;
for (ll i = 0; i < v; i++) {
for (const edge_data &temp : ed) {
if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost)
d[temp.to] = d[temp.from] + temp.cost;
if (!isDirected && d[temp.to] != INF &&
d[temp.from] > d[temp.to] + temp.cost)
d[temp.from] = d[temp.to] + temp.cost;
}
}
for (ll i = 0; i < v; i++) {
for (const edge_data &temp : ed) {
if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost)
d[temp.to] = -INF;
if (!isDirected && d[temp.to] != INF &&
d[temp.from] > d[temp.to] + temp.cost)
d[temp.from] = -INF;
}
}
return d;
}
vector<T> shortest_path(ll s) {
if (isMinasEdge)
return bellmanford(s);
else
return dijkstra(s);
}
T kruskal() {
// if (isDirected)
UnionFind uf(v);
auto edge_data_cmp = [](const edge_data &a, const edge_data &b) {
return a.cost < b.cost;
};
sort(ed.begin(), ed.end(), edge_data_cmp);
T ans = 0;
for (const edge_data &temp : ed) {
if (uf.isSame(temp.from, temp.to))
continue;
uf.merge(temp.from, temp.to);
ans += temp.cost;
}
return ans;
}
void scc_dfs(ll s) {
used[s] = true;
for (const edge &i : e[s])
if (!used[i.to])
scc_dfs(i.to);
vs.push_back(s);
}
void scc_rdfs(ll s, ll k) {
used[s] = true;
cmp[s] = k;
for (const edge &i : re[s])
if (!used[i.to])
scc_rdfs(i.to, k);
}
vector<ll> scc() {
used.resize(v);
fill(used.begin(), used.end(), false);
cmp.resize(v);
vs.clear();
for (ll i = 0; i < v; i++)
if (!used[i])
scc_dfs(i);
used.resize(v);
fill(used.begin(), used.end(), false);
ll k = 0;
for (ll i = vs.size() - 1; i >= 0; i--)
if (!used[vs[i]])
scc_rdfs(vs[i], k++);
return cmp;
}
};
class RollingHash {
int base;
vector<__int128> hash;
vector<__int128> pw;
const __int128 hashmod = (1ull << 61) - 1;
public:
RollingHash(string s, int base = 10007)
: base(base), hash(s.length() + 1, 0), pw(s.length() + 1, 1) {
for (int i = 0; i < (int)s.length(); i++) {
hash[i + 1] = (hash[i] * base + s[i]) % hashmod;
pw[i + 1] = pw[i] * base % hashmod;
}
}
ll get(ll a, ll b) { // [a, b)
__int128 tmp = hashmod + hash[b] - hash[a] * pw[b - a] % hashmod;
if (tmp >= hashmod)
tmp -= hashmod;
return (ll)tmp;
}
};
ll n, a[200000];
ll small(map<ll, ll> &mp, ll before, ll x) {
if (x == 1 && mp[before] > x)
return 0;
while (mp[before] > x) {
mp.erase(before);
before--;
if (before == 0)
return 0;
if (mp[before] == 0)
mp[before] = 1;
mp[before]++;
}
return before;
}
bool check(ll x) {
map<ll, ll> mp;
mp[a[0]] = 1;
ll before = a[0];
for (ll i = 1; i < n; i++) {
if (before < a[i]) {
before = a[i];
mp[a[i]] = 1;
} else if (before == a[i]) {
mp[a[i]]++;
before = small(mp, a[i], x);
if (before <= 0)
return false;
} else {
before = a[i];
ll tmp;
while (!mp.empty() && ((tmp = mp.rbegin()->first) > a[i]))
mp.erase(tmp);
if (mp[a[i]] == 0)
mp[a[i]] = 1;
mp[a[i]]++;
before = small(mp, a[i], x);
if (before <= 0)
return false;
}
// for (auto it = mp.begin(); it != mp.end(); it++) printf("%lld %lld\n",
// it->first, it->second); printf("\n");
}
return true;
}
int main() {
scanf("%lld", &n);
for (ll i = 0; i < n; i++)
scanf("%lld", &a[i]);
ll lb = 0, ub = n;
while (lb + 1 < ub) {
ll mid = (lb + ub) / 2;
if (check(mid))
ub = mid;
else
lb = mid;
}
printf("%lld\n", ub);
}
| insert | 346 | 346 | 346 | 348 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define long int64_t
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef priority_queue<pii, vector<pii>, greater<pii>> min_pq;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
OST;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF << 1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
const int N = 200001;
int a[N];
bool check(int k, int n) {
unordered_map<int, int> m;
stack<int> s;
for (int i = 1; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
while (!s.empty() and s.top() > a[i]) {
m[s.top()] = 0;
s.pop();
}
int p = a[i];
while (p) {
m[p]++;
if (s.empty() or s.top() != p)
s.push(p);
if (m[p] == k) {
m[p] = 0;
s.pop();
p--;
} else
break;
}
if (p == 0)
return false;
}
return true;
}
int main() {
fio;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int l = 1, r = n;
while (l != r) {
int mid = l + r >> 1;
if (check(mid, n))
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define long int64_t
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef priority_queue<pii, vector<pii>, greater<pii>> min_pq;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
OST;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF << 1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
const int N = 200001;
int a[N];
bool check(int k, int n) {
unordered_map<int, int> m;
stack<int> s;
for (int i = 1; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
if (k == 1)
return false;
while (!s.empty() and s.top() > a[i]) {
m[s.top()] = 0;
s.pop();
}
int p = a[i];
while (p) {
m[p]++;
if (s.empty() or s.top() != p)
s.push(p);
if (m[p] == k) {
m[p] = 0;
s.pop();
p--;
} else
break;
}
if (p == 0)
return false;
}
return true;
}
int main() {
fio;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int l = 1, r = n;
while (l != r) {
int mid = l + r >> 1;
if (check(mid, n))
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
}
| insert | 44 | 44 | 44 | 46 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
vector<ll> A(N);
for (auto &e : A) {
cin >> e;
}
int l = 0, r = N;
while (r - l > 1) {
int mid = (l + r) / 2;
map<int, int> mp;
mp[A[0]] = 0;
bool ok = true;
for (int i = 1; i < N; i++) {
if (A[i - 1] < A[i]) {
auto it = --mp.end();
if (it->second == 0) {
mp.erase(it);
}
mp[A[i]] = 0;
} else {
auto it = mp.lower_bound(A[i]);
if (it->second == mid - 1) {
while (it != mp.begin() && it->second == mid - 1) {
--it;
}
if (it == mp.begin() && it->second == mid - 1) {
ok = false;
break;
}
if (it->first != 1 && mp.find(it->first - 1) == mp.end()) {
mp[it->first - 1] = it->second;
}
it->second++;
auto nit = --mp.end();
while (it != nit) {
mp.erase(nit);
nit = --mp.end();
}
assert(it->first < A[i]);
mp[A[i]] = 0;
} else {
if (A[i] != 1 && mp.lower_bound(A[i] - 1) == it) {
mp[A[i] - 1] = it->second;
}
mp[A[i]] = it->second + 1;
mp.erase(it, mp.end());
}
}
}
if (ok) {
r = mid;
} else {
l = mid;
}
}
cout << r << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
vector<ll> A(N);
for (auto &e : A) {
cin >> e;
}
int l = 0, r = N;
while (r - l > 1) {
int mid = (l + r) / 2;
map<int, int> mp;
mp[A[0]] = 0;
bool ok = true;
for (int i = 1; i < N; i++) {
if (A[i - 1] < A[i]) {
auto it = --mp.end();
if (it->second == 0) {
mp.erase(it);
}
mp[A[i]] = 0;
} else {
auto it = mp.lower_bound(A[i]);
if (it->second == mid - 1) {
while (it != mp.begin() && it->second == mid - 1) {
--it;
}
if (it == mp.begin() && it->second == mid - 1) {
ok = false;
break;
}
if (it->first != 1 && mp.find(it->first - 1) == mp.end()) {
mp[it->first - 1] = it->second;
}
it->second++;
auto nit = --mp.end();
while (it != nit) {
mp.erase(nit);
nit = --mp.end();
}
assert(it->first < A[i]);
mp[A[i]] = 0;
} else {
if (A[i] != 1 && mp.lower_bound(A[i] - 1) == it) {
mp[A[i] - 1] = it->second;
}
mp[A[i]] = it->second + 1;
mp.erase(mp.upper_bound(A[i]), mp.end());
}
}
}
if (ok) {
r = mid;
} else {
l = mid;
}
}
cout << r << endl;
return 0;
} | replace | 55 | 56 | 55 | 56 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, a[200005];
map<ll, ll> p;
bool check(ll x) {
p.clear();
for (int i = 1; i < n; i++) {
ll b = a[i - 1], c = a[i];
if (b >= c) {
p.erase(p.upper_bound(c), p.end());
while (1) {
if (c == 0)
return false;
if (++p[c] < x)
break;
p.erase(c);
c--;
}
}
}
return true;
}
int main(void) {
scanf("%lld", &n);
for (int i = 0; i < n; i++)
scanf("%lld", a + i);
ll l = 0, r = n;
while (r - l > 1) {
ll m = (l + r) / 2;
if (check(m))
r = m;
else
l = m;
}
printf("%lld\n", r);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, a[200005];
map<ll, ll> p;
bool check(ll x) {
p.clear();
for (int i = 1; i < n; i++) {
ll b = a[i - 1], c = a[i];
if (b >= c) {
if (x == 1)
return false;
p.erase(p.upper_bound(c), p.end());
while (1) {
if (c == 0)
return false;
if (++p[c] < x)
break;
p.erase(c);
c--;
}
}
}
return true;
}
int main(void) {
scanf("%lld", &n);
for (int i = 0; i < n; i++)
scanf("%lld", a + i);
ll l = 0, r = n;
while (r - l > 1) {
ll m = (l + r) / 2;
if (check(m))
r = m;
else
l = m;
}
printf("%lld\n", r);
} | insert | 10 | 10 | 10 | 12 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define brep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define brep1(i, n) for (int i = n - 1; i >= 1; i--)
vector<int> a;
int n;
bool check(int x) { // x文字以内で要件を満たせるかどうか
map<int, int> mp;
rep1(i, a.size()) {
if (a[i - 1] < a[i])
continue; // 後ろに文字追加してるだけなのでスキップ
mp[a[i]]++; // a[i]文字目の番号を+1
mp.erase(mp.upper_bound(a[i]), mp.end()); // a[i]より後ろはリセット
brep1(j, a[i] + 1) {
if (mp[j] >= x) {
if (j == 1)
return false; // 最初の文字を越えて繰り上がるようなら失敗
mp[j] = 0;
mp[j - 1]++; // 繰り上がり
} else
break; // 繰り上がり処理の終了
}
}
return true; // 最後までいったら成功
}
int main(void) {
cin >> n;
rep(i, n) {
int num;
cin >> num;
a.emplace_back(num);
}
int min = 0;
int max = n;
while (max - min > 1) { // min<x<=maxでxを二部探索
int mid = (max + min) / 2;
if (check(mid))
max = mid;
else
min = mid;
}
cout << max << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define brep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define brep1(i, n) for (int i = n - 1; i >= 1; i--)
vector<int> a;
int n;
bool check(int x) { // x文字以内で要件を満たせるかどうか
map<int, int> mp;
rep1(i, a.size()) {
if (a[i - 1] < a[i])
continue; // 後ろに文字追加してるだけなのでスキップ
if (x == 1)
return false;
mp[a[i]]++; // a[i]文字目の番号を+1
mp.erase(mp.upper_bound(a[i]), mp.end()); // a[i]より後ろはリセット
brep1(j, a[i] + 1) {
if (mp[j] >= x) {
if (j == 1)
return false; // 最初の文字を越えて繰り上がるようなら失敗
mp[j] = 0;
mp[j - 1]++; // 繰り上がり
} else
break; // 繰り上がり処理の終了
}
}
return true; // 最後までいったら成功
}
int main(void) {
cin >> n;
rep(i, n) {
int num;
cin >> num;
a.emplace_back(num);
}
int min = 0;
int max = n;
while (max - min > 1) { // min<x<=maxでxを二部探索
int mid = (max + min) / 2;
if (check(mid))
max = mid;
else
min = mid;
}
cout << max << endl;
} | replace | 15 | 16 | 15 | 18 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define LL long long
#define LD long double
using namespace std;
const int NN = 200000 + 117;
const int MM = 200000 + 117;
int read() {
int fl = 1, x;
char c;
for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
;
if (c == '-') {
fl = -1;
c = getchar();
}
for (x = 0; c >= '0' && c <= '9'; c = getchar())
x = (x << 3) + (x << 1) + c - '0';
return x * fl;
}
void open() {
freopen("a.in", "r", stdin);
// freopen("a.out","w",stdout);
}
void close() {
fclose(stdin);
fclose(stdout);
}
int m, n;
int a[NN] = {};
struct node {
int p, v;
} s[NN] = {};
bool chk(int x) {
int top = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] <= a[i - 1]) {
int now = a[i];
while (top && s[top - 1].p > now)
--top;
bool fl = 1;
while (top && s[top - 1].p == now) {
++s[top - 1].v;
if (s[top - 1].v < x) {
fl = 0;
break;
}
--top;
--now;
}
if (fl) {
if (now == 0)
return false;
s[top].p = now;
s[top].v = 1;
++top;
}
}
}
return true;
}
int main() {
open();
n = read();
for (int i = 1; i <= n; ++i) {
a[i] = read();
}
bool fl = 0;
for (int i = 2; i <= n; ++i) {
if (a[i] <= a[i - 1]) {
fl = 1;
}
}
if (!fl) {
printf("1\n");
return 0;
}
int l = 2;
int r = n;
while (l != r) {
int mid = (l + r) >> 1;
if (chk(mid)) {
r = mid;
} else
l = mid + 1;
}
printf("%d\n", l);
close();
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define LL long long
#define LD long double
using namespace std;
const int NN = 200000 + 117;
const int MM = 200000 + 117;
int read() {
int fl = 1, x;
char c;
for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
;
if (c == '-') {
fl = -1;
c = getchar();
}
for (x = 0; c >= '0' && c <= '9'; c = getchar())
x = (x << 3) + (x << 1) + c - '0';
return x * fl;
}
void open() {
freopen("a.in", "r", stdin);
// freopen("a.out","w",stdout);
}
void close() {
fclose(stdin);
fclose(stdout);
}
int m, n;
int a[NN] = {};
struct node {
int p, v;
} s[NN] = {};
bool chk(int x) {
int top = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] <= a[i - 1]) {
int now = a[i];
while (top && s[top - 1].p > now)
--top;
bool fl = 1;
while (top && s[top - 1].p == now) {
++s[top - 1].v;
if (s[top - 1].v < x) {
fl = 0;
break;
}
--top;
--now;
}
if (fl) {
if (now == 0)
return false;
s[top].p = now;
s[top].v = 1;
++top;
}
}
}
return true;
}
int main() {
// open();
n = read();
for (int i = 1; i <= n; ++i) {
a[i] = read();
}
bool fl = 0;
for (int i = 2; i <= n; ++i) {
if (a[i] <= a[i - 1]) {
fl = 1;
}
}
if (!fl) {
printf("1\n");
return 0;
}
int l = 2;
int r = n;
while (l != r) {
int mid = (l + r) >> 1;
if (chk(mid)) {
r = mid;
} else
l = mid + 1;
}
printf("%d\n", l);
close();
return 0;
} | replace | 69 | 70 | 69 | 70 | TLE | |
p03202 | C++ | Time Limit Exceeded | // problem:agc029_c
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
inline int read() {
int f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline ll readll() {
ll f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n, a[200005];
bool check(int mid) {
map<int, int> mp;
for (int i = 1; i <= n; ++i) {
if (a[i] <= a[i - 1]) {
while (mp.size() && mp.rbegin()->fst > a[i]) {
map<int, int>::iterator it = mp.end();
mp.erase(--it);
}
for (int j = a[i]; j >= 0; --j) {
if (!j)
return 0;
mp[j]++;
if (mp[j] == mid)
mp[j] = 0;
else
break;
}
}
}
return 1;
}
int main() {
n = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
int l = 1, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
} | // problem:agc029_c
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
inline int read() {
int f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline ll readll() {
ll f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n, a[200005];
bool check(int mid) {
map<int, int> mp;
for (int i = 1; i <= n; ++i) {
if (a[i] <= a[i - 1]) {
if (mid == 1)
return 0;
while (mp.size() && mp.rbegin()->fst > a[i]) {
map<int, int>::iterator it = mp.end();
mp.erase(--it);
}
for (int j = a[i]; j >= 0; --j) {
if (!j)
return 0;
mp[j]++;
if (mp[j] == mid)
mp[j] = 0;
else
break;
}
}
}
return 1;
}
int main() {
n = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
int l = 1, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
} | insert | 50 | 50 | 50 | 52 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, a[N], l, r, t;
vector<int> p, q;
bool C(int k) {
p.clear(), q.clear();
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1]) {
if (k == 1)
return false;
while (!p.empty() && p[p.size() - 1] > a[i])
p.pop_back(), q.pop_back();
if (!p.empty() && p[p.size() - 1] == a[i])
q[q.size() - 1]++;
else
p.push_back(a[i]), q.push_back(1);
while (!p.empty() && q[q.size() - 1] == k) {
t = p[p.size() - 1], p.pop_back(), q.pop_back();
if (!p.size() && p[p.size() - 1] == t - 1)
q[q.size() - 1]++;
else
p.push_back(t - 1), q.push_back(1);
}
if (p[0] == 0)
return false;
}
return true;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
l = 1, r = n;
while (l < r)
if (C((l + r) / 2))
r = (l + r) / 2;
else
l = (l + r) / 2 + 1;
cout << l;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, a[N], l, r, t;
vector<int> p, q;
bool C(int k) {
p.clear(), q.clear();
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1]) {
if (k == 1)
return false;
while (!p.empty() && p[p.size() - 1] > a[i])
p.pop_back(), q.pop_back();
if (!p.empty() && p[p.size() - 1] == a[i])
q[q.size() - 1]++;
else
p.push_back(a[i]), q.push_back(1);
while (!p.empty() && q[q.size() - 1] == k) {
t = p[p.size() - 1], p.pop_back(), q.pop_back();
if (!p.empty() && p[p.size() - 1] == t - 1)
q[q.size() - 1]++;
else
p.push_back(t - 1), q.push_back(1);
}
if (p[0] == 0)
return false;
}
return true;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
l = 1, r = n;
while (l < r)
if (C((l + r) / 2))
r = (l + r) / 2;
else
l = (l + r) / 2 + 1;
cout << l;
return 0;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define each(a, b) for (auto &(a) : (b))
#define all(v) (v).begin(), (v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define cmx(x, y) x = max(x, y)
#define cmn(x, y) x = min(x, y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout << #x << " = " << (x) << endl
#define spair(p) cout << #p << ": " << p.fi << " " << p.se << endl
#define sar(a, n) \
cout << #a << ":"; \
rep(pachico, n) cout << " " << a[pachico]; \
cout << endl
#define svec(v) \
cout << #v << ":"; \
rep(pachico, v.size()) cout << " " << v[pachico]; \
cout << endl
#define svecp(v) \
cout << #v << ":"; \
each(pachico, v) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
#define sset(s) \
cout << #s << ":"; \
each(pachico, s) cout << " " << pachico; \
cout << endl
#define smap(m) \
cout << #m << ":"; \
each(pachico, m) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;
const int MAX_N = 200005;
int n, a[MAX_N];
bool possible(int cri) {
map<int, int> mp;
int prv = 0;
rep(i, n) {
if (a[i] <= prv) {
mp.erase(mp.upper_bound(a[i]), mp.end());
rrep(j, a[i] + 1) {
if (j == 0) {
return false;
}
if (mp[j] < cri - 1) {
mp[j]++;
break;
} else {
mp.erase(j);
}
}
}
prv = a[i];
}
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
int flag = -1;
rep(i, n) {
cin >> a[i];
if (flag >= a[i]) {
flag = INF;
}
cmx(flag, a[i]);
}
if (flag != INF) {
cout << "1\n";
return 0;
}
int l = 0, r = n;
while (r - l > 1) {
int mid = (l + r) / 2;
if (possible(mid)) {
r = mid;
} else {
l = mid;
}
}
cout << r << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define each(a, b) for (auto &(a) : (b))
#define all(v) (v).begin(), (v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define cmx(x, y) x = max(x, y)
#define cmn(x, y) x = min(x, y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout << #x << " = " << (x) << endl
#define spair(p) cout << #p << ": " << p.fi << " " << p.se << endl
#define sar(a, n) \
cout << #a << ":"; \
rep(pachico, n) cout << " " << a[pachico]; \
cout << endl
#define svec(v) \
cout << #v << ":"; \
rep(pachico, v.size()) cout << " " << v[pachico]; \
cout << endl
#define svecp(v) \
cout << #v << ":"; \
each(pachico, v) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
#define sset(s) \
cout << #s << ":"; \
each(pachico, s) cout << " " << pachico; \
cout << endl
#define smap(m) \
cout << #m << ":"; \
each(pachico, m) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;
const int MAX_N = 200005;
int n, a[MAX_N];
bool possible(int cri) {
map<int, int> mp;
int prv = 0;
rep(i, n) {
if (a[i] <= prv) {
mp.erase(mp.upper_bound(a[i]), mp.end());
rrep(j, a[i] + 1) {
if (j == 0) {
return false;
}
if (mp[j] < cri - 1) {
mp[j]++;
break;
} else {
mp.erase(j);
}
}
}
prv = a[i];
}
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
int flag = -1;
rep(i, n) {
cin >> a[i];
if (flag >= a[i]) {
flag = INF;
}
cmx(flag, a[i]);
}
if (flag != INF) {
cout << "1\n";
return 0;
}
int l = 1, r = n;
while (r - l > 1) {
int mid = (l + r) / 2;
if (possible(mid)) {
r = mid;
} else {
l = mid;
}
}
cout << r << "\n";
return 0;
}
| replace | 97 | 98 | 97 | 98 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr, __VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i, a, b) for (int i = a, ThxDem = b; i < ThxDem; ++i)
#define SZ(x) ((int)(x).size())
#define mset(a, v) memset(a, v, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long ll;
int n;
int a[200005];
map<int, int> d;
bool can(int b) {
d.clear();
fore(i, 1, n) {
if (a[i] <= a[i - 1]) {
while (!d.empty() && d.rbegin()->fst >= a[i])
d.erase(d.rbegin()->fst);
int k = a[i] - 1;
while (k >= 0 && d[k] == b - 1)
d[k] = 0, k--;
if (k < 0)
return false;
d[k]++;
}
}
return true;
}
int main() {
scanf("%d", &n);
fore(i, 0, n) scanf("%d", a + i);
int s = 1, e = 200005;
while (e - s > 1) {
int m = (s + e) / 2;
if (can(m - 1))
e = m;
else
s = m;
}
printf("%d\n", s);
return 0;
} | #include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr, __VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i, a, b) for (int i = a, ThxDem = b; i < ThxDem; ++i)
#define SZ(x) ((int)(x).size())
#define mset(a, v) memset(a, v, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long ll;
int n;
int a[200005];
map<int, int> d;
bool can(int b) {
d.clear();
fore(i, 1, n) {
if (a[i] <= a[i - 1]) {
if (b == 1)
return false;
while (!d.empty() && d.rbegin()->fst >= a[i])
d.erase(d.rbegin()->fst);
int k = a[i] - 1;
while (k >= 0 && d[k] == b - 1)
d[k] = 0, k--;
if (k < 0)
return false;
d[k]++;
}
}
return true;
}
int main() {
scanf("%d", &n);
fore(i, 0, n) scanf("%d", a + i);
int s = 1, e = 200005;
while (e - s > 1) {
int m = (s + e) / 2;
if (can(m - 1))
e = m;
else
s = m;
}
printf("%d\n", s);
return 0;
} | insert | 27 | 27 | 27 | 29 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 2e5 + 55;
int n;
ll a[maxN];
bool chk(ll x) {
map<ll, ll> mp;
for (int i = 2; i <= n; i++) {
if (a[i - 1] >= a[i]) {
while (!mp.empty()) {
ll mx = mp.rbegin()->first;
if (mx > a[i]) {
mp.erase(mx);
} else {
break;
}
}
int j = a[i];
while (j > 0 && mp[j] + 1 == x) {
mp.erase(j);
j--;
}
if (j == 0) {
return false;
}
mp[j]++;
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int lo = 1, hi = n, ans = n;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (chk(mid)) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 2e5 + 55;
int n;
ll a[maxN];
bool chk(ll x) {
map<ll, ll> mp;
for (int i = 2; i <= n; i++) {
if (a[i - 1] >= a[i]) {
if (x == 1) {
return false;
}
while (!mp.empty()) {
ll mx = mp.rbegin()->first;
if (mx > a[i]) {
mp.erase(mx);
} else {
break;
}
}
int j = a[i];
while (j > 0 && mp[j] + 1 == x) {
mp.erase(j);
j--;
}
if (j == 0) {
return false;
}
mp[j]++;
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int lo = 1, hi = n, ans = n;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (chk(mid)) {
ans = mid;
hi = mid - 1;
} else {
lo = mid + 1;
}
}
cout << ans << '\n';
return 0;
} | insert | 15 | 15 | 15 | 18 | TLE | |
p03202 | C++ | Time Limit Exceeded | // user:halahen
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int i, j, k;
int n, a[maxn];
int l, r, mid, ans;
int read() {
int tot = 0, fh = 1;
char c = getchar();
while ((c < '0') || (c > '9')) {
if (c == '-')
fh = -1;
c = getchar();
}
while ((c >= '0') && (c <= '9')) {
tot = tot * 10 + c - '0';
c = getchar();
}
return tot * fh;
}
map<int, int> mp;
int check(int col) {
int i, j;
mp.clear();
for (i = 2; i <= n; i++) {
if (a[i] <= a[i - 1]) {
j = a[i - 1] + 1;
while (-(mp.upper_bound(-j)->first) > a[i]) {
j = -(mp.upper_bound(-j)->first);
mp.erase(-j);
}
if (mp[-a[i]] == 0)
mp[-a[i]] = 2;
else
mp[-a[i]]++;
j = a[i];
while (mp[-j] > col) {
if (j == 1)
return 0;
mp[-j] = mp[-j] - col;
if (mp[-j + 1] == 0)
mp[-j + 1] = 1;
mp[-j + 1] = mp[-j + 1] + 1;
j--;
}
}
}
return 1;
}
int main() {
n = read();
for (i = 1; i <= n; i++) {
a[i] = read();
}
l = 1;
r = n;
while (l <= r) {
mid = (l + r) >> 1;
if (check(mid) == 1) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
printf("%d\n", ans);
return 0;
} | // user:halahen
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int i, j, k;
int n, a[maxn];
int l, r, mid, ans;
int read() {
int tot = 0, fh = 1;
char c = getchar();
while ((c < '0') || (c > '9')) {
if (c == '-')
fh = -1;
c = getchar();
}
while ((c >= '0') && (c <= '9')) {
tot = tot * 10 + c - '0';
c = getchar();
}
return tot * fh;
}
map<int, int> mp;
int check(int col) {
int i, j;
mp.clear();
for (i = 2; i <= n; i++) {
if (a[i] <= a[i - 1]) {
if (col == 1)
return 0;
j = a[i - 1] + 1;
while (-(mp.upper_bound(-j)->first) > a[i]) {
j = -(mp.upper_bound(-j)->first);
mp.erase(-j);
}
if (mp[-a[i]] == 0)
mp[-a[i]] = 2;
else
mp[-a[i]]++;
j = a[i];
while (mp[-j] > col) {
if (j == 1)
return 0;
mp[-j] = mp[-j] - col;
if (mp[-j + 1] == 0)
mp[-j + 1] = 1;
mp[-j + 1] = mp[-j + 1] + 1;
j--;
}
}
}
return 1;
}
int main() {
n = read();
for (i = 1; i <= n; i++) {
a[i] = read();
}
l = 1;
r = n;
while (l <= r) {
mid = (l + r) >> 1;
if (check(mid) == 1) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
printf("%d\n", ans);
return 0;
} | insert | 27 | 27 | 27 | 29 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <functional>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define LOG(FMT...) fprintf(stderr, FMT)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 200010;
int n;
int a[N];
bool pred(int x) {
map<int, int> cur;
for (int i = 2; i <= n; ++i) {
if (a[i] > a[i - 1])
continue;
int pos = a[i] - 1;
cur.erase(cur.lower_bound(a[i]), cur.end());
while (pos && cur[pos] == x - 1)
cur.erase(pos--);
if (cur[pos] == x - 1)
return false;
++cur[pos];
}
return true;
}
int main() {
#ifdef LBT
freopen("test.in", "r", stdin);
int nol_cl = clock();
#endif
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
int l = 1, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (pred(mid))
r = mid;
else
l = mid + 1;
}
printf("%d\n", l);
#ifdef LBT
LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
return 0;
}
| #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <functional>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define LOG(FMT...) fprintf(stderr, FMT)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 200010;
int n;
int a[N];
bool pred(int x) {
map<int, int> cur;
for (int i = 2; i <= n; ++i) {
if (a[i] > a[i - 1])
continue;
int pos = a[i] - 1;
cur.erase(cur.lower_bound(a[i]), cur.end());
while (pos && cur[pos] == x - 1)
cur.erase(pos--);
if (cur[pos] == x - 1)
return false;
++cur[pos];
}
return true;
}
int main() {
#ifdef LBT
freopen("test.in", "r", stdin);
int nol_cl = clock();
#endif
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
bool flag = true;
for (int i = 2; i <= n; ++i)
flag &= a[i] > a[i - 1];
if (flag) {
puts("1");
return 0;
}
int l = 2, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (pred(mid))
r = mid;
else
l = mid + 1;
}
printf("%d\n", l);
#ifdef LBT
LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
return 0;
}
| replace | 53 | 54 | 53 | 61 | TLE | |
p03202 | C++ | Time Limit Exceeded | //{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a, b, c, x, ...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__, rep3, rep2, loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__, rrep3, rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, begin, end) \
for (int i = (int)(begin), i##_end = (int)(end); i < i##_end; ++i)
#define rrep2(i, n) rrep3(i, n, 0)
#define rrep3(i, begin, end) \
for (int i = (int)(begin - 1), i##_end = (int)(end); i >= i##_end; --i)
#define foreach(x, a) for (auto &x : a)
using ll = long long;
const ll mod = (ll)1e9 + 7;
//}}}
int N;
int a[200000];
map<int, int> mp;
bool f(int n) {
mp.clear();
mp[a[0]] = 0;
rep(i, 1, N) {
if (a[i] <= a[i - 1]) {
int pos = a[i];
{
auto it = mp.find(pos);
if (it == mp.end()) {
mp[pos] = 0;
} else {
it++;
if (it != mp.end())
mp.erase(it, mp.end());
}
}
{
while (mp[pos] == n - 1) {
mp[pos] = 0;
pos--;
}
if (pos == 0) {
return false;
}
mp[pos]++;
}
}
}
return true;
}
int main() {
cin >> N;
rep(i, N) scanf("%d", &a[i]);
{
bool flag = true;
rep(i, 1, N) {
if (a[i] <= a[i - 1]) {
flag = false;
break;
}
}
if (flag) {
cout << 1 << endl;
return 0;
}
}
int hi = N;
int lo = 1;
while (hi - lo > 1) {
int mi = (hi + lo) / 2;
if (f(mi)) {
hi = mi;
} else {
lo = mi;
}
}
cout << hi << endl;
return 0;
}
| //{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a, b, c, x, ...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__, rep3, rep2, loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__, rrep3, rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, begin, end) \
for (int i = (int)(begin), i##_end = (int)(end); i < i##_end; ++i)
#define rrep2(i, n) rrep3(i, n, 0)
#define rrep3(i, begin, end) \
for (int i = (int)(begin - 1), i##_end = (int)(end); i >= i##_end; --i)
#define foreach(x, a) for (auto &x : a)
using ll = long long;
const ll mod = (ll)1e9 + 7;
//}}}
int N;
int a[200000];
map<int, int> mp;
bool f(int n) {
mp.clear();
mp[a[0]] = 0;
rep(i, 1, N) {
if (a[i] <= a[i - 1]) {
int pos = a[i];
{
auto it = mp.find(pos);
if (it == mp.end()) {
mp[pos] = 0;
}
}
{
auto it = mp.find(pos);
auto itt = mp.end();
for (itt--; itt != it; itt--) {
mp.erase(itt);
}
}
{
while (mp[pos] == n - 1) {
mp[pos] = 0;
pos--;
}
if (pos == 0) {
return false;
}
mp[pos]++;
}
}
}
return true;
}
int main() {
cin >> N;
rep(i, N) scanf("%d", &a[i]);
{
bool flag = true;
rep(i, 1, N) {
if (a[i] <= a[i - 1]) {
flag = false;
break;
}
}
if (flag) {
cout << 1 << endl;
return 0;
}
}
int hi = N;
int lo = 1;
while (hi - lo > 1) {
int mi = (hi + lo) / 2;
if (f(mi)) {
hi = mi;
} else {
lo = mi;
}
}
cout << hi << endl;
return 0;
}
| replace | 33 | 37 | 33 | 40 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#define dump(x) cout << #x << " = " << (x) << endl
const int MN = 100010;
int N;
int A[MN];
bool ok(int x) {
set<pii> S;
int cl = A[0];
map<int, int> M;
for (int i = 1; i < N; ++i) {
if (A[i] <= cl) {
while (!M.empty()) {
auto it = M.end();
--it;
if (it->fi >= A[i]) {
M.erase(it);
} else {
break;
}
}
int p = A[i] - 1;
++M[p];
while (M[p] >= x) {
M.erase(p);
--p;
if (p < 0) {
return false;
}
++M[p];
}
}
cl = A[i];
}
return true;
}
int main() {
cin >> N;
rep(i, N) { cin >> A[i]; }
bool mon = 1;
rep(i, N - 1) if (A[i] <= A[i - 1]) { mon = 0; }
if (mon) {
puts("1");
return 0;
}
int lo = 1, hi = N;
while (hi - lo > 1) {
int m = (lo + hi) / 2;
if (ok(m)) {
hi = m;
} else {
lo = m;
}
}
cout << hi << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#define dump(x) cout << #x << " = " << (x) << endl
const int MN = 200010;
int N;
int A[MN];
bool ok(int x) {
set<pii> S;
int cl = A[0];
map<int, int> M;
for (int i = 1; i < N; ++i) {
if (A[i] <= cl) {
while (!M.empty()) {
auto it = M.end();
--it;
if (it->fi >= A[i]) {
M.erase(it);
} else {
break;
}
}
int p = A[i] - 1;
++M[p];
while (M[p] >= x) {
M.erase(p);
--p;
if (p < 0) {
return false;
}
++M[p];
}
}
cl = A[i];
}
return true;
}
int main() {
cin >> N;
rep(i, N) { cin >> A[i]; }
bool mon = 1;
rep(i, N - 1) if (A[i] <= A[i - 1]) { mon = 0; }
if (mon) {
puts("1");
return 0;
}
int lo = 1, hi = N;
while (hi - lo > 1) {
int m = (lo + hi) / 2;
if (ok(m)) {
hi = m;
} else {
lo = m;
}
}
cout << hi << endl;
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p03202 | C++ | Time Limit Exceeded | #define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x) for (ll i = 0; i < (ll)(x); i++)
#define rrep(i, x) for (ll i = (ll)(x)-1; 0 <= i; i--)
#define reps(i, x) for (ll i = 1; i < (ll)(x) + 1; i++)
#define rreps(i, x) for (ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max() / 4;
constexpr ll n_max = 2e5 + 10;
#define int ll
template <typename A, typename B> string to_string(pair<A, B> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char c) { return to_string((string)&c); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <size_t N> string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++)
res += static_cast<char>('0' + v[i]);
return res;
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first)
res += ", ";
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
auto c = [&](ll x) {
if (x == 1) {
bool ok = true;
rep(i, n - 1) ok &= a[i + 1] > a[i];
return ok;
}
map<ll, ll> mp;
reps(i, n - 1) {
if (a[i] > a[i - 1])
continue;
mp[a[i]]++;
auto itr = mp.find(a[i]);
itr++;
mp.erase(itr, mp.end());
if (mp[a[i]] == x) {
ll t = a[i];
while (mp[t] >= x) {
mp[--t]++;
mp.erase(t + 1);
}
}
}
return mp.count(0) == 0;
};
ll ok = 1e9;
ll ng = 0;
while (abs(ok - ng) > 1) {
ll x = (ok + ng) / 2;
if (c(x))
ok = x;
else
ng = x;
}
cout << ok << endl;
return 0;
} | #define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x) for (ll i = 0; i < (ll)(x); i++)
#define rrep(i, x) for (ll i = (ll)(x)-1; 0 <= i; i--)
#define reps(i, x) for (ll i = 1; i < (ll)(x) + 1; i++)
#define rreps(i, x) for (ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max() / 4;
constexpr ll n_max = 2e5 + 10;
#define int ll
template <typename A, typename B> string to_string(pair<A, B> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char c) { return to_string((string)&c); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <size_t N> string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++)
res += static_cast<char>('0' + v[i]);
return res;
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first)
res += ", ";
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
auto c = [&](ll x) {
if (x == 1) {
bool ok = true;
rep(i, n - 1) ok &= a[i + 1] > a[i];
return ok;
}
map<ll, ll> mp;
reps(i, n - 1) {
if (a[i] > a[i - 1])
continue;
mp[a[i]]++;
auto itr = mp.find(a[i]);
itr++;
mp.erase(itr, mp.end());
if (mp[a[i]] == x) {
ll t = a[i];
while (mp[t] >= x) {
mp[--t]++;
mp.erase(t + 1);
}
}
}
return mp.count(0) == 0;
};
ll ok = 1e6;
ll ng = 0;
while (abs(ok - ng) > 1) {
ll x = (ok + ng) / 2;
if (c(x))
ok = x;
else
ng = x;
}
cout << ok << endl;
return 0;
} | replace | 92 | 93 | 92 | 93 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int, int>
#define poly vector<ll>
#define For(i, l, r) for (int i = (int)(l); i <= (int)(r); i++)
#define Rep(i, r, l) for (int i = (int)(r); i >= (int)(l); i--)
#define pb push_back
#define fi first
#define se second
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
#define gc getchar
inline ll read() {
ll x = 0;
char ch = gc();
bool positive = 1;
for (; !isdigit(ch); ch = gc())
if (ch == '-')
positive = 0;
for (; isdigit(ch); ch = gc())
x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(ll a) {
if (a < 0) {
a = -a;
putchar('-');
}
if (a >= 10)
write(a / 10);
putchar('0' + a % 10);
}
inline void writeln(ll a) {
write(a);
puts("");
}
inline void wri(ll a) {
write(a);
putchar(' ');
}
inline ull rnd() { return ((ull)rand() << 30 ^ rand()) << 4 | rand() % 4; }
const int N = 200005;
int n, a[N];
bool check(int x) {
map<int, int> M;
For(i, 2, n) {
if (a[i] <= a[i - 1]) {
M[a[i]]++;
while (1) {
auto it = M.end();
it--;
if (it->fi > a[i])
M.erase(it);
else
break;
}
int len = a[i]; // cout<<len<<" "<<M[len]<<endl;
while (M[len] == x) {
if (len == 1)
return 0;
M.erase(len);
M[--len]++;
}
}
}
return 1;
}
int main() {
n = read();
For(i, 1, n) a[i] = read();
// cout<<check(2)<<endl; return 0;
int l = 1, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
// cout<<l<<" "<<r<<endl;
}
cout << l << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int, int>
#define poly vector<ll>
#define For(i, l, r) for (int i = (int)(l); i <= (int)(r); i++)
#define Rep(i, r, l) for (int i = (int)(r); i >= (int)(l); i--)
#define pb push_back
#define fi first
#define se second
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
#define gc getchar
inline ll read() {
ll x = 0;
char ch = gc();
bool positive = 1;
for (; !isdigit(ch); ch = gc())
if (ch == '-')
positive = 0;
for (; isdigit(ch); ch = gc())
x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(ll a) {
if (a < 0) {
a = -a;
putchar('-');
}
if (a >= 10)
write(a / 10);
putchar('0' + a % 10);
}
inline void writeln(ll a) {
write(a);
puts("");
}
inline void wri(ll a) {
write(a);
putchar(' ');
}
inline ull rnd() { return ((ull)rand() << 30 ^ rand()) << 4 | rand() % 4; }
const int N = 200005;
int n, a[N];
bool check(int x) {
map<int, int> M;
For(i, 2, n) {
if (a[i] <= a[i - 1]) {
M[a[i]]++;
while (1) {
auto it = M.end();
it--;
if (it->fi > a[i])
M.erase(it);
else
break;
}
int len = a[i]; // cout<<len<<" "<<M[len]<<endl;
while (M[len] == x) {
if (len == 1 || x == 1)
return 0;
M.erase(len);
M[--len]++;
}
}
}
return 1;
}
int main() {
n = read();
For(i, 1, n) a[i] = read();
// cout<<check(2)<<endl; return 0;
int l = 1, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
// cout<<l<<" "<<r<<endl;
}
cout << l << endl;
} | replace | 66 | 67 | 66 | 67 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <cstdio>
#include <iostream>
#include <map>
using namespace std;
const int N = 2e5 + 10;
int n, a[N], l = 1, r = N - 10, mid, ans;
map<int, int> p;
inline bool judge(int x) {
p.clear();
for (register int i = 2; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
++p[a[i]];
map<int, int>::iterator it = p.upper_bound(a[i]);
while (it != p.end())
p.erase(it), it = p.upper_bound(a[i]);
int pos = a[i];
while (pos && p[pos] == x)
p[pos] = 0, ++p[--pos];
if (!pos)
return 0;
}
return 1;
}
int main() {
scanf("%d", &n);
for (register int i = 1; i <= n; i++)
scanf("%d", &a[i]);
while (l <= r) {
mid = (l + r + 1) >> 1;
if (judge(mid))
ans = mid, r = mid - 1;
else
l = mid + 1;
}
printf("%d\n", ans);
return 0;
} | #include <cstdio>
#include <iostream>
#include <map>
using namespace std;
const int N = 2e5 + 10;
int n, a[N], l = 1, r = N - 10, mid, ans;
map<int, int> p;
inline bool judge(int x) {
p.clear();
for (register int i = 2; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
if (x == 1)
return 0;
++p[a[i]];
map<int, int>::iterator it = p.upper_bound(a[i]);
while (it != p.end())
p.erase(it), it = p.upper_bound(a[i]);
int pos = a[i];
while (pos && p[pos] == x)
p[pos] = 0, ++p[--pos];
if (!pos)
return 0;
}
return 1;
}
int main() {
scanf("%d", &n);
for (register int i = 1; i <= n; i++)
scanf("%d", &a[i]);
while (l <= r) {
mid = (l + r + 1) >> 1;
if (judge(mid))
ans = mid, r = mid - 1;
else
l = mid + 1;
}
printf("%d\n", ans);
return 0;
} | insert | 12 | 12 | 12 | 14 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int a[200100], n;
bool chk(int x) {
mp.clear();
for (int i = 1; i <= n; ++i)
if (a[i] <= a[i - 1]) {
for (auto it = mp.upper_bound(a[i]); it != mp.end();
it = mp.upper_bound(a[i]))
mp.erase(it);
++mp[a[i]];
for (int j = a[i]; mp[j] >= x; --j) {
if (j == 1)
return 0;
mp[j] -= x;
mp[j - 1]++;
}
}
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
int l = 1, r = n;
while (l < r) {
int mid = (l + r) / 2;
if (chk(mid))
r = mid;
else
l = mid + 1;
}
cout << l << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int a[200100], n;
bool chk(int x) {
mp.clear();
for (int i = 1; i <= n; ++i)
if (a[i] <= a[i - 1]) {
for (auto it = mp.upper_bound(a[i]); it != mp.end();
it = mp.upper_bound(a[i]))
mp.erase(it);
++mp[a[i]];
if (x == 1)
return 0;
for (int j = a[i]; mp[j] >= x; --j) {
if (j == 1)
return 0;
mp[j] -= x;
mp[j - 1]++;
}
}
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
int l = 1, r = n;
while (l < r) {
int mid = (l + r) / 2;
if (chk(mid))
r = mid;
else
l = mid + 1;
}
cout << l << '\n';
return 0;
}
| insert | 13 | 13 | 13 | 15 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
// #include <unordered_set>
// #include <unordered_map>
// #include <bits/stdc++.h>
#define MP(A, B) make_pair(A, B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define fi first
#define se second
using namespace std;
template <typename T> inline bool upmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T> inline bool upmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int, int> PR;
typedef vector<int> VI;
const lod eps = 1e-11;
const lod pi = acos(-1);
const int oo = 1 << 30;
const ll loo = 1ll << 62;
const int mods = 998244353;
const int MAXN = 600005;
const int INF = 0x3f3f3f3f; // 1061109567
/*--------------------------------------------------------------------*/
inline int read() {
int f = 1, x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x * f;
}
map<int, int> Map;
int a[MAXN], n;
bool check(int k) {
Map.clear();
for (int i = 2; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
while (!Map.empty()) {
int t = Map.rbegin()->fi;
if (t > a[i])
Map.erase(t);
else
break;
}
int j = a[i];
while (j && Map[j] == k - 1)
Map.erase(j), j--;
if (j == 0)
return 0;
Map[j]++;
}
return 1;
}
int main() {
n = read();
int l = 1, r = n, flag = 1;
for (int i = 1; i <= n; i++)
a[i] = read(), flag &= (a[i] > a[i - 1]);
if (flag) {
puts("1");
return 0;
}
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%d\n", r);
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
// #include <unordered_set>
// #include <unordered_map>
// #include <bits/stdc++.h>
#define MP(A, B) make_pair(A, B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define fi first
#define se second
using namespace std;
template <typename T> inline bool upmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T> inline bool upmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int, int> PR;
typedef vector<int> VI;
const lod eps = 1e-11;
const lod pi = acos(-1);
const int oo = 1 << 30;
const ll loo = 1ll << 62;
const int mods = 998244353;
const int MAXN = 600005;
const int INF = 0x3f3f3f3f; // 1061109567
/*--------------------------------------------------------------------*/
inline int read() {
int f = 1, x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return x * f;
}
map<int, int> Map;
int a[MAXN], n;
bool check(int k) {
Map.clear();
for (int i = 2; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
while (!Map.empty()) {
int t = Map.rbegin()->fi;
if (t > a[i])
Map.erase(t);
else
break;
}
int j = a[i];
while (j && Map[j] == k - 1)
Map.erase(j), j--;
if (j == 0)
return 0;
Map[j]++;
}
return 1;
}
int main() {
n = read();
int l = 2, r = n, flag = 1;
for (int i = 1; i <= n; i++)
a[i] = read(), flag &= (a[i] > a[i - 1]);
if (flag) {
puts("1");
return 0;
}
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%d\n", r);
return 0;
} | replace | 98 | 99 | 98 | 99 | TLE | |
p03202 | C++ | Time Limit Exceeded | #pragma GCC optimize(2)
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;
int n, a[200010], cnt;
pair<int, int> q[200010];
inline bool check(int x) {
if (x == 1) {
bool flag = false;
for (int i = 1; i < n; i++)
if (a[i] >= a[i + 1]) {
flag = true;
break;
}
if (!flag)
return true;
}
int pre = 0;
map<int, int> mp;
mp.clear();
for (int i = 1; i <= n; i++) {
if (a[i] <= pre) {
pre = a[i];
while (pre >= 1) {
if (mp[pre] + 1 < x)
break;
mp[pre] = 0;
pre--;
}
if (pre == 0)
return false;
mp[pre]++;
} else
pre = a[i];
mp.erase(mp.upper_bound(pre), mp.end());
}
return true;
}
signed main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int l = 1, r = INF, ans = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
cout << ans << endl;
return 0;
} | #pragma GCC optimize(2)
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;
int n, a[200010], cnt;
pair<int, int> q[200010];
inline bool check(int x) {
if (x == 1) {
bool flag = false;
for (int i = 1; i < n; i++)
if (a[i] >= a[i + 1]) {
flag = true;
break;
}
if (!flag)
return true;
return false;
}
int pre = 0;
map<int, int> mp;
mp.clear();
for (int i = 1; i <= n; i++) {
if (a[i] <= pre) {
pre = a[i];
while (pre >= 1) {
if (mp[pre] + 1 < x)
break;
mp[pre] = 0;
pre--;
}
if (pre == 0)
return false;
mp[pre]++;
} else
pre = a[i];
mp.erase(mp.upper_bound(pre), mp.end());
}
return true;
}
signed main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
int l = 1, r = INF, ans = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
cout << ans << endl;
return 0;
} | insert | 18 | 18 | 18 | 19 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) \
sort(all(v)); \
(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
type x; \
cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f) \
if ((f)) { \
cout << (TRUE__) << endl; \
} else { \
cout << FALSE__ << endl; \
}
#define RS(N) resize(N)
#define CINV(v, N) \
do { \
v.RS(N); \
rep(i, N) cin >> v[i]; \
} while (0);
#define RCINV(v, N) \
do { \
v.RS(N); \
rrep(i, N) cin >> v[i]; \
} while (0);
#define MOD 1000000007
void init();
void solve();
signed main() {
init();
solve();
}
int N;
vector<int> A;
void init() {
cin >> N;
CINV(A, N);
}
int X;
inline void add(int x, map<int, int> &m) {
m[x]++;
if (m[x] == X) {
m.erase(x);
add(x - 1, m);
}
}
inline bool isok(int x) {
X = x;
int pre = 0;
map<int, int> m;
rep(i, N) {
if (pre < A[i]) {
pre = A[i];
continue;
}
pre = A[i];
add(A[i], m);
for (auto x = m.rbegin(); x != m.rend(); x++) {
if ((*x).second > A[i]) {
m.erase((*x).first);
} else {
break;
}
}
if (m.count(0))
return false;
}
return true;
}
void solve() {
bool f = true;
rep(i, N - 1) { f &= A[i] < A[i + 1]; }
if (f) {
cout << 1 << endl;
return;
}
int ok = 1000000000;
int ng = 1;
int cnt = 1;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid))
ok = mid;
else
ng = mid;
}
cout << ok << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) \
sort(all(v)); \
(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
type x; \
cin >> x
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PRINT(f) \
if ((f)) { \
cout << (TRUE__) << endl; \
} else { \
cout << FALSE__ << endl; \
}
#define RS(N) resize(N)
#define CINV(v, N) \
do { \
v.RS(N); \
rep(i, N) cin >> v[i]; \
} while (0);
#define RCINV(v, N) \
do { \
v.RS(N); \
rrep(i, N) cin >> v[i]; \
} while (0);
#define MOD 1000000007
void init();
void solve();
signed main() {
init();
solve();
}
int N;
vector<int> A;
void init() {
cin >> N;
CINV(A, N);
}
int X;
inline void add(int x, map<int, int> &m) {
m[x]++;
if (m[x] == X) {
m.erase(x);
add(x - 1, m);
}
}
inline bool isok(int x) {
X = x;
int pre = 0;
map<int, int> m;
rep(i, N) {
if (pre < A[i]) {
pre = A[i];
continue;
}
pre = A[i];
add(A[i], m);
for (auto x = m.rbegin(); x != m.rend(); x++) {
if ((*x).first > A[i]) {
m.erase((*x).first);
} else {
break;
}
}
if (m.count(0))
return false;
}
return true;
}
void solve() {
bool f = true;
rep(i, N - 1) { f &= A[i] < A[i + 1]; }
if (f) {
cout << 1 << endl;
return;
}
int ok = 1000000000;
int ng = 1;
int cnt = 1;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
if (isok(mid))
ok = mid;
else
ng = mid;
}
cout << ok << endl;
}
| replace | 79 | 80 | 79 | 80 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
using namespace std;
using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
inline void yes() {
cout << "Yes" << '\n';
exit(0);
}
inline void no() {
cout << "No" << '\n';
exit(0);
}
inline i64 gcd(i64 a, i64 b) {
if (min(a, b) == 0)
return max(a, b);
if (a % b == 0)
return b;
return gcd(b, a % b);
}
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() {
static u64 x = 88172645463325252ull;
x = x ^ (x << 7);
return x = x ^ (x >> 9);
}
void solve();
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(16);
solve();
return 0;
}
template <typename T>
class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T>
class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) {
if (x < y)
x = y;
}
template <typename T> inline void amin(T &x, T y) {
if (x > y)
x = y;
}
template <typename T> inline T power(T x, i64 n, T e = 1) {
T r = e;
while (n > 0) {
if (n & 1)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
each(x, v) is >> x;
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
rep(i, v.size()) {
if (i)
os << ' ';
os << v[i];
}
return os;
}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
os << p.first << ' ' << p.second;
return os;
}
int N;
vector<int> a;
bool check(int x) {
map<int, int> ma;
for (int i = 1; i < N; i++) {
if (a[i - 1] < a[i]) {
continue;
}
int idx = a[i];
auto it = ma.upper_bound(idx);
while (it != ma.end()) {
ma.erase(it++);
}
while (true) {
ma[idx]++;
if (ma[idx] < x) {
break;
}
if (idx == 1)
return false;
ma.erase(idx);
idx--;
}
}
return true;
}
void solve() {
cin >> N;
a.resize(N);
cin >> a;
int ok = 200000, ng = 0;
while (ok - ng > 1) {
int md = (ok + ng) / 2;
check(md) ? (ok = md) : (ng = md);
}
cout << ok << '\n';
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
using namespace std;
using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
inline void yes() {
cout << "Yes" << '\n';
exit(0);
}
inline void no() {
cout << "No" << '\n';
exit(0);
}
inline i64 gcd(i64 a, i64 b) {
if (min(a, b) == 0)
return max(a, b);
if (a % b == 0)
return b;
return gcd(b, a % b);
}
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() {
static u64 x = 88172645463325252ull;
x = x ^ (x << 7);
return x = x ^ (x >> 9);
}
void solve();
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(16);
solve();
return 0;
}
template <typename T>
class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T>
class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) {
if (x < y)
x = y;
}
template <typename T> inline void amin(T &x, T y) {
if (x > y)
x = y;
}
template <typename T> inline T power(T x, i64 n, T e = 1) {
T r = e;
while (n > 0) {
if (n & 1)
r *= x;
x *= x;
n >>= 1;
}
return r;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
each(x, v) is >> x;
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
rep(i, v.size()) {
if (i)
os << ' ';
os << v[i];
}
return os;
}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
os << p.first << ' ' << p.second;
return os;
}
int N;
vector<int> a;
bool check(int x) {
map<int, int> ma;
for (int i = 1; i < N; i++) {
if (a[i - 1] < a[i]) {
continue;
}
if (x == 1)
return false;
int idx = a[i];
auto it = ma.upper_bound(idx);
while (it != ma.end()) {
ma.erase(it++);
}
while (true) {
ma[idx]++;
if (ma[idx] < x) {
break;
}
if (idx == 1)
return false;
ma.erase(idx);
idx--;
}
}
return true;
}
void solve() {
cin >> N;
a.resize(N);
cin >> a;
int ok = 200000, ng = 0;
while (ok - ng > 1) {
int md = (ok + ng) / 2;
check(md) ? (ok = md) : (ng = md);
}
cout << ok << '\n';
}
| insert | 109 | 109 | 109 | 111 | TLE | |
p03202 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch;
do {
ch = getchar();
if (ch == '-')
f = -1;
} while (ch < '0' || ch > '9');
do {
x = x * 10 + ch - '0';
ch = getchar();
} while (ch >= '0' && ch <= '9');
return x * f;
}
const int N = 400010, INF = 0x3f3f3f3f;
int a[N], n;
struct DATA {
int x, y;
} s[N];
int ls, mid;
inline void insert(int x) {
if (s[ls].x > x) {
while (s[ls].x > x)
--ls;
if (s[ls].x < x)
s[++ls] = (DATA){x, 1};
}
if (s[ls].x == x) {
++s[ls].y;
if (s[ls].y > mid)
insert(x - 1), s[++ls] = (DATA){x, 1};
} else
s[++ls] = (DATA){x, 1};
}
inline bool judge() {
ls = 0;
s[++ls] = (DATA){0, 0};
for (int i = 1; i <= n; ++i) {
insert(a[i]);
if (s[1].y)
return 0;
}
return 1;
}
int main() {
n = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
int l = 1, r = n;
while (l < r) {
mid = (l + r) >> 1;
if (judge())
r = mid;
else
l = mid + 1;
}
printf("%d\n", l);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch;
do {
ch = getchar();
if (ch == '-')
f = -1;
} while (ch < '0' || ch > '9');
do {
x = x * 10 + ch - '0';
ch = getchar();
} while (ch >= '0' && ch <= '9');
return x * f;
}
const int N = 400010, INF = 0x3f3f3f3f;
int a[N], n;
struct DATA {
int x, y;
} s[N];
int ls, mid;
inline void insert(int x) {
if (s[ls].x > x) {
while (s[ls].x > x)
--ls;
if (s[ls].x < x)
s[++ls] = (DATA){x, 1};
}
if (s[ls].x == x) {
++s[ls].y;
if (s[ls].y > mid)
insert(x - 1), s[++ls] = (DATA){x, 1};
} else
s[++ls] = (DATA){x, 1};
}
inline bool judge() {
ls = 0;
s[++ls] = (DATA){0, 0};
for (int i = 1; i <= n; ++i) {
if (mid == 1 && a[i] <= a[i - 1])
return 0;
insert(a[i]);
if (s[1].y)
return 0;
}
return 1;
}
int main() {
n = read();
for (int i = 1; i <= n; ++i)
a[i] = read();
int l = 1, r = n;
while (l < r) {
mid = (l + r) >> 1;
if (judge())
r = mid;
else
l = mid + 1;
}
printf("%d\n", l);
return 0;
} | insert | 43 | 43 | 43 | 45 | 0 | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, l, r, mid, ans;
int a[100005];
struct node {
int u, l, r;
};
int check(int x) {
stack<node> f;
f.push((node){1, 1, a[1]});
for (int i = 2; i <= n; i++) {
if (a[i] > a[i - 1])
f.push((node){1, a[i - 1] + 1, a[i]});
else {
int p;
while (!f.empty()) {
node v = f.top();
if (v.l > a[i])
f.pop();
else {
p = v.u;
f.pop();
if (v.l < a[i])
f.push((node){p, v.l, a[i] - 1});
break;
}
}
if (p < x)
f.push((node){p + 1, a[i], a[i]});
else {
while (!f.empty()) {
node v = f.top();
p = v.u;
f.pop();
if (p < x) {
if (v.l != v.r)
f.push((node){p, v.l, v.r - 1});
f.push((node){p + 1, v.r, v.r});
f.push((node){1, v.r + 1, a[i]});
break;
}
}
if (p >= x)
return 0;
}
}
}
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
l = 1, r = 1e9, ans = 1e9 + 1;
while (l <= r) {
mid = (l + r) / 2;
if (check(mid))
ans = min(ans, mid), r = mid - 1;
else
l = mid + 1;
}
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, l, r, mid, ans;
int a[200005];
struct node {
int u, l, r;
};
int check(int x) {
stack<node> f;
f.push((node){1, 1, a[1]});
for (int i = 2; i <= n; i++) {
if (a[i] > a[i - 1])
f.push((node){1, a[i - 1] + 1, a[i]});
else {
int p;
while (!f.empty()) {
node v = f.top();
if (v.l > a[i])
f.pop();
else {
p = v.u;
f.pop();
if (v.l < a[i])
f.push((node){p, v.l, a[i] - 1});
break;
}
}
if (p < x)
f.push((node){p + 1, a[i], a[i]});
else {
while (!f.empty()) {
node v = f.top();
p = v.u;
f.pop();
if (p < x) {
if (v.l != v.r)
f.push((node){p, v.l, v.r - 1});
f.push((node){p + 1, v.r, v.r});
f.push((node){1, v.r + 1, a[i]});
break;
}
}
if (p >= x)
return 0;
}
}
}
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
l = 1, r = 1e9, ans = 1e9 + 1;
while (l <= r) {
mid = (l + r) / 2;
if (check(mid))
ans = min(ans, mid), r = mid - 1;
else
l = mid + 1;
}
printf("%d\n", ans);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int check(int m, vector<int> &A) {
map<int, int> S;
for (int i = 1; i < A.size(); i++) {
if (A[i - 1] < A[i])
continue;
if (m == 0)
return 0;
int a = A[i];
S.erase(S.upper_bound(a), S.end());
while (S[a] == m - 1) {
a--;
if (a == 0)
return 0;
}
S[a]++;
S.erase(S.upper_bound(a), S.end());
}
return 1;
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int &a : A)
cin >> a;
int l = 0, r = N;
while (1 < r - l) {
int m = (l + r) / 2;
if (check(m, A))
r = m;
else
l = m;
}
cout << r << endl;
} | #include <bits/stdc++.h>
using namespace std;
int check(int m, vector<int> &A) {
map<int, int> S;
for (int i = 1; i < A.size(); i++) {
if (A[i - 1] < A[i])
continue;
if (m == 1)
return 0;
int a = A[i];
S.erase(S.upper_bound(a), S.end());
while (S[a] == m - 1) {
a--;
if (a == 0)
return 0;
}
S[a]++;
S.erase(S.upper_bound(a), S.end());
}
return 1;
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int &a : A)
cin >> a;
int l = 0, r = N;
while (1 < r - l) {
int m = (l + r) / 2;
if (check(m, A))
r = m;
else
l = m;
}
cout << r << endl;
} | replace | 8 | 9 | 8 | 9 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<LL, LL> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 60;
const int INF = 1 << 30;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
template <typename T> struct SparseTable {
vector<vector<T>> st;
vector<int> lookup;
SparseTable(const vector<T> &v) {
int b = 0;
while ((1 << b) <= v.size())
++b;
st.assign(b, vector<T>(1 << b));
for (int i = 0; i < v.size(); i++) {
st[0][i] = v[i];
}
for (int i = 1; i < b; i++) {
for (int j = 0; j + (1 << i) <= (1 << b); j++) {
st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
}
}
lookup.resize(v.size() + 1);
for (int i = 2; i < lookup.size(); i++) {
lookup[i] = lookup[i >> 1] + 1;
}
}
inline T rmq(int l, int r) {
int b = lookup[r - l];
return min(st[b][l], st[b][r - (1 << b)]);
}
};
int n;
bool f(int k, SparseTable<int> &st, vector<int> &a) {
unordered_map<int, P> ma;
int bf = 0;
for (int i = 0; i < n; i++) {
int t = a[i];
if (ma.find(t) != ma.end()) {
if (st.rmq(ma[t].sc, i) < t)
ma[t] = mp(0, i);
}
if (t < bf && ma[t].fs == 0)
ma[t] = mp(1, i);
ma[t].fs++;
ma[t].sc = i;
while (ma[t].fs == k + 1) {
ma[t].fs = 1;
if (ma.find(t - 1) != ma.end()) {
if (st.rmq(ma[t - 1].sc, i) < t - 1)
ma[t - 1] = mp(1, i);
else
ma[t - 1].sc = i;
} else
ma[t - 1] = mp(1, i);
ma[t - 1].fs++;
t--;
if (t <= 0 || k == 1)
return false;
}
bf = a[i];
}
return true;
};
int main() {
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
SparseTable<int> st(a);
int l = 0, r = INF;
while (abs(r - l) > 1) {
int m = l + (r - l) / 2;
if (f(m, st, a))
r = m;
else
l = m;
}
cout << r << endl;
return 0;
}
| #include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<LL, LL> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 60;
const int INF = 1 << 30;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
template <typename T> struct SparseTable {
vector<vector<T>> st;
vector<int> lookup;
SparseTable(const vector<T> &v) {
int b = 0;
while ((1 << b) <= v.size())
++b;
st.assign(b, vector<T>(1 << b));
for (int i = 0; i < v.size(); i++) {
st[0][i] = v[i];
}
for (int i = 1; i < b; i++) {
for (int j = 0; j + (1 << i) <= (1 << b); j++) {
st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
}
}
lookup.resize(v.size() + 1);
for (int i = 2; i < lookup.size(); i++) {
lookup[i] = lookup[i >> 1] + 1;
}
}
inline T rmq(int l, int r) {
int b = lookup[r - l];
return min(st[b][l], st[b][r - (1 << b)]);
}
};
int n;
bool f(int k, SparseTable<int> &st, vector<int> &a) {
unordered_map<int, P> ma;
int bf = 0;
for (int i = 0; i < n; i++) {
int t = a[i];
if (ma.find(t) != ma.end()) {
if (st.rmq(ma[t].sc, i) < t)
ma[t] = mp(0, i);
}
if (t < bf && ma[t].fs == 0)
ma[t] = mp(1, i);
ma[t].fs++;
ma[t].sc = i;
while (ma[t].fs == k + 1) {
ma[t].fs = 1;
if (ma.find(t - 1) != ma.end()) {
if (st.rmq(ma[t - 1].sc, i) < t - 1)
ma[t - 1] = mp(1, i);
else
ma[t - 1].sc = i;
} else
ma[t - 1] = mp(1, i);
ma[t - 1].fs++;
t--;
if (t <= 0 || k == 1)
return false;
}
bf = a[i];
}
return true;
};
int main() {
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
SparseTable<int> st(a);
int l = 0, r = INF;
while (abs(r - l) > 1) {
int m = l + (r - l) / 2;
if (f(m, st, a))
r = m;
else
l = m;
}
cout << r << endl;
return 0;
}
| replace | 85 | 86 | 85 | 86 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long i64;
const int inf = (int)1.05e9;
int construct_tree(int v, vector<int> &as, vector<vector<int>> &tree) {
int h = as[v];
int it = v + 1;
while (it < (int)as.size() && h < as[it]) {
tree[v].push_back(it);
int n_it = construct_tree(it, as, tree);
it = n_it;
}
return it;
}
int down(int from, int to, int v, int k) {
for (int i = 0; i < (from - to); ++i) {
if (v == 1)
return 1;
v = (v + k - 1) / k;
}
return v;
}
int compute_values(int v, vector<int> &as, vector<vector<int>> &tree, int k) {
vector<pair<int, int>> buffer;
for (int w_it = tree[v].size() - 1; w_it >= 0; --w_it) {
int w = tree[v][w_it];
int val = compute_values(w, as, tree, k);
buffer.push_back({as[w], val});
}
while (buffer.size() > 1) {
int sz = buffer.size();
auto front = buffer[sz - 1];
int fh = front.first, fv = front.second;
auto next = buffer[sz - 2];
int nh = next.first, nv = next.second;
buffer.pop_back();
buffer.pop_back();
assert(fh >= nh);
buffer.push_back({nh, down(fh, nh, fv, k) + nv});
}
if (buffer.size() > 0) {
int fh = buffer[0].first;
int fv = buffer[0].second;
return down(fh, as[v], fv, k);
} else {
return 1;
}
}
int main() {
int n;
vector<int> as;
scanf("%d", &n);
as.resize(n + 1);
as[0] = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &as[i + 1]);
}
vector<vector<int>> tree(n + 1);
construct_tree(0, as, tree);
int lo = 0, hi = 2 * n;
while (hi - lo > 1) {
int mid = (hi + lo) / 2;
int val = compute_values(0, as, tree, mid);
bool ok = (val <= 1);
if (ok) {
hi = mid;
} else {
lo = mid;
}
}
int ans = hi;
printf("%d\n", ans);
return 0;
}
/* waffle */
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long i64;
const int inf = (int)1.05e9;
int construct_tree(int v, vector<int> &as, vector<vector<int>> &tree) {
int h = as[v];
int it = v + 1;
while (it < (int)as.size() && h < as[it]) {
tree[v].push_back(it);
int n_it = construct_tree(it, as, tree);
it = n_it;
}
return it;
}
int down(int from, int to, int v, int k) {
if (k == 1)
return v;
for (int i = 0; i < (from - to); ++i) {
if (v == 1)
return 1;
v = (v + k - 1) / k;
}
return v;
}
int compute_values(int v, vector<int> &as, vector<vector<int>> &tree, int k) {
vector<pair<int, int>> buffer;
for (int w_it = tree[v].size() - 1; w_it >= 0; --w_it) {
int w = tree[v][w_it];
int val = compute_values(w, as, tree, k);
buffer.push_back({as[w], val});
}
while (buffer.size() > 1) {
int sz = buffer.size();
auto front = buffer[sz - 1];
int fh = front.first, fv = front.second;
auto next = buffer[sz - 2];
int nh = next.first, nv = next.second;
buffer.pop_back();
buffer.pop_back();
assert(fh >= nh);
buffer.push_back({nh, down(fh, nh, fv, k) + nv});
}
if (buffer.size() > 0) {
int fh = buffer[0].first;
int fv = buffer[0].second;
return down(fh, as[v], fv, k);
} else {
return 1;
}
}
int main() {
int n;
vector<int> as;
scanf("%d", &n);
as.resize(n + 1);
as[0] = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &as[i + 1]);
}
vector<vector<int>> tree(n + 1);
construct_tree(0, as, tree);
int lo = 0, hi = 2 * n;
while (hi - lo > 1) {
int mid = (hi + lo) / 2;
int val = compute_values(0, as, tree, mid);
bool ok = (val <= 1);
if (ok) {
hi = mid;
} else {
lo = mid;
}
}
int ans = hi;
printf("%d\n", ans);
return 0;
}
/* waffle */
| insert | 30 | 30 | 30 | 32 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 1000000;
const int MOD = 1000000007;
signed main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int ok = n, ng = 0, mid, j;
map<int, int> mp;
while (abs(ok - ng) > 1) {
mp.clear();
mid = (ok + ng) / 2;
for (int i = 1; i < n; i++) {
if (a[i - 1] < a[i])
continue;
while (mp.size() > 0 && mp.rbegin()->first >= a[i])
mp.erase((next(mp.rbegin())).base());
// mp.erase(mp.lower_bound(a[i]),mp.end());
j = a[i] - 1;
mp[j]++;
while (j > 0 && mp[j] == mid) {
mp[j] = 0;
j--;
mp[j]++;
}
if (mp[0] >= mid)
break;
}
if (mp[0] >= mid)
ng = mid;
else
ok = mid;
}
cout << ok;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 1000000;
const int MOD = 1000000007;
signed main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 1; i < n; i++) {
if (a[i - 1] >= a[i])
break;
if (i == n - 1) {
cout << 1;
return 0;
}
}
if (n == 1) {
cout << 1;
return 0;
}
int ok = n, ng = 1, mid, j;
map<int, int> mp;
while (abs(ok - ng) > 1) {
mp.clear();
mid = (ok + ng) / 2;
for (int i = 1; i < n; i++) {
if (a[i - 1] < a[i])
continue;
while (mp.size() > 0 && mp.rbegin()->first >= a[i])
mp.erase((next(mp.rbegin())).base());
// mp.erase(mp.lower_bound(a[i]),mp.end());
j = a[i] - 1;
mp[j]++;
while (j > 0 && mp[j] == mid) {
mp[j] = 0;
j--;
mp[j]++;
}
if (mp[0] >= mid)
break;
}
if (mp[0] >= mid)
ng = mid;
else
ok = mid;
}
cout << ok;
return 0;
}
| replace | 13 | 14 | 13 | 26 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define db double
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define A first
#define B second
#define lowbit(p) (p & (-p))
using namespace std;
void read(int &x) {
x = 0;
char c = getchar();
int p = 1;
for (; c < 48; c = getchar())
if (c == '-')
p = -1;
for (; c > 47; c = getchar())
x = (x << 1) + (x << 3) + (c ^ 48);
x *= p;
}
void read(ll &x) {
x = 0;
char c = getchar();
int p = 1;
for (; c < 48; c = getchar())
if (c == '-')
p = -1;
for (; c > 47; c = getchar())
x = (x << 1) + (x << 3) + (c ^ 48);
x *= p;
}
void Min(int &x, int y) {
if (x > y)
x = y;
}
void Min(ll &x, ll y) {
if (x > y)
x = y;
}
void Max(int &x, int y) {
if (x < y)
x = y;
}
void Max(ll &x, ll y) {
if (x < y)
x = y;
}
map<int, int> f;
struct node {
priority_queue<int> q;
void clear() {
for (; !q.empty();)
q.pop();
}
void push(int x) { q.push(x); }
void upd(int x) {
// q.top()>x f[q.top()]=0
for (; !q.empty();) {
int t = q.top();
if (t > x) {
f[t] = 0;
q.pop();
} else
return;
}
}
} q;
#define M 100005
int a[M], n;
bool chk(int l) {
q.clear();
f.clear();
q.push(1);
if (a[1] != 1) {
q.push(a[1]);
}
int i, x;
for (i = 2; i <= n; i++) {
if (a[i] > a[i - 1]) {
q.push(a[i]);
} else if (a[i] == a[i - 1]) {
x = a[i];
f[x]++;
for (; f[x] == l;) {
if (x == 1)
return 0;
f[x] = 0;
f[x - 1]++;
x--;
q.push(x);
}
} else {
x = a[i];
q.upd(x);
q.push(x);
f[x]++;
for (; f[x] == l;) {
if (x == 1)
return 0;
f[x] = 0;
f[x - 1]++;
x--;
q.push(x);
}
}
}
return 1;
}
int main() {
// freopen("1.in","r",stdin);
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
read(n);
int i, l, r, mid, res = 0;
for (i = 1; i <= n; i++) {
read(a[i]);
}
int fl = 1;
for (i = 2; i <= n; i++)
if (a[i - 1] >= a[i])
fl = 0;
if (fl) {
printf("1\n");
return 0;
}
l = 2;
r = n;
for (; l <= r;) {
mid = (l + r) >> 1;
if (chk(mid)) {
r = mid - 1;
res = mid;
} else {
l = mid + 1;
}
}
printf("%d\n", res);
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define db double
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define A first
#define B second
#define lowbit(p) (p & (-p))
using namespace std;
void read(int &x) {
x = 0;
char c = getchar();
int p = 1;
for (; c < 48; c = getchar())
if (c == '-')
p = -1;
for (; c > 47; c = getchar())
x = (x << 1) + (x << 3) + (c ^ 48);
x *= p;
}
void read(ll &x) {
x = 0;
char c = getchar();
int p = 1;
for (; c < 48; c = getchar())
if (c == '-')
p = -1;
for (; c > 47; c = getchar())
x = (x << 1) + (x << 3) + (c ^ 48);
x *= p;
}
void Min(int &x, int y) {
if (x > y)
x = y;
}
void Min(ll &x, ll y) {
if (x > y)
x = y;
}
void Max(int &x, int y) {
if (x < y)
x = y;
}
void Max(ll &x, ll y) {
if (x < y)
x = y;
}
map<int, int> f;
struct node {
priority_queue<int> q;
void clear() {
for (; !q.empty();)
q.pop();
}
void push(int x) { q.push(x); }
void upd(int x) {
// q.top()>x f[q.top()]=0
for (; !q.empty();) {
int t = q.top();
if (t > x) {
f[t] = 0;
q.pop();
} else
return;
}
}
} q;
#define M 200005
int a[M], n;
bool chk(int l) {
q.clear();
f.clear();
q.push(1);
if (a[1] != 1) {
q.push(a[1]);
}
int i, x;
for (i = 2; i <= n; i++) {
if (a[i] > a[i - 1]) {
q.push(a[i]);
} else if (a[i] == a[i - 1]) {
x = a[i];
f[x]++;
for (; f[x] == l;) {
if (x == 1)
return 0;
f[x] = 0;
f[x - 1]++;
x--;
q.push(x);
}
} else {
x = a[i];
q.upd(x);
q.push(x);
f[x]++;
for (; f[x] == l;) {
if (x == 1)
return 0;
f[x] = 0;
f[x - 1]++;
x--;
q.push(x);
}
}
}
return 1;
}
int main() {
// freopen("1.in","r",stdin);
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
read(n);
int i, l, r, mid, res = 0;
for (i = 1; i <= n; i++) {
read(a[i]);
}
int fl = 1;
for (i = 2; i <= n; i++)
if (a[i - 1] >= a[i])
fl = 0;
if (fl) {
printf("1\n");
return 0;
}
l = 2;
r = n;
for (; l <= r;) {
mid = (l + r) >> 1;
if (chk(mid)) {
r = mid - 1;
res = mid;
} else {
l = mid + 1;
}
}
printf("%d\n", res);
return 0;
} | replace | 69 | 70 | 69 | 70 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int a[200005];
int b[200005];
int n;
map<int, int> mp;
bool check(int mid) {
mp.clear();
for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1])
continue;
mp.erase(mp.upper_bound(a[i]), mp.end());
int j;
for (j = a[i]; j > 0; j--) {
if (mp[j] < mid) {
mp[j]++;
break;
}
mp.erase(mp.find(j));
}
if (j == 0)
return 0;
}
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int l = 0, r = n, res = -1;
while (l <= r) {
int mid = l + r >> 1;
if (!check(mid)) {
l = mid + 1;
} else {
res = mid;
r = mid - 1;
}
}
cout << res + 1;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int a[200005];
int b[200005];
int n;
map<int, int> mp;
bool check(int mid) {
mp.clear();
for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1])
continue;
mp.erase(mp.upper_bound(a[i]), mp.end());
int j;
for (j = a[i]; j > 0; j--) {
if (mp[j] < mid) {
mp[j]++;
break;
}
mp.erase(mp.find(j));
}
if (j == 0)
return 0;
}
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
bool flag = 0;
for (int i = 0; i < n - 1; i++)
if (a[i] >= a[i + 1])
flag = 1;
if (!flag) {
cout << 1;
return 0;
}
int l = 1, r = n, res = -1;
while (l <= r) {
int mid = l + r >> 1;
if (!check(mid)) {
l = mid + 1;
} else {
res = mid;
r = mid - 1;
}
}
cout << res + 1;
} | replace | 44 | 45 | 44 | 53 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
int n;
vector<int> a;
bool check(int x) {
map<int, int> cnt;
for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1])
continue;
while (cnt.size() && a[i] < cnt.rbegin()->first) {
cnt.erase(--cnt.end());
}
int cur = a[i];
while (cur > 0 && cnt[cur] == x)
cur--;
if (cur == 0)
return 0;
cnt[cur]++;
while (cnt.size() && cur < cnt.rbegin()->first) {
cnt.erase(--cnt.end());
}
}
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
a.resize(n);
for (auto &i : a)
cin >> i;
int l = 0, r = n;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid))
r = mid - 1;
else
l = mid + 1;
}
cout << l + 1 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
int n;
vector<int> a;
bool check(int x) {
map<int, int> cnt;
for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1])
continue;
while (cnt.size() && a[i] < cnt.rbegin()->first) {
cnt.erase(--cnt.end());
}
int cur = a[i];
while (cur > 0 && cnt[cur] == x)
cur--;
if (cur == 0)
return 0;
cnt[cur]++;
while (cnt.size() && cur < cnt.rbegin()->first) {
cnt.erase(--cnt.end());
}
}
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
a.resize(n);
for (auto &i : a)
cin >> i;
bool ok = 1;
for (int i = 1; i < n; i++) {
ok &= (a[i] > a[i - 1]);
}
if (ok)
finish(1);
int l = 1, r = n;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid))
r = mid - 1;
else
l = mid + 1;
}
cout << l + 1 << endl;
}
| replace | 35 | 36 | 35 | 42 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define dbg(...) \
do { \
cerr << __LINE__ << ": "; \
dbgprint(#__VA_ARGS__, __VA_ARGS__); \
} while (0);
using namespace std;
namespace std {
template <class S, class T> struct hash<pair<S, T>> {
size_t operator()(const pair<S, T> &p) const {
return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second);
}
};
template <class T> struct hash<vector<T>> {
size_t operator()(const vector<T> &v) const {
size_t h = 0;
for (auto i : v)
h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1;
return h;
}
};
} // namespace std
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[ ";
rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", ");
return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "{ ";
for (const auto &i : v)
os << i << ", ";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &v) {
os << "{";
for (const auto &i : v)
os << " " << i.first << ": " << i.second << ",";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
void dbgprint(const string &fmt) { cerr << endl; }
template <class H, class... T>
void dbgprint(const string &fmt, const H &h, const T &...r) {
cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " ";
dbgprint(fmt.substr(fmt.find(",") + 1), r...);
}
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n;
cin >> n;
vi v(n);
rep(i, n) cin >> v[i];
int lo = 0, hi = n, mid;
while (lo + 1 < hi) {
mid = (lo + hi) / 2;
map<int, int> p;
rep(i, n - 1) {
if (v[i] < v[i + 1])
continue;
int pos = -v[i + 1];
while (p.size() && p.begin()->first < pos)
p.erase(p.begin());
while (pos < 0) {
if (++p[pos] >= mid) {
p.erase(pos);
++pos;
} else
break;
}
if (pos == 0) {
lo = mid;
goto END;
}
}
hi = mid;
END:;
}
cout << hi << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define dbg(...) \
do { \
cerr << __LINE__ << ": "; \
dbgprint(#__VA_ARGS__, __VA_ARGS__); \
} while (0);
using namespace std;
namespace std {
template <class S, class T> struct hash<pair<S, T>> {
size_t operator()(const pair<S, T> &p) const {
return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second);
}
};
template <class T> struct hash<vector<T>> {
size_t operator()(const vector<T> &v) const {
size_t h = 0;
for (auto i : v)
h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1;
return h;
}
};
} // namespace std
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[ ";
rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", ");
return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "{ ";
for (const auto &i : v)
os << i << ", ";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &v) {
os << "{";
for (const auto &i : v)
os << " " << i.first << ": " << i.second << ",";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
void dbgprint(const string &fmt) { cerr << endl; }
template <class H, class... T>
void dbgprint(const string &fmt, const H &h, const T &...r) {
cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " ";
dbgprint(fmt.substr(fmt.find(",") + 1), r...);
}
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n;
cin >> n;
vi v(n);
rep(i, n) cin >> v[i];
{
bool ok = 1;
rep(i, n - 1) if (v[i] >= v[i + 1]) ok = 0;
if (ok) {
cout << 1 << endl;
return 0;
}
}
int lo = 1, hi = n, mid;
while (lo + 1 < hi) {
mid = (lo + hi) / 2;
map<int, int> p;
rep(i, n - 1) {
if (v[i] < v[i + 1])
continue;
int pos = -v[i + 1];
while (p.size() && p.begin()->first < pos)
p.erase(p.begin());
while (pos < 0) {
if (++p[pos] >= mid) {
p.erase(pos);
++pos;
} else
break;
}
if (pos == 0) {
lo = mid;
goto END;
}
}
hi = mid;
END:;
}
cout << hi << endl;
return 0;
} | replace | 68 | 69 | 68 | 79 | TLE | |
p03202 | C++ | Time Limit Exceeded | /*
`-:://:::-
`//:-------:/:`
.+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.o:--...```..---+/`
`/y+o/---....---:+o.
`...````-os+/:---:/+o/--.`
`-/+++++/:. `...` :h+d+oooo+/+-` ...
`/++//:::://++-`....` -.`//````````:` `..`
`o+/::------://o/` `-` -. -` `..`
`---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..``
`....o+:-++/:--.```..-://s. `-` .- -` `-o:
.-//::::/:-`
`:s+/:--....-::/+s-` .- `- -` -///:--------:/:`
./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ
`+:--........--:/`
.:ooo+++++osso-` `.:-...`/` ./::-------:/:` -`
:+--..``````.--:+:...-+:-`
`.-/+++++/+-.-` -. ``:so:/:--.......--:+`
`-```````o+/+--..`````..--:o/-..:s+:.
```````:``.. `-` -`
`+:--..`````..--/+-.../.`````..-o:--.......---/o. `
`: `:- -. .o:--..`` ``..--:o` `-`
`:o+:--------:+o-`
`-`-... .. .o/--...```..--:+/` `-`
`oy/so/////++o/.`
-/` `-` `- ``+s/o/:---...---:++. `-`
.-../d://///:-.`
`.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-.
````
`:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `-
-++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `-
`` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.-
-----ss+:++/:--.```..-://s. /. `:: `-:. ./`
`````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-`
`-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-`
`:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-`
`./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:.
``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `-
`.:--h.``..```
-.-`.- .- `+:--..`````..--//` `-
/s-//::::::::.
-` `/- .. .o:--..`` ``..--:o.```.-
`//:--------://`
-` .-`.-`
-.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`
..`-. `-. ``:os:o/:---...---:++. `-
``///+:-..``````.--:+-````-.`
`.:///////.-` .:-..` -``-+o+/:::::/+o/. `-
`:+:-..`````..--:o/:--/ys+-
`-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o.
`.`
`++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-`
`````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.`
-----syo/o+/:--.```..-://s. .-` `- .- `...
``-:////:-``
.` `/s//:--....-::/+s. -. `-` .- `..`
.+o+/:::--:://+s/-..` .::+y ``` .- `..`
./oo++////+oso-` `.... :y-+:::::::/` ...
`.:+oooooo/-` `....-. .//:-------:/:-.`
``...`` /+:+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.+/--...```..--:+/`
`-o/:---...---:++.
`-+o+/:---:/+o/.
`.:+oooo+/-.`
``````
*/
#ifdef aimbot
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <limits>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define umap unordered_map
#define uset unordered_set
#define elif else if
#define len(v) ((int)v.size())
#define f(i, n) for (int i = 0; i < (n); i++)
#define rof(i, n) for (int i = ((n)-1); i >= 0; i--)
#define apply(v, act) \
for (auto &x : v) { \
act; \
}
#define log(args...) \
{ \
string s = #args; \
deque<string> deq; \
string buf = ""; \
int bal = 0; \
for (char c : s) { \
if (c == '(' || c == '[' || c == '{') { \
bal++; \
} else if (c == ')' || c == ']' || c == '}') { \
bal--; \
} else { \
if (bal == 0) { \
if (c == ',') { \
deq.pb(buf); \
buf = ""; \
} else { \
if (c != ' ') { \
buf += c; \
} \
} \
} \
} \
} \
if (!buf.empty()) { \
deq.pb(buf); \
} \
smart_io::precall_print(); \
smart_io::_print(deq, args); \
}
#define print \
smart_io::precall_print(); \
cout,
#define scan cin,
#ifdef fast_allocator
const int MAXMEM = 200 * 1000 * 1024;
char _memory[MAXMEM];
size_t _ptr = 0;
void *operator new(size_t _x) {
_ptr += _x;
assert(_ptr < MAXMEM);
return _memory + _ptr - _x;
}
void operator delete(void *) noexcept {}
#endif
using namespace std;
char string_in_buffer[(int)260];
void fast_scan(int &x) { scanf("%d", &x); }
void fast_scan(long long &x) { scanf("%lld", &x); }
void fast_scan(unsigned long long &x) { scanf("%llu", &x); }
void fast_scan(double &x) { scanf("%lf", &x); }
void fast_scan(long double &x) { scanf("%Lf", &x); }
void fast_scan(char &x) {
scanf("%c", &x);
if (x == '\n') {
fast_scan(x);
}
}
void fast_scan(string &x) {
scanf("%s", string_in_buffer);
x = string(string_in_buffer);
}
template <class TFirst, class TSecond>
void fast_scan(pair<TFirst, TSecond> &p) {
fast_scan(p.first);
fast_scan(p.second);
}
template <class T> void fast_scan(vector<T> &v) {
for (auto &x : v)
fast_scan(x);
}
void fast_print(const int &x) { printf("%d", x); }
void fast_print(const unsigned int &x) { printf("%u", x); }
void fast_print(const long long &x) { printf("%lld", x); }
void fast_print(const unsigned long long &x) { printf("%llu", x); }
void fast_print(const double &x) { printf("%.15lf", x); }
void fast_print(const long double &x) { printf("%.15Lf", x); }
void fast_print(const char &x) { printf("%c", x); };
void fast_print(const string &x) { printf("%s", x.c_str()); }
void fast_print(const char v[]) { fast_print((string)v); }
template <class TFirst, class TSecond>
void fast_print(const pair<TFirst, TSecond> &p) {
fast_print(p.first);
fast_print(' ');
fast_print(p.second);
}
template <class T> void fast_print(const vector<T> &v) {
if (v.empty())
return;
fast_print(v[0]);
for (int i = 1; i < v.size(); i++) {
fast_print(' ');
fast_print(v[i]);
}
}
template <class T> void fast_print(const vector<vector<T>> &v) {
if (v.empty())
return;
fast_print(v[0]);
for (int i = 1; i < v.size(); i++) {
fast_print('\n');
fast_print(v[i]);
}
}
template <class T> void fast_print(const T &v) {
for (const auto &x : v) {
fast_print(x);
fast_print(' ');
}
}
using namespace std;
namespace smart_io {
string print_start = "";
string sep = " ";
bool first_print = false;
void precall_print() {
fast_print(print_start);
print_start = "\n";
first_print = true;
}
void _print(deque<string>) {}
template <class T, class... Args>
void _print(deque<string> names, T elem, Args... args) {
if (!first_print) {
fast_print("\n");
} else {
first_print = false;
}
fast_print(names.front());
fast_print(" = ");
fast_print(elem);
names.pop_front();
_print(names, args...);
}
} // namespace smart_io
template <class T> ostream &operator,(ostream &os, const T &object) {
if (!smart_io::first_print) {
fast_print(smart_io::sep);
} else {
smart_io::first_print = false;
}
fast_print(object);
return os;
}
template <class T> istream &operator,(istream &is, T &object) {
fast_scan(object);
return is;
}
#define int long long
namespace typedefs {
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef long double ld;
} // namespace typedefs
namespace numbers_operation {
template <class T> T floor_mod(T a, T b) {
if (a % b == 0)
return 0;
if (a >= 0 && b >= 0)
return a % b;
if (a <= 0 && b <= 0)
return a % b;
return abs(b) - (abs(a) % abs(b));
}
} // namespace numbers_operation
using namespace numbers_operation;
using namespace typedefs;
int n;
vector<int> v;
bool inc(map<int, int> &x, int ind, int base) {
if (ind < 0)
return false;
x[ind]++;
if (x[ind] == base) {
x[ind] = 0;
return inc(x, ind - 1, base);
}
return true;
}
signed main(signed argc, char *argv[]) {
scan n;
v.resize(n);
scan v;
int left = 0;
int right = 1e9;
while (right - left > 1) {
int mid = (left + right) / 2;
bool fail = false;
map<int, int> num;
int cur = 0;
for (int l : v) {
if (l > cur) {
cur = l;
continue;
}
while (!num.empty() && num.rbegin()->first > l - 1) {
num.erase(num.rbegin()->first);
}
if (!inc(num, l - 1, mid)) {
fail = true;
break;
}
cur = l;
}
if (fail) {
left = mid;
} else {
right = mid;
}
}
print right;
}
| /*
`-:://:::-
`//:-------:/:`
.+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.o:--...```..---+/`
`/y+o/---....---:+o.
`...````-os+/:---:/+o/--.`
`-/+++++/:. `...` :h+d+oooo+/+-` ...
`/++//:::://++-`....` -.`//````````:` `..`
`o+/::------://o/` `-` -. -` `..`
`---.-o/:./o/::-..``..-ЗАПУСКАЕМ .. .. -` `... ``..``
`....o+:-++/:--.```..-://s. `-` .- -` `-o:
.-//::::/:-`
`:s+/:--....-::/+s-` .- `- -` -///:--------:/:`
./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ
`+:--........--:/`
.:ooo+++++osso-` `.:-...`/` ./::-------:/:` -`
:+--..``````.--:+:...-+:-`
`.-/+++++/+-.-` -. ``:so:/:--.......--:+`
`-```````o+/+--..`````..--:o/-..:s+:.
```````:``.. `-` -`
`+:--..`````..--/+-.../.`````..-o:--.......---/o. `
`: `:- -. .o:--..`` ``..--:o` `-`
`:o+:--------:+o-`
`-`-... .. .o/--...```..--:+/` `-`
`oy/so/////++o/.`
-/` `-` `- ``+s/o/:---...---:++. `-`
.-../d://///:-.`
`.---..``-..- .-/..`````-oo+/:::::/+o+- `-``-` `-.
````
`:++++/+++++- ..``.-/:` /y-:/++o++/:.`..` ./. `-
-++/::::::://+/..:-``:` .. `-.` ```.``` `..` `..`-` `-
`` -o//:--....-::/++` -.-` `-`.-` `..`..` `-.-
-----ss+:++/:--.```..-://s. /. `:: `-:. ./`
`````/:..+o/::-..``.--:/+s. ..-` `-``-` ..` `-` `-`-`
`-s+/::-----::/+oo---``-` .. .:- ``` .-` .-.- `-`
`:oo+//::://+os/..:`..-/:` :y.-:::::::.`.-` ./-` `-`
`./+oooooooo+/.`- .-:...`.. .//:-------://` `- `..` `:.
``.-::::-.``-/` `-` `- `oo:+:--.......--:/` `-
`.:--h.``..```
-.-`.- .- `+:--..`````..--//` `-
/s-//::::::::.
-` `/- .. .o:--..`` ``..--:o.```.-
`//:--------://`
-` .-`.-`
-.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`
..`-. `-. ``:os:o/:---...---:++. `-
``///+:-..``````.--:+-````-.`
`.:///////.-` .:-..` -``-+o+/:::::/+o/. `-
`:+:-..`````..--:o/:--/ys+-
`-++///////+o/. ``....`-. :` `.:++++++/:.` .- -o/---......---/o.
`.`
`++//:-----::/+o:..` .-` : ``````` .- `+so+:--------:++-`
`````:-``:o/::-..`..--:/+o` -. `- .- `../../+o+////+o+:.`
-----syo/o+/:--.```..-://s. .-` `- .- `...
``-:////:-``
.` `/s//:--....-::/+s. -. `-` .- `..`
.+o+/:::--:://+s/-..` .::+y ``` .- `..`
./oo++////+oso-` `.... :y-+:::::::/` ...
`.:+oooooo/-` `....-. .//:-------:/:-.`
``...`` /+:+:--.......--:+`
`+:--..`````..--//`
.o:--..`` ``..--:o`
.+/--...```..--:+/`
`-o/:---...---:++.
`-+o+/:---:/+o/.
`.:+oooo+/-.`
``````
*/
#ifdef aimbot
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#endif
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <limits>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define umap unordered_map
#define uset unordered_set
#define elif else if
#define len(v) ((int)v.size())
#define f(i, n) for (int i = 0; i < (n); i++)
#define rof(i, n) for (int i = ((n)-1); i >= 0; i--)
#define apply(v, act) \
for (auto &x : v) { \
act; \
}
#define log(args...) \
{ \
string s = #args; \
deque<string> deq; \
string buf = ""; \
int bal = 0; \
for (char c : s) { \
if (c == '(' || c == '[' || c == '{') { \
bal++; \
} else if (c == ')' || c == ']' || c == '}') { \
bal--; \
} else { \
if (bal == 0) { \
if (c == ',') { \
deq.pb(buf); \
buf = ""; \
} else { \
if (c != ' ') { \
buf += c; \
} \
} \
} \
} \
} \
if (!buf.empty()) { \
deq.pb(buf); \
} \
smart_io::precall_print(); \
smart_io::_print(deq, args); \
}
#define print \
smart_io::precall_print(); \
cout,
#define scan cin,
#ifdef fast_allocator
const int MAXMEM = 200 * 1000 * 1024;
char _memory[MAXMEM];
size_t _ptr = 0;
void *operator new(size_t _x) {
_ptr += _x;
assert(_ptr < MAXMEM);
return _memory + _ptr - _x;
}
void operator delete(void *) noexcept {}
#endif
using namespace std;
char string_in_buffer[(int)260];
void fast_scan(int &x) { scanf("%d", &x); }
void fast_scan(long long &x) { scanf("%lld", &x); }
void fast_scan(unsigned long long &x) { scanf("%llu", &x); }
void fast_scan(double &x) { scanf("%lf", &x); }
void fast_scan(long double &x) { scanf("%Lf", &x); }
void fast_scan(char &x) {
scanf("%c", &x);
if (x == '\n') {
fast_scan(x);
}
}
void fast_scan(string &x) {
scanf("%s", string_in_buffer);
x = string(string_in_buffer);
}
template <class TFirst, class TSecond>
void fast_scan(pair<TFirst, TSecond> &p) {
fast_scan(p.first);
fast_scan(p.second);
}
template <class T> void fast_scan(vector<T> &v) {
for (auto &x : v)
fast_scan(x);
}
void fast_print(const int &x) { printf("%d", x); }
void fast_print(const unsigned int &x) { printf("%u", x); }
void fast_print(const long long &x) { printf("%lld", x); }
void fast_print(const unsigned long long &x) { printf("%llu", x); }
void fast_print(const double &x) { printf("%.15lf", x); }
void fast_print(const long double &x) { printf("%.15Lf", x); }
void fast_print(const char &x) { printf("%c", x); };
void fast_print(const string &x) { printf("%s", x.c_str()); }
void fast_print(const char v[]) { fast_print((string)v); }
template <class TFirst, class TSecond>
void fast_print(const pair<TFirst, TSecond> &p) {
fast_print(p.first);
fast_print(' ');
fast_print(p.second);
}
template <class T> void fast_print(const vector<T> &v) {
if (v.empty())
return;
fast_print(v[0]);
for (int i = 1; i < v.size(); i++) {
fast_print(' ');
fast_print(v[i]);
}
}
template <class T> void fast_print(const vector<vector<T>> &v) {
if (v.empty())
return;
fast_print(v[0]);
for (int i = 1; i < v.size(); i++) {
fast_print('\n');
fast_print(v[i]);
}
}
template <class T> void fast_print(const T &v) {
for (const auto &x : v) {
fast_print(x);
fast_print(' ');
}
}
using namespace std;
namespace smart_io {
string print_start = "";
string sep = " ";
bool first_print = false;
void precall_print() {
fast_print(print_start);
print_start = "\n";
first_print = true;
}
void _print(deque<string>) {}
template <class T, class... Args>
void _print(deque<string> names, T elem, Args... args) {
if (!first_print) {
fast_print("\n");
} else {
first_print = false;
}
fast_print(names.front());
fast_print(" = ");
fast_print(elem);
names.pop_front();
_print(names, args...);
}
} // namespace smart_io
template <class T> ostream &operator,(ostream &os, const T &object) {
if (!smart_io::first_print) {
fast_print(smart_io::sep);
} else {
smart_io::first_print = false;
}
fast_print(object);
return os;
}
template <class T> istream &operator,(istream &is, T &object) {
fast_scan(object);
return is;
}
#define int long long
namespace typedefs {
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef long double ld;
} // namespace typedefs
namespace numbers_operation {
template <class T> T floor_mod(T a, T b) {
if (a % b == 0)
return 0;
if (a >= 0 && b >= 0)
return a % b;
if (a <= 0 && b <= 0)
return a % b;
return abs(b) - (abs(a) % abs(b));
}
} // namespace numbers_operation
using namespace numbers_operation;
using namespace typedefs;
int n;
vector<int> v;
bool inc(map<int, int> &x, int ind, int base) {
if (ind < 0)
return false;
x[ind]++;
if (x[ind] == base) {
x[ind] = 0;
return inc(x, ind - 1, base);
}
return true;
}
signed main(signed argc, char *argv[]) {
scan n;
v.resize(n);
scan v;
{
bool increase = true;
for (int i = 0; i < n - 1; i++) {
if (v[i] >= v[i + 1]) {
increase = false;
}
}
if (increase) {
print 1;
return 0;
}
}
int left = 1;
int right = 1e9;
while (right - left > 1) {
int mid = (left + right) / 2;
bool fail = false;
map<int, int> num;
int cur = 0;
for (int l : v) {
if (l > cur) {
cur = l;
continue;
}
while (!num.empty() && num.rbegin()->first > l - 1) {
num.erase(num.rbegin()->first);
}
if (!inc(num, l - 1, mid)) {
fail = true;
break;
}
cur = l;
}
if (fail) {
left = mid;
} else {
right = mid;
}
}
print right;
}
| replace | 331 | 332 | 331 | 344 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 5;
int n, a[N];
bool solve(int m) {
stack<pair<int, int>> s;
for (int i = 1; i <= n; i++) {
if (s.empty())
s.push({a[i], 1});
else {
if (a[i] > s.top().fi)
s.push({a[i], 1});
else {
if (m == 1)
return false;
while (!s.empty() && s.top().fi > a[i])
s.pop();
if (s.empty() || s.top().fi < a[i])
s.push({a[i], 2});
else {
int now = s.top().fi;
while (!s.empty() && s.top().fi == now && s.top().se == m) {
now--;
s.pop();
}
if (s.empty() && now == 0)
return false;
if (s.top().fi == now) {
int p = s.top().se + 1;
s.pop();
s.push({now, p});
} else
s.push({now, 2});
}
}
}
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
int l = 1, r = n, ans;
while (l <= r) {
int m = l + r >> 1;
if (solve(m))
ans = m, r = m - 1;
else
l = m + 1;
}
printf("%d\n", ans);
}
| #include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 5;
int n, a[N];
bool solve(int m) {
stack<pair<int, int>> s;
for (int i = 1; i <= n; i++) {
if (s.empty())
s.push({a[i], 1});
else {
if (a[i] > s.top().fi)
s.push({a[i], 1});
else {
if (m == 1)
return false;
while (!s.empty() && s.top().fi > a[i])
s.pop();
if (s.empty() || s.top().fi < a[i])
s.push({a[i], 2});
else {
int now = s.top().fi;
while (!s.empty() && s.top().fi == now && s.top().se == m) {
now--;
s.pop();
}
if (s.empty() && now == 0)
return false;
if (!s.empty() && s.top().fi == now) {
int p = s.top().se + 1;
s.pop();
s.push({now, p});
} else
s.push({now, 2});
}
}
}
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
int l = 1, r = n, ans;
while (l <= r) {
int m = l + r >> 1;
if (solve(m))
ans = m, r = m - 1;
else
l = m + 1;
}
printf("%d\n", ans);
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using ll = long long;
using namespace std;
using P = pair<long, long>;
#define fi first
#define se second
#define MAX 1000000000l
#define INF 1000000001l
long pow(long n, long k) {
if (k <= 0 || n == 1)
return 1;
if (k >= 30)
return INF;
long root = pow(n, k / 2), rr = root * root, odd = (k % 2 ? n : 1),
val = (rr < INF / odd ? rr * odd : INF);
return val;
}
int main() {
int n;
cin >> n;
long a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
long l = 0, r = MAX;
while (r - l > 1) {
long m = (l + r + 1) / 2;
stack<P> st;
st.push({0, 0});
bool under;
for (auto &ai : a) {
P next = st.top(), tp = next;
st.pop();
under = false;
while (ai < tp.fi) {
under = true;
next = st.top();
if (next.fi < ai) {
next = P{ai, 1};
st.push(next);
}
// cerr << tp.fi << ' ' << tp.se << '\n';
long p = pow(m, tp.fi - next.fi);
tp.se = (tp.se + p - 1) / p - 1;
tp.fi = next.fi;
tp.se += next.se;
st.pop();
// cerr << tp.fi << ' ' << tp.se << '\n';
}
st.push(tp);
if (ai == tp.fi) {
st.pop();
tp.se++;
st.push(tp);
} else { // ai > tp.fi
st.push({ai, 1 + under});
}
}
P next = st.top(), tp = next;
st.pop();
while (tp.fi > 0) {
cerr << tp.fi << ' ' << tp.se << '\n';
next = st.top();
long p = pow(m, tp.fi - next.fi);
tp.se = (tp.se + p - 1) / p - 1;
tp.fi = next.fi;
tp.se += next.se;
st.pop();
}
// cerr << tp.se << ' ' << l << ' ' << m << ' ' << r << '\n';
if (tp.se > 0)
l = m;
else
r = m;
}
cout << r << '\n';
return 0;
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using ll = long long;
using namespace std;
using P = pair<long, long>;
#define fi first
#define se second
#define MAX 1000000000l
#define INF 1000000001l
long pow(long n, long k) {
if (k <= 0 || n == 1)
return 1;
if (k >= 30)
return INF;
long root = pow(n, k / 2), rr = root * root, odd = (k % 2 ? n : 1),
val = (rr < INF / odd ? rr * odd : INF);
return val;
}
int main() {
int n;
cin >> n;
long a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
long l = 0, r = MAX;
while (r - l > 1) {
long m = (l + r + 1) / 2;
stack<P> st;
st.push({0, 0});
bool under;
for (auto &ai : a) {
P next = st.top(), tp = next;
st.pop();
under = false;
while (ai < tp.fi) {
under = true;
next = st.top();
if (next.fi < ai) {
next = P{ai, 1};
st.push(next);
}
// cerr << tp.fi << ' ' << tp.se << '\n';
long p = pow(m, tp.fi - next.fi);
tp.se = (tp.se + p - 1) / p - 1;
tp.fi = next.fi;
tp.se += next.se;
st.pop();
// cerr << tp.fi << ' ' << tp.se << '\n';
}
st.push(tp);
if (ai == tp.fi) {
st.pop();
tp.se++;
st.push(tp);
} else { // ai > tp.fi
st.push({ai, 1 + under});
}
}
P next = st.top(), tp = next;
st.pop();
while (tp.fi > 0) {
// cerr << tp.fi << ' ' << tp.se << '\n';
next = st.top();
long p = pow(m, tp.fi - next.fi);
tp.se = (tp.se + p - 1) / p - 1;
tp.fi = next.fi;
tp.se += next.se;
st.pop();
}
// cerr << tp.se << ' ' << l << ' ' << m << ' ' << r << '\n';
if (tp.se > 0)
l = m;
else
r = m;
}
cout << r << '\n';
return 0;
} | replace | 71 | 72 | 71 | 72 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i++)
#define re0(i, n) for (rint i = 0; i < (int)n; i++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
typedef long long lo;
template <typename tp> inline void read(tp &x) {
x = 0;
char c = getchar();
int f = 0;
for (; c < '0' || c > '9'; f |= c == '-', c = getchar())
;
for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
;
if (f)
x = -x;
}
const int N = 3e5 + 233;
int top = 0, st[N], val[N];
int n, a[N];
inline void init(void) {
top = 0;
memset(st, 0, sizeof st);
memset(val, 0, sizeof val);
}
inline bool add(int x, int mid, int fff = 0) {
if (!x)
return false;
// cout << x << " " << mid << "ss\n";
if (st[top] != x) {
st[++top] = x;
val[top] = fff;
}
if (top && st[top] == x) {
if (val[top] == mid) {
--top;
if (!add(x - 1, mid, 1))
return false;
st[++top] = x;
val[top] = 1;
} else {
++val[top];
}
}
return true;
}
inline bool check(int mid) {
init();
rep(i, n) {
if (!top || st[top] <= a[i]) {
if (!add(a[i], mid))
return false;
} else {
while (top && st[top] > a[i])
--top;
if (st[top] != a[i]) {
st[++top] = a[i];
val[top] = 1;
} // else {
// if (val[top] == mid) {
// -- top;
// if (!add(a[i] - 1, mid))
// return false;
// st[++ top] = a[i];
// val[top] = 0;
// } else {
// ++ val[top];
// }
// }
// rep (i, top) cout << st[i] << " "; cout << "\n";
// rep (i, top) cout << val[i] << " "; cout << "\n";
if (!add(a[i], mid))
return false;
}
}
return true;
}
int main(void) {
read(n);
rep(i, n) read(a[i]);
int l = 1, r = 1e9;
while (l < r) {
int mid = l + (r - l) / 2;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << r << "\n";
}
| #include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i++)
#define re0(i, n) for (rint i = 0; i < (int)n; i++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
typedef long long lo;
template <typename tp> inline void read(tp &x) {
x = 0;
char c = getchar();
int f = 0;
for (; c < '0' || c > '9'; f |= c == '-', c = getchar())
;
for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
;
if (f)
x = -x;
}
const int N = 3e5 + 233;
int top = 0, st[N], val[N];
int n, a[N];
inline void init(void) {
top = 0;
memset(st, 0, sizeof st);
memset(val, 0, sizeof val);
}
inline bool add(int x, int mid, int fff = 0) {
if (!x)
return false;
// cout << x << " " << mid << "ss\n";
if (st[top] != x) {
st[++top] = x;
val[top] = fff;
}
if (top && st[top] == x) {
if (val[top] == mid) {
--top;
if (!add(x - 1, mid, 1))
return false;
st[++top] = x;
val[top] = 1;
} else {
++val[top];
}
}
return true;
}
inline bool check(int mid) {
init();
rep(i, n) {
if (!top || st[top] <= a[i]) {
if (!add(a[i], mid))
return false;
} else {
while (top && st[top] > a[i])
--top;
if (st[top] != a[i]) {
st[++top] = a[i];
val[top] = 1;
} // else {
// if (val[top] == mid) {
// -- top;
// if (!add(a[i] - 1, mid))
// return false;
// st[++ top] = a[i];
// val[top] = 0;
// } else {
// ++ val[top];
// }
// }
// rep (i, top) cout << st[i] << " "; cout << "\n";
// rep (i, top) cout << val[i] << " "; cout << "\n";
if (!add(a[i], mid))
return false;
}
}
return true;
}
int main(void) {
read(n);
rep(i, n) read(a[i]);
int f = 1;
rep(i, n - 1) f &= a[i] < a[i + 1];
if (f) {
cout << "1\n";
return 0;
}
int l = 2, r = 1e9;
while (l < r) {
int mid = l + (r - l) / 2;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << r << "\n";
}
| replace | 87 | 88 | 87 | 94 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
vector<int> A;
int check(int x) {
if (x == 1)
return is_sorted(A.begin(), A.end());
map<int, int> m;
for (int i = 1; i < A.size(); i++) {
if (A[i - 1] < A[i])
continue;
m.erase(m.upper_bound(A[i]));
int k = A[i];
m[k]++;
while (k > 0 && m[k] == x)
m.erase(k), m[--k]++;
if (k == 0)
return false;
}
return true;
}
int main(void) {
int N;
cin >> N;
A.resize(N);
for (int &a : A)
cin >> a;
int l = 0, h = N;
while (h - l > 1) {
int m = (l + h) / 2;
if (check(m))
h = m;
else
l = m;
}
cout << h << endl;
}
| #include <bits/stdc++.h>
using namespace std;
vector<int> A;
int check(int x) {
if (x == 1)
return is_sorted(A.begin(), A.end());
map<int, int> m;
for (int i = 1; i < A.size(); i++) {
if (A[i - 1] < A[i])
continue;
if (m.upper_bound(A[i]) != m.end())
m.erase(m.upper_bound(A[i]));
int k = A[i];
m[k]++;
while (k > 0 && m[k] == x)
m.erase(k), m[--k]++;
if (k == 0)
return false;
}
return true;
}
int main(void) {
int N;
cin >> N;
A.resize(N);
for (int &a : A)
cin >> a;
int l = 0, h = N;
while (h - l > 1) {
int m = (l + h) / 2;
if (check(m))
h = m;
else
l = m;
}
cout << h << endl;
}
| replace | 10 | 11 | 10 | 12 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <class T> ostream &prnt(ostream &out, T v) {
out << v.size() << '\n';
for (auto e : v)
out << e << ' ';
return out;
}
template <class T> ostream &operator<<(ostream &out, vector<T> v) {
return prnt(out, v);
}
template <class T> ostream &operator<<(ostream &out, set<T> v) {
return prnt(out, v);
}
template <class T1, class T2> ostream &operator<<(ostream &out, map<T1, T2> v) {
return prnt(out, v);
}
template <class T1, class T2>
ostream &operator<<(ostream &out, pair<T1, T2> p) {
return out << '(' << p.st << ' ' << p.nd << ')';
}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << H;
debug_out(T...);
}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) \
do { \
cerr << #x "[]: "; \
for (int _ = 0; _ < n; ++_) \
cerr << x[_] << " "; \
cerr << '\n'; \
} while (0)
#define dbg_ok cerr << "OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define MOD 1000000007
#define zeros(x) x &(x - 1) ^ x
#define fi first
#define se second
#define Nmax 500005
const long double PI = acos(-1);
int n, v[Nmax], sz, mx;
map<int, int> M;
bool solve(int x) {
// dbg(x,sz);
if (x <= sz) {
while (!M.empty() && prev(M.end())->first > sz) {
M.erase(prev(M.end()));
}
sz = x;
M[sz]++;
int i = sz;
while (M[i] > mx) {
// dbg(x,i,mx);
if (i == 1)
return 0;
M[i] = 0;
M[i - 1]++;
i--;
}
return 1;
} else {
sz = x;
return 1;
}
return 0;
}
bool OK(int x) {
mx = x;
M.clear();
sz = 0;
for (int i = 1; i <= n; i++) {
if (!solve(v[i])) {
return 0;
}
}
return 1;
}
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
int st = 0, p = 1;
for (; p <= n; p <<= 1)
;
for (; p >= 1; p >>= 1) {
if (st + p <= n && !OK(st + p)) {
st += p;
}
}
if (!OK(st))
st++;
cout << st + 1 << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <class T> ostream &prnt(ostream &out, T v) {
out << v.size() << '\n';
for (auto e : v)
out << e << ' ';
return out;
}
template <class T> ostream &operator<<(ostream &out, vector<T> v) {
return prnt(out, v);
}
template <class T> ostream &operator<<(ostream &out, set<T> v) {
return prnt(out, v);
}
template <class T1, class T2> ostream &operator<<(ostream &out, map<T1, T2> v) {
return prnt(out, v);
}
template <class T1, class T2>
ostream &operator<<(ostream &out, pair<T1, T2> p) {
return out << '(' << p.st << ' ' << p.nd << ')';
}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << H;
debug_out(T...);
}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) \
do { \
cerr << #x "[]: "; \
for (int _ = 0; _ < n; ++_) \
cerr << x[_] << " "; \
cerr << '\n'; \
} while (0)
#define dbg_ok cerr << "OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define MOD 1000000007
#define zeros(x) x &(x - 1) ^ x
#define fi first
#define se second
#define Nmax 500005
const long double PI = acos(-1);
int n, v[Nmax], sz, mx;
map<int, int> M;
bool solve(int x) {
// dbg(x,sz);
if (x <= sz) {
if (mx == 0)
return 0;
while (!M.empty() && prev(M.end())->first > sz) {
M.erase(prev(M.end()));
}
sz = x;
M[sz]++;
int i = sz;
while (M[i] > mx) {
// dbg(x,i,mx);
if (i == 1)
return 0;
M[i] = 0;
M[i - 1]++;
i--;
}
return 1;
} else {
sz = x;
return 1;
}
return 0;
}
bool OK(int x) {
mx = x;
M.clear();
sz = 0;
for (int i = 1; i <= n; i++) {
if (!solve(v[i])) {
return 0;
}
}
return 1;
}
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
int st = 0, p = 1;
for (; p <= n; p <<= 1)
;
for (; p >= 1; p >>= 1) {
if (st + p <= n && !OK(st + p)) {
st += p;
}
}
if (!OK(st))
st++;
cout << st + 1 << '\n';
return 0;
} | insert | 52 | 52 | 52 | 54 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
#define MOD2 998244353
#define int long long
// #define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
for (int i = 0; i < A.size(); i++)
os << A[i] << " ";
os << endl;
return os;
}
template <> ostream &operator<<(ostream &os, const vector<vector<int>> &A) {
int N = A.size();
int M;
if (N > 0)
M = A[0].size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
os << A[i][j] << " ";
os << endl;
}
return os;
}
typedef pair<int, int> pii;
typedef long long ll;
struct edge {
int from, to, d, c;
edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
from = _from;
to = _to;
d = _d;
c = _c;
}
bool operator<(const edge &rhs) const {
return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
}
};
struct aabb {
int x1, y1, x2, y2;
aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};
typedef vector<edge> edges;
typedef vector<edges> graph;
struct flow {
int to, cap, rev, cost;
flow(int to = 0, int cap = 0, int rev = 0, int cost = 0)
: to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector<vector<flow>> flows;
const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);
int pow2(int n) { return 1 << n; }
template <typename T, typename U> bool chmin(T &x, const U &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T, typename U> bool chmax(T &x, const U &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
struct initializer {
initializer() { cout << fixed << setprecision(20); }
};
initializer _____;
int N, M, K, T, Q, H, W;
bool check(vector<int> &A, int m) {
map<int, int> mp;
for (int i = 1; i < N; i++) {
if (A[i] > A[i - 1])
continue;
auto it = mp.upper_bound(A[i]);
mp.erase(it, mp.end());
int j = A[i];
while (1) {
if (j == 0)
return false;
mp[j]++;
if (mp[j] < m) {
break;
}
mp[j] = 0;
--j;
}
}
return true;
}
signed main() {
cin >> N;
vector<int> A(N);
rep(i, N) cin >> A[i];
int l = 0, r = N + 10;
while (r - l > 1) {
int m = (l + r) / 2;
if (check(A, m)) {
r = m;
} else {
l = m;
}
}
cout << r << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
#define MOD2 998244353
#define int long long
// #define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
for (int i = 0; i < A.size(); i++)
os << A[i] << " ";
os << endl;
return os;
}
template <> ostream &operator<<(ostream &os, const vector<vector<int>> &A) {
int N = A.size();
int M;
if (N > 0)
M = A[0].size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
os << A[i][j] << " ";
os << endl;
}
return os;
}
typedef pair<int, int> pii;
typedef long long ll;
struct edge {
int from, to, d, c;
edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
from = _from;
to = _to;
d = _d;
c = _c;
}
bool operator<(const edge &rhs) const {
return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
}
};
struct aabb {
int x1, y1, x2, y2;
aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};
typedef vector<edge> edges;
typedef vector<edges> graph;
struct flow {
int to, cap, rev, cost;
flow(int to = 0, int cap = 0, int rev = 0, int cost = 0)
: to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector<vector<flow>> flows;
const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);
int pow2(int n) { return 1 << n; }
template <typename T, typename U> bool chmin(T &x, const U &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T, typename U> bool chmax(T &x, const U &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
struct initializer {
initializer() { cout << fixed << setprecision(20); }
};
initializer _____;
int N, M, K, T, Q, H, W;
bool check(vector<int> &A, int m) {
map<int, int> mp;
for (int i = 1; i < N; i++) {
if (A[i] > A[i - 1])
continue;
if (m == 1)
return false;
auto it = mp.upper_bound(A[i]);
mp.erase(it, mp.end());
int j = A[i];
while (1) {
if (j == 0)
return false;
mp[j]++;
if (mp[j] < m) {
break;
}
mp[j] = 0;
--j;
}
}
return true;
}
signed main() {
cin >> N;
vector<int> A(N);
rep(i, N) cin >> A[i];
int l = 0, r = N + 10;
while (r - l > 1) {
int m = (l + r) / 2;
if (check(A, m)) {
r = m;
} else {
l = m;
}
}
cout << r << endl;
return 0;
} | insert | 108 | 108 | 108 | 110 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 200200;
int n;
int a[N];
map<int, int> st;
bool test(int cnt) {
st.clear();
for (int i = 1; i <= n; i++) {
if (a[i] <= a[i - 1]) {
int j = a[i];
while (++st[j] == cnt) {
j--;
if (j == 0) {
return false;
}
}
while (!st.empty() && (--st.end())->first > j) {
st.erase(--st.end());
}
}
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
a[0] = 0;
int l = 1, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (test(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
printf("%d\n", l);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 200200;
int n;
int a[N];
map<int, int> st;
bool test(int cnt) {
st.clear();
for (int i = 1; i <= n; i++) {
if (a[i] <= a[i - 1]) {
int j = a[i];
while (++st[j] == cnt) {
j--;
if (j == 0 || cnt == 1) {
return false;
}
}
while (!st.empty() && (--st.end())->first > j) {
st.erase(--st.end());
}
}
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
a[0] = 0;
int l = 1, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (test(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
printf("%d\n", l);
} | replace | 14 | 15 | 14 | 15 | TLE | |
p03202 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define LL long long
#define fgx cerr << "--------------" << endl;
#define dgx cerr << "==============" << endl;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 100010;
const int INF = 2147483600;
#define op first
#define ed second
int N;
int a[MAXN + 1];
pair<int, int> s[MAXN + 1];
int top;
inline bool check(int k) {
top = 0;
for (int i = 1; i <= N; i++) {
int len = a[i];
if (s[top].ed < len) {
s[++top] = make_pair(1, len);
continue;
}
while (top > 1 && s[top - 1].ed >= len)
--top;
s[top].ed = min(s[top].ed, len);
while (top && s[top].op == k)
--top;
if (!top)
return 0;
int ps = s[top].ed, val = s[top].op;
if (ps - 1 == s[top - 1].ed)
--top;
if (ps > 1)
s[top].ed = ps - 1;
s[++top] = make_pair(val + 1, ps);
if (len > ps)
s[++top] = make_pair(1, len);
}
return 1;
}
int ans;
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
N = read();
for (int i = 1; i <= N; i++)
a[i] = read();
int l = 1, r = N;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid))
ans = mid, r = mid - 1;
else
l = mid + 1;
}
printf("%d\n", ans);
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define LL long long
#define fgx cerr << "--------------" << endl;
#define dgx cerr << "==============" << endl;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 200010;
const int INF = 2147483600;
#define op first
#define ed second
int N;
int a[MAXN + 1];
pair<int, int> s[MAXN + 1];
int top;
inline bool check(int k) {
top = 0;
for (int i = 1; i <= N; i++) {
int len = a[i];
if (s[top].ed < len) {
s[++top] = make_pair(1, len);
continue;
}
while (top > 1 && s[top - 1].ed >= len)
--top;
s[top].ed = min(s[top].ed, len);
while (top && s[top].op == k)
--top;
if (!top)
return 0;
int ps = s[top].ed, val = s[top].op;
if (ps - 1 == s[top - 1].ed)
--top;
if (ps > 1)
s[top].ed = ps - 1;
s[++top] = make_pair(val + 1, ps);
if (len > ps)
s[++top] = make_pair(1, len);
}
return 1;
}
int ans;
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
N = read();
for (int i = 1; i <= N; i++)
a[i] = read();
int l = 1, r = N;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid))
ans = mid, r = mid - 1;
else
l = mid + 1;
}
printf("%d\n", ans);
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p03202 | C++ | Time Limit Exceeded | // ΔAGC029C
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 222222;
int n, a[N];
map<int, int> M;
set<int> S;
int ok(int x) {
int i, t = 0;
M.clear();
S.clear();
for (i = 1; i <= n; i = i + 1) {
if (a[i] > a[i - 1])
continue;
t = a[i];
while (!S.empty() && *S.rbegin() > t) {
M[*S.rbegin()] = 0;
S.erase(*S.rbegin());
}
while (M[t] == x - 1) {
M[t] = 0;
S.erase(t);
t--;
}
if (t <= 0)
return 0;
M[t]++;
S.insert(t);
}
return 1;
}
int main() {
int i, l, r;
scanf("%d", &n);
for (i = 1; i <= n; i = i + 1)
scanf("%d", a + i);
for (i = 2; i <= n; i = i + 1)
if (a[i - 1] >= a[i])
break;
if (i > n) {
cout << 1;
return 0;
}
l = 2, r = n;
while (l < r) {
i = l + r >> 1;
if (ok(i))
r = i;
else
l = i + 1;
}
cout << l;
return 0;
} | // ΔAGC029C
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 222222;
int n, a[N];
map<int, int> M;
set<int> S;
int ok(int x) {
int i, t = 0;
M.clear();
S.clear();
for (i = 1; i <= n; i = i + 1) {
if (a[i] > a[i - 1])
continue;
t = a[i];
while (!S.empty() && *S.rbegin() > t) {
M[*S.rbegin()] = 0;
S.erase(*S.rbegin());
}
while (M[t] == x - 1) {
M[t] = 0;
S.erase(t);
t--;
}
if (t <= 0)
return 0;
M[t]++;
S.insert(t);
}
return 1;
}
int main() {
int i, l, r;
scanf("%d", &n);
for (i = 1; i <= n; i = i + 1)
scanf("%d", a + i);
for (i = 2; i <= n; i = i + 1)
if (a[i - 1] >= a[i])
break;
if (i > n) {
cout << 1;
return 0;
}
for (i = 2; i <= 5; i = i + 1) {
if (ok(i)) {
cout << i;
return 0;
}
}
l = 6, r = n;
while (l < r) {
i = l + r >> 1;
if (ok(i))
r = i;
else
l = i + 1;
}
cout << l;
return 0;
} | replace | 56 | 57 | 56 | 63 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(it, c) \
for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
inline int read() {
int x = 0, f = 1, c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f ^= 1;
for (; isdigit(c); c = getchar())
x = x * 10 + c - '0';
return f ? x : -x;
}
int n;
int a[100005];
bool check(int mxc) {
set<pii> nw;
rep(i, n) if (i) {
if (a[i] > a[i - 1])
continue;
while (!nw.empty() && nw.rbegin()->first > a[i])
nw.erase(--nw.end());
int nwpos = a[i];
while (nwpos && !nw.empty() && nw.rbegin()->first == nwpos &&
nw.rbegin()->second == mxc) {
nw.erase(--nw.end());
--nwpos;
}
if (!nwpos)
return 0;
if (!nw.empty() && nw.rbegin()->first == nwpos) {
int x = nw.rbegin()->second;
nw.erase(--nw.end());
nw.insert(mp(nwpos, x + 1));
} else {
if (2 > mxc)
return 0;
nw.insert(mp(nwpos, 2));
}
}
return 1;
}
int main() {
n = read();
rep(i, n) a[i] = read();
int lb = 1, rb = n;
while (lb < rb) {
int md = (lb + rb) >> 1;
if (check(md))
rb = md;
else
lb = md + 1;
}
printf("%d\n", lb);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector<int>
#define pii pair<int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(it, c) \
for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
inline int read() {
int x = 0, f = 1, c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f ^= 1;
for (; isdigit(c); c = getchar())
x = x * 10 + c - '0';
return f ? x : -x;
}
int n;
int a[200005];
bool check(int mxc) {
set<pii> nw;
rep(i, n) if (i) {
if (a[i] > a[i - 1])
continue;
while (!nw.empty() && nw.rbegin()->first > a[i])
nw.erase(--nw.end());
int nwpos = a[i];
while (nwpos && !nw.empty() && nw.rbegin()->first == nwpos &&
nw.rbegin()->second == mxc) {
nw.erase(--nw.end());
--nwpos;
}
if (!nwpos)
return 0;
if (!nw.empty() && nw.rbegin()->first == nwpos) {
int x = nw.rbegin()->second;
nw.erase(--nw.end());
nw.insert(mp(nwpos, x + 1));
} else {
if (2 > mxc)
return 0;
nw.insert(mp(nwpos, 2));
}
}
return 1;
}
int main() {
n = read();
rep(i, n) a[i] = read();
int lb = 1, rb = n;
while (lb < rb) {
int md = (lb + rb) >> 1;
if (check(md))
rb = md;
else
lb = md + 1;
}
printf("%d\n", lb);
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p03202 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int s[100];
int main() {
int n;
cin >> n;
int a[n];
rep(i, n) cin >> a[i];
bool inc = true;
rep(i, n - 1) if (a[i] >= a[i + 1]) inc = false;
if (inc) {
cout << 1 << endl;
return 0;
}
int ng = 1, ok = n;
while (ok - ng > 1) {
int mid = (ok + ng) / 2;
rep(i, min(a[0], 100)) s[i] = 1;
REP(i, a[0], 100) s[i] = 0;
bool tempura = true;
rep(i, n - 1) {
if (a[i + 1] > a[i])
REP(j, a[i], min(100, a[i + 1])) s[j] = 1;
else {
if (a[i + 1] > 100)
continue;
REP(j, a[i + 1], a[i]) s[j] = 0;
bool can = false;
for (int j = a[i + 1] - 1; j >= 0; --j) {
if (s[j] < mid) {
++s[j];
REP(k, j + 1, a[i + 1]) s[k] = 1;
can = true;
break;
}
}
if (!can) {
tempura = false;
break;
}
}
}
if (tempura)
ok = mid;
else
ng = mid;
}
cout << ok << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int s[100];
int main() {
int n;
cin >> n;
int a[n];
rep(i, n) cin >> a[i];
bool inc = true;
rep(i, n - 1) if (a[i] >= a[i + 1]) inc = false;
if (inc) {
cout << 1 << endl;
return 0;
}
int ng = 1, ok = n;
while (ok - ng > 1) {
int mid = (ok + ng) / 2;
rep(i, min(a[0], 100)) s[i] = 1;
REP(i, a[0], 100) s[i] = 0;
bool tempura = true;
rep(i, n - 1) {
if (a[i + 1] > a[i])
REP(j, a[i], min(100, a[i + 1])) s[j] = 1;
else {
if (a[i + 1] > 100)
continue;
REP(j, a[i + 1], min(100, a[i])) s[j] = 0;
bool can = false;
for (int j = a[i + 1] - 1; j >= 0; --j) {
if (s[j] < mid) {
++s[j];
REP(k, j + 1, a[i + 1]) s[k] = 1;
can = true;
break;
}
}
if (!can) {
tempura = false;
break;
}
}
}
if (tempura)
ok = mid;
else
ng = mid;
}
cout << ok << endl;
return 0;
}
| replace | 48 | 49 | 48 | 49 | 0 | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
struct fast_ios {
fast_ios() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
template <typename T> inline int sz(T &x) { return x.size(); }
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << '(' << p.first << ", " << p.second << ')';
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v)
is >> e;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto &e : v)
os << e << ' ';
return os;
}
template <typename T> inline int count_between(vector<T> &a, T l, T r) {
return lower_bound(all(a), r) - lower_bound(all(a), l);
} // [l, r)
inline int fLog2(const int x) {
assert(x > 0);
return 31 - __builtin_clz(x);
} // floor(log2(x))
inline int fLog2(const ll x) {
assert(x > 0);
return 63 - __builtin_clzll(x);
}
inline int cLog2(const int x) {
assert(x > 0);
return (x == 1) ? 0 : 32 - __builtin_clz(x - 1);
} // ceil(log2(x))
inline int cLog2(const ll x) {
assert(x > 0);
return (x == 1) ? 0 : 64 - __builtin_clzll(x - 1);
}
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
void fail() {
cout << -1 << '\n';
exit(0);
}
// const int INF = 1<<30;
// const ll INFll = 1ll<<62;
// const ld EPS = 1e-10;
// const ld PI = acos(-1.0);
// const int MOD = int(1e9)+7;
// const int MOD = 998244353;
using VP = vector<P>;
bool inc(VP &v, int k) {
auto [x, y] = v.back();
// assert(0 <= x && x < k && 0 < y);
if (x < k - 1) {
--v.back().second;
if (v.back().second == 0)
v.pop_back();
if (v.back().first == x + 1)
++v.back().second;
else
v.emplace_back(x + 1, 1);
return true;
}
if (sz(v) == 1)
return false;
v.pop_back();
// assert(inc(v, k));
inc(v, k);
v.emplace_back(0, y);
return true;
}
int main() {
int n;
cin >> n;
V a(n);
cin >> a;
auto f = [&](int k) {
VP v = {{0, a[0]}};
// cout << v << '\n';
rep2(i, 1, n) {
if (a[i - 1] == a[i]) {
if (!inc(v, k))
return false;
} else if (a[i - 1] < a[i]) {
auto [x, y] = v.back();
if (x == 0)
v.back().second += a[i] - a[i - 1];
else
v.emplace_back(0, a[i] - a[i - 1]);
} else {
int d = a[i - 1] - a[i];
while (d) {
if (v.back().second > d) {
v.back().second -= d;
d = 0;
} else {
d -= v.back().second;
v.pop_back();
}
}
if (!inc(v, k))
return false;
}
// cout << v << '\n';
}
return true;
};
ll ok = ll(1e9) + 5;
ll ng = 0;
while (llabs(ok - ng) > 1) {
ll md = (ok + ng) >> 1;
if (f(md))
ok = md;
else
ng = md;
}
ll ans = ok;
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
struct fast_ios {
fast_ios() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
template <typename T> inline int sz(T &x) { return x.size(); }
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << '(' << p.first << ", " << p.second << ')';
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v)
is >> e;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto &e : v)
os << e << ' ';
return os;
}
template <typename T> inline int count_between(vector<T> &a, T l, T r) {
return lower_bound(all(a), r) - lower_bound(all(a), l);
} // [l, r)
inline int fLog2(const int x) {
assert(x > 0);
return 31 - __builtin_clz(x);
} // floor(log2(x))
inline int fLog2(const ll x) {
assert(x > 0);
return 63 - __builtin_clzll(x);
}
inline int cLog2(const int x) {
assert(x > 0);
return (x == 1) ? 0 : 32 - __builtin_clz(x - 1);
} // ceil(log2(x))
inline int cLog2(const ll x) {
assert(x > 0);
return (x == 1) ? 0 : 64 - __builtin_clzll(x - 1);
}
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
void fail() {
cout << -1 << '\n';
exit(0);
}
// const int INF = 1<<30;
// const ll INFll = 1ll<<62;
// const ld EPS = 1e-10;
// const ld PI = acos(-1.0);
// const int MOD = int(1e9)+7;
// const int MOD = 998244353;
using VP = vector<P>;
bool inc(VP &v, int k) {
auto [x, y] = v.back();
// assert(0 <= x && x < k && 0 < y);
if (x < k - 1) {
--v.back().second;
if (v.back().second == 0)
v.pop_back();
if (sz(v) && v.back().first == x + 1)
++v.back().second;
else
v.emplace_back(x + 1, 1);
return true;
}
if (sz(v) == 1)
return false;
v.pop_back();
// assert(inc(v, k));
inc(v, k);
v.emplace_back(0, y);
return true;
}
int main() {
int n;
cin >> n;
V a(n);
cin >> a;
auto f = [&](int k) {
VP v = {{0, a[0]}};
// cout << v << '\n';
rep2(i, 1, n) {
if (a[i - 1] == a[i]) {
if (!inc(v, k))
return false;
} else if (a[i - 1] < a[i]) {
auto [x, y] = v.back();
if (x == 0)
v.back().second += a[i] - a[i - 1];
else
v.emplace_back(0, a[i] - a[i - 1]);
} else {
int d = a[i - 1] - a[i];
while (d) {
if (v.back().second > d) {
v.back().second -= d;
d = 0;
} else {
d -= v.back().second;
v.pop_back();
}
}
if (!inc(v, k))
return false;
}
// cout << v << '\n';
}
return true;
};
ll ok = ll(1e9) + 5;
ll ng = 0;
while (llabs(ok - ng) > 1) {
ll md = (ok + ng) >> 1;
if (f(md))
ok = md;
else
ng = md;
}
ll ans = ok;
cout << ans << '\n';
return 0;
}
| replace | 105 | 106 | 105 | 106 | 0 | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
#define llong long long
#define pii pair<int, int>
#define mkpr make_pair
#define riterator reverse_iterator
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) {
if (ch == '-')
f = -1;
}
for (; isdigit(ch); ch = getchar()) {
x = x * 10 + ch - 48;
}
return x * f;
}
const int N = 1e5;
int len[N + 3];
set<pii> a;
int n;
bool check(int s) {
// printf("check %d\n",s);
a.clear();
for (int i = 1; i <= n; i++) {
if (len[i] <= len[i - 1]) {
set<pii>::riterator iter = a.rbegin();
while (iter != a.rend() && (*iter).first > len[i]) {
a.erase((++iter).base());
iter = a.rbegin();
}
int tmp = len[i];
while (iter != a.rend() && (*iter).first == tmp &&
(*iter).second == s - 1) {
a.erase((++iter).base());
tmp--;
iter = a.rbegin();
}
if (tmp == 0) {
return false;
}
int x = 1;
if (iter != a.rend() && (*iter).first == tmp) {
x = (*iter).second + 1;
a.erase((++iter).base());
iter = a.rbegin();
}
a.insert(mkpr(tmp, x));
// printf("i=%d ",i); for(set<pii>::iterator
//iter=a.begin(); iter!=a.end(); iter++) printf("(%d,%d)
//",(*iter).first,(*iter).second); puts("");
}
}
return true;
}
int main() {
scanf("%d", &n);
bool f = true;
for (int i = 1; i <= n; i++) {
scanf("%d", &len[i]);
if (len[i] <= len[i - 1]) {
f = false;
}
}
if (f) {
puts("1");
return 0;
}
int left = 2, right = n;
while (left < right) {
int mid = left + (right - left >> 1);
bool ok = check(mid);
if (ok)
right = mid;
else
left = mid + 1;
}
printf("%d\n", right);
return 0;
} | #include <bits/stdc++.h>
#define llong long long
#define pii pair<int, int>
#define mkpr make_pair
#define riterator reverse_iterator
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) {
if (ch == '-')
f = -1;
}
for (; isdigit(ch); ch = getchar()) {
x = x * 10 + ch - 48;
}
return x * f;
}
const int N = 2e5;
int len[N + 3];
set<pii> a;
int n;
bool check(int s) {
// printf("check %d\n",s);
a.clear();
for (int i = 1; i <= n; i++) {
if (len[i] <= len[i - 1]) {
set<pii>::riterator iter = a.rbegin();
while (iter != a.rend() && (*iter).first > len[i]) {
a.erase((++iter).base());
iter = a.rbegin();
}
int tmp = len[i];
while (iter != a.rend() && (*iter).first == tmp &&
(*iter).second == s - 1) {
a.erase((++iter).base());
tmp--;
iter = a.rbegin();
}
if (tmp == 0) {
return false;
}
int x = 1;
if (iter != a.rend() && (*iter).first == tmp) {
x = (*iter).second + 1;
a.erase((++iter).base());
iter = a.rbegin();
}
a.insert(mkpr(tmp, x));
// printf("i=%d ",i); for(set<pii>::iterator
//iter=a.begin(); iter!=a.end(); iter++) printf("(%d,%d)
//",(*iter).first,(*iter).second); puts("");
}
}
return true;
}
int main() {
scanf("%d", &n);
bool f = true;
for (int i = 1; i <= n; i++) {
scanf("%d", &len[i]);
if (len[i] <= len[i - 1]) {
f = false;
}
}
if (f) {
puts("1");
return 0;
}
int left = 2, right = n;
while (left < right) {
int mid = left + (right - left >> 1);
bool ok = check(mid);
if (ok)
right = mid;
else
left = mid + 1;
}
printf("%d\n", right);
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p03202 | C++ | Time Limit Exceeded | // By Don4ick
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
const int N = (int)2e5 + 228;
using namespace std;
struct Block {
int l, r, ch;
};
int n, a[N];
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie();
// cout.tie();
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
//~read
scanf("%d", &n);
forn(i, n) scanf("%d", &a[i]);
//~solve
int l = 0, r = n + 1;
while (l < r - 1) {
int ans = (l + r) >> 1;
vector<Block> t;
bool good = true;
t.pb({1, a[1], 1});
for (int i = 2; i <= n; i++) {
vector<Block> v;
if (a[i] > a[i - 1]) {
v = t;
v.pb({a[i - 1] + 1, a[i], 1});
} else {
for (int j = (int)t.size() - 1; j >= 0; j--) {
if (t[j].ch == ans)
continue;
if (t[j].l > a[i])
continue;
for (int k = 0; k < j; k++)
v.pb(t[k]);
int pos = min(a[i], t[j].r);
if (pos > t[j].l)
v.pb({t[j].l, pos - 1, t[j].ch});
v.pb({pos, pos, t[j].ch + 1});
if (pos < a[i])
v.pb({pos + 1, a[i], 1});
break;
}
}
if (v.empty()) {
good = false;
break;
}
t = v;
}
if (good)
r = ans;
else
l = ans;
}
cout << r << endl;
return 0;
}
| // By Don4ick
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
const int N = (int)2e5 + 228;
using namespace std;
struct Block {
int l, r, ch;
};
int n, a[N];
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie();
// cout.tie();
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
//~read
scanf("%d", &n);
forn(i, n) scanf("%d", &a[i]);
//~solve
int l = 0, r = n + 1;
while (l < r - 1) {
int ans = (l + r) >> 1;
vector<Block> t;
bool good = true;
t.pb({1, a[1], 1});
for (int i = 2; i <= n; i++) {
vector<Block> v;
if (a[i] > a[i - 1]) {
v = t;
v.pb({a[i - 1] + 1, a[i], 1});
} else {
for (int j = (int)t.size() - 1; j >= 0; j--) {
if (t[j].ch == ans)
continue;
if (t[j].l > a[i])
continue;
for (int k = 0; k < j; k++)
v.pb(t[k]);
int pos = min(a[i], t[j].r);
if (pos > t[j].l)
v.pb({t[j].l, pos - 1, t[j].ch});
v.pb({pos, pos, t[j].ch + 1});
if (pos < a[i])
v.pb({pos + 1, a[i], 1});
break;
}
}
if (v.empty()) {
good = false;
break;
}
t.clear();
int ll = 1;
for (int i = 0; i < (int)v.size(); i++) {
if (i == (int)v.size() - 1 || v[i].ch != v[i + 1].ch) {
t.pb({ll, v[i].r, v[i].ch});
ll = v[i].r + 1;
}
}
}
if (good)
r = ans;
else
l = ans;
}
cout << r << endl;
return 0;
}
| replace | 73 | 74 | 73 | 81 | TLE | |
p03202 | C++ | Time Limit Exceeded | //{{{By oToToT
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
/* include everything for Kotori~ <3 */
using lld = int64_t;
using llu = uint64_t;
using llf = long double;
using PII = pair<int, int>;
using PIL = pair<int, lld>;
using PLI = pair<lld, int>;
using PLL = pair<lld, lld>;
template <typename T> using maxHeap = priority_queue<T, vector<T>, less<T>>;
template <typename T> using minHeap = priority_queue<T, vector<T>, greater<T>>;
/* define some types for Ruby! */
#define FF first
#define SS second
#define SZ(x) (int)((x).size())
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while (x--)
/* make code shorter for Di~a~ */
template <typename Iter> ostream &_out(ostream &s, Iter b, Iter e) {
s << "[";
for (auto it = b; it != e; it++)
s << (it == b ? "" : " ") << *it;
s << "]";
return s;
}
template <typename A, typename B>
ostream &operator<<(ostream &s, const pair<A, B> &p) {
return s << "(" << p.FF << "," << p.SS << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &c) {
return _out(s, ALL(c));
}
/* make output easier for Ainyan~n~ */
bool debug = 0;
#define DUMP(x) \
if (debug) \
cerr << __PRETTY_FUNCTION__ << ":" << __LINE__ << " - " << (#x) << "=" \
<< (x) << '\n'
template <typename T> void DEBUG(const T &x) {
if (debug)
cerr << x;
}
template <typename T, typename... Args>
void DEBUG(const T &head, const Args &...tail) {
if (debug) {
cerr << head;
DEBUG(tail...);
}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 200000 + 5;
inline bool isOK(int, int);
int arr[N];
int main(int argc, char *argv[]) {
if (argc > 1 and string(argv[1]) == "-D")
debug = 1;
if (!debug) {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
int l = 0, r = n;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (isOK(mid - 1, n))
r = mid;
else
l = mid;
}
cout << r << '\n';
return 0;
}
inline bool isOK(int mx, int n) {
map<int, int> mp;
for (int i = 1; i < n; i++) {
if (arr[i] > arr[i - 1])
continue;
int p = arr[i];
while (p >= 1 and mp[p] == mx) {
p--;
}
if (p == 0)
return false;
mp[p]++;
auto it = mp.upper_bound(p);
while (it != mp.end())
it = mp.erase(it);
}
return true;
} | //{{{By oToToT
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
/* include everything for Kotori~ <3 */
using lld = int64_t;
using llu = uint64_t;
using llf = long double;
using PII = pair<int, int>;
using PIL = pair<int, lld>;
using PLI = pair<lld, int>;
using PLL = pair<lld, lld>;
template <typename T> using maxHeap = priority_queue<T, vector<T>, less<T>>;
template <typename T> using minHeap = priority_queue<T, vector<T>, greater<T>>;
/* define some types for Ruby! */
#define FF first
#define SS second
#define SZ(x) (int)((x).size())
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while (x--)
/* make code shorter for Di~a~ */
template <typename Iter> ostream &_out(ostream &s, Iter b, Iter e) {
s << "[";
for (auto it = b; it != e; it++)
s << (it == b ? "" : " ") << *it;
s << "]";
return s;
}
template <typename A, typename B>
ostream &operator<<(ostream &s, const pair<A, B> &p) {
return s << "(" << p.FF << "," << p.SS << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &c) {
return _out(s, ALL(c));
}
/* make output easier for Ainyan~n~ */
bool debug = 0;
#define DUMP(x) \
if (debug) \
cerr << __PRETTY_FUNCTION__ << ":" << __LINE__ << " - " << (#x) << "=" \
<< (x) << '\n'
template <typename T> void DEBUG(const T &x) {
if (debug)
cerr << x;
}
template <typename T, typename... Args>
void DEBUG(const T &head, const Args &...tail) {
if (debug) {
cerr << head;
DEBUG(tail...);
}
}
/* Let's debug with Nico~Nico~Ni */
//}}}
const int N = 200000 + 5;
inline bool isOK(int, int);
int arr[N];
int main(int argc, char *argv[]) {
if (argc > 1 and string(argv[1]) == "-D")
debug = 1;
if (!debug) {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
int l = 0, r = n;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (isOK(mid - 1, n))
r = mid;
else
l = mid;
}
cout << r << '\n';
return 0;
}
inline bool isOK(int mx, int n) {
map<int, int> mp;
for (int i = 1; i < n; i++) {
if (arr[i] > arr[i - 1])
continue;
if (mx == 0)
return false;
int p = arr[i];
while (p >= 1 and mp[p] == mx) {
p--;
}
if (p == 0)
return false;
mp[p]++;
auto it = mp.upper_bound(p);
while (it != mp.end())
it = mp.erase(it);
}
return true;
} | insert | 112 | 112 | 112 | 114 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <iostream>
#include <map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define INF 1000000007
void p(vec<int> a) {
rep(i, a.size()) cout << a[i] << endl;
return;
}
bool check(vec<int> a, int k) {
map<int, int> s;
s[a[0] - 1] = 1;
rep(i, a.size() - 1) {
if (a[i + 1] > a[i]) {
s[a[i + 1] - 1] = 1;
} else {
int cur = a[i + 1] - 1;
while (cur >= 0) {
int temp = s.find(cur) == end(s) ? 1 : s[cur];
temp++;
if (temp <= k) {
s[cur] = temp;
break;
}
s[cur] = 1;
cur--;
}
if (cur < 0)
return false;
}
auto it = s.find(a[i + 1] - 1);
it++;
s.erase(it, end(s));
}
return true;
}
int main(void) {
int n;
cin >> n;
vec<int> a(n);
rep(i, n) cin >> a[i];
int left = 1, right = n;
while (left < right) {
int mid = (left + right) / 2;
if (check(a, mid))
right = mid;
else
left = mid + 1;
}
cout << left << endl;
return 0;
}
| #include <iostream>
#include <map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define INF 1000000007
void p(vec<int> a) {
rep(i, a.size()) cout << a[i] << endl;
return;
}
bool check(vec<int> a, int k) {
map<int, int> s;
s[a[0] - 1] = 1;
rep(i, a.size() - 1) {
if (a[i + 1] > a[i]) {
s[a[i + 1] - 1] = 1;
} else {
if (k == 1)
return false;
int cur = a[i + 1] - 1;
while (cur >= 0) {
int temp = s.find(cur) == end(s) ? 1 : s[cur];
temp++;
if (temp <= k) {
s[cur] = temp;
break;
}
s[cur] = 1;
cur--;
}
if (cur < 0)
return false;
}
auto it = s.find(a[i + 1] - 1);
it++;
s.erase(it, end(s));
}
return true;
}
int main(void) {
int n;
cin >> n;
vec<int> a(n);
rep(i, n) cin >> a[i];
int left = 1, right = n;
while (left < right) {
int mid = (left + right) / 2;
if (check(a, mid))
right = mid;
else
left = mid + 1;
}
cout << left << endl;
return 0;
}
| insert | 22 | 22 | 22 | 24 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\n'
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll inf = 1e9 + 7;
const ll mod = 998244353;
signed main() {
int n;
cin >> n;
int ng = -1, ok = n;
vector<int> a(n);
rep(i, n) cin >> a[i];
while (ok - ng > 1) {
int mid = ng + (ok - ng) / 2;
map<ll, ll> ma;
bool f = 1;
int la = 0;
rep(i, n) {
if (la < a[i]) {
la = a[i];
} else {
for (auto e : ma) {
if (e.fi >= -a[i])
break;
ma.erase(e.fi);
}
ll now = 1;
ll z = -a[i];
while (now == 1) {
if (ma[z] == mid && z < 0) {
ma.erase(z);
z++;
} else {
ma[z]++;
now = 0;
}
}
if (ma[0] > 0) {
f = 0;
break;
}
la = a[i];
}
}
if (f)
ok = mid;
else
ng = mid;
}
cout << ok + 1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\n'
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll inf = 1e9 + 7;
const ll mod = 998244353;
signed main() {
int n;
cin >> n;
int ng = -1, ok = n;
vector<int> a(n);
rep(i, n) cin >> a[i];
while (ok - ng > 1) {
int mid = ng + (ok - ng) / 2;
map<ll, ll> ma;
bool f = 1;
int la = 0;
rep(i, n) {
if (la < a[i]) {
la = a[i];
} else {
if (mid == 0) {
f = 0;
break;
}
for (auto e : ma) {
if (e.fi >= -a[i])
break;
ma.erase(e.fi);
}
ll now = 1;
ll z = -a[i];
while (now == 1) {
if (ma[z] == mid && z < 0) {
ma.erase(z);
z++;
} else {
ma[z]++;
now = 0;
}
}
if (ma[0] > 0) {
f = 0;
break;
}
la = a[i];
}
}
if (f)
ok = mid;
else
ng = mid;
}
cout << ok + 1 << endl;
} | insert | 35 | 35 | 35 | 39 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int n;
vi a;
bool f(int m) {
stack<P> st;
st.push({0, a[0]});
for (int i = 1; i < n; i++) {
if (a[i - 1] < a[i])
st.push({0, a[i] - a[i - 1]});
else {
int t = 0, L = a[i - 1];
while (L > a[i]) {
P p = st.top();
st.pop();
L -= p.second;
if (L < 0)
st.push({p.first, -L});
}
while (!st.empty()) {
P p = st.top();
st.pop();
if (p.first < m - 1) {
p.second--;
if (p.second)
st.push(p);
st.push({p.first + 1, 1});
if (t)
st.push({0, t});
break;
}
t += p.second;
}
if (st.empty())
return 0;
}
}
return 1;
}
int main() {
cin >> n;
a = vi(n);
for (auto &i : a)
cin >> i;
int l = 0, r = n;
while (r - l > 1) {
int m = (l + r) / 2;
if (f(m))
r = m;
else
l = m;
}
cout << r << endl;
} | #include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int n;
vi a;
bool f(int m) {
stack<P> st;
st.push({0, a[0]});
for (int i = 1; i < n; i++) {
if (a[i - 1] < a[i])
st.push({0, a[i] - a[i - 1]});
else {
int t = 0, L = a[i - 1];
while (L > a[i]) {
P p = st.top();
st.pop();
L -= p.second;
if (L < a[i])
st.push({p.first, a[i] - L});
}
while (!st.empty()) {
P p = st.top();
st.pop();
if (p.first < m - 1) {
p.second--;
if (p.second)
st.push(p);
st.push({p.first + 1, 1});
if (t)
st.push({0, t});
break;
}
t += p.second;
}
if (st.empty())
return 0;
}
}
return 1;
}
int main() {
cin >> n;
a = vi(n);
for (auto &i : a)
cin >> i;
int l = 0, r = n;
while (r - l > 1) {
int m = (l + r) / 2;
if (f(m))
r = m;
else
l = m;
}
cout << r << endl;
} | replace | 42 | 44 | 42 | 44 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using Int = long long;
bool test(const vector<int> &A, int k) {
int last = 0;
map<int, int> m;
for (int a : A) {
if (a <= last) {
m[a] += 1;
m.erase(++m.find(a), m.end());
int b = a;
while (b > 0 && m[b] >= k) {
m[b] = 0;
m[b - 1]++;
b--;
}
if (b == 0)
return false;
}
last = a;
}
return true;
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (auto &a : A)
cin >> a;
int lo = 0, hi = N;
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
(test(A, mid) ? hi : lo) = mid;
}
cout << hi << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using Int = long long;
bool test(const vector<int> &A, int k) {
int last = 0;
if (k == 1) {
for (int a : A) {
if (a <= last)
return false;
last = a;
}
return true;
}
map<int, int> m;
for (int a : A) {
if (a <= last) {
m[a] += 1;
m.erase(++m.find(a), m.end());
int b = a;
while (b > 0 && m[b] >= k) {
m[b] = 0;
m[b - 1]++;
b--;
}
if (b == 0)
return false;
}
last = a;
}
return true;
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (auto &a : A)
cin >> a;
int lo = 0, hi = N;
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
(test(A, mid) ? hi : lo) = mid;
}
cout << hi << endl;
return 0;
}
| insert | 5 | 5 | 5 | 13 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);
int N;
int A[220000];
signed main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
int lb = 0, ub = N + 1;
while (ub - lb > 1) {
int mid = (lb + ub) / 2;
map<int, int> mp;
for (int i = 1; i < N; i++) {
if (A[i - 1] >= A[i]) {
for (auto it = mp.upper_bound(A[i]);
it->first <= A[i - 1] && it != mp.end();
it = mp.upper_bound(A[i])) {
mp.erase(it);
}
for (int j = A[i]; j > 0; j--) {
if (mp[j] == mid - 1)
mp.erase(j);
else {
mp[j]++;
goto umiko;
}
}
lb = mid;
goto nene;
}
umiko:;
}
ub = mid;
nene:;
}
cout << ub << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);
int N;
int A[220000];
signed main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
for (int i = 1; i < N; i++)
if (A[i - 1] >= A[i])
goto aoba;
cout << 1 << endl;
return 0;
aoba:;
int lb = 1, ub = N + 1;
while (ub - lb > 1) {
int mid = (lb + ub) / 2;
map<int, int> mp;
for (int i = 1; i < N; i++) {
if (A[i - 1] >= A[i]) {
for (auto it = mp.upper_bound(A[i]);
it->first <= A[i - 1] && it != mp.end();
it = mp.upper_bound(A[i])) {
mp.erase(it);
}
for (int j = A[i]; j > 0; j--) {
if (mp[j] == mid - 1)
mp.erase(j);
else {
mp[j]++;
goto umiko;
}
}
lb = mid;
goto nene;
}
umiko:;
}
ub = mid;
nene:;
}
cout << ub << endl;
}
| replace | 19 | 20 | 19 | 26 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG \
fprintf(stderr, "Running on Line %d in Function %s\n", __LINE__, __FUNCTION__)
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read() {
char ch = getchar();
int nega = 1;
while (!isdigit(ch)) {
if (ch == '-')
nega = -1;
ch = getchar();
}
int ans = 0;
while (isdigit(ch)) {
ans = ans * 10 + ch - 48;
ch = getchar();
}
if (nega == -1)
return -ans;
return ans;
}
typedef pair<int, int> pii;
#define N 100005
int a[N], n;
bool chk(int mid) {
stack<pii> s;
s.emplace(0, 0);
for (int i = 1; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
while (s.top().fir > a[i])
s.pop();
int val = a[i];
while (s.top().fir == val && s.top().sec == mid - 1) {
s.pop();
val--;
}
if (!val)
return 0;
if (s.top().fir == val) {
auto [v, w] = s.top();
s.pop();
s.emplace(v, w + 1);
} else
s.emplace(val, 1);
}
return 1;
}
signed main() {
cin >> n;
for (int i = 1; i <= n; i++)
a[i] = read();
bool ok = 1;
for (int i = 1; i <= n; i++)
ok &= (a[i] > a[i - 1]);
if (ok) {
cout << 1 << endl;
return 0;
}
int l = 2, r = n, ans;
while (l <= r) {
int mid = (l + r) / 2;
if (chk(mid))
ans = mid, r = mid - 1;
else
l = mid + 1;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG \
fprintf(stderr, "Running on Line %d in Function %s\n", __LINE__, __FUNCTION__)
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read() {
char ch = getchar();
int nega = 1;
while (!isdigit(ch)) {
if (ch == '-')
nega = -1;
ch = getchar();
}
int ans = 0;
while (isdigit(ch)) {
ans = ans * 10 + ch - 48;
ch = getchar();
}
if (nega == -1)
return -ans;
return ans;
}
typedef pair<int, int> pii;
#define N 200005
int a[N], n;
bool chk(int mid) {
stack<pii> s;
s.emplace(0, 0);
for (int i = 1; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
while (s.top().fir > a[i])
s.pop();
int val = a[i];
while (s.top().fir == val && s.top().sec == mid - 1) {
s.pop();
val--;
}
if (!val)
return 0;
if (s.top().fir == val) {
auto [v, w] = s.top();
s.pop();
s.emplace(v, w + 1);
} else
s.emplace(val, 1);
}
return 1;
}
signed main() {
cin >> n;
for (int i = 1; i <= n; i++)
a[i] = read();
bool ok = 1;
for (int i = 1; i <= n; i++)
ok &= (a[i] > a[i - 1]);
if (ok) {
cout << 1 << endl;
return 0;
}
int l = 2, r = n, ans;
while (l <= r) {
int mid = (l + r) / 2;
if (chk(mid))
ans = mid, r = mid - 1;
else
l = mid + 1;
}
cout << ans << endl;
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.