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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b) \
for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)
#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v) \
cout << #v << ":"; \
REP(i, v.size()) cout << " " << v[i]; \
cout << endl
#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))
// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a) % MOD + MOD) % MOD
// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(a, b) (abs(a - b) < EPS)
typedef complex<Real> P;
const int INF = 1 << 30;
int b;
int n;
int a[252521];
const int N = 1 << 18;
pii seg[2 * N];
pii qmin(int l, int r, int a, int b, int k) {
if (r <= a || b <= l)
return pii(INF, INF);
if (l <= a && b <= r)
return seg[k];
int m = (a + b) / 2;
return min(qmin(l, r, a, m, 2 * k + 1), qmin(l, r, m, b, 2 * k + 2));
}
ll dfs(int l, int r, int x) {
if (r == l)
return 0;
if (r - l == 1)
return 1;
ll ret = 0;
int cnt = 0;
pii P = qmin(l, r, 0, N, 0);
int v = P.first;
int p = P.second;
if (l < p)
ret = min(ret + max(1ll, dfs(l, p, v)), 1ll << 60);
p++;
while (p < r) {
P = qmin(p, r, 0, N, 0);
if (P.first != v)
break;
int q = P.second;
ret = min(ret + max(1ll, dfs(p, q, v)), 1ll << 60);
p = q + 1;
}
ret = min(ret + max(1ll, dfs(p, r, v)), 1ll << 60);
int sa = v - x;
ll a = b;
ll c = sa;
ll bsa = 1;
while (c) {
if (c & 1)
bsa = min(bsa * a, 1ll << 60);
a = min(a * a, 1ll << 60);
c >>= 1;
}
return (ret + bsa - 1) / bsa;
}
int main() {
scanf("%d", &n);
REP(i, n) scanf("%d", a + i);
// 1 check
bool ok1 = true;
REP(i, n - 1) if (a[i] >= a[i + 1]) {
ok1 = false;
break;
}
if (ok1) {
puts("1");
return 0;
}
// seg
REP(i, n) seg[i + N - 1] = pii(a[i], i);
FOR(i, n, N) seg[i + N - 1] = pii(INF, INF);
FORR(i, 0, N - 1) seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]);
int low = 1, high = n + 10;
while (low + 1 < high) {
b = (low + high) / 2;
ll ret = dfs(0, n, 0);
if (ret <= 1) {
high = b;
} else {
low = b;
}
}
printf("%d\n", high);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef int _loop_int;
#define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i)
#define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i)
#define FORR(i, a, b) \
for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i)
#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v) \
cout << #v << ":"; \
REP(i, v.size()) cout << " " << v[i]; \
cout << endl
#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))
// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a) % MOD + MOD) % MOD
// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(a, b) (abs(a - b) < EPS)
typedef complex<Real> P;
const int INF = 1 << 30;
int b;
int n;
int a[252521];
const int N = 1 << 18;
pii seg[2 * N];
pii qmin(int l, int r, int a, int b, int k) {
if (r <= a || b <= l)
return pii(INF, INF);
if (l <= a && b <= r)
return seg[k];
int m = (a + b) / 2;
return min(qmin(l, r, a, m, 2 * k + 1), qmin(l, r, m, b, 2 * k + 2));
}
ll dfs(int l, int r, int x) {
if (r == l)
return 0;
if (r - l == 1)
return 1;
ll ret = 0;
int cnt = 0;
pii P = qmin(l, r, 0, N, 0);
int v = P.first;
int p = P.second;
if (l < p)
ret = min(ret + max(1ll, dfs(l, p, v)), 1ll << 60);
p++;
while (p < r) {
P = qmin(p, r, 0, N, 0);
if (P.first != v)
break;
int q = P.second;
ret = min(ret + max(1ll, dfs(p, q, v)), 1ll << 60);
p = q + 1;
}
ret = min(ret + max(1ll, dfs(p, r, v)), 1ll << 60);
int sa = v - x;
ll a = b;
ll c = sa;
ll bsa = 1;
while (c) {
if (c & 1)
bsa = min(bsa * a, 1ll << 30);
a = min(a * a, 1ll << 30);
c >>= 1;
}
return (ret + bsa - 1) / bsa;
}
int main() {
scanf("%d", &n);
REP(i, n) scanf("%d", a + i);
// 1 check
bool ok1 = true;
REP(i, n - 1) if (a[i] >= a[i + 1]) {
ok1 = false;
break;
}
if (ok1) {
puts("1");
return 0;
}
// seg
REP(i, n) seg[i + N - 1] = pii(a[i], i);
FOR(i, n, N) seg[i + N - 1] = pii(INF, INF);
FORR(i, 0, N - 1) seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]);
int low = 1, high = n + 10;
while (low + 1 < high) {
b = (low + high) / 2;
ll ret = dfs(0, n, 0);
if (ret <= 1) {
high = b;
} else {
low = b;
}
}
printf("%d\n", high);
return 0;
}
| replace | 83 | 85 | 83 | 85 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
struct node {
map<int, int> s;
inline void clear(int x) {
while (s.size() && (--s.end())->first >= x)
s.erase(--s.end());
}
inline int &operator[](int x) {
if (!s.count(x))
s[x] = 0;
return s[x];
}
} s;
int n, a[200010];
inline int check(int x) {
s.clear(0);
for (int i = 2; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
s.clear(a[i]);
int now = a[i] - 1;
while (now >= 0) {
if (++s[now] != x)
break;
s[now] = 0;
now--;
}
if (now < 0)
return 0;
}
return 1;
}
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 mid = l + r >> 1;
if (check(mid))
ans = mid, r = mid - 1;
else
l = mid + 1;
}
return cout << ans << endl, 0;
} | #include <bits/stdc++.h>
using namespace std;
struct node {
map<int, int> s;
inline void clear(int x) {
while (s.size() && (--s.end())->first >= x)
s.erase(--s.end());
}
inline int &operator[](int x) {
if (!s.count(x))
s[x] = 0;
return s[x];
}
} s;
int n, a[200010];
inline int check(int x) {
s.clear(0);
for (int i = 2; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
s.clear(a[i]);
int now = a[i] - 1;
while (now >= 0) {
if (++s[now] != x)
break;
s[now] = 0;
now--;
}
if (now < 0)
return 0;
}
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", a + i);
int tag = 1;
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1])
tag = 0;
if (tag)
return puts("1"), 0;
int l = 2, r = n, ans;
while (l <= r) {
int mid = l + r >> 1;
if (check(mid))
ans = mid, r = mid - 1;
else
l = mid + 1;
}
return cout << ans << endl, 0;
} | replace | 37 | 38 | 37 | 44 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
vector<long long> a;
bool check(int k) {
map<int, int> mp;
for (int i = 1; i < a.size(); i++) {
if (a[i] <= a[i - 1]) {
int p = a[i];
mp.erase(mp.upper_bound(p), mp.end());
while (mp[p] == k - 1) {
p--;
if (p == 0)
return false;
}
mp[p]++;
mp.erase(mp.upper_bound(p), mp.end());
}
}
return true;
}
int main() {
int n;
cin >> n;
a.resize(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int l = 0, r = 200010;
while (r - l > 1) {
int mid = (l + r) / 2;
if (check(mid))
r = mid;
else
l = mid;
}
cout << r << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
vector<long long> a;
bool check(int k) {
map<int, int> mp;
for (int i = 1; i < a.size(); i++) {
if (a[i] > a[i - 1])
continue;
if (k == 1)
return false;
if (a[i] <= a[i - 1]) {
int p = a[i];
mp.erase(mp.upper_bound(p), mp.end());
while (mp[p] == k - 1) {
p--;
if (p == 0)
return false;
}
mp[p]++;
mp.erase(mp.upper_bound(p), mp.end());
}
}
return true;
}
int main() {
int n;
cin >> n;
a.resize(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int l = 0, r = 200010;
while (r - l > 1) {
int mid = (l + r) / 2;
if (check(mid))
r = mid;
else
l = mid;
}
cout << r << endl;
return 0;
}
| insert | 12 | 12 | 12 | 16 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int MaxN = 200000 + 5;
int N;
int A[MaxN];
vector<pii> vec;
void init() {
scanf("%d", &N);
for (int i = 1; i <= N; ++i)
scanf("%d", &A[i]);
}
bool is_increase() {
for (int i = 2; i <= N; ++i)
if (A[i] <= A[i - 1])
return false;
return true;
}
inline bool check(int m) {
vec.clear();
vec.push_back(make_pair(1, 0));
int id = A[1];
if (id != 1)
vec.push_back(make_pair(id, 0));
for (int i = 2; i <= N; ++i) {
/* printf("m = %d, i = %d\n", m, i);
for (auto v : vec) {
printf("[%d, %d]\n", v.first, v.second);
} */
if (A[i] > id) {
id = A[i];
vec.push_back(make_pair(id, 0));
} else if (A[i] == id) {
if ((vec.end() - 1)->first != id)
vec.push_back(make_pair(id, 0));
int worst = id;
while ((vec.end() - 1)->second == m - 1) {
worst = (vec.end() - 1)->first - 1;
vec.erase(vec.end() - 1);
if (vec.empty() == true)
return false;
if ((vec.end() - 1)->first != worst)
vec.push_back(make_pair(worst, 0));
}
pii p = *(vec.end() - 1);
p.second++;
vec.erase(vec.end() - 1);
vec.push_back(p);
if ((vec.end() - 1)->first != id)
vec.push_back(make_pair(id, 0));
} else {
id = A[i];
while ((vec.end() - 1)->first > id) {
vec.erase(vec.end() - 1);
if (vec.empty() == true)
return false;
}
if ((vec.end() - 1)->first != id)
vec.push_back(make_pair(id, 0));
int worst = id;
while ((vec.end() - 1)->second == m - 1) {
worst = (vec.end() - 1)->first - 1;
vec.erase(vec.end() - 1);
if (vec.empty() == true)
return false;
if ((vec.end() - 1)->first != worst)
vec.push_back(make_pair(worst, 0));
}
pii p = *(vec.end() - 1);
p.second++;
vec.erase(vec.end() - 1);
vec.push_back(p);
if ((vec.end() - 1)->first != id)
vec.push_back(make_pair(id, 0));
}
// printf("m = %d, id = %d\n", m, id);
}
return true;
}
void solve() {
if (is_increase() == true) {
cout << 1 << endl;
return;
}
int lbound = 1, rbound = N, ans;
while (lbound <= rbound) {
int mid = (lbound + rbound) >> 1;
if (check(mid) == true) {
ans = mid;
rbound = mid - 1;
} else {
lbound = mid + 1;
}
}
cout << ans << endl;
}
int main() {
init();
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int MaxN = 200000 + 5;
int N;
int A[MaxN];
vector<pii> vec;
void init() {
scanf("%d", &N);
for (int i = 1; i <= N; ++i)
scanf("%d", &A[i]);
}
bool is_increase() {
for (int i = 2; i <= N; ++i)
if (A[i] <= A[i - 1])
return false;
return true;
}
inline bool check(int m) {
vec.clear();
vec.push_back(make_pair(1, 0));
int id = A[1];
if (id != 1)
vec.push_back(make_pair(id, 0));
for (int i = 2; i <= N; ++i) {
/* printf("m = %d, i = %d\n", m, i);
for (auto v : vec) {
printf("[%d, %d]\n", v.first, v.second);
} */
if (A[i] > id) {
id = A[i];
vec.push_back(make_pair(id, 0));
} else if (A[i] == id) {
if ((vec.end() - 1)->first != id)
vec.push_back(make_pair(id, 0));
int worst = id;
while ((vec.end() - 1)->second == m - 1) {
worst = (vec.end() - 1)->first - 1;
vec.erase(vec.end() - 1);
if (vec.empty() == true)
return false;
if ((vec.end() - 1)->first != worst)
vec.push_back(make_pair(worst, 0));
}
pii p = *(vec.end() - 1);
p.second++;
vec.erase(vec.end() - 1);
vec.push_back(p);
if ((vec.end() - 1)->first != id)
vec.push_back(make_pair(id, 0));
} else {
id = A[i];
while ((vec.end() - 1)->first > id) {
vec.erase(vec.end() - 1);
if (vec.empty() == true)
return false;
}
if ((vec.end() - 1)->first != id)
vec.push_back(make_pair(id, 0));
int worst = id;
while ((vec.end() - 1)->second == m - 1) {
worst = (vec.end() - 1)->first - 1;
vec.erase(vec.end() - 1);
if (vec.empty() == true)
return false;
if ((vec.end() - 1)->first != worst)
vec.push_back(make_pair(worst, 0));
}
pii p = *(vec.end() - 1);
p.second++;
vec.erase(vec.end() - 1);
vec.push_back(p);
if ((vec.end() - 1)->first != id)
vec.push_back(make_pair(id, 0));
}
// printf("m = %d, id = %d\n", m, id);
}
return true;
}
void solve() {
if (is_increase() == true) {
cout << 1 << endl;
return;
}
int lbound = 2, rbound = N, ans;
while (lbound <= rbound) {
int mid = (lbound + rbound) >> 1;
if (check(mid) == true) {
ans = mid;
rbound = mid - 1;
} else {
lbound = mid + 1;
}
}
cout << ans << endl;
}
int main() {
init();
solve();
return 0;
} | replace | 102 | 103 | 102 | 103 | TLE | |
p03202 | C++ | Time Limit Exceeded | // #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 long double LD;
typedef pair<int, int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \
(WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#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 LD(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const int NINF = -1044266559;
const LL LINF = 4557430888798830399;
const ld eps = 1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)
/*
#define MB_LEN_MAX 5
#define SHRT_MIN (-32768)
#define SHRT_MAX 32767
#define USHRT_MAX 0xffffU
#define INT_MIN (-2147483647 - 1)
#define INT_MAX 2147483647
#define UINT_MAX 0xffffffffU
#define LONG_MIN (-2147483647L - 1)
#define LONG_MAX 2147483647L
#define ULONG_MAX 0xffffffffUL
#define LLONG_MAX 9223372036854775807ll
#define LLONG_MIN (-9223372036854775807ll - 1)
#define ULLONG_MAX 0xffffffffffffffffull
*/
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define Log(x, y) log(x) / log(y)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++)
#define repa(i, a, n) for (int i = ((int)(a)); i < ((int)(n)); i++)
#define repa1(i, a, n) for (int i = ((int)(a)); i <= ((int)(n)); i++)
#define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repda(i, n, a) for (int i = ((int)(n)); i > ((int)(a)); i--)
#define repda1(i, n, a) for (int i = ((int)(n)); i >= ((int)(a)); i--)
#define FOR(i, a, n, step) \
for (int i = ((int)(a)); i < ((int)(n)); i += ((int)(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 MINF(x) MS(x, 63)
#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 % MOD;
}
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, a[maxn];
map<int, int> str;
inline bool check(int x) {
int len = 0;
str.clear();
rep(i, n) if (a[i] > len) { len = a[i]; }
else {
while (!str.empty() && str.rbegin()->fs >= a[i])
str.erase(str.rbegin()->fs);
int cur = a[i] - 1;
str[cur]++;
while (str[cur] >= x) {
str.erase(cur);
str[--cur]++;
if (cur < 0)
return 0;
}
len = a[i];
}
return 1;
}
int main() {
SF("%d", &n);
rep(i, n) SF("%d", &a[i]);
bool f = 1;
rep1(i, n - 1) if (a[i] <= a[i - 1]) f = 0;
if (f)
return !PF("1");
int l = 1, r = n + 1; // [l,r)
while (l < r) {
int mid = (l + r) / 2;
if (check(mid))
r = mid;
else
l = mid + 1;
}
PF("%d", r);
return 0;
}
/*************************************************************End**************************************************************/ | // #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 long double LD;
typedef pair<int, int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || \
(WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#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 LD(n) ((long double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed << setprecision(n)
const int INF = 1061109567;
const int NINF = -1044266559;
const LL LINF = 4557430888798830399;
const ld eps = 1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)
/*
#define MB_LEN_MAX 5
#define SHRT_MIN (-32768)
#define SHRT_MAX 32767
#define USHRT_MAX 0xffffU
#define INT_MIN (-2147483647 - 1)
#define INT_MAX 2147483647
#define UINT_MAX 0xffffffffU
#define LONG_MIN (-2147483647L - 1)
#define LONG_MAX 2147483647L
#define ULONG_MAX 0xffffffffUL
#define LLONG_MAX 9223372036854775807ll
#define LLONG_MIN (-9223372036854775807ll - 1)
#define ULLONG_MAX 0xffffffffffffffffull
*/
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(), (a).end()
#define pall(a) (a).rbegin(), (a).rend()
#define Log(x, y) log(x) / log(y)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++)
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++)
#define repa(i, a, n) for (int i = ((int)(a)); i < ((int)(n)); i++)
#define repa1(i, a, n) for (int i = ((int)(a)); i <= ((int)(n)); i++)
#define repd(i, n) for (int i = ((int)(n)) - 1; i >= 0; i--)
#define repd1(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repda(i, n, a) for (int i = ((int)(n)); i > ((int)(a)); i--)
#define repda1(i, n, a) for (int i = ((int)(n)); i >= ((int)(a)); i--)
#define FOR(i, a, n, step) \
for (int i = ((int)(a)); i < ((int)(n)); i += ((int)(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 MINF(x) MS(x, 63)
#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 % MOD;
}
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, a[maxn];
map<int, int> str;
inline bool check(int x) {
int len = 0;
str.clear();
rep(i, n) if (a[i] > len) { len = a[i]; }
else {
while (!str.empty() && str.rbegin()->fs >= a[i])
str.erase(str.rbegin()->fs);
int cur = a[i] - 1;
str[cur]++;
while (str[cur] >= x) {
str.erase(cur);
str[--cur]++;
if (cur < 0)
return 0;
}
len = a[i];
}
return 1;
}
int main() {
SF("%d", &n);
rep(i, n) SF("%d", &a[i]);
bool f = 1;
rep1(i, n - 1) if (a[i] <= a[i - 1]) f = 0;
if (f)
return !PF("1");
int l = 2, r = n + 1; // [l,r)
while (l < r) {
int mid = (l + r) / 2;
if (check(mid))
r = mid;
else
l = mid + 1;
}
PF("%d", r);
return 0;
}
/*************************************************************End**************************************************************/ | replace | 239 | 240 | 239 | 240 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) \
{}
#endif
ll n;
vector<ll> a;
struct sdata {
ll len;
ll count;
};
ll mpow_table[64]; // mのべき乗
vector<sdata> v;
void dump() {
return;
eprintf("len=%d ", SZ(v));
for (auto it : v)
eprintf("[%lld %lld] ", it.len, it.count);
eprintf("\n");
}
bool is_possible(ll m) {
ll mp = 1;
rep(i, 64) {
mpow_table[i] = mp;
mp = min(mp * m, 200001LL);
}
auto mpow = [&](ll p) {
if (m == 1)
return 1LL;
if (p < 64)
return mpow_table[p];
return 200001LL;
};
v.resize(0);
ll keta = 0;
eprintf("\n\nm=%lld\n", m);
rep(i, n) {
dump();
if (keta < a[i]) {
v.push_back({a[i] - keta, 0});
keta = a[i];
} else {
// v.top の桁を狭める
while (keta - v.back().len >= a[i]) {
keta -= v.back().len;
v.pop_back();
}
ll keta_reduce = keta - a[i];
rep(j, keta_reduce) v.back().count /= m;
v.back().len -= keta_reduce;
keta -= keta_reduce;
v.back().count++;
while (v.back().count >= mpow(v.back().len)) {
keta -= v.back().len;
v.pop_back();
if (v.empty())
return false;
v.back().count++;
}
}
}
dump();
return true;
}
int main() {
cin >> n;
a.resize(n);
rep(i, n) { cin >> a[i]; }
// l種類では不可能、h種類では可能.
ll h = 200001;
ll l = 0;
while (h - l > 1) {
ll m = l + (h - l) / 2;
if (is_possible(m))
h = m;
else
l = m;
}
cout << h << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) \
{}
#endif
ll n;
vector<ll> a;
struct sdata {
ll len;
ll count;
};
ll mpow_table[64]; // mのべき乗
vector<sdata> v;
void dump() {
return;
eprintf("len=%d ", SZ(v));
for (auto it : v)
eprintf("[%lld %lld] ", it.len, it.count);
eprintf("\n");
}
bool is_possible(ll m) {
ll mp = 1;
rep(i, 64) {
mpow_table[i] = mp;
mp = min(mp * m, 200001LL);
}
auto mpow = [&](ll p) {
if (m == 1)
return 1LL;
if (p < 64)
return mpow_table[p];
return 200001LL;
};
v.resize(0);
ll keta = 0;
eprintf("\n\nm=%lld\n", m);
rep(i, n) {
dump();
if (keta < a[i]) {
v.push_back({a[i] - keta, 0});
keta = a[i];
} else {
// v.top の桁を狭める
while (keta - v.back().len >= a[i]) {
keta -= v.back().len;
v.pop_back();
}
ll keta_reduce = keta - a[i];
rep(j, keta_reduce) {
v.back().count /= m;
if (v.back().count == 0)
break;
}
v.back().len -= keta_reduce;
keta -= keta_reduce;
v.back().count++;
while (v.back().count >= mpow(v.back().len)) {
keta -= v.back().len;
v.pop_back();
if (v.empty())
return false;
v.back().count++;
}
}
}
dump();
return true;
}
int main() {
cin >> n;
a.resize(n);
rep(i, n) { cin >> a[i]; }
// l種類では不可能、h種類では可能.
ll h = 200001;
ll l = 0;
while (h - l > 1) {
ll m = l + (h - l) / 2;
if (is_possible(m))
h = m;
else
l = m;
}
cout << h << endl;
return 0;
}
| replace | 84 | 85 | 84 | 89 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int mx = 200005;
int n, a[mx], l, r = mx;
int main() {
scanf("%d", &n);
rep(i, n) scanf("%d", a + i);
while (l + 1 < r) {
int mid = (l + r) / 2, hight = 0;
bool ok = true;
map<int, int> mp;
rep(i, n) {
if (hight < a[i])
hight = a[i];
else {
hight = a[i];
while (++mp[hight] >= mid && hight > 0)
hight--;
if (hight == 0) {
ok = false;
break;
}
}
mp.erase(mp.upper_bound(hight), mp.end());
}
(ok ? r : l) = mid;
}
printf("%d\n", r);
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int mx = 200005;
int n, a[mx], l, r = mx;
int main() {
scanf("%d", &n);
rep(i, n) scanf("%d", a + i);
while (l + 1 < r) {
int mid = (l + r) / 2, hight = 0;
bool ok = true;
map<int, int> mp;
rep(i, n) {
if (hight < a[i])
hight = a[i];
else {
if (mid == 1) {
ok = false;
break;
}
hight = a[i];
while (++mp[hight] >= mid && hight > 0)
hight--;
if (hight == 0) {
ok = false;
break;
}
}
mp.erase(mp.upper_bound(hight), mp.end());
}
(ok ? r : l) = mid;
}
printf("%d\n", r);
} | insert | 17 | 17 | 17 | 21 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define pp pair<int, int>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define mk make_pair
ll MOD = 1000000007;
int inf = 1000001000;
ll INF = 100000000000000000;
int main() {
int n;
cin >> n;
int l = 1, r = n;
vector<int> a(n), b(0);
rep(i, n) {
cin >> a.at(i);
if (i != 0) {
if (a.at(i) <= a.at(i - 1))
b.push_back(a.at(i));
}
}
while (l != r) {
int mid = (l + r) / 2;
map<int, int> m;
bool t = false;
rep(i, b.size()) {
while (!m.empty() && m.rbegin()->first > b[i])
m.erase(prev(m.end()));
int x = b[i];
m[x]++;
if (mid == 1)
t = true;
while (m[x] == mid) {
m.erase(m.find(x));
x--;
m[x]++;
if (x <= 0) {
t = true;
break;
}
}
if (x <= 0)
t = true;
}
if (t)
l = mid + 1;
else
r = mid;
}
cout << l << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define pp pair<int, int>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define mk make_pair
ll MOD = 1000000007;
int inf = 1000001000;
ll INF = 100000000000000000;
int main() {
int n;
cin >> n;
int l = 1, r = n;
vector<int> a(n), b(0);
rep(i, n) {
cin >> a.at(i);
if (i != 0) {
if (a.at(i) <= a.at(i - 1))
b.push_back(a.at(i));
}
}
while (l != r) {
int mid = (l + r) / 2;
map<int, int> m;
bool t = false;
rep(i, b.size()) {
while (!m.empty() && m.rbegin()->first > b[i])
m.erase(prev(m.end()));
int x = b[i];
m[x]++;
if (mid == 1)
t = true;
if (t)
break;
while (m[x] == mid) {
m.erase(m.find(x));
x--;
m[x]++;
if (x <= 0) {
t = true;
break;
}
}
if (x <= 0)
t = true;
}
if (t)
l = mid + 1;
else
r = mid;
}
cout << l << endl;
}
| insert | 36 | 36 | 36 | 38 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
bool can(int n, const vector<int> &a, int x) {
map<int, int> ma;
for (int i = 1; i < n; ++i) {
if (a[i] > a[i - 1])
continue;
int k = a[i];
auto p = ma.upper_bound(k);
if (p != ma.end())
ma.erase(p);
++ma[k];
while (k > 0 && ma[k] == x) {
ma.erase(k);
++ma[--k];
}
if (k == 0)
return false;
}
return true;
}
int main() {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int i = 0; i < n; ++i)
scanf("%d", &a[i]);
int low = 0, high = n + 1;
while (low + 1 < high) {
int mid = (low + high) / 2;
(can(n, a, mid) ? high : low) = mid;
}
printf("%d\n", high);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
bool can(int n, const vector<int> &a, int x) {
if (x == 1)
for (int i = 1; i < n; ++i)
if (a[i] <= a[i - 1])
return false;
map<int, int> ma;
for (int i = 1; i < n; ++i) {
if (a[i] > a[i - 1])
continue;
int k = a[i];
auto p = ma.upper_bound(k);
if (p != ma.end())
ma.erase(p);
++ma[k];
while (k > 0 && ma[k] == x) {
ma.erase(k);
++ma[--k];
}
if (k == 0)
return false;
}
return true;
}
int main() {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int i = 0; i < n; ++i)
scanf("%d", &a[i]);
int low = 0, high = n + 1;
while (low + 1 < high) {
int mid = (low + high) / 2;
(can(n, a, mid) ? high : low) = mid;
}
printf("%d\n", high);
return 0;
} | insert | 4 | 4 | 4 | 8 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう!
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう?
map<int, int> me;
int a[200100];
int n, m;
bool f;
// meからboより大きいのを消す
void cl(int bo) {
// if(me.size()<1) return;
// cout<<bo<<endl;
// map<int,int>::iterator it=me.end();
// cout<<bo<<endl;
// it--;
// cout<<bo<<endl;
while (me.size() > 0 && me.rbegin()->fi > bo) {
me.erase(me.rbegin()->fi);
}
// cout<<bo<<endl;
}
void update(int x) {
if (x < 1)
f = false;
else {
me[x]++;
if (me[x] >= m) {
me[x] = 0;
update(x - 1);
}
}
}
bool cal(int mi) {
me.clear();
f = true;
m = mi;
rep(i, n - 1) {
if (a[i + 1] <= a[i]) {
if (a[i + 1] < a[i])
cl(a[i + 1]);
update(a[i + 1]);
}
if (!f)
return false;
}
return f;
}
int main() {
cin >> n;
rep(i, n) cin >> a[i];
/*if(n==1){
cout<<1<<endl;return 0;
}*/
int lo = 1, hi = n;
while (hi > lo) {
int mi = (hi + lo) / 2;
if (cal(mi))
hi = mi;
else
lo = mi + 1;
}
cout << lo << endl;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int, int> pint;
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// 問題文および制約はちゃんと確認しよう!
// サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう?
map<int, int> me;
int a[200100];
int n, m;
bool f;
// meからboより大きいのを消す
void cl(int bo) {
// if(me.size()<1) return;
// cout<<bo<<endl;
// map<int,int>::iterator it=me.end();
// cout<<bo<<endl;
// it--;
// cout<<bo<<endl;
while (me.size() > 0 && me.rbegin()->fi > bo) {
me.erase(me.rbegin()->fi);
}
// cout<<bo<<endl;
}
void update(int x) {
if (x < 1)
f = false;
else {
me[x]++;
if (me[x] >= m) {
me[x] = 0;
update(x - 1);
}
}
}
bool cal(int mi) {
me.clear();
f = true;
m = mi;
rep(i, n - 1) {
if (a[i + 1] <= a[i]) {
if (a[i + 1] < a[i])
cl(a[i + 1]);
update(a[i + 1]);
}
if (!f)
return false;
}
return f;
}
int main() {
cin >> n;
rep(i, n) cin >> a[i];
int fl = 0;
rep(i, n - 1) {
if (a[i + 1] <= a[i])
fl = 1;
}
if (fl < 1) {
cout << 1 << endl;
return 0;
}
int lo = 2, hi = n;
while (hi > lo) {
int mi = (hi + lo) / 2;
if (cal(mi))
hi = mi;
else
lo = mi + 1;
}
cout << lo << endl;
}
| replace | 82 | 86 | 82 | 92 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
bool f(const long kind, const size_t n, const vector<long> &a) {
map<long, long> c;
for (size_t i = 0; i < n - 1; i++) {
if (a[i] >= a[i + 1]) {
for_each(c.lower_bound(a[i + 1]), c.end(),
[](pair<const long, long> &x) { x.second = 0; });
long j = a[i + 1] - 1;
c[j]++;
for (;;) {
if (c[j] < kind) {
break;
} else if (j <= 0) {
return false;
} else {
c[j] = 0;
c[j - 1]++;
j--;
}
}
}
}
return true;
}
bool strict_increasing(const vector<long> &a) {
size_t n = a.size();
for (size_t i = 1; i < n; i++) {
if (a[i - 1] >= a[i]) {
return false;
}
}
return true;
}
int main(void) {
long n;
cin >> n;
vector<long> a(n);
for (long i = 0; i < n; i++) {
cin >> a[i];
}
if (strict_increasing(a)) {
cout << 1 << endl;
return 0;
}
long left = 1, right = n;
for (;;) {
const long mid = (left + right) / 2;
if (right - left <= 1) {
if (f(right, n, a)) {
cout << right << endl;
} else {
cout << left << endl;
}
return 0;
}
const bool b = f(mid, n, a);
// printf("[%ld, %ld] %ld %s\n", left, right, mid, b ? "true" : "false");
if (b) {
right = mid;
} else {
left = mid;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
bool f(const long kind, const size_t n, const vector<long> &a) {
map<long, long> c;
for (size_t i = 1; i < n; i++) {
if (a[i - 1] >= a[i]) {
c.erase(c.lower_bound(a[i]), c.end());
long j = a[i] - 1;
c[j]++;
for (;;) {
if (c[j] < kind) {
break;
} else if (j <= 0) {
return false;
} else {
c[j] = 0;
c[j - 1]++;
j--;
}
}
}
}
return true;
}
bool strict_increasing(const vector<long> &a) {
size_t n = a.size();
for (size_t i = 1; i < n; i++) {
if (a[i - 1] >= a[i]) {
return false;
}
}
return true;
}
int main(void) {
long n;
cin >> n;
vector<long> a(n);
for (long i = 0; i < n; i++) {
cin >> a[i];
}
if (strict_increasing(a)) {
cout << 1 << endl;
return 0;
}
long left = 1, right = n;
for (;;) {
const long mid = (left + right) / 2;
if (right - left <= 1) {
if (f(right, n, a)) {
cout << right << endl;
} else {
cout << left << endl;
}
return 0;
}
const bool b = f(mid, n, a);
// printf("[%ld, %ld] %ld %s\n", left, right, mid, b ? "true" : "false");
if (b) {
right = mid;
} else {
left = mid;
}
}
}
| replace | 5 | 10 | 5 | 9 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(), x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i, x, y) for (ll i = x; i <= y; i++)
#define FOr(i, x, y) for (ll i = x; i >= y; i--)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to... Red
inline void Input_Output() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
}
const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;
const int M = 22;
const int pri = 997;
const int Magic = 2101;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, m, k;
int a[N];
bool check(int x) {
map<int, int> s;
for (int i = 2; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
if (s.upper_bound(a[i]) != s.end()) {
s.erase(s.upper_bound(a[i]));
}
int k = a[i];
s[k]++;
while (k > 0 && s[k] == x)
s.erase(k), s[--k]++;
if (k == 0)
return 0;
}
return 1;
}
int main() {
SpeedForce;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
int l = 0, r = 1e9 + 1;
while (r - l > 1) {
int md = (l + r) >> 1;
if (check(md))
r = md;
else
l = md;
}
assert(r != 1e9 + 1);
cout << r << '\n';
return Accepted;
}
// B...a | #include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(), x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i, x, y) for (ll i = x; i <= y; i++)
#define FOr(i, x, y) for (ll i = x; i >= y; i--)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to... Red
inline void Input_Output() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
}
const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;
const int M = 22;
const int pri = 997;
const int Magic = 2101;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, m, k;
int a[N];
bool check(int x) {
if (x == 1)
return is_sorted(a + 1, a + n + 1);
map<int, int> s;
for (int i = 2; i <= n; i++) {
if (a[i] > a[i - 1])
continue;
if (s.upper_bound(a[i]) != s.end()) {
s.erase(s.upper_bound(a[i]));
}
int k = a[i];
s[k]++;
while (k > 0 && s[k] == x)
s.erase(k), s[--k]++;
if (k == 0)
return 0;
}
return 1;
}
int main() {
SpeedForce;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
int l = 0, r = 1e9 + 1;
while (r - l > 1) {
int md = (l + r) >> 1;
if (check(md))
r = md;
else
l = md;
}
assert(r != 1e9 + 1);
cout << r << '\n';
return Accepted;
}
// B...a | insert | 45 | 45 | 45 | 48 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rer(i, a, b) for (int i = int(a) - 1; i >= int(b); i--)
using namespace std;
typedef long long int ll;
ll A[200000];
int N;
bool C(ll x) {
map<ll, int> m;
rep(i, 1, N) {
if (A[i] <= A[i - 1]) {
rer(j, A[i - 1] + 1, A[i] + 1) { m.erase(j); }
if (m.find(A[i]) == m.end()) {
m.insert(make_pair(A[i], 1));
if (x == 1)
return false;
} else {
m[A[i]]++;
ll j = A[i];
while (m[j] == x) {
if (j == 1)
return false;
m[j] = 0;
if (m.find(j - 1) == m.end())
m.insert(make_pair(j - 1, 1));
else
m[j - 1]++;
j--;
}
}
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
rep(i, 0, N) cin >> A[i];
ll l = 0, r = 2 * 1e5;
while (r - l > 1) {
ll mid = (l + r) / 2;
if (C(mid))
r = mid;
else
l = mid;
}
cout << r << "\n";
} | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rer(i, a, b) for (int i = int(a) - 1; i >= int(b); i--)
using namespace std;
typedef long long int ll;
ll A[200000];
int N;
bool C(ll x) {
map<ll, int> m;
rep(i, 1, N) {
if (A[i] <= A[i - 1]) {
m.erase(m.upper_bound(A[i]), m.end());
if (m.find(A[i]) == m.end()) {
m.insert(make_pair(A[i], 1));
if (x == 1)
return false;
} else {
m[A[i]]++;
ll j = A[i];
while (m[j] == x) {
if (j == 1)
return false;
m[j] = 0;
if (m.find(j - 1) == m.end())
m.insert(make_pair(j - 1, 1));
else
m[j - 1]++;
j--;
}
}
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
rep(i, 0, N) cin >> A[i];
ll l = 0, r = 2 * 1e5;
while (r - l > 1) {
ll mid = (l + r) / 2;
if (C(mid))
r = mid;
else
l = mid;
}
cout << r << "\n";
} | replace | 12 | 13 | 12 | 13 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
#define N 100010
using namespace std;
typedef long long ll;
char *p1, *p2, buf[100000];
#define nc() \
(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) \
? EOF \
: *p1++)
int rd() {
int x = 0, f = 1;
char c = nc();
while (c < 48) {
if (c == '-')
f = -1;
c = nc();
}
while (c > 47) {
x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
}
return x * f;
}
int a[N], n;
map<ll, ll> MP;
bool check(int x) {
MP.clear();
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) {
return false;
}
MP[j]++;
}
}
return true;
}
int main() {
n = rd();
for (int i = 1; i <= n; i++) {
a[i] = rd();
}
int l = 1, r = n, ans = n;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define N 200010
using namespace std;
typedef long long ll;
char *p1, *p2, buf[100000];
#define nc() \
(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) \
? EOF \
: *p1++)
int rd() {
int x = 0, f = 1;
char c = nc();
while (c < 48) {
if (c == '-')
f = -1;
c = nc();
}
while (c > 47) {
x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
}
return x * f;
}
int a[N], n;
map<ll, ll> MP;
bool check(int x) {
MP.clear();
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) {
return false;
}
MP[j]++;
}
}
return true;
}
int main() {
n = rd();
for (int i = 1; i <= n; i++) {
a[i] = rd();
}
int l = 1, r = n, ans = n;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << ans << endl;
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <cstdio>
#include <iostream>
#include <map>
using namespace std;
int n, a[200005];
int lt = 1, rt, md, ans;
int f(int p) {
int i, t;
map<int, int> mp;
for (i = 2; i <= n; i++)
if (a[i] <= a[i - 1]) {
t = a[i];
mp.erase(mp.upper_bound(t), mp.end());
for (; t && mp[t] == p - 1; t--)
mp.erase(t);
if (!t)
return 0;
else
mp[t]++;
}
return 1;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
rt = n;
while (lt <= rt) {
md = lt + rt >> 1;
if (f(md))
ans = md, rt = md - 1;
else
lt = md + 1;
}
cout << ans;
return 0;
} | #include <cstdio>
#include <iostream>
#include <map>
using namespace std;
int n, a[200005];
int lt = 1, rt, md, ans;
int f(int p) {
int i, t;
map<int, int> mp;
if (p == 1) {
for (i = 2; i <= n; i++)
if (a[i] <= a[i - 1])
return 0;
return 1;
}
for (i = 2; i <= n; i++)
if (a[i] <= a[i - 1]) {
t = a[i];
mp.erase(mp.upper_bound(t), mp.end());
for (; t && mp[t] == p - 1; t--)
mp.erase(t);
if (!t)
return 0;
else
mp[t]++;
}
return 1;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
rt = n;
while (lt <= rt) {
md = lt + rt >> 1;
if (f(md))
ans = md, rt = md - 1;
else
lt = md + 1;
}
cout << ans;
return 0;
} | insert | 11 | 11 | 11 | 17 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
const int N = 2e5 + 5;
int n, top;
int a[N];
struct node {
int v, c;
node(int v = 0, int c = 0) : v(v), c(c) {}
} st[N];
void insert(int v, int x) {
while (st[top].v > v)
top--;
if (st[top].v == v)
st[top].c++;
else
st[++top] = node(v, 1);
if (top > 1 && st[top].c == x)
top--, insert(v - 1, x);
}
inline bool check(int mid) {
st[top = 1] = node();
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1])
insert(a[i], mid);
return st[1].c == 0;
}
int main() {
n = read();
a[1] = read();
int cnt = 0;
for (int i = 2; i <= n; i++)
a[i] = read(), cnt += a[i] <= a[i - 1];
// if(!cnt) return puts("1") , 0;
int l = 1, r = n, ans = 0;
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>
using namespace std;
typedef long long ll;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
const int N = 2e5 + 5;
int n, top;
int a[N];
struct node {
int v, c;
node(int v = 0, int c = 0) : v(v), c(c) {}
} st[N];
void insert(int v, int x) {
while (st[top].v > v)
top--;
if (st[top].v == v)
st[top].c++;
else
st[++top] = node(v, 1);
if (top > 1 && st[top].c == x)
top--, insert(v - 1, x);
}
inline bool check(int mid) {
st[top = 1] = node();
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1])
insert(a[i], mid);
return st[1].c == 0;
}
int main() {
n = read();
a[1] = read();
int cnt = 0;
for (int i = 2; i <= n; i++)
a[i] = read(), cnt += a[i] <= a[i - 1];
if (!cnt)
return puts("1"), 0;
int l = 2, r = n, ans = 0;
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 | 50 | 52 | 50 | 53 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i <= int(n); ++i)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << (#x) << ": " << (x) << endl
int n;
vector<int> a;
void show(map<int, int> mp, int size) {
rep1(i, size) { cout << char('a' + mp[i]); }
cout << endl;
}
int check(int m) {
// cout << char('a'+m-1) << "まで" << endl;
map<int, int> mp;
rep1(i, n - 1) {
if (a[i - 1] < a[i])
continue;
if (m == 0)
return false;
int pos = a[i];
mp.erase(mp.upper_bound(pos), mp.end());
while (true) {
if (mp[pos] < m - 1) {
mp[pos]++;
break;
}
mp.erase(--mp.end());
pos--;
if (pos == 0)
return false;
}
// show(mp,size);
}
return true;
}
int main(void) {
cin >> n;
a.resize(n);
rep(i, n) scanf("%d", &a[i]);
int l = 0, r = n;
while (l + 1 < r) {
int m = (l + r) / 2;
if (check(m)) {
r = m;
} else {
l = m;
}
}
cout << r << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i <= int(n); ++i)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << (#x) << ": " << (x) << endl
int n;
vector<int> a;
void show(map<int, int> mp, int size) {
rep1(i, size) { cout << char('a' + mp[i]); }
cout << endl;
}
int check(int m) {
// cout << char('a'+m-1) << "まで" << endl;
map<int, int> mp;
rep1(i, n - 1) {
if (a[i - 1] < a[i])
continue;
if (m == 1)
return false;
int pos = a[i];
mp.erase(mp.upper_bound(pos), mp.end());
while (true) {
if (mp[pos] < m - 1) {
mp[pos]++;
break;
}
mp.erase(--mp.end());
pos--;
if (pos == 0)
return false;
}
// show(mp,size);
}
return true;
}
int main(void) {
cin >> n;
a.resize(n);
rep(i, n) scanf("%d", &a[i]);
int l = 0, r = n;
while (l + 1 < r) {
int m = (l + r) / 2;
if (check(m)) {
r = m;
} else {
l = m;
}
}
cout << r << endl;
return 0;
}
| replace | 21 | 22 | 21 | 22 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#define M 400010
#define PI pair<int, int>
#define f first
#define s second
using namespace std;
typedef long long ll;
int n, ans;
int X[M];
bool check(int x) {
int t = 1;
vector<PI> V(0);
for (int i = 2; i <= n; i++)
if (X[i] <= X[i - 1]) {
while (!V.empty() && V.back().f > X[i])
V.pop_back();
if (V.empty() || V.back().f != X[i])
V.push_back(PI(X[i], 0));
V.back().s++;
while (!V.empty() && V.back().s == x) {
PI tmp = V.back();
V.pop_back();
if (V.empty() || V.back().f != tmp.f - 1)
V.push_back(PI(tmp.f - 1, 0));
V.back().s++;
if (V.back().f == 0)
return 0;
}
}
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &X[i]);
int l = 1, r = n;
int flag = 1;
for (int i = 2; i <= n; i++)
if (X[i] <= X[i - 1]) {
flag = 0;
break;
}
if (flag) {
puts("1");
return 0;
}
for (; l <= r;) {
int md = (l + r) / 2;
if (check(md))
ans = md, r = md - 1;
else
l = md + 1;
}
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#define M 400010
#define PI pair<int, int>
#define f first
#define s second
using namespace std;
typedef long long ll;
int n, ans;
int X[M];
bool check(int x) {
int t = 1;
vector<PI> V(0);
for (int i = 2; i <= n; i++)
if (X[i] <= X[i - 1]) {
while (!V.empty() && V.back().f > X[i])
V.pop_back();
if (V.empty() || V.back().f != X[i])
V.push_back(PI(X[i], 0));
V.back().s++;
while (!V.empty() && V.back().s == x) {
PI tmp = V.back();
V.pop_back();
if (V.empty() || V.back().f != tmp.f - 1)
V.push_back(PI(tmp.f - 1, 0));
V.back().s++;
if (V.back().f == 0)
return 0;
}
}
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &X[i]);
int l = 2, r = n;
int flag = 1;
for (int i = 2; i <= n; i++)
if (X[i] <= X[i - 1]) {
flag = 0;
break;
}
if (flag) {
puts("1");
return 0;
}
for (; l <= r;) {
int md = (l + r) / 2;
if (check(md))
ans = md, r = md - 1;
else
l = md + 1;
}
printf("%d\n", ans);
return 0;
} | replace | 42 | 43 | 42 | 43 | TLE | |
p03202 | C++ | Time Limit Exceeded | /*{{{*/
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define CASET \
int ___T; \
scanf("%d", &___T); \
for (int cs = 1; cs <= ___T; cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
template <class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U> void R(T &head, U &...tail) {
_R(head);
R(tail...);
}
template <class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U> void _W(const pair<T, U> &x) {
_W(x.F);
putchar(' ');
_W(x.S);
}
template <class T> void _W(const vector<T> &x) {
for (auto i = x.begin(); i != x.end(); _W(*i++))
if (i != x.cbegin())
putchar(' ');
}
void W() {}
template <class T, class... U> void W(const T &head, const U &...tail) {
_W(head);
putchar(sizeof...(tail) ? ' ' : '\n');
W(tail...);
}
#ifdef HOME
#define DEBUG(...) \
{ \
printf("# "); \
printf(__VA_ARGS__); \
puts(""); \
}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
void ADD(LL &x, LL v) {
x = (x + v) % MOD;
if (x < 0)
x += MOD;
}
/*}}}*/
const int SIZE = 1e6 + 10;
int A[SIZE];
bool valid(int N, int v) {
map<int, int> AA;
REPP(i, 1, N) {
if (A[i] <= A[i - 1]) {
while (SZ(AA) && AA.rbegin()->F > A[i]) {
AA.erase(prev(AA.end()));
}
AA[A[i]]++;
int now = A[i];
while (AA[now] >= v) {
AA.erase(now--);
if (!now)
return 0;
AA[now]++;
}
}
}
return 1;
}
int main() {
int N;
R(N);
REP(i, N) R(A[i]);
bool can_one = 1;
REPP(i, 1, N) {
if (A[i] <= A[i - 1]) {
can_one = 0;
}
}
if (can_one) {
W(1);
return 0;
}
int ll = 1, rr = N;
while (ll < rr) {
int mm = (ll + rr) / 2;
if (valid(N, mm))
rr = mm;
else
ll = mm + 1;
}
W(ll);
return 0;
}
| /*{{{*/
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define CASET \
int ___T; \
scanf("%d", &___T); \
for (int cs = 1; cs <= ___T; cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
template <class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U> void R(T &head, U &...tail) {
_R(head);
R(tail...);
}
template <class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U> void _W(const pair<T, U> &x) {
_W(x.F);
putchar(' ');
_W(x.S);
}
template <class T> void _W(const vector<T> &x) {
for (auto i = x.begin(); i != x.end(); _W(*i++))
if (i != x.cbegin())
putchar(' ');
}
void W() {}
template <class T, class... U> void W(const T &head, const U &...tail) {
_W(head);
putchar(sizeof...(tail) ? ' ' : '\n');
W(tail...);
}
#ifdef HOME
#define DEBUG(...) \
{ \
printf("# "); \
printf(__VA_ARGS__); \
puts(""); \
}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
void ADD(LL &x, LL v) {
x = (x + v) % MOD;
if (x < 0)
x += MOD;
}
/*}}}*/
const int SIZE = 1e6 + 10;
int A[SIZE];
bool valid(int N, int v) {
map<int, int> AA;
REPP(i, 1, N) {
if (A[i] <= A[i - 1]) {
while (SZ(AA) && AA.rbegin()->F > A[i]) {
AA.erase(prev(AA.end()));
}
AA[A[i]]++;
int now = A[i];
while (AA[now] >= v) {
AA.erase(now--);
if (!now)
return 0;
AA[now]++;
}
}
}
return 1;
}
int main() {
int N;
R(N);
REP(i, N) R(A[i]);
bool can_one = 1;
REPP(i, 1, N) {
if (A[i] <= A[i - 1]) {
can_one = 0;
}
}
if (can_one) {
W(1);
return 0;
}
int ll = 2, rr = N;
while (ll < rr) {
int mm = (ll + rr) / 2;
if (valid(N, mm))
rr = mm;
else
ll = mm + 1;
}
W(ll);
return 0;
}
| replace | 133 | 134 | 133 | 134 | TLE | |
p03202 | C++ | Runtime Error | #include <stdio.h>
int a[131072];
int wz[131072], val[131072];
int num = 0;
int mid;
bool inc(int wz1) {
if (wz1 <= 0) {
return false;
}
if (mid == 1) {
return false;
}
while (num) {
if (wz[num - 1] <= wz1) {
break;
}
num--;
}
if (!num) {
wz[num] = wz1;
val[num] = 0;
num++;
}
if (wz[num - 1] < wz1) {
wz[num] = wz1;
val[num] = 0;
num++;
}
val[num - 1]++;
if (val[num - 1] == mid) {
return inc(wz1 - 1);
}
return true;
}
int len = 0;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int l = 1, r = n;
while (l < r) {
mid = ((l + r) >> 1);
num = 0;
len = 0;
bool ok = true;
for (int i = 0; i < n; i++) {
if (a[i] > len) {
len = a[i];
} else {
len = a[i];
if (!inc(len)) {
ok = false;
break;
}
}
}
if (ok) {
r = mid;
} else {
l = mid + 1;
}
}
printf("%d\n", l);
return 0;
} | #include <stdio.h>
int a[262144];
int wz[262144], val[262144];
int num = 0;
int mid;
bool inc(int wz1) {
if (wz1 <= 0) {
return false;
}
if (mid == 1) {
return false;
}
while (num) {
if (wz[num - 1] <= wz1) {
break;
}
num--;
}
if (!num) {
wz[num] = wz1;
val[num] = 0;
num++;
}
if (wz[num - 1] < wz1) {
wz[num] = wz1;
val[num] = 0;
num++;
}
val[num - 1]++;
if (val[num - 1] == mid) {
return inc(wz1 - 1);
}
return true;
}
int len = 0;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int l = 1, r = n;
while (l < r) {
mid = ((l + r) >> 1);
num = 0;
len = 0;
bool ok = true;
for (int i = 0; i < n; i++) {
if (a[i] > len) {
len = a[i];
} else {
len = a[i];
if (!inc(len)) {
ok = false;
break;
}
}
}
if (ok) {
r = mid;
} else {
l = mid + 1;
}
}
printf("%d\n", l);
return 0;
} | replace | 1 | 3 | 1 | 3 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int n, m;
int i, j, k;
string str;
int a[200000];
bool test() {
vector<int> d, dv;
d.push_back(a[0]);
dv.push_back(1);
for (i = 1; i < n; i++) {
if (a[i] > a[i - 1]) {
d.push_back(a[i]);
dv.push_back(1);
} else if (a[i] == a[i - 1]) {
dv[dv.size() - 1]++;
} else {
while (d[d.size() - 1] > a[i]) {
j = d[d.size() - 1] - 1;
k = (dv[dv.size() - 1] - 1) / m;
d.pop_back();
dv.pop_back();
if (k > 0) {
if (j == 0)
return false;
else if (d.size() > 0 && d[d.size() - 1] == j) {
dv[dv.size() - 1] += k;
} else {
d.push_back(j);
dv.push_back(k + 1);
}
} else if (d.size() == 0) {
break;
}
}
if (d.size() > 0 && d[d.size() - 1] == a[i]) {
dv[dv.size() - 1]++;
} else {
d.push_back(a[i]);
dv.push_back(2);
}
}
}
while (d.size() > 0) {
j = d[d.size() - 1] - 1;
k = (dv[dv.size() - 1] - 1) / m;
d.pop_back();
dv.pop_back();
if (k > 0) {
if (j == 0)
return false;
else if (d.size() > 0 && d[d.size() - 1] == j) {
dv[dv.size() - 1] += k;
} else {
d.push_back(j);
dv.push_back(k + 1);
}
}
}
return true;
}
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
int s = 0, e = n;
while (e - s > 1) {
m = (e + s + 1) / 2;
if (test()) {
e = m;
} else {
s = m;
}
}
cout << e << endl;
} | #include <bits/stdc++.h>
using namespace std;
int n, m;
int i, j, k;
string str;
int a[200000];
bool test() {
if (m == 1) {
for (i = 1; i < n; i++) {
if (a[i] <= a[i - 1]) {
return false;
}
}
}
vector<int> d, dv;
d.push_back(a[0]);
dv.push_back(1);
for (i = 1; i < n; i++) {
if (a[i] > a[i - 1]) {
d.push_back(a[i]);
dv.push_back(1);
} else if (a[i] == a[i - 1]) {
dv[dv.size() - 1]++;
} else {
while (d[d.size() - 1] > a[i]) {
j = d[d.size() - 1] - 1;
k = (dv[dv.size() - 1] - 1) / m;
d.pop_back();
dv.pop_back();
if (k > 0) {
if (j == 0)
return false;
else if (d.size() > 0 && d[d.size() - 1] == j) {
dv[dv.size() - 1] += k;
} else {
d.push_back(j);
dv.push_back(k + 1);
}
} else if (d.size() == 0) {
break;
}
}
if (d.size() > 0 && d[d.size() - 1] == a[i]) {
dv[dv.size() - 1]++;
} else {
d.push_back(a[i]);
dv.push_back(2);
}
}
}
while (d.size() > 0) {
j = d[d.size() - 1] - 1;
k = (dv[dv.size() - 1] - 1) / m;
d.pop_back();
dv.pop_back();
if (k > 0) {
if (j == 0)
return false;
else if (d.size() > 0 && d[d.size() - 1] == j) {
dv[dv.size() - 1] += k;
} else {
d.push_back(j);
dv.push_back(k + 1);
}
}
}
return true;
}
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
int s = 0, e = n;
while (e - s > 1) {
m = (e + s + 1) / 2;
if (test()) {
e = m;
} else {
s = m;
}
}
cout << e << endl;
} | insert | 9 | 9 | 9 | 16 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 200005;
int A[MX];
vector<pair<int, int>> st;
int lt[MX];
int a[MX];
int M;
void inc(int i, int t) {
while (true) {
int j = (int)st.size() - 1;
while (st[j].first > i)
j--;
if (lt[i] < st[j].second) {
lt[i] = t;
a[i] = 0;
}
// cout << st[j].first << " " << st[j].second << " " << i << endl;
a[i]++;
if (i > 0 && a[i] == M) {
a[i] = 0;
i--;
} else {
break;
}
}
}
int main() {
int n;
ignore = scanf("%d", &n);
for (int i = 1; i <= n; i++) {
ignore = scanf("%d", A + i);
}
int L = 1, R = n - 1;
int B = n;
// int L = 2, R = 2; /////
// int B = 0; //////
while (L <= R) {
M = (L + R) / 2;
memset(lt, 0, sizeof lt);
memset(a, 0, sizeof a);
st.clear();
bool ok = true;
st.push_back({1, 0});
for (int i = 1; i <= n; i++) {
while (A[i] + 1 <= st.back().first)
st.pop_back();
st.push_back({A[i] + 1, i});
if (i > 1 && A[i] <= A[i - 1]) {
inc(A[i], i);
}
if (a[0] > 0) {
ok = false;
break;
}
}
if (ok) {
B = M;
R = M - 1;
} else {
L = M + 1;
}
}
printf("%d\n", B);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 200005;
int A[MX];
vector<pair<int, int>> st;
int lt[MX];
int a[MX];
int M;
void inc(int i, int t) {
while (true) {
int j = (int)st.size() - 1;
while (st[j].first > i)
j--;
if (lt[i] < st[j].second) {
lt[i] = t;
a[i] = 0;
}
// cout << st[j].first << " " << st[j].second << " " << i << endl;
a[i]++;
if (i > 0 && a[i] == M) {
a[i] = 0;
i--;
} else {
break;
}
}
}
int main() {
int n;
ignore = scanf("%d", &n);
for (int i = 1; i <= n; i++) {
ignore = scanf("%d", A + i);
if (A[i] > 200000)
A[i] = 200000;
}
int L = 1, R = n - 1;
int B = n;
// int L = 2, R = 2; /////
// int B = 0; //////
while (L <= R) {
M = (L + R) / 2;
memset(lt, 0, sizeof lt);
memset(a, 0, sizeof a);
st.clear();
bool ok = true;
st.push_back({1, 0});
for (int i = 1; i <= n; i++) {
while (A[i] + 1 <= st.back().first)
st.pop_back();
st.push_back({A[i] + 1, i});
if (i > 1 && A[i] <= A[i - 1]) {
inc(A[i], i);
}
if (a[0] > 0) {
ok = false;
break;
}
}
if (ok) {
B = M;
R = M - 1;
} else {
L = M + 1;
}
}
printf("%d\n", B);
}
| insert | 42 | 42 | 42 | 44 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>/*{{{*/
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int, int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
namespace RA {
int r(int p) { return 1ll * rand() * rand() % p; }
int r(int L, int R) { return r(R - L + 1) + L; }
} // namespace RA
/******************heading******************/
const int N = 2e5 + 5;
int n;
int a[N];
namespace S1 {
int c[40]; // 在这一位上是右儿子的边数
bool check(int k) {
int len = 0;
memset(c, 0, sizeof(c));
FOR(i, 1, n) {
if (a[i] > len) {
FOR(j, len + 1, a[i])++ c[j];
len = a[i];
} else {
int pos = a[i];
while (c[pos] == k)
--pos;
if (pos == 0)
return 0;
c[pos]++;
FOR(j, pos + 1, 30) c[j] = 0; // 清空
FOR(j, pos + 1, a[i]) c[j]++;
len = a[i];
}
}
return 1;
}
} // namespace S1
int tot = 0;
namespace S2 {
map<int, int> c;
bool check(int k) {
int len = 0;
c.clear();
FOR(i, 1, n) {
if (a[i] > len) {
} else {
int pos = a[i];
while (tot < 4e6 && pos && c[pos] == k - 1)
--pos, ++tot;
if (pos == 0)
return 0;
c[pos]++;
map<int, int>::iterator it = c.find(pos);
++it;
c.erase(it, c.end());
}
len = a[i];
// if(tot>=1e7)return 0;
if (tot >= 4e6)
return 0;
}
return 1;
}
} // namespace S2
int main() {
scanf("%d", &n);
FOR(i, 1, n) scanf("%d", &a[i]);
int l = 1, r = n + 1, mid;
while (l < r && tot < 4e6)
mid = (l + r) >> 1, S2::check(mid) ? r = mid : l = mid + 1;
if (tot >= 4e6) {
FOR(i, 1, n) a[i] = min(a[i], 30);
l = 1, r = n + 1;
while (l < r)
mid = (l + r) >> 1, S1::check(mid) ? r = mid : l = mid + 1;
}
printf("%d\n", l);
return 0;
}
| #include <algorithm>/*{{{*/
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int, int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
namespace RA {
int r(int p) { return 1ll * rand() * rand() % p; }
int r(int L, int R) { return r(R - L + 1) + L; }
} // namespace RA
/******************heading******************/
const int N = 2e5 + 5;
int n;
int a[N];
namespace S1 {
int c[40]; // 在这一位上是右儿子的边数
bool check(int k) {
int len = 0;
memset(c, 0, sizeof(c));
FOR(i, 1, n) {
if (a[i] > len) {
FOR(j, len + 1, a[i])++ c[j];
len = a[i];
} else {
int pos = a[i];
while (c[pos] == k)
--pos;
if (pos == 0)
return 0;
c[pos]++;
FOR(j, pos + 1, 30) c[j] = 0; // 清空
FOR(j, pos + 1, a[i]) c[j]++;
len = a[i];
}
}
return 1;
}
} // namespace S1
int tot = 0;
namespace S2 {
map<int, int> c;
bool check(int k) {
int len = 0;
c.clear();
FOR(i, 1, n) {
if (a[i] > len) {
} else {
int pos = a[i];
if (k == 1)
return 0;
while (tot < 4e6 && pos && c.count(pos) && c[pos] == k - 1)
--pos, ++tot;
if (pos == 0)
return 0;
c[pos]++;
map<int, int>::iterator it = c.find(pos);
++it;
c.erase(it, c.end());
}
len = a[i];
// if(tot>=1e7)return 0;
if (tot >= 4e6)
return 0;
}
return 1;
}
} // namespace S2
int main() {
scanf("%d", &n);
FOR(i, 1, n) scanf("%d", &a[i]);
int l = 1, r = n + 1, mid;
while (l < r && tot < 4e6)
mid = (l + r) >> 1, S2::check(mid) ? r = mid : l = mid + 1;
if (tot >= 4e6) {
FOR(i, 1, n) a[i] = min(a[i], 30);
l = 1, r = n + 1;
while (l < r)
mid = (l + r) >> 1, S1::check(mid) ? r = mid : l = mid + 1;
}
printf("%d\n", l);
return 0;
}
| replace | 70 | 71 | 70 | 73 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int(i) = (n - 1); (i) >= (0); (i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;
int main() {
int N;
cin >> N;
vi A(N);
rep(i, N) cin >> A[i];
vi Adec;
int M = 0;
rep(i, N - 1) {
if (A[i] >= A[i + 1]) {
Adec.push_back(A[i + 1]);
M++;
}
}
int L = 0;
int R = InfL * 2;
while (1) {
int anstmp = (L + R) / 2;
if (L == anstmp)
break;
map<int, int> Stmp;
bool can = true;
rep(i, M) {
int Atmp = Adec[i];
for (auto it = Stmp.upper_bound(Atmp); it != Stmp.end();)
Stmp.erase(it++);
while (1) {
Stmp[Atmp]++;
if (Stmp[Atmp] >= anstmp) {
Stmp[Atmp] = 0;
if (Atmp == 1) {
can = false;
break;
}
Atmp--;
} else
break;
}
}
if (can)
R = anstmp;
else
L = anstmp;
}
int ans = R;
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int(i) = (n - 1); (i) >= (0); (i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;
int main() {
int N;
cin >> N;
vi A(N);
rep(i, N) cin >> A[i];
vi Adec;
int M = 0;
rep(i, N - 1) {
if (A[i] >= A[i + 1]) {
Adec.push_back(A[i + 1]);
M++;
}
}
if (M == 0) {
cout << "1" << endl;
return 0;
}
int L = 1;
int R = InfL * 2;
while (1) {
int anstmp = (L + R) / 2;
if (L == anstmp)
break;
map<int, int> Stmp;
bool can = true;
rep(i, M) {
int Atmp = Adec[i];
for (auto it = Stmp.upper_bound(Atmp); it != Stmp.end();)
Stmp.erase(it++);
while (1) {
Stmp[Atmp]++;
if (Stmp[Atmp] >= anstmp) {
Stmp[Atmp] = 0;
if (Atmp == 1) {
can = false;
break;
}
Atmp--;
} else
break;
}
}
if (can)
R = anstmp;
else
L = anstmp;
}
int ans = R;
cout << ans << endl;
return 0;
} | replace | 39 | 40 | 39 | 44 | TLE | |
p03202 | C++ | Runtime Error | #include <cstdio>
#include <vector>
using namespace std;
const int N = 100500;
int L[N];
int n;
struct item {
bool zero;
int x;
};
bool can(int al) {
vector<item> st = {{true, L[0]}};
for (int i = 1; i < n; i++) {
if (L[i] > L[i - 1]) {
st.emplace_back(item{true, L[i] - L[i - 1]});
} else if (al == 1) {
return false;
} else {
int cur = L[i - 1];
while (cur > L[i]) {
if (!st.back().zero) {
st.pop_back();
--cur;
} else {
int dec = min(st.back().x, cur - L[i]);
st.back().x -= dec;
cur -= dec;
if (st.back().x == 0) {
st.pop_back();
} else {
break;
}
}
}
for (int i = (int)st.size() - 1; i >= -1; i--) {
if (i == -1) {
return false;
}
if (st[i].zero) {
st[i].x--;
st.insert(st.begin() + i + 1, item{false, 1});
if (st[i].x == 0) {
st.erase(st.begin() + i);
}
break;
} else if (st[i].x + 1 == al) {
st[i].x = 0;
} else {
st[i].x++;
break;
}
}
}
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &L[i]);
}
int lo = 0, hi = n;
while (lo + 1 < hi) {
int mid = (lo + hi) / 2;
if (can(mid)) {
hi = mid;
} else {
lo = mid;
}
}
printf("%d\n", hi);
}
| #include <cstdio>
#include <vector>
using namespace std;
const int N = 3e5 + 7;
int L[N];
int n;
struct item {
bool zero;
int x;
};
bool can(int al) {
vector<item> st = {{true, L[0]}};
for (int i = 1; i < n; i++) {
if (L[i] > L[i - 1]) {
st.emplace_back(item{true, L[i] - L[i - 1]});
} else if (al == 1) {
return false;
} else {
int cur = L[i - 1];
while (cur > L[i]) {
if (!st.back().zero) {
st.pop_back();
--cur;
} else {
int dec = min(st.back().x, cur - L[i]);
st.back().x -= dec;
cur -= dec;
if (st.back().x == 0) {
st.pop_back();
} else {
break;
}
}
}
for (int i = (int)st.size() - 1; i >= -1; i--) {
if (i == -1) {
return false;
}
if (st[i].zero) {
st[i].x--;
st.insert(st.begin() + i + 1, item{false, 1});
if (st[i].x == 0) {
st.erase(st.begin() + i);
}
break;
} else if (st[i].x + 1 == al) {
st[i].x = 0;
} else {
st[i].x++;
break;
}
}
}
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &L[i]);
}
int lo = 0, hi = n;
while (lo + 1 < hi) {
int mid = (lo + hi) / 2;
if (can(mid)) {
hi = mid;
} else {
lo = mid;
}
}
printf("%d\n", hi);
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
using namespace std;
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
ll max(ll a, ll b) {
if (a > b) {
return a;
}
return b;
}
ll min(ll a, ll b) {
if (a > b) {
return b;
}
return a;
}
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
if (a < b) {
return gcd(b, a);
}
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
struct edge {
ll ind;
ll fr;
ll to;
ll d;
};
class mint {
long long x;
public:
mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint operator^(const ll &t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
//////////////////////////
ll N;
vector<ll> A;
bool ch(ll X) {
stack<pair<ll, ll>> st;
for (ll i = 2; i <= N; i++) {
if (A[i] > A[i - 1]) {
continue;
}
while (!st.empty() && st.top().first > A[i]) {
st.pop();
}
if (!st.empty() && st.top().first == A[i]) {
auto p = st.top();
st.pop();
st.push({p.first, p.second + 1});
}
else {
st.push({A[i], 1});
}
while (st.top().second == X) {
auto p = st.top();
st.pop();
if (!st.empty() && st.top().first == p.first - 1) {
auto q = st.top();
st.pop();
st.push({q.first, q.second + 1});
} else {
st.push({p.first - 1, 1});
}
if (st.top().first == 0) {
return false;
}
}
}
return true;
}
int main() {
cin >> N;
A.assign(N + 1, 0);
repn(i, N) cin >> A[i];
ll le = 0;
ll ri = MAX;
while (ri - le > 1) {
ll m = (ri + le) / 2;
if (ch(m)) {
ri = m;
} else {
le = m;
}
}
cout << ri;
system("PAUSE");
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#define _USE_MATH_DEFINES
#include <functional>
#include <math.h>
using namespace std;
#define rep(i, x) for (ll i = 0; i < x; i++)
#define repn(i, x) for (ll i = 1; i <= x; i++)
typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
ll max(ll a, ll b) {
if (a > b) {
return a;
}
return b;
}
ll min(ll a, ll b) {
if (a > b) {
return b;
}
return a;
}
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
if (a < b) {
return gcd(b, a);
}
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
struct edge {
ll ind;
ll fr;
ll to;
ll d;
};
class mint {
long long x;
public:
mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint operator^(const ll &t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
//////////////////////////
ll N;
vector<ll> A;
bool ch(ll X) {
stack<pair<ll, ll>> st;
for (ll i = 2; i <= N; i++) {
if (A[i] > A[i - 1]) {
continue;
}
if (X == 1) {
return false;
}
while (!st.empty() && st.top().first > A[i]) {
st.pop();
}
if (!st.empty() && st.top().first == A[i]) {
auto p = st.top();
st.pop();
st.push({p.first, p.second + 1});
}
else {
st.push({A[i], 1});
}
while (st.top().second == X) {
auto p = st.top();
st.pop();
if (!st.empty() && st.top().first == p.first - 1) {
auto q = st.top();
st.pop();
st.push({q.first, q.second + 1});
} else {
st.push({p.first - 1, 1});
}
if (st.top().first == 0) {
return false;
}
}
}
return true;
}
int main() {
cin >> N;
A.assign(N + 1, 0);
repn(i, N) cin >> A[i];
ll le = 0;
ll ri = MAX;
while (ri - le > 1) {
ll m = (ri + le) / 2;
if (ch(m)) {
ri = m;
} else {
le = m;
}
}
cout << ri;
system("PAUSE");
} | insert | 134 | 134 | 134 | 138 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define N 200005
using namespace std;
int n, a[N], cur;
class Segment_T {
struct tree {
int lc, rc, v, f;
void set() {
v = 0;
f = 1;
}
} t[N * 100];
int root, sz;
bool flag;
void pushdown(int x) {
if (t[x].f) {
if (t[x].lc)
t[t[x].lc].set();
if (t[x].rc)
t[t[x].rc].set();
t[x].f = 0;
}
}
void cover(int &x, int l, int r, int L, int R) {
if (!x)
x = ++sz, t[x].lc = t[x].rc = t[x].v = t[x].f = 0;
if (L <= l && R >= r) {
t[x].set();
return;
}
pushdown(x);
int mid = (l + r) >> 1;
if (L <= mid)
cover(t[x].lc, l, mid, L, R);
if (R > mid)
cover(t[x].rc, mid + 1, r, L, R);
}
void modify(int &x, int l, int r, int p) {
if (!x)
x = ++sz, t[x].lc = t[x].rc = t[x].v = t[x].f = 0;
if (l == r) {
if (t[x].v == cur) {
flag = 1;
t[x].v = 0;
} else
t[x].v++;
return;
}
pushdown(x);
int mid = (l + r) >> 1;
if (p <= mid)
modify(t[x].lc, l, mid, p);
else
modify(t[x].rc, mid + 1, r, p);
}
public:
void Cover(int l, int r) { cover(root, 1, 1e9, l, r); }
bool Modify(int x) {
flag = 1;
int pos = x;
while (flag) {
flag = 0;
modify(root, 1, 1e9, pos);
pos--;
if (flag && pos == 0)
return 0;
}
return 1;
}
void Clear() {
sz = 0;
root = 0;
}
} T;
bool pd(int x) {
cur = x;
T.Clear();
for (int i = 1; i <= n; i++) {
if (a[i] <= a[i - 1]) {
T.Cover(a[i] + 1, 1e9);
if (!T.Modify(a[i]))
return 0;
}
}
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
bool bj = 0;
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1]) {
bj = 1;
break;
}
if (!bj) {
puts("1");
return 0;
}
// for(int i=0;i<=n;i++) cout<<pd(i)<<endl;
int L = 0, R = n, mid;
while (L < R) {
// cout<<L<<" "<<R<<endl;
mid = (L + R) / 2;
if (!pd(mid))
L = mid + 1;
else
R = mid;
}
printf("%d\n", L + 1);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define N 200005
using namespace std;
int n, a[N], cur;
class Segment_T {
struct tree {
int lc, rc, v, f;
void set() {
v = 0;
f = 1;
}
} t[N * 100];
int root, sz;
bool flag;
void pushdown(int x) {
if (t[x].f) {
if (t[x].lc)
t[t[x].lc].set();
if (t[x].rc)
t[t[x].rc].set();
t[x].f = 0;
}
}
void cover(int &x, int l, int r, int L, int R) {
if (!x)
x = ++sz, t[x].lc = t[x].rc = t[x].v = t[x].f = 0;
if (L <= l && R >= r) {
t[x].set();
return;
}
pushdown(x);
int mid = (l + r) >> 1;
if (L <= mid)
cover(t[x].lc, l, mid, L, R);
if (R > mid)
cover(t[x].rc, mid + 1, r, L, R);
}
void modify(int &x, int l, int r, int p) {
if (!x)
x = ++sz, t[x].lc = t[x].rc = t[x].v = t[x].f = 0;
if (l == r) {
if (t[x].v == cur) {
flag = 1;
t[x].v = 0;
} else
t[x].v++;
return;
}
pushdown(x);
int mid = (l + r) >> 1;
if (p <= mid)
modify(t[x].lc, l, mid, p);
else
modify(t[x].rc, mid + 1, r, p);
}
public:
void Cover(int l, int r) { cover(root, 1, 1e9, l, r); }
bool Modify(int x) {
flag = 1;
int pos = x;
while (flag) {
flag = 0;
modify(root, 1, 1e9, pos);
pos--;
if (flag && pos == 0)
return 0;
}
return 1;
}
void Clear() {
sz = 0;
root = 0;
}
} T;
bool pd(int x) {
cur = x;
T.Clear();
for (int i = 1; i <= n; i++) {
if (a[i] <= a[i - 1]) {
T.Cover(a[i] + 1, 1e9);
if (!T.Modify(a[i]))
return 0;
}
}
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
bool bj = 0;
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1]) {
bj = 1;
break;
}
if (!bj) {
puts("1");
return 0;
}
for (int i = 1; i <= 10; i++)
if (pd(i)) {
printf("%d\n", i + 1);
return 0;
}
// for(int i=0;i<=n;i++) cout<<pd(i)<<endl;
int L = 0, R = n, mid;
while (L < R) {
// cout<<L<<" "<<R<<endl;
mid = (L + R) / 2;
if (!pd(mid))
L = mid + 1;
else
R = mid;
}
printf("%d\n", L + 1);
return 0;
} | insert | 106 | 106 | 106 | 111 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N, M, H, W, K, Q, A, B;
string S;
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll, ll> P;
vec a(0);
bool ok(ll kind) {
map<ll, ll> st;
ll last = 0;
st[0] = 0;
// rep(i,N) st[a[i]] = 0;
rep(i, N) {
if (a[i] > 1e+6)
continue;
if (last > a[i]) {
for (auto ite = st.rbegin(); ite->fi > a[i] && ite != st.rend(); ++ite)
st.erase(ite->fi); // ite->se = 0;
++st[a[i]];
} else if (last == a[i]) {
++st[a[i]];
} else {
st[a[i]] = 0;
}
ll see = a[i];
while (st[see] >= kind && see != 0) {
st.erase(see);
--see;
++st[see];
}
if (see == 0) {
st.clear();
return false;
}
last = a[i];
}
st.clear();
return true;
}
int main() {
cin >> N;
rep(i, N) cin >> A, a.push_back(A);
ll lb = 0, ub = 2e+5;
while (ub - lb > 1) {
ll cen = (ub + lb) / 2;
(ok(cen) ? ub : lb) = cen;
// cout<<cen<<endl;
}
cout << ub << endl;
}
| #include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N, M, H, W, K, Q, A, B;
string S;
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll, ll> P;
vec a(0);
bool ok(ll kind) {
map<ll, ll> st;
ll last = 0;
st[0] = 0;
// rep(i,N) st[a[i]] = 0;
rep(i, N) {
if (a[i] > 1e+6)
continue;
if (last > a[i]) {
for (auto ite = st.rbegin(); ite->fi > a[i] && ite != st.rend(); ++ite)
st.erase(ite->fi); // ite->se = 0;
++st[a[i]];
} else if (last == a[i]) {
++st[a[i]];
}
ll see = a[i];
while (st[see] >= kind && see != 0) {
st.erase(see);
--see;
++st[see];
}
if (see == 0) {
st.clear();
return false;
}
last = a[i];
}
st.clear();
return true;
}
int main() {
cin >> N;
rep(i, N) cin >> A, a.push_back(A);
ll lb = 0, ub = 2e+5;
while (ub - lb > 1) {
ll cen = (ub + lb) / 2;
(ok(cen) ? ub : lb) = cen;
// cout<<cen<<endl;
}
cout << ub << endl;
}
| delete | 37 | 39 | 37 | 37 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
int main() {
int n;
cin >> n;
VI a(n);
REP(i, n) { a[i] = in(); }
int ok = n, ng = 0;
while (ok - ng > 1) {
int k = (ok + ng) / 2;
bool f = true;
map<int, int> mp;
// cout << " " << k << endl;
FOR(i, 1, n - 1) {
// cout << i << endl;
if (a[i] > a[i - 1])
continue;
auto itr = mp.lower_bound(a[i]);
auto itr2 = mp.lower_bound(a[i - 1]);
mp.erase(itr, itr2);
int x = a[i] - 1;
mp[x]++;
while (x > 0) {
if (mp[x] == k) {
mp.erase(x);
mp[x - 1]++;
x--;
} else {
break;
}
}
if (mp[0] >= k) {
f = false;
break;
}
// for (P p : mp) cout << p.first << " " << p.second << endl;
}
if (f)
ok = k;
else
ng = k;
}
cout << ok << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
int main() {
int n;
cin >> n;
VI a(n);
REP(i, n) { a[i] = in(); }
bool one = true;
REP(i, n - 1) {
if (a[i] >= a[i + 1])
one = false;
}
if (one) {
cout << 1 << endl;
return 0;
}
int ok = n, ng = 1;
while (ok - ng > 1) {
int k = (ok + ng) / 2;
bool f = true;
map<int, int> mp;
// cout << " " << k << endl;
FOR(i, 1, n - 1) {
// cout << i << endl;
if (a[i] > a[i - 1])
continue;
auto itr = mp.lower_bound(a[i]);
auto itr2 = mp.lower_bound(a[i - 1]);
mp.erase(itr, itr2);
int x = a[i] - 1;
mp[x]++;
while (x > 0) {
if (mp[x] == k) {
mp.erase(x);
mp[x - 1]++;
x--;
} else {
break;
}
}
if (mp[0] >= k) {
f = false;
break;
}
// for (P p : mp) cout << p.first << " " << p.second << endl;
}
if (f)
ok = k;
else
ng = k;
}
cout << ok << endl;
return 0;
}
| replace | 47 | 48 | 47 | 58 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, g, I;
cin >> n;
long long S[n], M = 5000000000, p, k, L = 0, R = 200002, t;
for (int i = 0; i < n; i++) {
cin >> S[i];
}
while (R - L > 1) {
t = (L + R) / 2;
g = 1;
set<long long> Se;
set<long long>::iterator it;
map<long long, long long> Ma;
for (int i = 1; i < n; i++) {
it = Se.lower_bound(M - 2000000000);
while (it != Se.end() && M - (*it) >= S[i]) {
Ma[M - *it] = 0;
Se.erase(it);
it = Se.lower_bound(M - 200000000);
}
if (S[i] <= S[i - 1]) {
if (t == 1) {
g = 0;
break;
}
I = S[i] - 1;
while (I >= 0 && Ma[I] == t - 1) {
Se.erase(Se.find(M - I));
Ma[I] = 0;
I--;
}
if (I < 0) {
g = 0;
break;
}
if (Ma[I] == 0) {
Se.insert(M - I);
}
Ma[I]++;
}
}
if (g == 1) {
R = t;
} else {
L = t;
}
}
cout << R;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, g, I;
cin >> n;
long long S[n], M = 5000000000, p, k, L = 0, R = 200002, t;
for (int i = 0; i < n; i++) {
cin >> S[i];
}
while (R - L > 1) {
t = (L + R) / 2;
g = 1;
set<long long> Se;
set<long long>::iterator it;
unordered_map<long long, long long> Ma;
for (int i = 1; i < n; i++) {
it = Se.lower_bound(M - 2000000000);
while (it != Se.end() && M - (*it) >= S[i]) {
Ma[M - *it] = 0;
Se.erase(it);
it = Se.lower_bound(M - 200000000);
}
if (S[i] <= S[i - 1]) {
if (t == 1) {
g = 0;
break;
}
I = S[i] - 1;
while (I >= 0 && Ma[I] == t - 1) {
Se.erase(Se.find(M - I));
Ma[I] = 0;
I--;
}
if (I < 0) {
g = 0;
break;
}
if (Ma[I] == 0) {
Se.insert(M - I);
}
Ma[I]++;
}
}
if (g == 1) {
R = t;
} else {
L = t;
}
}
cout << R;
return 0;
}
| replace | 16 | 17 | 16 | 17 | TLE | |
p03202 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
using namespace std;
using ll = long long int;
using vv = vector<vector<ll>>;
using vvv = vector<vector<vector<ll>>>;
using edge = struct {
int to;
int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec) \
std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec) \
std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ priority_queue<ll, vector<ll>, greater<ll>>
#define VVI(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVI(a, b, c, d) \
vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
typedef pair<ll, ll> Pair;
bool pairCompare(const Pair &firstElof, const Pair &secondElof) {
return firstElof.second > secondElof.second;
}
ll POW(ll n, ll m) {
if (m == 0) {
return 1;
} else if (m % 2 == 0) {
ll tmp = POW(n, m / 2);
return (tmp * tmp) % MOD;
} else {
return (n * POW(n, m - 1)) % MOD;
}
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
ll N;
cin >> N;
vector<ll> A(N, 0);
REP(i, N) cin >> A[i];
ll left = 1;
ll right = N + 1;
while (right - left > 1) {
ll mid = left + (right - left) / 2;
ll LAST = 0;
vector<Pair>
X; // 辞書順先頭の文字(0)以外の文字を格納、{先頭から何番目か,記号の種類}
AUTO(a, A) {
if (LAST >= a) {
while (!X.empty() && X.back().first > a)
X.pop_back();
X.push_back(make_pair(a + 1, mid));
}
LAST = a;
while (!X.empty() && X.back().second == mid) {
ll po = X.back().first;
X.pop_back();
if (!X.empty() && X.back().first == po - 1) {
ll yo = X.back().second;
X.pop_back();
X.push_back(make_pair(po - 1, yo + 1));
} else {
X.push_back(make_pair(po - 1, 1));
}
}
}
// 最初の桁が0以下だとオーバーフローしている
if (X.front().first > 0)
right = mid;
else
left = mid;
}
cout << right << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
using namespace std;
using ll = long long int;
using vv = vector<vector<ll>>;
using vvv = vector<vector<vector<ll>>>;
using edge = struct {
int to;
int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec) \
std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec) \
std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ priority_queue<ll, vector<ll>, greater<ll>>
#define VVI(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVI(a, b, c, d) \
vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
typedef pair<ll, ll> Pair;
bool pairCompare(const Pair &firstElof, const Pair &secondElof) {
return firstElof.second > secondElof.second;
}
ll POW(ll n, ll m) {
if (m == 0) {
return 1;
} else if (m % 2 == 0) {
ll tmp = POW(n, m / 2);
return (tmp * tmp) % MOD;
} else {
return (n * POW(n, m - 1)) % MOD;
}
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
ll N;
cin >> N;
vector<ll> A(N, 0);
REP(i, N) cin >> A[i];
ll left = 1;
ll right = N;
bool end = true;
ll LAST = 0;
AUTO(a, A) {
if (LAST >= a)
end = false;
LAST = a;
}
if (end) {
cout << 1 << endl;
return 0;
}
while (right - left > 1) {
ll mid = left + (right - left) / 2;
ll LAST = 0;
vector<Pair>
X; // 辞書順先頭の文字(0)以外の文字を格納、{先頭から何番目か,記号の種類}
AUTO(a, A) {
if (LAST >= a) {
while (!X.empty() && X.back().first > a)
X.pop_back();
X.push_back(make_pair(a + 1, mid));
}
LAST = a;
while (!X.empty() && X.back().second == mid) {
ll po = X.back().first;
X.pop_back();
if (!X.empty() && X.back().first == po - 1) {
ll yo = X.back().second;
X.pop_back();
X.push_back(make_pair(po - 1, yo + 1));
} else {
X.push_back(make_pair(po - 1, 1));
}
}
}
// 最初の桁が0以下だとオーバーフローしている
if (X.front().first > 0)
right = mid;
else
left = mid;
}
cout << right << endl;
return 0;
}
| replace | 68 | 69 | 68 | 80 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 2e5 + 20;
int a[MAXN], n;
map<int, int> mp;
inline bool check(int mid) {
mp.clear();
int tmp = 0;
rep(i, 2, n) if (a[i - 1] >= a[i]) {
auto it = mp.lower_bound(a[i]);
mp.erase(it, mp.end());
++mp[tmp = a[i] - 1];
while (tmp >= 0 && mp[tmp] >= mid) {
mp.erase(tmp), ++mp[--tmp];
}
if (tmp < 0)
return false;
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n;
rep(i, 1, n) { cin >> a[i]; }
int l = 1, r = n;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid)) {
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << r + 1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 2e5 + 20;
int a[MAXN], n;
map<int, int> mp;
inline bool check(int mid) {
mp.clear();
int tmp = 0;
if (mid == 1) {
rep(i, 2, n) {
if (a[i - 1] >= a[i])
return false;
}
return true;
}
rep(i, 2, n) if (a[i - 1] >= a[i]) {
auto it = mp.lower_bound(a[i]);
mp.erase(it, mp.end());
++mp[tmp = a[i] - 1];
while (tmp >= 0 && mp[tmp] >= mid) {
mp.erase(tmp), ++mp[--tmp];
}
if (tmp < 0)
return false;
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n;
rep(i, 1, n) { cin >> a[i]; }
int l = 1, r = n;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid)) {
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << r + 1 << endl;
return 0;
} | insert | 25 | 25 | 25 | 32 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; i++)
#define DREP(i, a, b) for (int i = (a), _end_ = (b); i >= _end_; i--)
#define EREP(i, u) for (int i = start[u]; i; i = e[i].next)
#define fi first
#define se second
#define mkr(a, b) make_pair(a, b)
#define SZ(A) ((int)A.size())
template <class T> inline void chkmin(T &a, T b) {
if (a > b)
a = b;
}
template <class T> inline void chkmax(T &a, T b) {
if (a < b)
a = b;
}
inline int read() {
int s = 0, f = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-')
ch = getchar();
if (ch == '-')
ch = getchar(), f = -1;
while (isdigit(ch))
s = s * 10 + ch - '0', ch = getchar();
return ~f ? s : -s;
}
const int maxn = 2e5 + 20;
const int inf = 0x3f3f3f3f;
inline int power(int a, int b) {
int ans = 1;
while (b) {
if (b & 1)
ans = min((ll)ans * a, (ll)inf);
b >>= 1;
a = min((ll)a * a, (ll)inf);
}
return ans;
}
int n, a[maxn];
inline void init() {
n = read();
REP(i, 1, n) a[i] = read();
}
#define pii pair<int, int>
inline bool check(int x) {
vector<pii> v;
v.push_back(mkr(0, 0));
REP(i, 1, n) {
if (a[i] > v.back().fi) {
v.push_back(mkr(a[i], 0));
} else {
while (v.back().fi > a[i])
v.pop_back();
int ad = a[i];
while (1) {
if (ad != v.back().fi)
v.push_back(mkr(ad, 0));
if (v.back().fi == 0)
return 0;
int len = SZ(v) - 1;
v[len].se++;
if (v[len].se == x) {
v[len].se = 0;
ad--;
v.pop_back();
} else {
REP(j, ad + 1, a[i]) v.push_back(mkr(j, 0));
break;
}
}
}
}
return 1;
}
inline void doing() {
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", l);
}
int main() {
init();
doing();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; i++)
#define DREP(i, a, b) for (int i = (a), _end_ = (b); i >= _end_; i--)
#define EREP(i, u) for (int i = start[u]; i; i = e[i].next)
#define fi first
#define se second
#define mkr(a, b) make_pair(a, b)
#define SZ(A) ((int)A.size())
template <class T> inline void chkmin(T &a, T b) {
if (a > b)
a = b;
}
template <class T> inline void chkmax(T &a, T b) {
if (a < b)
a = b;
}
inline int read() {
int s = 0, f = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-')
ch = getchar();
if (ch == '-')
ch = getchar(), f = -1;
while (isdigit(ch))
s = s * 10 + ch - '0', ch = getchar();
return ~f ? s : -s;
}
const int maxn = 2e5 + 20;
const int inf = 0x3f3f3f3f;
inline int power(int a, int b) {
int ans = 1;
while (b) {
if (b & 1)
ans = min((ll)ans * a, (ll)inf);
b >>= 1;
a = min((ll)a * a, (ll)inf);
}
return ans;
}
int n, a[maxn];
inline void init() {
n = read();
REP(i, 1, n) a[i] = read();
}
#define pii pair<int, int>
inline bool check(int x) {
if (x == 1) {
REP(i, 1, n - 1) if (a[i] > a[i + 1]) return 0;
return 1;
}
vector<pii> v;
v.push_back(mkr(0, 0));
REP(i, 1, n) {
if (a[i] > v.back().fi) {
v.push_back(mkr(a[i], 0));
} else {
while (v.back().fi > a[i])
v.pop_back();
int ad = a[i];
while (1) {
if (ad != v.back().fi)
v.push_back(mkr(ad, 0));
if (v.back().fi == 0)
return 0;
int len = SZ(v) - 1;
v[len].se++;
if (v[len].se == x) {
v[len].se = 0;
ad--;
v.pop_back();
} else {
REP(j, ad + 1, a[i]) v.push_back(mkr(j, 0));
break;
}
}
}
}
return 1;
}
inline void doing() {
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", l);
}
int main() {
init();
doing();
return 0;
}
| insert | 54 | 54 | 54 | 58 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, s, t) for (int i = s; i <= (t); ++i)
#define dec(i, s, t) for (int i = s; i >= (t); --i)
#define mp(a, b) make_pair(a, b)
using namespace std;
const int N = 1e5 + 50;
int n, a[N];
bool chk(int x) {
if (x == 1) {
rep(i, 2, n) if (a[i] <= a[i - 1]) return false;
return true;
}
set<pair<int, int>> s;
rep(j, 2, n) {
if (a[j] <= a[j - 1]) {
while (!s.empty() && (s.rbegin()->first >= a[j]))
s.erase(*s.rbegin());
dec(i, a[j] - 1, 0) {
if (s.empty() || s.rbegin()->first != i) {
s.insert(mp(i, 1));
break;
}
if (s.rbegin()->second + 1 < x) {
auto t = *s.rbegin();
s.erase(*s.rbegin());
++t.second;
s.insert(t);
break;
} else {
s.erase(*s.rbegin());
}
}
if (s.empty())
return false;
}
}
return true;
}
int main() {
scanf("%d", &n);
rep(i, 1, n) scanf("%d", a + i);
int l = 0, r = n;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (chk(mid))
r = mid;
else
l = mid;
}
printf("%d\n", r);
return 0;
} | #include <bits/stdc++.h>
#define rep(i, s, t) for (int i = s; i <= (t); ++i)
#define dec(i, s, t) for (int i = s; i >= (t); --i)
#define mp(a, b) make_pair(a, b)
using namespace std;
const int N = 3e5 + 50;
int n, a[N];
bool chk(int x) {
if (x == 1) {
rep(i, 2, n) if (a[i] <= a[i - 1]) return false;
return true;
}
set<pair<int, int>> s;
rep(j, 2, n) {
if (a[j] <= a[j - 1]) {
while (!s.empty() && (s.rbegin()->first >= a[j]))
s.erase(*s.rbegin());
dec(i, a[j] - 1, 0) {
if (s.empty() || s.rbegin()->first != i) {
s.insert(mp(i, 1));
break;
}
if (s.rbegin()->second + 1 < x) {
auto t = *s.rbegin();
s.erase(*s.rbegin());
++t.second;
s.insert(t);
break;
} else {
s.erase(*s.rbegin());
}
}
if (s.empty())
return false;
}
}
return true;
}
int main() {
scanf("%d", &n);
rep(i, 1, n) scanf("%d", a + i);
int l = 0, r = n;
while (r - l > 1) {
int mid = (l + r) >> 1;
if (chk(mid))
r = mid;
else
l = mid;
}
printf("%d\n", r);
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03202 | C++ | Time Limit Exceeded | // #pragma GCC optimize("Ofast")
// #pragma GCC target("avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const ll mod = 1e9 + 7;
int n, pos[200200], num[200200], sz;
vi a;
bool check(int x) {
sz = 0;
for (int i = 1; i < a.size(); i++) {
if (a[i] > a[i - 1])
continue;
int j = a[i];
while (j) {
if (pos[sz - 1] > j) {
--sz;
continue;
}
if (!sz || pos[sz - 1] < j) {
pos[sz] = j;
num[sz] = 0;
sz++;
}
if (++num[sz - 1] >= x) {
sz--;
j--;
} else
break;
}
if (!j)
return false;
}
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
a.resize(n);
for (auto &i : a)
cin >> i;
ll ans = 0;
for (int i = 1 << 17; i; i >>= 1)
if (!check(ans + i))
ans += i;
cout << 1 + ans;
}
| // #pragma GCC optimize("Ofast")
// #pragma GCC target("avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("trapv")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const ll mod = 1e9 + 7;
int n, pos[200200], num[200200], sz;
vi a;
bool check(int x) {
sz = 0;
for (int i = 1; i < a.size(); i++) {
if (a[i] > a[i - 1])
continue;
int j = a[i];
while (j) {
if (pos[sz - 1] > j) {
--sz;
continue;
}
if (!sz || pos[sz - 1] < j) {
pos[sz] = j;
num[sz] = 0;
sz++;
}
if (++num[sz - 1] >= x) {
sz--;
j--;
} else
break;
}
if (!j)
return false;
}
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
a.resize(n);
for (auto &i : a)
cin >> i;
ll ans = 0;
for (int i = 1 << 17; i; i >>= 1)
if (!check(ans + i))
ans += i;
cout << 1 + ans;
}
| replace | 3 | 4 | 3 | 4 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;
int n, a[200005];
bool check(int m) {
map<int, int> cur;
for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1])
continue;
map<int, int>::iterator cc;
while ((cc = cur.upper_bound(a[i])) != cur.end())
cur.erase(cc);
cur[a[i]]++;
int cp = a[i];
while (cur[cp] >= m) {
cur.erase(cp);
cp--;
cur[cp]++;
if (cp == 0)
return false;
}
}
return true;
}
int main() {
scanf("%d", &n);
rep(i, n) 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>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;
int n, a[200005];
bool check(int m) {
if (m == 1) {
for (int i = 1; i < n; i++)
if (a[i] <= a[i - 1])
return false;
return true;
}
map<int, int> cur;
for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1])
continue;
map<int, int>::iterator cc;
while ((cc = cur.upper_bound(a[i])) != cur.end())
cur.erase(cc);
cur[a[i]]++;
int cp = a[i];
while (cur[cp] >= m) {
cur.erase(cp);
cp--;
cur[cp]++;
if (cp == 0)
return false;
}
}
return true;
}
int main() {
scanf("%d", &n);
rep(i, n) 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;
} | insert | 13 | 13 | 13 | 19 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template <class T> constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template <class T> constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char> T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char> T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = {-1, -1, -1, 0, 1, 1, 1, 0},
vx[] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int popcnt(unsigned long long n) {
int cnt = 0;
for (int i = 0; i < 64; i++)
if ((n >> i) & 1)
cnt++;
return cnt;
}
int d_sum(LL n) {
int ret = 0;
while (n > 0) {
ret += n % 10;
n /= 10;
}
return ret;
}
int d_cnt(LL n) {
int ret = 0;
while (n > 0) {
ret++;
n /= 10;
}
return ret;
}
LL gcd(LL a, LL b) {
if (b == 0)
return a;
return gcd(b, a % b);
};
LL lcm(LL a, LL b) {
LL g = gcd(a, b);
return a / g * b;
};
#define ALL(qpqpq) (qpqpq).begin(), (qpqpq).end()
#define UNIQUE(wpwpw) \
sort(ALL((wpwpw))); \
(wpwpw).erase(unique(ALL((wpwpw))), (wpwpw).end())
#define LOWER(epepe) transform(ALL((epepe)), (epepe).begin(), TL<char>)
#define UPPER(rprpr) transform(ALL((rprpr)), (rprpr).begin(), TU<char>)
#define FOR(i, tptpt, ypypy) for (LL i = (tptpt); i < (ypypy); i++)
#define REP(i, upupu) FOR(i, 0, upupu)
#define INIT \
std::ios::sync_with_stdio(false); \
std::cin.tie(0)
int n;
int a[202020];
map<int, int> num;
bool calc(int mid) {
num.erase(ALL(num));
for (int i = 1; i < n; i++) {
if (a[i - 1] >= a[i]) {
if (num.empty()) {
num[a[i]] = 1;
} else {
auto it = num.upper_bound(a[i]);
num.erase(it, num.end());
num[a[i]]++;
int d = a[i];
while (num[d] == mid) {
if (d == 1)
return false;
num.erase(d);
d--;
num[d]++;
}
}
}
}
return true;
}
int lis(vector<LL> &v) {
vector<LL> ans(v.size(), HINF<LL>());
for (int i = 0; i < v.size(); i++) {
(*lower_bound(ans.begin(), ans.end(), v[i])) = v[i];
}
return lower_bound(ans.begin(), ans.end(), HINF<LL>()) - ans.begin();
}
vector<LL> v;
int main() {
INIT;
cin >> n;
REP(i, n) {
cin >> a[i];
v.emplace_back(a[i]);
}
if (lis(v) == n) {
cout << 1 << endl;
return 0;
}
int ng = 0, ok = n + 1;
while (ok - ng > 1) {
int mid = (ok + ng) / 2;
if (calc(mid)) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok << endl;
} | #include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template <class T> constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template <class T> constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char> T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char> T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = {-1, -1, -1, 0, 1, 1, 1, 0},
vx[] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int popcnt(unsigned long long n) {
int cnt = 0;
for (int i = 0; i < 64; i++)
if ((n >> i) & 1)
cnt++;
return cnt;
}
int d_sum(LL n) {
int ret = 0;
while (n > 0) {
ret += n % 10;
n /= 10;
}
return ret;
}
int d_cnt(LL n) {
int ret = 0;
while (n > 0) {
ret++;
n /= 10;
}
return ret;
}
LL gcd(LL a, LL b) {
if (b == 0)
return a;
return gcd(b, a % b);
};
LL lcm(LL a, LL b) {
LL g = gcd(a, b);
return a / g * b;
};
#define ALL(qpqpq) (qpqpq).begin(), (qpqpq).end()
#define UNIQUE(wpwpw) \
sort(ALL((wpwpw))); \
(wpwpw).erase(unique(ALL((wpwpw))), (wpwpw).end())
#define LOWER(epepe) transform(ALL((epepe)), (epepe).begin(), TL<char>)
#define UPPER(rprpr) transform(ALL((rprpr)), (rprpr).begin(), TU<char>)
#define FOR(i, tptpt, ypypy) for (LL i = (tptpt); i < (ypypy); i++)
#define REP(i, upupu) FOR(i, 0, upupu)
#define INIT \
std::ios::sync_with_stdio(false); \
std::cin.tie(0)
int n;
int a[202020];
map<int, int> num;
bool calc(int mid) {
num.erase(ALL(num));
for (int i = 1; i < n; i++) {
if (a[i - 1] >= a[i]) {
if (num.empty()) {
num[a[i]] = 1;
} else {
auto it = num.upper_bound(a[i]);
num.erase(it, num.end());
num[a[i]]++;
int d = a[i];
while (num[d] == mid) {
if (d == 1)
return false;
num.erase(d);
d--;
num[d]++;
}
}
}
}
return true;
}
int lis(vector<LL> &v) {
vector<LL> ans(v.size(), HINF<LL>());
for (int i = 0; i < v.size(); i++) {
(*lower_bound(ans.begin(), ans.end(), v[i])) = v[i];
}
return lower_bound(ans.begin(), ans.end(), HINF<LL>()) - ans.begin();
}
vector<LL> v;
int main() {
INIT;
cin >> n;
REP(i, n) {
cin >> a[i];
v.emplace_back(a[i]);
}
if (lis(v) == n) {
cout << 1 << endl;
return 0;
}
int ng = 1, ok = n + 1;
while (ok - ng > 1) {
int mid = (ok + ng) / 2;
if (calc(mid)) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok << endl;
} | replace | 105 | 106 | 105 | 106 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
int l = 0, r = N;
while (r - l > 1) {
int c = (l + r) / 2;
map<int, int> mp;
for (int i = 1; i < N; i++) {
if (A[i] >= 100000)
continue;
if (A[i - 1] >= A[i]) {
int t = A[i];
mp[t]++;
auto it = mp.upper_bound(t);
mp.erase(it, mp.end());
while (t > 0 && mp[t] == c) {
mp[t] = 0;
mp[t - 1]++;
t--;
}
}
}
if (mp[0] == 0)
r = c;
else
l = c;
}
cout << r << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
int l = 0, r = N;
while (r - l > 1) {
int c = (l + r) / 2;
map<int, int> mp;
for (int i = 1; i < N; i++) {
if (A[i] >= 100000)
continue;
if (A[i - 1] >= A[i]) {
int t = A[i];
mp[t]++;
auto it = mp.upper_bound(t);
mp.erase(it, mp.end());
while (t > 0 && mp[t] == c) {
mp[t] = 0;
mp[t - 1]++;
t--;
}
}
if (mp[0] > 0)
break;
}
if (mp[0] == 0)
r = c;
else
l = c;
}
cout << r << endl;
return 0;
}
| insert | 28 | 28 | 28 | 30 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
int n, a[maxn + 3];
bool check(int k) {
map<int, int> M;
for (int i = 1; i <= n; i++) {
if (a[i] <= a[i - 1]) {
while (!M.empty() && M.rbegin()->first > a[i]) {
map<int, int>::iterator it = M.end();
M.erase(--it);
}
for (int j = a[i]; j >= 0; j--) {
if (j == 0) {
return false;
}
if (++M[j] == k) {
M[j] = 0;
} else {
break;
}
}
}
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int l = 1, r = n, mid;
while (l < r) {
mid = (l + r) >> 1;
if (check(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
printf("%d\n", l);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
int n, a[maxn + 3];
bool check(int k) {
map<int, int> M;
for (int i = 1; i <= n; i++) {
if (a[i] <= a[i - 1]) {
if (k == 1) {
return false;
}
while (!M.empty() && M.rbegin()->first > a[i]) {
map<int, int>::iterator it = M.end();
M.erase(--it);
}
for (int j = a[i]; j >= 0; j--) {
if (j == 0) {
return false;
}
if (++M[j] == k) {
M[j] = 0;
} else {
break;
}
}
}
}
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int l = 1, r = n, mid;
while (l < r) {
mid = (l + r) >> 1;
if (check(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
printf("%d\n", l);
return 0;
} | insert | 10 | 10 | 10 | 13 | TLE | |
p03202 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool mini(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define dame \
{ \
cout << "1" \
<< "\n"; \
return; \
}
#define INF2 1000000000000000037
#define INF 1000000007
#define MOD 1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
//--GLOBAL---------------------------------
//--MAIN-----------------------------------
void Main() {
ll N;
cin >> N;
vector<ll> A(N);
rep(i, N) cin >> A[i];
bool okk = false;
rep(i, N - 1) if (A[i] >= A[i + 1]) okk = true;
if (!okk)
dame;
/*bis*/ ll low = 0, high = 201010; // min-1, max+1
while (abs(high - low) > 1) {
ll mid = (high + low) / 2;
bool ok = true;
deque<P> dq; // 位置,文字番号
reps(i, 1, N) {
if (A[i] > A[i - 1])
continue;
while (!dq.empty() and dq.back().first > A[i]) {
dq.pop_back();
}
if (!dq.empty() and dq.back().first == A[i]) {
dq.back().second++;
} else {
dq.emplace_back(A[i], 1);
}
while (dq.back().second == mid) {
ll d = dq.back().first;
if (d == 1) {
ok = false;
i = N + 1;
break;
}
dq.pop_back();
if (!dq.empty() and dq.back().first == d - 1) {
dq.back().second++;
} else {
dq.emplace_back(d - 1, 1);
}
}
}
(ok ? high : low) = mid;
} // if ok, okdir = mid
cout << high << "\n";
}
//--START----------------------------------
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
//-----------------------------------------
| #include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool mini(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define dame \
{ \
cout << "1" \
<< "\n"; \
return; \
}
#define INF2 1000000000000000037
#define INF 1000000007
#define MOD 1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
//--GLOBAL---------------------------------
//--MAIN-----------------------------------
void Main() {
ll N;
cin >> N;
vector<ll> A(N);
rep(i, N) cin >> A[i];
bool okk = false;
rep(i, N - 1) if (A[i] >= A[i + 1]) okk = true;
if (!okk)
dame;
/*bis*/ ll low = 1, high = 201010; // min-1, max+1
while (abs(high - low) > 1) {
ll mid = (high + low) / 2;
bool ok = true;
deque<P> dq; // 位置,文字番号
reps(i, 1, N) {
if (A[i] > A[i - 1])
continue;
while (!dq.empty() and dq.back().first > A[i]) {
dq.pop_back();
}
if (!dq.empty() and dq.back().first == A[i]) {
dq.back().second++;
} else {
dq.emplace_back(A[i], 1);
}
while (dq.back().second == mid) {
ll d = dq.back().first;
if (d == 1) {
ok = false;
i = N + 1;
break;
}
dq.pop_back();
if (!dq.empty() and dq.back().first == d - 1) {
dq.back().second++;
} else {
dq.emplace_back(d - 1, 1);
}
}
}
(ok ? high : low) = mid;
} // if ok, okdir = mid
cout << high << "\n";
}
//--START----------------------------------
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
//-----------------------------------------
| replace | 47 | 48 | 47 | 48 | TLE | |
p03202 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 10;
int N, A[MAX_N];
bool check(int sigma) {
static pair<int, int> stk[MAX_N];
int top = 0;
for (int i = 1; i <= N; i++) {
int delta = A[i] - A[i - 1];
if (delta > 0) {
stk[++top] = make_pair(1, delta);
} else {
while (delta) {
if (delta + stk[top].second <= 0) {
delta += stk[top].second;
top--;
} else {
stk[top].second += delta;
delta = 0;
}
}
int popped = 0;
while (top && stk[top].first == sigma) {
popped += stk[top].second;
top--;
}
if (!top)
return false;
if (stk[top].second != 1) {
stk[top + 1] = make_pair(stk[top].first, 1);
stk[top].second--;
top++;
}
stk[top].first++;
stk[++top] = make_pair(1, popped);
}
}
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 m = (l + r) / 2;
if (check(m))
r = m;
else
l = m + 1;
}
printf("%d\n", l);
}
| #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 10;
int N, A[MAX_N];
bool check(int sigma) {
static pair<int, int> stk[MAX_N];
int top = 0;
for (int i = 1; i <= N; i++) {
int delta = A[i] - A[i - 1];
if (delta > 0) {
stk[++top] = make_pair(1, delta);
} else {
while (delta) {
if (delta + stk[top].second <= 0) {
delta += stk[top].second;
top--;
} else {
stk[top].second += delta;
delta = 0;
}
}
int popped = 0;
while (top && stk[top].first == sigma) {
popped += stk[top].second;
top--;
}
if (!top)
return false;
if (stk[top].second != 1) {
stk[top + 1] = make_pair(stk[top].first, 1);
stk[top].second--;
top++;
}
stk[top].first++;
if (popped) {
stk[++top] = make_pair(1, popped);
}
}
}
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 m = (l + r) / 2;
if (check(m))
r = m;
else
l = m + 1;
}
printf("%d\n", l);
}
| replace | 38 | 39 | 38 | 41 | 0 | |
p03202 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
using namespace std;
int n;
int a[200005], l, r, tail;
struct que {
int x, v;
} sta[200005];
void insert(int x, int v) {
while (sta[tail].x > x)
tail--;
if (sta[tail].x == x)
sta[tail].v++;
else
sta[++tail] = (que){x, 1};
if (tail > 1 && sta[tail].v == v)
tail--, insert(x - 1, v);
}
bool check(int v) {
tail = 0;
sta[++tail] = (que){0, 0};
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1])
insert(a[i], v);
return !sta[1].v;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
bool flag = 1;
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1])
flag = 0;
if (flag) {
puts("1");
return 0;
}
l = 1, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%d", l);
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
using namespace std;
int n;
int a[200005], l, r, tail;
struct que {
int x, v;
} sta[200005];
void insert(int x, int v) {
while (sta[tail].x > x)
tail--;
if (sta[tail].x == x)
sta[tail].v++;
else
sta[++tail] = (que){x, 1};
if (tail > 1 && sta[tail].v == v)
tail--, insert(x - 1, v);
}
bool check(int v) {
tail = 0;
sta[++tail] = (que){0, 0};
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1])
insert(a[i], v);
return !sta[1].v;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
bool flag = 1;
for (int i = 2; i <= n; i++)
if (a[i] <= a[i - 1])
flag = 0;
if (flag) {
puts("1");
return 0;
}
l = 2, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
printf("%d", l);
} | replace | 43 | 44 | 43 | 44 | TLE | |
p03202 | C++ | Time Limit Exceeded | //
// main.cpp
//
#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();
template <typename T> vector<T> make_vec_nd(T init, ll size) {
return vector<T>(size, init);
}
template <typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
auto inner = make_vec_nd(init, rest...);
return vector<decltype(inner)>(size, inner);
}
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)
int main() {
ll N;
cin >> N;
vector<ll> As(N);
rep(i, 0, N) { cin >> As[i]; }
if (N == 1) {
cout << 1 << endl;
return 0;
}
auto is_ok = [&As, N](ll n) {
map<ll, ll> digits;
rep(i, 1, N) {
if (As[i] <= As[i - 1]) {
ll d = As[i] - 1;
digits.erase(digits.upper_bound(d), digits.end());
digits[d]++;
while (digits[d] >= n) {
if (d == 0) {
return false;
}
digits.erase(d);
d--;
digits[d]++;
}
}
}
return true;
};
ll ng = 1;
ll ok = 1;
while (is_ok(ok) == false) {
ok *= 2;
}
while (ok - ng >= 2) {
ll mid = (ng + ok) / 2;
if (is_ok(mid)) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok << endl;
}
/*
1
1
2
1 1
3
1 1 1
4
1 1 1 1
1
2
2
2 2
3
2 2 2
4
2 2 2 2
5
2 2 2 2 2
*/
| //
// main.cpp
//
#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();
template <typename T> vector<T> make_vec_nd(T init, ll size) {
return vector<T>(size, init);
}
template <typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
auto inner = make_vec_nd(init, rest...);
return vector<decltype(inner)>(size, inner);
}
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)
int main() {
ll N;
cin >> N;
vector<ll> As(N);
rep(i, 0, N) { cin >> As[i]; }
if (N == 1) {
cout << 1 << endl;
return 0;
}
auto is_ok = [&As, N](ll n) {
if (n == 1) {
rep(i, 1, N) {
if (As[i] <= As[i - 1]) {
return false;
}
}
return true;
}
map<ll, ll> digits;
rep(i, 1, N) {
if (As[i] <= As[i - 1]) {
ll d = As[i] - 1;
digits.erase(digits.upper_bound(d), digits.end());
digits[d]++;
while (digits[d] >= n) {
if (d == 0) {
return false;
}
digits.erase(d);
d--;
digits[d]++;
}
}
}
return true;
};
ll ng = 1;
ll ok = 1;
while (is_ok(ok) == false) {
ok *= 2;
}
while (ok - ng >= 2) {
ll mid = (ng + ok) / 2;
if (is_ok(mid)) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok << endl;
}
/*
1
1
2
1 1
3
1 1 1
4
1 1 1 1
1
2
2
2 2
3
2 2 2
4
2 2 2 2
5
2 2 2 2 2
*/
| insert | 55 | 55 | 55 | 63 | TLE | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define range(i, m, n) for (int i = m; i < n; i++)
#define husk(i, m, n) for (int i = m; i > n; i--)
int n, h, w;
int main() {
cin >> h >> w >> n;
set<pair<int, int>> obs;
vector<vector<int>> to(w);
range(i, 0, n) {
int x, y;
cin >> x >> y;
x--;
y--;
if (x < y)
continue;
to[x].push_back(y);
obs.insert(make_pair(x, y));
}
range(i, 0, w) {
to[i].push_back(h);
sort(to[i].begin(), to[i].end());
}
range(x, 0, h) obs.insert(make_pair(x, w));
range(y, 0, w) obs.insert(make_pair(h, y));
int x = 0;
int y = 0;
vector<pair<int, int>> cur;
auto ted = [&]() {
if (cur.size() < 3) {
if (cur.size() == 2) {
return (cur[0] == cur[1] && cur[0] == make_pair(0, 0));
}
return false;
}
int sz = cur.size();
return (cur[sz - 1] == cur[sz - 2] && cur[sz - 2] == cur[sz - 3]);
};
while (true) {
if (obs.find(make_pair(x + 1, y)) != obs.end()) {
cur.emplace_back(x, y);
if (ted())
break;
cur.emplace_back(x, y);
break;
}
x++;
cur.emplace_back(x, y);
int c = obs.find(make_pair(x, y + 1)) == obs.end();
y += c;
cur.emplace_back(x, y);
}
int res = cur.size();
for (int i = 0; i < (int)cur.size(); i += 2) {
int u = cur[i].first, v = cur[i].second;
int su = *lower_bound(to[v].begin(), to[v].end(), u);
res = min(res, i + 1 + (su - u) * 2);
}
cout << (res + 1) / 2;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define range(i, m, n) for (int i = m; i < n; i++)
#define husk(i, m, n) for (int i = m; i > n; i--)
int n, h, w;
int main() {
cin >> h >> w >> n;
set<pair<int, int>> obs;
vector<vector<int>> to(w);
range(i, 0, n) {
int x, y;
cin >> x >> y;
x--;
y--;
if (x < y)
continue;
to[y].push_back(x);
obs.insert(make_pair(x, y));
}
range(i, 0, w) {
to[i].push_back(h);
sort(to[i].begin(), to[i].end());
}
range(x, 0, h) obs.insert(make_pair(x, w));
range(y, 0, w) obs.insert(make_pair(h, y));
int x = 0;
int y = 0;
vector<pair<int, int>> cur;
auto ted = [&]() {
if (cur.size() < 3) {
if (cur.size() == 2) {
return (cur[0] == cur[1] && cur[0] == make_pair(0, 0));
}
return false;
}
int sz = cur.size();
return (cur[sz - 1] == cur[sz - 2] && cur[sz - 2] == cur[sz - 3]);
};
while (true) {
if (obs.find(make_pair(x + 1, y)) != obs.end()) {
cur.emplace_back(x, y);
if (ted())
break;
cur.emplace_back(x, y);
break;
}
x++;
cur.emplace_back(x, y);
int c = obs.find(make_pair(x, y + 1)) == obs.end();
y += c;
cur.emplace_back(x, y);
}
int res = cur.size();
for (int i = 0; i < (int)cur.size(); i += 2) {
int u = cur[i].first, v = cur[i].second;
int su = *lower_bound(to[v].begin(), to[v].end(), u);
res = min(res, i + 1 + (su - u) * 2);
}
cout << (res + 1) / 2;
return 0;
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, m, q;
#define Maxn 100010
int mins[Maxn];
inline void rd(int &x) {
x = 0;
char ch = getchar();
while (ch < '0' || ch > '9')
ch = getchar();
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
}
int main() {
memset(mins, 127, sizeof(mins));
rd(n);
rd(m);
rd(q);
int x, y;
for (register int i = 1; i <= q; ++i) {
rd(x);
rd(y);
x--;
y--;
mins[x] = min(mins[x], y);
}
int right = 0;
for (register int i = 1; i < n; ++i)
if (right >= mins[i]) {
printf("%d\n", i);
return 0;
} else if (right + 1 < mins[i])
right++;
printf("%d\n", n);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, m, q;
#define Maxn 200010
int mins[Maxn];
inline void rd(int &x) {
x = 0;
char ch = getchar();
while (ch < '0' || ch > '9')
ch = getchar();
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
}
int main() {
memset(mins, 127, sizeof(mins));
rd(n);
rd(m);
rd(q);
int x, y;
for (register int i = 1; i <= q; ++i) {
rd(x);
rd(y);
x--;
y--;
mins[x] = min(mins[x], y);
}
int right = 0;
for (register int i = 1; i < n; ++i)
if (right >= mins[i]) {
printf("%d\n", i);
return 0;
} else if (right + 1 < mins[i])
right++;
printf("%d\n", n);
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const double eps = 1e-8;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;
int main() {
ll H, W, N;
cin >> H >> W >> N;
vector<set<ll>> sets(H);
for (int i = 0; i < N; i++) {
ll x, y;
cin >> x >> y;
x--;
y--;
sets[y].insert(x);
}
for (int y = 0; y < H; y++)
sets[y].insert(W);
ll answer = INF;
ll y = 0;
ll x = 0;
while (true) {
if (sets[y].lower_bound(x) == sets[y].end())
break;
ll near = *sets[y].lower_bound(x);
answer = min(answer, near);
x++;
if (x >= W)
break;
if (sets[y].find(x) != sets[y].end())
break;
if (y >= H - 1)
break;
if (sets[y + 1].find(x) == sets[y + 1].end())
y++;
if (y >= H || x >= W)
break;
}
cout << answer << endl;
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const double eps = 1e-8;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;
int main() {
ll H, W, N;
cin >> W >> H >> N;
vector<set<ll>> sets(H);
for (int i = 0; i < N; i++) {
ll x, y;
cin >> x >> y;
x--;
y--;
sets[y].insert(x);
}
for (int y = 0; y < H; y++)
sets[y].insert(W);
ll answer = INF;
ll y = 0;
ll x = 0;
while (true) {
if (sets[y].lower_bound(x) == sets[y].end())
break;
ll near = *sets[y].lower_bound(x);
answer = min(answer, near);
x++;
if (x >= W)
break;
if (sets[y].find(x) != sets[y].end())
break;
if (y >= H - 1)
break;
if (sets[y + 1].find(x) == sets[y + 1].end())
y++;
if (y >= H || x >= W)
break;
}
cout << answer << endl;
return 0;
}
| replace | 32 | 33 | 32 | 33 | 0 | |
p03203 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int h, w, n;
cin >> h >> w >> n;
set<int> xs[w];
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
--y;
--x;
xs[y].insert(x);
}
for (int i = 0; i < w; i++) {
xs[i].insert(h);
}
if (h == 1 || xs[1].find(0) != xs[1].end()) {
cout << 1 << endl;
return 0;
}
int ans = 1e6;
int cur_w = 0;
for (int i = 1; i < h; i++) {
if (xs[cur_w].find(i) != xs[cur_w].end()) {
ans = min(i, ans);
break;
}
auto it = xs[cur_w].upper_bound(i);
ans = min(*it, ans);
if (cur_w < w - 1) {
if (xs[cur_w + 1].find(i) == xs[cur_w + 1].end()) {
++cur_w;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int h, w, n;
cin >> h >> w >> n;
set<int> xs[w];
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
--y;
--x;
xs[y].insert(x);
}
for (int i = 0; i < w; i++) {
xs[i].insert(h);
}
if (h == 1 || (w > 1 && xs[1].find(0) != xs[1].end())) {
cout << 1 << endl;
return 0;
}
int ans = 1e6;
int cur_w = 0;
for (int i = 1; i < h; i++) {
if (xs[cur_w].find(i) != xs[cur_w].end()) {
ans = min(i, ans);
break;
}
auto it = xs[cur_w].upper_bound(i);
ans = min(*it, ans);
if (cur_w < w - 1) {
if (xs[cur_w + 1].find(i) == xs[cur_w + 1].end()) {
++cur_w;
}
}
}
cout << ans << endl;
} | replace | 17 | 18 | 17 | 18 | TLE | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define pr(...) \
cerr << GET_MACRO(__VA_ARGS__, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define prArr(a) \
{ \
cerr << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
cerr << (i++ ? ", " : "") << t; \
cerr << "}" << endl; \
}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Int mod = (1e9) + 7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
for (T t : a)
o << (i++ ? " " : "") << t;
return o;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
// INSERT ABOVE HERE
set<P> S;
vector<vector<Int>> X;
Int H, W, N;
Int calc(Int x, Int y) {
Int idx = lower_bound(X[y].begin(), X[y].end(), x) - X[y].begin();
return X[y][idx] - x;
}
Int bfs() {
using T = tuple<Int, Int, Int>;
queue<T> Q;
map<T, Int> D;
vector<Int> used(H + 1);
map<T, Int> visited;
Q.push(T(0, 0, 0));
D[T(0, 0, 0)] = 0;
Int ans = INF;
while (!Q.empty()) {
Int x, y, turn;
tie(x, y, turn) = Q.front();
Q.pop();
Int cost = D[T(x, y, turn)];
if (!used[y])
Min(ans, cost + calc(x, y));
visited[T(x, y, turn)] = 1;
used[y] = 1;
if (turn == 0 && used[y + 1] == 0) {
if (S.count(P(x + 1, y)) || x + 1 >= W)
continue;
Q.push(T(x + 1, y, !turn));
D[T(x + 1, y, !turn)] = cost;
}
if (turn == 1) {
if (S.count(P(x, y + 1))) {
if (!visited[T(x, y, !turn)]) {
Q.push(T(x, y, !turn));
D[T(x, y, !turn)] = cost + 1;
}
} else if (y + 1 < H) {
Q.push(T(x, y + 1, !turn));
D[T(x, y + 1, !turn)] = cost + 1;
}
}
}
return ans;
}
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
cin >> H >> W >> N;
X.resize(H);
for (Int i = 0; i < N; i++) {
Int x, y;
cin >> x >> y;
x--, y--;
S.insert(P(x, y));
X[y].push_back(x);
}
for (Int i = 0; i < H; i++) {
X[i].push_back(W);
sort(X[i].begin(), X[i].end());
}
Int ans = bfs();
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define pr(...) \
cerr << GET_MACRO(__VA_ARGS__, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define prArr(a) \
{ \
cerr << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
cerr << (i++ ? ", " : "") << t; \
cerr << "}" << endl; \
}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Int mod = (1e9) + 7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
for (T t : a)
o << (i++ ? " " : "") << t;
return o;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
// INSERT ABOVE HERE
set<P> S;
vector<vector<Int>> X;
Int H, W, N;
Int calc(Int x, Int y) {
Int idx = lower_bound(X[y].begin(), X[y].end(), x) - X[y].begin();
return X[y][idx] - x;
}
Int bfs() {
using T = tuple<Int, Int, Int>;
queue<T> Q;
map<T, Int> D;
vector<Int> used(H + 1);
map<T, Int> visited;
Q.push(T(0, 0, 0));
D[T(0, 0, 0)] = 0;
Int ans = INF;
while (!Q.empty()) {
Int x, y, turn;
tie(x, y, turn) = Q.front();
Q.pop();
Int cost = D[T(x, y, turn)];
if (!used[y])
Min(ans, cost + calc(x, y));
visited[T(x, y, turn)] = 1;
used[y] = 1;
if (turn == 0 && used[y + 1] == 0) {
if (S.count(P(x + 1, y)) || x + 1 >= W)
continue;
Q.push(T(x + 1, y, !turn));
D[T(x + 1, y, !turn)] = cost;
}
if (turn == 1) {
if (S.count(P(x, y + 1))) {
if (!visited[T(x, y, !turn)]) {
Q.push(T(x, y, !turn));
D[T(x, y, !turn)] = cost + 1;
}
} else if (y + 1 < H) {
Q.push(T(x, y + 1, !turn));
D[T(x, y + 1, !turn)] = cost + 1;
}
}
}
return ans;
}
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
cin >> W >> H >> N;
X.resize(H);
for (Int i = 0; i < N; i++) {
Int x, y;
cin >> x >> y;
x--, y--;
S.insert(P(x, y));
X[y].push_back(x);
}
for (Int i = 0; i < H; i++) {
X[i].push_back(W);
sort(X[i].begin(), X[i].end());
}
Int ans = bfs();
cout << ans << endl;
return 0;
}
| replace | 112 | 113 | 112 | 113 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x, vector<x>, greater<x>>
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
#define vtpl(x, y, z) vector<tuple<x, y, z>>
#define rev(x) reverse(x);
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const ll dx[9] = {0, -1, 0, 1, 1, -1, 1, -1, 0};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
ll h, w, n;
cin >> h >> w >> n;
vpl v(n);
rep(i, n) {
ll a, b;
cin >> a >> b;
a--;
b--;
v[i] = {a, b};
}
sort(all(v));
vl dp(w);
dp[0] = 1;
ll now = 0, see = 0;
rep(i, h) {
ll z = now;
while (z < n && v[z].fi == i) {
if (dp[v[z].se])
cout << i << endl, exit(0);
z++;
}
now = z;
if (!binary_search(all(v), make_pair(i + 1, see + 1))) {
see++;
dp[see]++;
}
// rep(j,w)cout << dp[j];cout << endl;
}
cout << h << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x, vector<x>, greater<x>>
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
#define vtpl(x, y, z) vector<tuple<x, y, z>>
#define rev(x) reverse(x);
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const ll dx[9] = {0, -1, 0, 1, 1, -1, 1, -1, 0};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
ll h, w, n;
cin >> h >> w >> n;
vpl v(n);
rep(i, n) {
ll a, b;
cin >> a >> b;
a--;
b--;
v[i] = {a, b};
}
sort(all(v));
vl dp(w);
dp[0] = 1;
ll now = 0, see = 0;
rep(i, h) {
ll z = now;
while (z < n && v[z].fi == i) {
if (dp[v[z].se])
cout << i << endl, exit(0);
z++;
}
now = z;
if (!binary_search(all(v), make_pair(i + 1, see + 1))) {
see++;
if (see < w)
dp[see]++;
}
// rep(j,w)cout << dp[j];cout << endl;
}
cout << h << endl;
} | replace | 66 | 67 | 66 | 68 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(), (v).end()
const ll MOD = 1e9 + 7;
// const ll MOD=998244353;
const ll INF = 1e9;
const ll IINF = 1e18;
const double EPS = 1e-8;
const double pi = acos(-1);
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int H, W, N;
cin >> H >> W >> N;
set<Pii> s;
vector<vector<int>> block(W);
vector<Pii> P(N);
rep(i, N) {
int x, y;
cin >> x >> y;
P[i] = {--x, --y};
s.insert({x, y});
}
sort(P.begin(), P.end());
rep(i, N) block[P[i].second].push_back(P[i].first);
rep(i, W) block[i].push_back(H);
int now = 0, ans = H;
rep(i, H) {
chmin(ans, *upper_bound(block[now].begin(), block[now].end(), i));
if (s.count({i + 1, now}))
break;
if (!s.count({i + 1, now + 1}))
++now;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(), (v).end()
const ll MOD = 1e9 + 7;
// const ll MOD=998244353;
const ll INF = 1e9;
const ll IINF = 1e18;
const double EPS = 1e-8;
const double pi = acos(-1);
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int H, W, N;
cin >> H >> W >> N;
set<Pii> s;
vector<vector<int>> block(W);
vector<Pii> P(N);
rep(i, N) {
int x, y;
cin >> x >> y;
P[i] = {--x, --y};
s.insert({x, y});
}
sort(P.begin(), P.end());
rep(i, N) block[P[i].second].push_back(P[i].first);
rep(i, W) block[i].push_back(H);
int now = 0, ans = H;
rep(i, H) {
chmin(ans, *upper_bound(block[now].begin(), block[now].end(), i));
if (s.count({i + 1, now}))
break;
if (!s.count({i + 1, now + 1}) && now < W - 1)
++now;
}
cout << ans << endl;
} | replace | 53 | 54 | 53 | 54 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
int h, w, n;
cin >> h >> w >> n;
vector<int> c(h + 2);
vector<set<int>> st(h + 2);
rep(i, n) {
int x, y;
cin >> x >> y;
st[y].insert(x);
}
c[1] = 1;
for (int i = 2; i <= h; i++) {
int t = c[i - 1] + 1;
if (st[i].size() != 0) {
auto p = st[i].lower_bound(t);
if (p == st[i].end()) {
c[i] = t;
if (c[i] == w) {
break;
}
}
if ((*p) != t) {
c[i] = t;
if (c[i] == w) {
break;
}
} else {
t++;
while (1) {
p++;
if (p != st[i].end()) {
if (*p != t) {
c[i] = t;
break;
}
} else {
c[i] = t;
break;
}
t++;
}
if (c[i] == w) {
break;
}
}
} else {
c[i] = t;
if (c[i] == w) {
break;
}
}
}
// rep(i,h)cout << c[i+1] << endl;
int ans = 10000000;
for (int i = 1; i <= h; i++) {
if (c[i] == 0)
break;
if (st[i].size() == 0) {
ans = min(ans, w);
} else {
auto p = st[i].lower_bound(c[i]);
if (p == st[i].end()) {
ans = min(ans, w);
} else {
// cerr <<c[i] << " " << *p << endl;
ans = min(ans, (*p) - 1);
}
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
int h, w, n;
cin >> h >> w >> n;
swap(h, w);
vector<int> c(h + 2);
vector<set<int>> st(h + 2);
rep(i, n) {
int x, y;
cin >> x >> y;
st[y].insert(x);
}
c[1] = 1;
for (int i = 2; i <= h; i++) {
int t = c[i - 1] + 1;
if (st[i].size() != 0) {
auto p = st[i].lower_bound(t);
if (p == st[i].end()) {
c[i] = t;
if (c[i] == w) {
break;
}
}
if ((*p) != t) {
c[i] = t;
if (c[i] == w) {
break;
}
} else {
t++;
while (1) {
p++;
if (p != st[i].end()) {
if (*p != t) {
c[i] = t;
break;
}
} else {
c[i] = t;
break;
}
t++;
}
if (c[i] == w) {
break;
}
}
} else {
c[i] = t;
if (c[i] == w) {
break;
}
}
}
// rep(i,h)cout << c[i+1] << endl;
int ans = 10000000;
for (int i = 1; i <= h; i++) {
if (c[i] == 0)
break;
if (st[i].size() == 0) {
ans = min(ans, w);
} else {
auto p = st[i].lower_bound(c[i]);
if (p == st[i].end()) {
ans = min(ans, w);
} else {
// cerr <<c[i] << " " << *p << endl;
ans = min(ans, (*p) - 1);
}
}
}
cout << ans << endl;
return 0;
} | insert | 26 | 26 | 26 | 27 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound
int shortest[200200];
set<int> obj[200200];
signed main() {
int H, W, N;
cin >> H >> W >> N;
rep(i, N) {
int x, y;
cin >> x >> y;
x--, y--;
obj[y].insert(x);
}
shortest[0] = 0;
for (int y = 1; y < W; ++y) {
if (shortest[y - 1] == INF) {
shortest[y] = INF;
continue;
}
for (int j = shortest[y - 1] + 1;; ++j) {
if (!obj[y].count(j)) {
shortest[y] = j;
break;
}
if (j > H) {
shortest[y] = INF;
break;
}
}
}
int ans = H;
for (int y = 0; y < W; ++y) {
auto ite = obj[y].upper_bound(shortest[y]);
if (ite == obj[y].end())
continue;
ans = min(ans, *ite);
}
if (ans == max(H, W))
return 1;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound
int shortest[200200];
set<int> obj[200200];
signed main() {
int H, W, N;
cin >> H >> W >> N;
rep(i, N) {
int x, y;
cin >> x >> y;
x--, y--;
obj[y].insert(x);
}
shortest[0] = 0;
for (int y = 1; y < W; ++y) {
if (shortest[y - 1] == INF) {
shortest[y] = INF;
continue;
}
for (int j = shortest[y - 1] + 1;; ++j) {
if (!obj[y].count(j)) {
shortest[y] = j;
break;
}
if (j > H) {
shortest[y] = INF;
break;
}
}
}
int ans = H;
for (int y = 0; y < W; ++y) {
auto ite = obj[y].upper_bound(shortest[y]);
if (ite == obj[y].end())
continue;
ans = min(ans, *ite);
}
cout << ans << endl;
return 0;
}
| delete | 46 | 48 | 46 | 46 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N, M, H, W, K, Q, A, B;
string S;
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll, ll> P;
int main() {
cin >> H >> W >> N;
vec x(N + 1), y(N + 1), ord(N + 1);
rep(i, N) cin >> x[i] >> y[i], --x[i], --y[i], ord[i] = i;
x[N] = H;
y[N] = 0;
sort(ALL(ord), [&](int a, int b) { return x[a] < x[b]; });
int id = 0, depth = 0;
reps(i, 1, H + 1) {
while (x[ord[id]] < i)
++id;
if (x[ord[id]] == i) {
if (y[ord[id]] <= depth) {
cout << i << endl;
return 0;
} else if (y[ord[id]] > depth + 1) {
++depth;
}
} else {
++depth;
}
}
} | #include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N, M, H, W, K, Q, A, B;
string S;
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll, ll> P;
int main() {
cin >> H >> W >> N;
vec x(N + 1), y(N + 1), ord(N + 1);
rep(i, N) cin >> x[i] >> y[i], --x[i], --y[i], ord[i] = i;
x[N] = H;
y[N] = 0;
ord[N] = N;
sort(ALL(ord), [&](int a, int b) {
if (x[a] == x[b])
return y[a] < y[b];
return x[a] < x[b];
});
int id = 0, depth = 0;
reps(i, 1, H + 1) {
while (x[ord[id]] < i)
++id;
if (x[ord[id]] == i) {
if (y[ord[id]] <= depth) {
cout << i << endl;
return 0;
} else if (y[ord[id]] > depth + 1) {
++depth;
}
} else {
++depth;
}
}
} | replace | 28 | 29 | 28 | 34 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
set<int> Se[100001];
int main() {
int n, m, k, X, Y, Mi = 20000000, t = 0;
cin >> m >> n >> k;
set<int>::iterator it;
for (int i = 0; i < k; i++) {
cin >> X >> Y;
X--;
Y--;
Se[Y].insert(X);
}
for (int i = 0; i < n; i++) {
Se[i].insert(m);
}
if (Se[0].find(1) != Se[0].end()) {
cout << 1;
return 0;
}
X = 1;
Y = 0;
t = 1;
while (X < m && Y < n) {
it = Se[Y].upper_bound(X);
Mi = min(Mi, *it - X - 1 + t);
if (Y == n - 1) {
break;
}
if (Se[Y + 1].find(X) == Se[Y + 1].end()) {
Y++;
}
it = Se[Y].upper_bound(X);
Mi = min(Mi, *it - X - 1 + t);
X++;
t++;
}
cout << Mi + 1;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
set<int> Se[200001];
int main() {
int n, m, k, X, Y, Mi = 20000000, t = 0;
cin >> m >> n >> k;
set<int>::iterator it;
for (int i = 0; i < k; i++) {
cin >> X >> Y;
X--;
Y--;
Se[Y].insert(X);
}
for (int i = 0; i < n; i++) {
Se[i].insert(m);
}
if (Se[0].find(1) != Se[0].end()) {
cout << 1;
return 0;
}
X = 1;
Y = 0;
t = 1;
while (X < m && Y < n) {
it = Se[Y].upper_bound(X);
Mi = min(Mi, *it - X - 1 + t);
if (Y == n - 1) {
break;
}
if (Se[Y + 1].find(X) == Se[Y + 1].end()) {
Y++;
}
it = Se[Y].upper_bound(X);
Mi = min(Mi, *it - X - 1 + t);
X++;
t++;
}
cout << Mi + 1;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(it, st, en) for (int it = (st); it < (int)(en); ++it)
#define all(c) (c).begin(), (c).end()
#define debug(x) cerr << #x << " = " << x << endl
#define eb emplace_back
#define X first
#define Y second
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int h, w, n;
cin >> h >> w >> n;
int ans = w;
vector<pii> p(n);
set<pii> blocked;
rep(i, 0, n) {
cin >> p[i].X >> p[i].Y;
blocked.insert(p[i]);
}
vi reach(w + 1);
reach[1] = 1;
rep(i, 2, w + 1) {
reach[i] = reach[i - 1] + 1;
if (blocked.count({i, reach[i]}))
--reach[i];
}
for (auto q : p) {
if (reach[q.X] >= q.Y) {
ans = min(ans, q.X - 1);
}
}
cout << ans << endl;
return 0;
}
/*
* T must ++x, otherwise A will pass to and end the game.
* A has two choices:
* pass: y += 0
* move: ++y
*
* Wich block can we reach?
*
* 1234 x
* 1....
* 2 .X.
* 3 ..
* 4 .
*
* ...
* ..X
* ...
*
*
*
*
*/
| #include <bits/stdc++.h>
using namespace std;
#define rep(it, st, en) for (int it = (st); it < (int)(en); ++it)
#define all(c) (c).begin(), (c).end()
#define debug(x) cerr << #x << " = " << x << endl
#define eb emplace_back
#define X first
#define Y second
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int h, w, n;
cin >> w >> h >> n;
int ans = w;
vector<pii> p(n);
set<pii> blocked;
rep(i, 0, n) {
cin >> p[i].X >> p[i].Y;
blocked.insert(p[i]);
}
vi reach(w + 1);
reach[1] = 1;
rep(i, 2, w + 1) {
reach[i] = reach[i - 1] + 1;
if (blocked.count({i, reach[i]}))
--reach[i];
}
for (auto q : p) {
if (reach[q.X] >= q.Y) {
ans = min(ans, q.X - 1);
}
}
cout << ans << endl;
return 0;
}
/*
* T must ++x, otherwise A will pass to and end the game.
* A has two choices:
* pass: y += 0
* move: ++y
*
* Wich block can we reach?
*
* 1234 x
* 1....
* 2 .X.
* 3 ..
* 4 .
*
* ...
* ..X
* ...
*
*
*
*
*/
| replace | 17 | 18 | 17 | 18 | 0 | |
p03203 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rfor(i, m, n) for (int i = (m); i >= (n); --i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range_it(a, l, r) (a).begin() + (l), (a).begin() + (r)
using namespace std;
using ll = long long;
using ld = long double;
using VB = vector<bool>;
using VVB = vector<VB>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VS = vector<string>;
using VD = vector<ld>;
using PII = pair<int, int>;
using VP = vector<PII>;
using PLL = pair<ll, ll>;
using VPL = vector<PLL>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQS = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = (int)1e9;
constexpr ll inf_ll = (ll)1e18, MOD = 1000000007;
constexpr ld PI = M_PI, EPS = 1e-12;
// --- input --- //
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#define fwrite_unlocked fwrite
#define fflush_unlocked _fflush_nolock
#endif
inline int gc() { return getchar_unlocked(); }
template <class T> inline void InputF(T &v) { cin >> v; }
inline void InputF(char &v) {
while (isspace(v = gc()))
;
}
inline void InputF(bool &v) {
char c;
InputF(c);
v = c != '0';
}
inline void InputF(string &v) {
v.clear();
char c;
for (InputF(c); !isspace(c); c = gc())
v += c;
}
inline void InputF(int &v) {
bool neg = false;
v = 0;
char c;
InputF(c);
if (c == '-') {
neg = true;
c = gc();
}
for (; isdigit(c); c = gc())
v = v * 10 + (c - '0');
if (neg)
v = -v;
}
inline void InputF(long long &v) {
bool neg = false;
v = 0;
char c;
InputF(c);
if (c == '-') {
neg = true;
c = gc();
}
for (; isdigit(c); c = gc())
v = v * 10 + (c - '0');
if (neg)
v = -v;
}
inline void InputF(double &v) {
double dp = 1;
bool neg = false, adp = false;
v = 0;
char c;
InputF(c);
if (c == '-') {
neg = true;
c = gc();
}
for (; isdigit(c) || c == '.'; c = gc()) {
if (c == '.')
adp = true;
else if (adp)
v += (c - '0') * (dp *= 0.1);
else
v = v * 10 + (c - '0');
}
if (neg)
v = -v;
}
template <class T, class U> inline void InputF(pair<T, U> &v) {
InputF(v.first);
InputF(v.second);
}
template <class T> inline void InputF(vector<T> &v) {
for (auto &e : v)
InputF(e);
}
template <class T> inline T InputF() {
T v;
InputF(v);
return v;
}
inline string GetLine() {
string v;
char c;
for (InputF(c); c != '\n' && c != '\0'; c = gc())
v += c;
return v;
}
struct InputV {
int n, m;
InputV(int N) : n(N), m(0) {}
InputV(pair<int, int> N) : n(N.first), m(N.second) {}
template <class T> operator vector<T>() {
vector<T> v(n);
InputF(v);
return v;
}
template <class T> operator vector<vector<T>>() {
vector<vector<T>> v(n, vector<T>(m));
InputF(v);
return v;
}
};
struct Input {
template <class T> operator T() { return InputF<T>(); }
int operator--(int) {
int v;
InputF(v);
v--;
return v;
}
InputV operator[](int n) { return InputV(n); }
InputV operator[](pair<int, int> n) { return InputV(n); }
void operator()() {}
template <class H, class... T> void operator()(H &&h, T &&...t) {
InputF(h);
operator()(forward<T>(t)...);
}
template <class T> Input &operator,(T &&v) {
InputF(v);
return *this;
}
} in;
#define input(T) InputF<T>()
#define INT input(int)
#define LL input(ll)
#define STR input(string)
#define inputs(T, ...) \
T __VA_ARGS__; \
in(__VA_ARGS__)
#define ini(...) inputs(int, __VA_ARGS__)
#define inl(...) inputs(ll, __VA_ARGS__)
#define ins(...) inputs(string, __VA_ARGS__)
// --- output --- //
struct BoolStr {
const char *t, *f;
BoolStr(const char *_t, const char *_f) : t(_t), f(_f) {}
} Yes("Yes", "No"), yes("yes", "no"), YES("YES", "NO"), Int("1", "0");
struct DivStr {
const char *d, *l;
DivStr(const char *_d, const char *_l) : d(_d), l(_l) {}
} spc(" ", "\n"), no_spc("", "\n"), end_line("\n", "\n"), comma(",", "\n"),
no_endl(" ", "");
class Output {
BoolStr B{Yes};
DivStr D{spc};
void p(int v) {
if (v < 0)
putchar_unlocked('-'), v = -v;
char b[10];
int i = 0;
while (v)
b[i++] = '0' + v % 10, v /= 10;
if (!i)
b[i++] = '0';
while (i--)
putchar_unlocked(b[i]);
}
void p(ll v) {
if (v < 0)
putchar_unlocked('-'), v = -v;
char b[20];
int i = 0;
while (v)
b[i++] = '0' + v % 10, v /= 10;
if (!i)
b[i++] = '0';
while (i--)
putchar_unlocked(b[i]);
}
void p(bool v) { p(v ? B.t : B.f); }
void p(char v) { putchar_unlocked(v); }
void p(const char *v) { fwrite_unlocked(v, 1, strlen(v), stdout); }
void p(double v) { printf("%.20f", v); }
void p(ld v) { printf("%.20Lf", v); }
template <class T> void p(const T &v) { cout << v; }
template <class T, class U> void p(const pair<T, U> &v) {
p(v.first);
p(D.d);
p(v.second);
}
template <class T> void p(const vector<T> &v) {
rep(i, sz(v)) {
if (i)
p(D.d);
p(v[i]);
}
}
template <class T> void p(const vector<vector<T>> &v) {
rep(i, sz(v)) {
if (i)
p(D.l);
p(v[i]);
}
}
public:
Output &operator()() {
p(D.l);
return *this;
}
template <class H> Output &operator()(H &&h) {
p(h);
p(D.l);
return *this;
}
template <class H, class... T> Output &operator()(H &&h, T &&...t) {
p(h);
p(D.d);
return operator()(forward<T>(t)...);
}
template <class... T> void exit(T &&...t) {
operator()(forward<T>(t)...);
std::exit(EXIT_SUCCESS);
}
Output &flush() {
fflush_unlocked(stdout);
return *this;
}
Output &set(const BoolStr &b) {
B = b;
return *this;
}
Output &set(const DivStr &d) {
D = d;
return *this;
}
Output &set(const char *t, const char *f) {
B = BoolStr(t, f);
return *this;
}
} out;
// --- step --- //
template <class T> struct Step {
class It {
T a, b, c;
public:
constexpr It() : a(T()), b(T()), c(T()) {}
constexpr It(T _b, T _c, T _s) : a(_b), b(_c), c(_s) {}
constexpr It &operator++() {
--b;
a += c;
return *this;
}
constexpr It operator++(int) {
It tmp = *this;
--b;
a += c;
return tmp;
}
constexpr const T &operator*() const { return a; }
constexpr const T *operator->() const { return &a; }
constexpr bool operator==(const It &i) const { return b == i.b; }
constexpr bool operator!=(const It &i) const { return !(b == i.b); }
constexpr T start() const { return a; }
constexpr T count() const { return b; }
constexpr T step() const { return c; }
};
constexpr Step(T b, T c, T s) : be(b, c, s) {}
constexpr It begin() const { return be; }
constexpr It end() const { return en; }
constexpr T start() const { return be.start(); }
constexpr T count() const { return be.count(); }
constexpr T step() const { return be.step(); }
constexpr T sum() const {
return start() * count() + step() * (count() * (count() - 1) / 2);
}
operator vector<T>() const { return as_vector(); }
template <class F> void each(const F &f) const {
for (T i : *this)
f(i);
}
vector<T> as_vector() const {
vector<T> res;
res.reserve(count());
each([&](T i) { res.push_back(i); });
return res;
}
template <class F, class U = decay_t<result_of_t<F(T)>>>
auto map(const F &f) const {
vector<U> res;
res.reserve(count());
each([&](T i) { res.push_back(f(i)); });
return res;
}
template <class F> vector<T> select(const F &f) const {
vector<T> res;
each([&](T i) {
if (f(i))
res.push_back(i);
});
return res;
}
template <class F> int count_if(const F &f) const {
int res = 0;
each([&](T i) {
if (f(i))
++res;
});
return res;
}
template <class F> T find_if(const F &f) const {
for (T i : *this)
if (f(i))
return i;
return 0;
}
template <class F> auto max_by(const F &f) const {
auto v = map(f);
return *max_element(v.begin(), v.end());
}
template <class F> auto min_by(const F &f) const {
auto v = map(f);
return *min_element(v.begin(), v.end());
}
template <class F, class U = decay_t<result_of_t<F(T)>>>
auto sum(const F &f) const {
U res = 0;
each([&](T i) { res += static_cast<U>(f(i)); });
return res;
}
using value_type = T;
using iterator = It;
private:
It be, en;
};
template <class T> inline constexpr auto step(T a) { return Step<T>(0, a, 1); }
template <class T> inline constexpr auto step(T a, T b) {
return Step<T>(a, b - a, 1);
}
template <class T> inline constexpr auto step(T a, T b, T c) {
return Step<T>(a, a < b ? (b - a - 1) / c + 1 : 0, c);
}
// --- functions --- //
inline namespace {
template <class T> inline void Sort(T &a) { sort(all(a)); }
template <class T> inline void RSort(T &a) { sort(rall(a)); }
template <class T> inline T Sorted(T a) {
Sort(a);
return a;
}
template <class T> inline T RSorted(T a) {
RSort(a);
return a;
}
template <class T, class F> inline void Sort(T &a, const F &f) {
sort(all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); });
}
template <class T, class F> inline void RSort(T &a, const F &f) {
sort(rall(a), [&](const auto &x, const auto &y) { return f(x) < f(y); });
}
template <class T> inline void Reverse(T &a) { reverse(all(a)); }
template <class T> inline void Unique(T &a) {
a.erase(unique(all(a)), a.end());
}
template <class T> inline void Uniq(T &a) {
Sort(a);
Unique(a);
}
template <class T> inline void Rotate(T &a, int left) {
rotate(a.begin(), a.begin() + left, a.end());
}
template <class T> inline T Reversed(T a) {
Reverse(a);
return a;
}
template <class T> inline T Uniqued(T a) {
Unique(a);
return a;
}
template <class T> inline T Uniqed(T a) {
Uniq(a);
return a;
}
template <class T> inline T Rotated(T a, int left) {
Rotate(a, left);
return a;
}
template <class T> inline auto Max(const T &a) { return *max_element(all(a)); }
template <class T> inline auto Min(const T &a) { return *min_element(all(a)); }
template <class T> inline int MaxPos(const T &a) {
return max_element(all(a)) - a.begin();
}
template <class T> inline int MinPos(const T &a) {
return min_element(all(a)) - a.begin();
}
template <class T, class F> inline auto Max(const T &a, const F &f) {
return *max_element(
all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); });
}
template <class T, class F> inline auto Min(const T &a, const F &f) {
return *min_element(
all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); });
}
template <class T, class U> inline int Count(const T &a, const U &v) {
return count(all(a), v);
}
template <class T, class F> inline int CountIf(const T &a, const F &f) {
return count_if(all(a), f);
}
template <class T, class U> inline int Find(const T &a, const U &v) {
return find(all(a), v) - a.begin();
}
template <class T, class F> inline int FindIf(const T &a, const F &f) {
return find_if(all(a), f) - a.begin();
}
template <class T, class U = typename T::value_type> inline U Sum(const T &a) {
return accumulate(all(a), U());
}
template <class T, class F> inline auto Sum(const T &v, const F &f) {
return accumulate(next(v.begin()), v.end(), f(v.front()),
[&](auto a, auto b) { return a + f(b); });
}
template <class T, class U> inline int Lower(const T &a, const U &v) {
return lower_bound(all(a), v) - a.begin();
}
template <class T, class U> inline int Upper(const T &a, const U &v) {
return upper_bound(all(a), v) - a.begin();
}
template <class T, class F> inline void RemoveIf(T &a, const F &f) {
a.erase(remove_if(all(a), f), a.end());
}
template <class F> inline auto Vector(size_t size, const F &f) {
vector<decay_t<result_of_t<F(size_t)>>> res(size);
for (size_t i = 0; i < size; ++i)
res[i] = f(i);
return res;
}
template <class T> inline auto Grid(size_t h, size_t w, const T &v = T()) {
return vector<vector<T>>(h, vector<T>(w, v));
}
template <class T> inline auto Slice(const T &v, size_t i, size_t len) {
return i < v.size() ? T(v.begin() + i, v.begin() + min(i + len, v.size()))
: T();
}
template <class T, class F> inline auto Each(const T &v, const F &f) {
for (auto &i : v)
f(i);
}
template <class T, class F> inline auto Select(const T &v, const F &f) {
T res;
for (const auto &e : v)
if (f(e))
res.push_back(e);
return res;
}
template <class T, class F> inline auto Map(const T &v, const F &f) {
vector<decay_t<result_of_t<F(typename T::value_type)>>> res(v.size());
size_t i = 0;
for (const auto &e : v)
res[i++] = f(e);
return res;
}
template <class T, class F> inline auto MapIndex(const T &v, const F &f) {
vector<decay_t<result_of_t<F(size_t, typename T::value_type)>>> res(v.size());
size_t i = 0;
for (auto it = v.begin(); it != v.end(); ++it, ++i)
res[i] = f(i, *it);
return res;
}
template <class T, class F> inline auto TrueIndex(const T &v, const F &f) {
vector<size_t> res;
for (size_t i = 0; i < v.size(); ++i)
if (f(v[i]))
res.push_back(i);
return res;
}
inline string operator*(string s, size_t n) {
string ret;
for (size_t i = 0; i < n; ++i)
ret += s;
return ret;
}
template <class T> inline T Ceil(T n, T m) { return (n + m - 1) / m; }
template <class T> inline T Ceil2(T n, T m) { return Ceil(n, m) * m; }
template <class T> inline T Tri(T n) {
return (n & 1) ? (n + 1) / 2 * n : n / 2 * (n + 1);
}
template <class T> inline T nC2(T n) {
return (n & 1) ? (n - 1) / 2 * n : n / 2 * (n - 1);
}
template <class T> inline T Mid(const T &l, const T &r) {
return l + (r - l) / 2;
}
inline int pop_count(int n) { return bitset<32>(n).count(); }
inline int pop_count(ll n) { return bitset<64>(n).count(); }
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool inRange(const T &v, const T &min, const T &max) {
return min <= v && v < max;
}
template <class T = ll> inline T BIT(int b) { return T(1) << b; }
template <class T> inline T Gcd(T n, T m) { return m ? Gcd(m, n % m) : n; }
template <class T> inline T Lcm(T n, T m) { return n / Gcd(n, m) * m; }
template <class T, class U = typename T::value_type> inline U Gcdv(const T &v) {
return accumulate(next(v.begin()), v.end(), U(*v.begin()), Gcd<U>);
}
template <class T, class U = typename T::value_type> inline U Lcmv(const T &v) {
return accumulate(next(v.begin()), v.end(), U(*v.begin()), Lcm<U>);
}
template <class T> inline T Pow(T a, T n) {
T r = 1;
while (n > 0) {
if (n & 1)
r *= a;
a *= a;
n /= 2;
}
return r;
}
template <class T> inline T Powmod(T a, T n, T m = MOD) {
T r = 1;
while (n > 0) {
if (n & 1)
r = r * a % m, n--;
else
a = a * a % m, n /= 2;
}
return r;
}
} // namespace
// --- dump --- //
#if __has_include("dump.hpp")
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
// ---------------------------------------------------------------- //
int main() {
ini(h, w, n);
vector<set<int>> s(w);
rep(i, n) {
int x = in--, y = in--;
s[x].insert(y);
}
int bottom = 0;
FOR(x, 1, w) {
if (s[x].size() && *s[x].begin() <= bottom) {
out.exit(x);
}
if (!s[x].count(bottom + 1)) {
bottom++;
}
}
out(w);
} | #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rfor(i, m, n) for (int i = (m); i >= (n); --i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range_it(a, l, r) (a).begin() + (l), (a).begin() + (r)
using namespace std;
using ll = long long;
using ld = long double;
using VB = vector<bool>;
using VVB = vector<VB>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VS = vector<string>;
using VD = vector<ld>;
using PII = pair<int, int>;
using VP = vector<PII>;
using PLL = pair<ll, ll>;
using VPL = vector<PLL>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQS = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = (int)1e9;
constexpr ll inf_ll = (ll)1e18, MOD = 1000000007;
constexpr ld PI = M_PI, EPS = 1e-12;
// --- input --- //
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#define fwrite_unlocked fwrite
#define fflush_unlocked _fflush_nolock
#endif
inline int gc() { return getchar_unlocked(); }
template <class T> inline void InputF(T &v) { cin >> v; }
inline void InputF(char &v) {
while (isspace(v = gc()))
;
}
inline void InputF(bool &v) {
char c;
InputF(c);
v = c != '0';
}
inline void InputF(string &v) {
v.clear();
char c;
for (InputF(c); !isspace(c); c = gc())
v += c;
}
inline void InputF(int &v) {
bool neg = false;
v = 0;
char c;
InputF(c);
if (c == '-') {
neg = true;
c = gc();
}
for (; isdigit(c); c = gc())
v = v * 10 + (c - '0');
if (neg)
v = -v;
}
inline void InputF(long long &v) {
bool neg = false;
v = 0;
char c;
InputF(c);
if (c == '-') {
neg = true;
c = gc();
}
for (; isdigit(c); c = gc())
v = v * 10 + (c - '0');
if (neg)
v = -v;
}
inline void InputF(double &v) {
double dp = 1;
bool neg = false, adp = false;
v = 0;
char c;
InputF(c);
if (c == '-') {
neg = true;
c = gc();
}
for (; isdigit(c) || c == '.'; c = gc()) {
if (c == '.')
adp = true;
else if (adp)
v += (c - '0') * (dp *= 0.1);
else
v = v * 10 + (c - '0');
}
if (neg)
v = -v;
}
template <class T, class U> inline void InputF(pair<T, U> &v) {
InputF(v.first);
InputF(v.second);
}
template <class T> inline void InputF(vector<T> &v) {
for (auto &e : v)
InputF(e);
}
template <class T> inline T InputF() {
T v;
InputF(v);
return v;
}
inline string GetLine() {
string v;
char c;
for (InputF(c); c != '\n' && c != '\0'; c = gc())
v += c;
return v;
}
struct InputV {
int n, m;
InputV(int N) : n(N), m(0) {}
InputV(pair<int, int> N) : n(N.first), m(N.second) {}
template <class T> operator vector<T>() {
vector<T> v(n);
InputF(v);
return v;
}
template <class T> operator vector<vector<T>>() {
vector<vector<T>> v(n, vector<T>(m));
InputF(v);
return v;
}
};
struct Input {
template <class T> operator T() { return InputF<T>(); }
int operator--(int) {
int v;
InputF(v);
v--;
return v;
}
InputV operator[](int n) { return InputV(n); }
InputV operator[](pair<int, int> n) { return InputV(n); }
void operator()() {}
template <class H, class... T> void operator()(H &&h, T &&...t) {
InputF(h);
operator()(forward<T>(t)...);
}
template <class T> Input &operator,(T &&v) {
InputF(v);
return *this;
}
} in;
#define input(T) InputF<T>()
#define INT input(int)
#define LL input(ll)
#define STR input(string)
#define inputs(T, ...) \
T __VA_ARGS__; \
in(__VA_ARGS__)
#define ini(...) inputs(int, __VA_ARGS__)
#define inl(...) inputs(ll, __VA_ARGS__)
#define ins(...) inputs(string, __VA_ARGS__)
// --- output --- //
struct BoolStr {
const char *t, *f;
BoolStr(const char *_t, const char *_f) : t(_t), f(_f) {}
} Yes("Yes", "No"), yes("yes", "no"), YES("YES", "NO"), Int("1", "0");
struct DivStr {
const char *d, *l;
DivStr(const char *_d, const char *_l) : d(_d), l(_l) {}
} spc(" ", "\n"), no_spc("", "\n"), end_line("\n", "\n"), comma(",", "\n"),
no_endl(" ", "");
class Output {
BoolStr B{Yes};
DivStr D{spc};
void p(int v) {
if (v < 0)
putchar_unlocked('-'), v = -v;
char b[10];
int i = 0;
while (v)
b[i++] = '0' + v % 10, v /= 10;
if (!i)
b[i++] = '0';
while (i--)
putchar_unlocked(b[i]);
}
void p(ll v) {
if (v < 0)
putchar_unlocked('-'), v = -v;
char b[20];
int i = 0;
while (v)
b[i++] = '0' + v % 10, v /= 10;
if (!i)
b[i++] = '0';
while (i--)
putchar_unlocked(b[i]);
}
void p(bool v) { p(v ? B.t : B.f); }
void p(char v) { putchar_unlocked(v); }
void p(const char *v) { fwrite_unlocked(v, 1, strlen(v), stdout); }
void p(double v) { printf("%.20f", v); }
void p(ld v) { printf("%.20Lf", v); }
template <class T> void p(const T &v) { cout << v; }
template <class T, class U> void p(const pair<T, U> &v) {
p(v.first);
p(D.d);
p(v.second);
}
template <class T> void p(const vector<T> &v) {
rep(i, sz(v)) {
if (i)
p(D.d);
p(v[i]);
}
}
template <class T> void p(const vector<vector<T>> &v) {
rep(i, sz(v)) {
if (i)
p(D.l);
p(v[i]);
}
}
public:
Output &operator()() {
p(D.l);
return *this;
}
template <class H> Output &operator()(H &&h) {
p(h);
p(D.l);
return *this;
}
template <class H, class... T> Output &operator()(H &&h, T &&...t) {
p(h);
p(D.d);
return operator()(forward<T>(t)...);
}
template <class... T> void exit(T &&...t) {
operator()(forward<T>(t)...);
std::exit(EXIT_SUCCESS);
}
Output &flush() {
fflush_unlocked(stdout);
return *this;
}
Output &set(const BoolStr &b) {
B = b;
return *this;
}
Output &set(const DivStr &d) {
D = d;
return *this;
}
Output &set(const char *t, const char *f) {
B = BoolStr(t, f);
return *this;
}
} out;
// --- step --- //
template <class T> struct Step {
class It {
T a, b, c;
public:
constexpr It() : a(T()), b(T()), c(T()) {}
constexpr It(T _b, T _c, T _s) : a(_b), b(_c), c(_s) {}
constexpr It &operator++() {
--b;
a += c;
return *this;
}
constexpr It operator++(int) {
It tmp = *this;
--b;
a += c;
return tmp;
}
constexpr const T &operator*() const { return a; }
constexpr const T *operator->() const { return &a; }
constexpr bool operator==(const It &i) const { return b == i.b; }
constexpr bool operator!=(const It &i) const { return !(b == i.b); }
constexpr T start() const { return a; }
constexpr T count() const { return b; }
constexpr T step() const { return c; }
};
constexpr Step(T b, T c, T s) : be(b, c, s) {}
constexpr It begin() const { return be; }
constexpr It end() const { return en; }
constexpr T start() const { return be.start(); }
constexpr T count() const { return be.count(); }
constexpr T step() const { return be.step(); }
constexpr T sum() const {
return start() * count() + step() * (count() * (count() - 1) / 2);
}
operator vector<T>() const { return as_vector(); }
template <class F> void each(const F &f) const {
for (T i : *this)
f(i);
}
vector<T> as_vector() const {
vector<T> res;
res.reserve(count());
each([&](T i) { res.push_back(i); });
return res;
}
template <class F, class U = decay_t<result_of_t<F(T)>>>
auto map(const F &f) const {
vector<U> res;
res.reserve(count());
each([&](T i) { res.push_back(f(i)); });
return res;
}
template <class F> vector<T> select(const F &f) const {
vector<T> res;
each([&](T i) {
if (f(i))
res.push_back(i);
});
return res;
}
template <class F> int count_if(const F &f) const {
int res = 0;
each([&](T i) {
if (f(i))
++res;
});
return res;
}
template <class F> T find_if(const F &f) const {
for (T i : *this)
if (f(i))
return i;
return 0;
}
template <class F> auto max_by(const F &f) const {
auto v = map(f);
return *max_element(v.begin(), v.end());
}
template <class F> auto min_by(const F &f) const {
auto v = map(f);
return *min_element(v.begin(), v.end());
}
template <class F, class U = decay_t<result_of_t<F(T)>>>
auto sum(const F &f) const {
U res = 0;
each([&](T i) { res += static_cast<U>(f(i)); });
return res;
}
using value_type = T;
using iterator = It;
private:
It be, en;
};
template <class T> inline constexpr auto step(T a) { return Step<T>(0, a, 1); }
template <class T> inline constexpr auto step(T a, T b) {
return Step<T>(a, b - a, 1);
}
template <class T> inline constexpr auto step(T a, T b, T c) {
return Step<T>(a, a < b ? (b - a - 1) / c + 1 : 0, c);
}
// --- functions --- //
inline namespace {
template <class T> inline void Sort(T &a) { sort(all(a)); }
template <class T> inline void RSort(T &a) { sort(rall(a)); }
template <class T> inline T Sorted(T a) {
Sort(a);
return a;
}
template <class T> inline T RSorted(T a) {
RSort(a);
return a;
}
template <class T, class F> inline void Sort(T &a, const F &f) {
sort(all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); });
}
template <class T, class F> inline void RSort(T &a, const F &f) {
sort(rall(a), [&](const auto &x, const auto &y) { return f(x) < f(y); });
}
template <class T> inline void Reverse(T &a) { reverse(all(a)); }
template <class T> inline void Unique(T &a) {
a.erase(unique(all(a)), a.end());
}
template <class T> inline void Uniq(T &a) {
Sort(a);
Unique(a);
}
template <class T> inline void Rotate(T &a, int left) {
rotate(a.begin(), a.begin() + left, a.end());
}
template <class T> inline T Reversed(T a) {
Reverse(a);
return a;
}
template <class T> inline T Uniqued(T a) {
Unique(a);
return a;
}
template <class T> inline T Uniqed(T a) {
Uniq(a);
return a;
}
template <class T> inline T Rotated(T a, int left) {
Rotate(a, left);
return a;
}
template <class T> inline auto Max(const T &a) { return *max_element(all(a)); }
template <class T> inline auto Min(const T &a) { return *min_element(all(a)); }
template <class T> inline int MaxPos(const T &a) {
return max_element(all(a)) - a.begin();
}
template <class T> inline int MinPos(const T &a) {
return min_element(all(a)) - a.begin();
}
template <class T, class F> inline auto Max(const T &a, const F &f) {
return *max_element(
all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); });
}
template <class T, class F> inline auto Min(const T &a, const F &f) {
return *min_element(
all(a), [&](const auto &x, const auto &y) { return f(x) < f(y); });
}
template <class T, class U> inline int Count(const T &a, const U &v) {
return count(all(a), v);
}
template <class T, class F> inline int CountIf(const T &a, const F &f) {
return count_if(all(a), f);
}
template <class T, class U> inline int Find(const T &a, const U &v) {
return find(all(a), v) - a.begin();
}
template <class T, class F> inline int FindIf(const T &a, const F &f) {
return find_if(all(a), f) - a.begin();
}
template <class T, class U = typename T::value_type> inline U Sum(const T &a) {
return accumulate(all(a), U());
}
template <class T, class F> inline auto Sum(const T &v, const F &f) {
return accumulate(next(v.begin()), v.end(), f(v.front()),
[&](auto a, auto b) { return a + f(b); });
}
template <class T, class U> inline int Lower(const T &a, const U &v) {
return lower_bound(all(a), v) - a.begin();
}
template <class T, class U> inline int Upper(const T &a, const U &v) {
return upper_bound(all(a), v) - a.begin();
}
template <class T, class F> inline void RemoveIf(T &a, const F &f) {
a.erase(remove_if(all(a), f), a.end());
}
template <class F> inline auto Vector(size_t size, const F &f) {
vector<decay_t<result_of_t<F(size_t)>>> res(size);
for (size_t i = 0; i < size; ++i)
res[i] = f(i);
return res;
}
template <class T> inline auto Grid(size_t h, size_t w, const T &v = T()) {
return vector<vector<T>>(h, vector<T>(w, v));
}
template <class T> inline auto Slice(const T &v, size_t i, size_t len) {
return i < v.size() ? T(v.begin() + i, v.begin() + min(i + len, v.size()))
: T();
}
template <class T, class F> inline auto Each(const T &v, const F &f) {
for (auto &i : v)
f(i);
}
template <class T, class F> inline auto Select(const T &v, const F &f) {
T res;
for (const auto &e : v)
if (f(e))
res.push_back(e);
return res;
}
template <class T, class F> inline auto Map(const T &v, const F &f) {
vector<decay_t<result_of_t<F(typename T::value_type)>>> res(v.size());
size_t i = 0;
for (const auto &e : v)
res[i++] = f(e);
return res;
}
template <class T, class F> inline auto MapIndex(const T &v, const F &f) {
vector<decay_t<result_of_t<F(size_t, typename T::value_type)>>> res(v.size());
size_t i = 0;
for (auto it = v.begin(); it != v.end(); ++it, ++i)
res[i] = f(i, *it);
return res;
}
template <class T, class F> inline auto TrueIndex(const T &v, const F &f) {
vector<size_t> res;
for (size_t i = 0; i < v.size(); ++i)
if (f(v[i]))
res.push_back(i);
return res;
}
inline string operator*(string s, size_t n) {
string ret;
for (size_t i = 0; i < n; ++i)
ret += s;
return ret;
}
template <class T> inline T Ceil(T n, T m) { return (n + m - 1) / m; }
template <class T> inline T Ceil2(T n, T m) { return Ceil(n, m) * m; }
template <class T> inline T Tri(T n) {
return (n & 1) ? (n + 1) / 2 * n : n / 2 * (n + 1);
}
template <class T> inline T nC2(T n) {
return (n & 1) ? (n - 1) / 2 * n : n / 2 * (n - 1);
}
template <class T> inline T Mid(const T &l, const T &r) {
return l + (r - l) / 2;
}
inline int pop_count(int n) { return bitset<32>(n).count(); }
inline int pop_count(ll n) { return bitset<64>(n).count(); }
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool inRange(const T &v, const T &min, const T &max) {
return min <= v && v < max;
}
template <class T = ll> inline T BIT(int b) { return T(1) << b; }
template <class T> inline T Gcd(T n, T m) { return m ? Gcd(m, n % m) : n; }
template <class T> inline T Lcm(T n, T m) { return n / Gcd(n, m) * m; }
template <class T, class U = typename T::value_type> inline U Gcdv(const T &v) {
return accumulate(next(v.begin()), v.end(), U(*v.begin()), Gcd<U>);
}
template <class T, class U = typename T::value_type> inline U Lcmv(const T &v) {
return accumulate(next(v.begin()), v.end(), U(*v.begin()), Lcm<U>);
}
template <class T> inline T Pow(T a, T n) {
T r = 1;
while (n > 0) {
if (n & 1)
r *= a;
a *= a;
n /= 2;
}
return r;
}
template <class T> inline T Powmod(T a, T n, T m = MOD) {
T r = 1;
while (n > 0) {
if (n & 1)
r = r * a % m, n--;
else
a = a * a % m, n /= 2;
}
return r;
}
} // namespace
// --- dump --- //
#if __has_include("dump.hpp")
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
// ---------------------------------------------------------------- //
int main() {
ini(w, h, n);
vector<set<int>> s(w);
rep(i, n) {
int x = in--, y = in--;
s[x].insert(y);
}
int bottom = 0;
FOR(x, 1, w) {
if (s[x].size() && *s[x].begin() <= bottom) {
out.exit(x);
}
if (!s[x].count(bottom + 1)) {
bottom++;
}
}
out(w);
} | replace | 587 | 588 | 587 | 588 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int H, W, N;
int main() {
cin >> H >> W >> N;
vector<vector<int>> G(H + 1);
vector<set<int>> A(H + 1);
for (int i = 0; i <= H; i++) {
G[i].push_back(W);
A[i].insert(W);
}
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
G[y].push_back(x);
A[y].insert(x);
}
for (int i = 0; i < H; i++)
sort(G[i].begin(), G[i].end());
int a = 0;
int ans = W;
for (int i = 0; i < H; i++) {
auto itr = upper_bound(G[i].begin(), G[i].end(), a);
int k = distance(G[i].begin(), itr);
if (G[i][k] < ans)
ans = G[i][k];
bool x = false;
int b = a;
for (int j = b + 1; j < G[i][k]; j++)
if (!A[i + 1].count(j)) {
a = j;
x = true;
break;
}
if (!x || ans < a)
break;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int H, W, N;
int main() {
cin >> W >> H >> N;
vector<vector<int>> G(H + 1);
vector<set<int>> A(H + 1);
for (int i = 0; i <= H; i++) {
G[i].push_back(W);
A[i].insert(W);
}
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
G[y].push_back(x);
A[y].insert(x);
}
for (int i = 0; i < H; i++)
sort(G[i].begin(), G[i].end());
int a = 0;
int ans = W;
for (int i = 0; i < H; i++) {
auto itr = upper_bound(G[i].begin(), G[i].end(), a);
int k = distance(G[i].begin(), itr);
if (G[i][k] < ans)
ans = G[i][k];
bool x = false;
int b = a;
for (int j = b + 1; j < G[i][k]; j++)
if (!A[i + 1].count(j)) {
a = j;
x = true;
break;
}
if (!x || ans < a)
break;
}
cout << ans << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define NDEBUG
#include <cassert>
typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> llll;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;
#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define FOR(var, from, to) for (int var = (from); var <= (to); ++var)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define rep1(var, n) for (int var = 1; var <= (n); ++var)
#define repC2(vari, varj, n) \
for (int vari = 0; vari < (n)-1; ++vari) \
for (int varj = vari + 1; varj < (n); ++varj)
#define repC3(vari, varj, vark, n) \
for (int vari = 0; vari < (n)-2; ++vari) \
for (int varj = vari + 1; varj < (n)-1; ++varj) \
for (int vark = varj + 1; vark < (n); ++vark)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define found(s, e) ((s).find(e) != (s).end())
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define mid(x, y) ((x) + ((y) - (x)) / 2)
#define IN(x, a, b) ((a) <= (x) && (x) <= (b))
#define cons make_pair
#define clamp(v, lo, hi) min(max(v, lo), hi)
template <class T> inline void amin(T &a, T const &b) { a = min(a, b); }
template <class T> inline void amax(T &a, T const &b) { a = max(a, b); }
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) {
while (a)
swap(a, b %= a);
return b;
}
template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; }
int solve(int H, int W, int N, vi &x, vi &y) {
vvi ps(H);
rep(i, N) {
if (x[i] >= y[i]) {
ps[x[i]].pb(y[i]);
}
}
int rightmost = 0;
int best = H;
rep(i, H) {
if (ps[1 + i].empty()) {
rightmost++;
} else {
sort(ALL(ps[1 + i]));
if (ps[1 + i][0] <= rightmost) {
best = 1 + i;
break;
} else if (rightmost + 1 == ps[1 + i][0]) {
;
} else {
rightmost++;
}
}
}
return best;
}
int main() {
int H, W, N;
scanf("%d%d%d", &H, &W, &N);
vi x(N), y(N);
rep(i, N) {
scanf("%d%d", &x[i], &y[i]);
--x[i];
--y[i];
}
cout << solve(H, W, N, x, y) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define NDEBUG
#include <cassert>
typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> llll;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;
#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define FOR(var, from, to) for (int var = (from); var <= (to); ++var)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define rep1(var, n) for (int var = 1; var <= (n); ++var)
#define repC2(vari, varj, n) \
for (int vari = 0; vari < (n)-1; ++vari) \
for (int varj = vari + 1; varj < (n); ++varj)
#define repC3(vari, varj, vark, n) \
for (int vari = 0; vari < (n)-2; ++vari) \
for (int varj = vari + 1; varj < (n)-1; ++varj) \
for (int vark = varj + 1; vark < (n); ++vark)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define found(s, e) ((s).find(e) != (s).end())
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define mid(x, y) ((x) + ((y) - (x)) / 2)
#define IN(x, a, b) ((a) <= (x) && (x) <= (b))
#define cons make_pair
#define clamp(v, lo, hi) min(max(v, lo), hi)
template <class T> inline void amin(T &a, T const &b) { a = min(a, b); }
template <class T> inline void amax(T &a, T const &b) { a = max(a, b); }
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) {
while (a)
swap(a, b %= a);
return b;
}
template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; }
int solve(int H, int W, int N, vi &x, vi &y) {
vvi ps(H + 1);
rep(i, N) {
if (x[i] >= y[i]) {
ps[x[i]].pb(y[i]);
}
}
int rightmost = 0;
int best = H;
rep(i, H) {
if (ps[1 + i].empty()) {
rightmost++;
} else {
sort(ALL(ps[1 + i]));
if (ps[1 + i][0] <= rightmost) {
best = 1 + i;
break;
} else if (rightmost + 1 == ps[1 + i][0]) {
;
} else {
rightmost++;
}
}
}
return best;
}
int main() {
int H, W, N;
scanf("%d%d%d", &H, &W, &N);
vi x(N), y(N);
rep(i, N) {
scanf("%d%d", &x[i], &y[i]);
--x[i];
--y[i];
}
cout << solve(H, W, N, x, y) << endl;
return 0;
}
| replace | 68 | 69 | 68 | 69 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define repeat(i, n) for (long long i = 0; (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x, n) \
for (long long i = 0; (i) < (n); ++(i)) \
cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x, n) \
for (long long i = 0; (i) < (n); ++(i)) \
cerr << #x << "[" << i << "]: " << x[i].first << " " << x[i].second << '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9 + 7;
int main() {
int H, W, N;
cin >> H >> W >> N;
vector<vll> array(H);
repeat(i, N) {
int x, y;
cin >> x >> y;
x--;
y--;
array[y].push_back(x);
}
repeat(i, W) {
array[i].push_back(H);
sort(array[i].begin(), array[i].end());
}
ll ans = H;
ll y = 0;
repeat(i, H) {
// debug(i);
// debug(y);
int idx =
lower_bound(array[y].begin(), array[y].end(), i + 1) - array[y].begin();
// debug(array[y][idx]);
ans = min(ans, array[y][idx]);
if (array[y][idx] == i + 1) {
break;
}
// debug(ans);
if (y + 1 >= W)
break;
idx = lower_bound(array[y + 1].begin(), array[y + 1].end(), i + 1) -
array[y + 1].begin();
if (array[y + 1][idx] != i + 1) {
y++;
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define repeat(i, n) for (long long i = 0; (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x, n) \
for (long long i = 0; (i) < (n); ++(i)) \
cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x, n) \
for (long long i = 0; (i) < (n); ++(i)) \
cerr << #x << "[" << i << "]: " << x[i].first << " " << x[i].second << '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9 + 7;
int main() {
int H, W, N;
cin >> H >> W >> N;
vector<vll> array(W);
repeat(i, N) {
int x, y;
cin >> x >> y;
x--;
y--;
array[y].push_back(x);
}
repeat(i, W) {
array[i].push_back(H);
sort(array[i].begin(), array[i].end());
}
ll ans = H;
ll y = 0;
repeat(i, H) {
// debug(i);
// debug(y);
int idx =
lower_bound(array[y].begin(), array[y].end(), i + 1) - array[y].begin();
// debug(array[y][idx]);
ans = min(ans, array[y][idx]);
if (array[y][idx] == i + 1) {
break;
}
// debug(ans);
if (y + 1 >= W)
break;
idx = lower_bound(array[y + 1].begin(), array[y + 1].end(), i + 1) -
array[y + 1].begin();
if (array[y + 1][idx] != i + 1) {
y++;
}
}
cout << ans << endl;
return 0;
}
| replace | 39 | 40 | 39 | 40 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cstdio>
#include <set>
#include <vector>
using namespace std;
#define sz(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
const int N = (int)3e5 + 10;
int h, w, n, x, y;
vector<int> bad[N];
int main() {
scanf("%d%d%d", &h, &w, &n);
for (int i = 0; i < h; ++i) {
bad[i].pb(0);
bad[i].pb(w + 1);
}
for (int i = 1; i <= w; ++i) {
bad[h + 1].pb(i);
}
for (int i = 0; i < n; ++i) {
scanf("%d%d", &x, &y);
bad[x].pb(y);
}
vector<pair<int, int>> good;
good.pb(mp(1, 0));
for (int x = 1; x <= h; ++x) {
{
for (int i = 0; i < sz(good); ++i) {
good[i].sc = min(good[i].sc + 1, w);
}
vector<pair<int, int>> ngood;
for (int i = 0; i < sz(good);) {
int j = i;
while ((j + 1 < sz(good)) && (good[j + 1].fs == good[j].sc + 1)) {
++j;
}
ngood.pb(mp(good[i].fs, good[j].sc));
i = j + 1;
}
good = ngood;
}
{
vector<pair<int, int>> ngood;
sort(bad[x].begin(), bad[x].end());
for (int i = 0, j = 0; i < sz(good); ++i) {
int l = good[i].fs, r = good[i].sc;
while (l <= r) {
while ((j < sz(bad[x])) && (bad[x][j] < good[i].fs)) {
++j;
}
if ((j < sz(bad[x])) && (bad[x][j] >= l) && (bad[x][j] <= r)) {
if (l < bad[x][j]) {
ngood.pb(mp(l, bad[x][j] - 1));
}
l = bad[x][j] + 1;
} else {
ngood.pb(mp(l, r));
break;
}
}
}
good = ngood;
}
for (int i = 0; i < sz(bad[x + 1]); ++i) {
int y = bad[x + 1][i];
int it =
upper_bound(good.begin(), good.end(), mp(y, -1)) - good.begin() - 1;
if ((it >= 0) && (good[it].fs <= y) && (y <= good[it].sc)) {
printf("%d\n", x);
return 0;
}
}
}
assert(false);
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cstdio>
#include <set>
#include <vector>
using namespace std;
#define sz(a) ((int)(a).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
const int N = (int)3e5 + 10;
int h, w, n, x, y;
vector<int> bad[N];
int main() {
scanf("%d%d%d", &h, &w, &n);
for (int i = 0; i < h; ++i) {
bad[i].pb(0);
bad[i].pb(w + 1);
}
for (int i = 1; i <= w; ++i) {
bad[h + 1].pb(i);
}
for (int i = 0; i < n; ++i) {
scanf("%d%d", &x, &y);
bad[x].pb(y);
}
vector<pair<int, int>> good;
good.pb(mp(1, 0));
for (int x = 1; x <= h; ++x) {
{
for (int i = 0; i < sz(good); ++i) {
good[i].sc = min(good[i].sc + 1, w);
}
vector<pair<int, int>> ngood;
for (int i = 0; i < sz(good);) {
int j = i;
while ((j + 1 < sz(good)) && (good[j + 1].fs == good[j].sc + 1)) {
++j;
}
ngood.pb(mp(good[i].fs, good[j].sc));
i = j + 1;
}
good = ngood;
}
{
vector<pair<int, int>> ngood;
sort(bad[x].begin(), bad[x].end());
for (int i = 0, j = 0; i < sz(good); ++i) {
int l = good[i].fs, r = good[i].sc;
while (l <= r) {
while ((j < sz(bad[x])) && (bad[x][j] < good[i].fs)) {
++j;
}
if ((j < sz(bad[x])) && (bad[x][j] >= l) && (bad[x][j] <= r)) {
if (l < bad[x][j]) {
ngood.pb(mp(l, bad[x][j] - 1));
}
l = bad[x][j] + 1;
} else {
ngood.pb(mp(l, r));
break;
}
}
}
good = ngood;
}
for (int i = 0; i < sz(bad[x + 1]); ++i) {
int y = bad[x + 1][i];
int it =
(upper_bound(good.begin(), good.end(), mp(y, w)) - good.begin()) - 1;
if ((it >= 0) && (good[it].fs <= y) && (y <= good[it].sc)) {
printf("%d\n", x);
return 0;
}
}
}
assert(false);
return 0;
}
| replace | 72 | 73 | 72 | 73 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, m;
int i, j, k;
string str;
int h, w;
int main() {
cin >> h >> w >> n;
vector<pair<int, int>> b(n);
vector<vector<int>> f(w);
for (i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
b[i] = make_pair(x, y);
}
sort(b.begin(), b.end());
for (i = 0; i < n; i++) {
f[b[i].first].push_back(b[i].second);
}
int s = 1;
int a = w;
for (i = 1; i < w; i++) {
if (f[i].size() > 0) {
if (f[i][0] < s) {
a = i;
break;
}
if (f[i][0] == s)
s--;
}
s++;
}
cout << a << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int n, m;
int i, j, k;
string str;
int h, w;
int main() {
cin >> w >> h >> n;
vector<pair<int, int>> b(n);
vector<vector<int>> f(w);
for (i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
b[i] = make_pair(x, y);
}
sort(b.begin(), b.end());
for (i = 0; i < n; i++) {
f[b[i].first].push_back(b[i].second);
}
int s = 1;
int a = w;
for (i = 1; i < w; i++) {
if (f[i].size() > 0) {
if (f[i][0] < s) {
a = i;
break;
}
if (f[i][0] == s)
s--;
}
s++;
}
cout << a << endl;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
namespace {
using Integer = long long; //__int128;
template <class T, class S> istream &operator>>(istream &is, pair<T, S> &p) {
return is >> p.first >> p.second;
}
template <class T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &val : vec)
is >> val;
return is;
}
template <class T> istream &operator,(istream &is, T &val) { return is >> val; }
template <class T, class S>
ostream &operator<<(ostream &os, const pair<T, S> &p) {
return os << p.first << " " << p.second;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i == vec.size() - 1 ? "" : " ");
return os;
}
template <class T> ostream &operator,(ostream &os, const T &val) {
return os << " " << val;
}
template <class H> void print(const H &head) { cout << head; }
template <class H, class... T> void print(const H &head, const T &...tail) {
cout << head << " ";
print(tail...);
}
template <class... T> void println(const T &...values) {
print(values...);
cout << endl;
}
template <class H> void eprint(const H &head) { cerr << head; }
template <class H, class... T> void eprint(const H &head, const T &...tail) {
cerr << head << " ";
eprint(tail...);
}
template <class... T> void eprintln(const T &...values) {
eprint(values...);
cerr << endl;
}
class range {
Integer start_, end_, step_;
public:
struct range_iterator {
Integer val, step_;
range_iterator(Integer v, Integer step) : val(v), step_(step) {}
Integer operator*() { return val; }
void operator++() { val += step_; }
bool operator!=(range_iterator &x) {
return step_ > 0 ? val < x.val : val > x.val;
}
};
range(Integer len) : start_(0), end_(len), step_(1) {}
range(Integer start, Integer end) : start_(start), end_(end), step_(1) {}
range(Integer start, Integer end, Integer step)
: start_(start), end_(end), step_(step) {}
range_iterator begin() { return range_iterator(start_, step_); }
range_iterator end() { return range_iterator(end_, step_); }
};
inline string operator"" _s(const char *str, size_t size) {
return move(string(str));
}
constexpr Integer my_pow(Integer x, Integer k, Integer z = 1) {
return k == 0 ? z
: k == 1 ? z * x
: (k & 1) ? my_pow(x * x, k >> 1, z * x)
: my_pow(x * x, k >> 1, z);
}
constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z = 1) {
return k == 0 ? z % M
: k == 1 ? z * x % M
: (k & 1) ? my_pow_mod(x * x % M, k >> 1, M, z * x % M)
: my_pow_mod(x * x % M, k >> 1, M, z);
}
constexpr unsigned long long operator"" _ten(unsigned long long value) {
return my_pow(10, value);
}
inline int k_bit(Integer x, int k) { return (x >> k) & 1; } // 0-indexed
mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count());
template <class T> string join(const vector<T> &v, const string &sep) {
stringstream ss;
for (size_t i = 0; i < v.size(); i++) {
if (i > 0)
ss << sep;
ss << v[i];
}
return ss.str();
}
inline string operator*(string s, int k) {
string ret;
while (k) {
if (k & 1)
ret += s;
s += s;
k >>= 1;
}
return ret;
}
} // namespace
constexpr long long mod = 9_ten + 7;
int main() {
int h, w, n;
cin >> h, w, n;
vector<pair<int, int>> p(n);
cin >> p;
sort(p.begin(), p.end());
vector<vector<int>> v(w + 10);
for (auto b : p) {
v[b.first].push_back(b.second);
}
for (int i = 1; i <= w; i++) {
v[i].push_back(h + 1);
sort(v[i].begin(), v[i].end());
}
vector<int> ub(w + 10, 0);
vector<int> unko(h + 10, 1e8);
int y = 1, x = 1;
ub[1] = 1;
unko[1] = 1;
for (; x < w; x++) {
if (binary_search(v[x + 1].begin(), v[x + 1].end(), y + 1)) {
} else if (y + 1 <= h) {
y++;
}
ub[x + 1] = y;
unko[y] = min(unko[y], x + 1);
}
int ans = w;
for (int xx = 1; xx <= w; xx++) {
for (auto yy : v[xx]) {
if (yy > h)
continue;
if (unko[yy] >= xx)
continue;
ans = min(ans, xx - 1);
}
}
println(ans);
return 0;
}
| #include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
namespace {
using Integer = long long; //__int128;
template <class T, class S> istream &operator>>(istream &is, pair<T, S> &p) {
return is >> p.first >> p.second;
}
template <class T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &val : vec)
is >> val;
return is;
}
template <class T> istream &operator,(istream &is, T &val) { return is >> val; }
template <class T, class S>
ostream &operator<<(ostream &os, const pair<T, S> &p) {
return os << p.first << " " << p.second;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (size_t i = 0; i < vec.size(); i++)
os << vec[i] << (i == vec.size() - 1 ? "" : " ");
return os;
}
template <class T> ostream &operator,(ostream &os, const T &val) {
return os << " " << val;
}
template <class H> void print(const H &head) { cout << head; }
template <class H, class... T> void print(const H &head, const T &...tail) {
cout << head << " ";
print(tail...);
}
template <class... T> void println(const T &...values) {
print(values...);
cout << endl;
}
template <class H> void eprint(const H &head) { cerr << head; }
template <class H, class... T> void eprint(const H &head, const T &...tail) {
cerr << head << " ";
eprint(tail...);
}
template <class... T> void eprintln(const T &...values) {
eprint(values...);
cerr << endl;
}
class range {
Integer start_, end_, step_;
public:
struct range_iterator {
Integer val, step_;
range_iterator(Integer v, Integer step) : val(v), step_(step) {}
Integer operator*() { return val; }
void operator++() { val += step_; }
bool operator!=(range_iterator &x) {
return step_ > 0 ? val < x.val : val > x.val;
}
};
range(Integer len) : start_(0), end_(len), step_(1) {}
range(Integer start, Integer end) : start_(start), end_(end), step_(1) {}
range(Integer start, Integer end, Integer step)
: start_(start), end_(end), step_(step) {}
range_iterator begin() { return range_iterator(start_, step_); }
range_iterator end() { return range_iterator(end_, step_); }
};
inline string operator"" _s(const char *str, size_t size) {
return move(string(str));
}
constexpr Integer my_pow(Integer x, Integer k, Integer z = 1) {
return k == 0 ? z
: k == 1 ? z * x
: (k & 1) ? my_pow(x * x, k >> 1, z * x)
: my_pow(x * x, k >> 1, z);
}
constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z = 1) {
return k == 0 ? z % M
: k == 1 ? z * x % M
: (k & 1) ? my_pow_mod(x * x % M, k >> 1, M, z * x % M)
: my_pow_mod(x * x % M, k >> 1, M, z);
}
constexpr unsigned long long operator"" _ten(unsigned long long value) {
return my_pow(10, value);
}
inline int k_bit(Integer x, int k) { return (x >> k) & 1; } // 0-indexed
mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count());
template <class T> string join(const vector<T> &v, const string &sep) {
stringstream ss;
for (size_t i = 0; i < v.size(); i++) {
if (i > 0)
ss << sep;
ss << v[i];
}
return ss.str();
}
inline string operator*(string s, int k) {
string ret;
while (k) {
if (k & 1)
ret += s;
s += s;
k >>= 1;
}
return ret;
}
} // namespace
constexpr long long mod = 9_ten + 7;
int main() {
int h, w, n;
cin >> w, h, n;
vector<pair<int, int>> p(n);
cin >> p;
sort(p.begin(), p.end());
vector<vector<int>> v(w + 10);
for (auto b : p) {
v[b.first].push_back(b.second);
}
for (int i = 1; i <= w; i++) {
v[i].push_back(h + 1);
sort(v[i].begin(), v[i].end());
}
vector<int> ub(w + 10, 0);
vector<int> unko(h + 10, 1e8);
int y = 1, x = 1;
ub[1] = 1;
unko[1] = 1;
for (; x < w; x++) {
if (binary_search(v[x + 1].begin(), v[x + 1].end(), y + 1)) {
} else if (y + 1 <= h) {
y++;
}
ub[x + 1] = y;
unko[y] = min(unko[y], x + 1);
}
int ans = w;
for (int xx = 1; xx <= w; xx++) {
for (auto yy : v[xx]) {
if (yy > h)
continue;
if (unko[yy] >= xx)
continue;
ans = min(ans, xx - 1);
}
}
println(ans);
return 0;
}
| replace | 134 | 135 | 134 | 135 | 0 | |
p03203 | C++ | Runtime Error | #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, w;
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[505][505];
ll dp[300][300];
ll kyo;
int main() {
cin >> h >> w >> n;
for (i = 0; i < n; i++) {
cin >> a >> b;
x[i] = 300000 * a + b;
}
for (i = n; i < h + n; i++) {
x[i] = 300000 * (i - n) + w + 1;
}
for (i = n + h; i < n + h + w; i++) {
x[i] = 300000 * (h + 1) + (i - n - h);
}
n = n + h + w;
sort(x, x + n);
a = 1;
b = 1;
while (1) {
// 下に行けるか判定
// pe(a);p(b);
c = lb(x, x + n, (a + 1) * 300000 + 1 + b) -
lb(x, x + n, (a + 1) * 300000 + 1);
if (c >= 1) {
break;
} else {
a++;
}
// 右に動いてみる
c = lb(x, x + n, a * 300000 + b + 2) - lb(x, x + n, a * 300000 + b + 1);
if (c == 0)
b++;
}
p(a);
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, w;
ll a, b, c, d, e, g, h, r;
ll l, ans, num;
ll x[800005], y[500005], z[500005];
bool dame, flag;
char s[500005], t[500005];
bool used[505][505];
ll dp[300][300];
ll kyo;
int main() {
cin >> h >> w >> n;
for (i = 0; i < n; i++) {
cin >> a >> b;
x[i] = 300000 * a + b;
}
for (i = n; i < h + n; i++) {
x[i] = 300000 * (i - n) + w + 1;
}
for (i = n + h; i < n + h + w; i++) {
x[i] = 300000 * (h + 1) + (i - n - h);
}
n = n + h + w;
sort(x, x + n);
a = 1;
b = 1;
while (1) {
// 下に行けるか判定
// pe(a);p(b);
c = lb(x, x + n, (a + 1) * 300000 + 1 + b) -
lb(x, x + n, (a + 1) * 300000 + 1);
if (c >= 1) {
break;
} else {
a++;
}
// 右に動いてみる
c = lb(x, x + n, a * 300000 + b + 2) - lb(x, x + n, a * 300000 + b + 1);
if (c == 0)
b++;
}
p(a);
return 0;
} | replace | 83 | 84 | 83 | 84 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <set>
int const maxN = 21;
int op[maxN];
std::set<int> ops[maxN];
int main() {
int h, w, n;
scanf("%d%d%d", &h, &w, &n);
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
ops[y].emplace(x);
}
int offset = 0;
for (int i = 1; i <= w; i++) {
while (ops[i].count(i + offset) > 0)
offset++;
if (i + offset > h || ops[i].lower_bound(i + offset) == ops[i].end()) {
op[i] = h;
} else {
op[i] = *(ops[i].lower_bound(i + offset)) - 1;
}
}
std::sort(op + 1, op + w + 1);
printf("%d", op[1]);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <set>
int const maxN = 200001;
int op[maxN];
std::set<int> ops[maxN];
int main() {
int h, w, n;
scanf("%d%d%d", &h, &w, &n);
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
ops[y].emplace(x);
}
int offset = 0;
for (int i = 1; i <= w; i++) {
while (ops[i].count(i + offset) > 0)
offset++;
if (i + offset > h || ops[i].lower_bound(i + offset) == ops[i].end()) {
op[i] = h;
} else {
op[i] = *(ops[i].lower_bound(i + offset)) - 1;
}
}
std::sort(op + 1, op + w + 1);
printf("%d", op[1]);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 1LL << 50;
set<ll> s[100010];
int main() {
ll h, w, n;
cin >> h >> w >> n;
// vector<vector<char>> v(h+1, vector<char>(w+1,'.') );
map<pair<ll, ll>, bool> m;
rep(i, n) {
ll x, y;
cin >> x >> y;
// v[x-1][y-1]='#';
m[{x - 1, y - 1}] = 1;
s[y - 1].insert(x - 1);
}
// rep(i,w)v[i][w]='#';
rep(i, h) m[{i, w}] = 1;
// rep(i,h){v[h][i]='#';s[i].insert(h);}
rep(i, w) {
m[{h, i}] = 1;
s[i].insert(h);
}
ll x = 0, y = 0;
/* rep(i,h+1){
rep(j,w+1)cout << v[i][j];
cout << endl;
} */
rep(i, h) {
ans = min(ans, *upper_bound(s[y].begin(), s[y].end(), x));
// if(v[x+1][y]=='#')break;
if (m.find({x + 1, y}) != m.end())
break;
x++;
// if(v[x][y+1]=='.')y++;
if (m.find({x, y + 1}) == m.end())
y++;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 1LL << 50;
set<ll> s[200010];
int main() {
ll h, w, n;
cin >> h >> w >> n;
// vector<vector<char>> v(h+1, vector<char>(w+1,'.') );
map<pair<ll, ll>, bool> m;
rep(i, n) {
ll x, y;
cin >> x >> y;
// v[x-1][y-1]='#';
m[{x - 1, y - 1}] = 1;
s[y - 1].insert(x - 1);
}
// rep(i,w)v[i][w]='#';
rep(i, h) m[{i, w}] = 1;
// rep(i,h){v[h][i]='#';s[i].insert(h);}
rep(i, w) {
m[{h, i}] = 1;
s[i].insert(h);
}
ll x = 0, y = 0;
/* rep(i,h+1){
rep(j,w+1)cout << v[i][j];
cout << endl;
} */
rep(i, h) {
ans = min(ans, *upper_bound(s[y].begin(), s[y].end(), x));
// if(v[x+1][y]=='#')break;
if (m.find({x + 1, y}) != m.end())
break;
x++;
// if(v[x][y+1]=='.')y++;
if (m.find({x, y + 1}) == m.end())
y++;
}
cout << ans << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using pii = pair<int, int>;
int main() {
ios_base::sync_with_stdio(false);
int h, w, n;
cin >> h >> w >> n;
vector<pii> objs;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
--x;
--y;
objs.emplace_back(y, x);
}
sort(objs.begin(), objs.end());
const int init =
lower_bound(objs.begin(), objs.end(), pii(1, 0)) - objs.begin();
vector<int> leftmost(h, w);
leftmost[0] = 0;
for (int y = 1, i = init; y < h; ++y) {
leftmost[y] = leftmost[y - 1] + 1;
while (i < n && objs[i].first == y) {
if (objs[i].second == leftmost[y]) {
++leftmost[y];
}
++i;
}
leftmost[y] = min(w - 1, leftmost[y]);
}
int answer = w;
for (const auto &p : objs) {
const int y = p.first, x = p.second;
if (x - 1 < leftmost[y]) {
continue;
}
answer = min(answer, x);
}
cout << answer << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using pii = pair<int, int>;
int main() {
ios_base::sync_with_stdio(false);
int h, w, n;
cin >> w >> h >> n;
vector<pii> objs;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
--x;
--y;
objs.emplace_back(y, x);
}
sort(objs.begin(), objs.end());
const int init =
lower_bound(objs.begin(), objs.end(), pii(1, 0)) - objs.begin();
vector<int> leftmost(h, w);
leftmost[0] = 0;
for (int y = 1, i = init; y < h; ++y) {
leftmost[y] = leftmost[y - 1] + 1;
while (i < n && objs[i].first == y) {
if (objs[i].second == leftmost[y]) {
++leftmost[y];
}
++i;
}
leftmost[y] = min(w - 1, leftmost[y]);
}
int answer = w;
for (const auto &p : objs) {
const int y = p.first, x = p.second;
if (x - 1 < leftmost[y]) {
continue;
}
answer = min(answer, x);
}
cout << answer << endl;
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> kabe[200005];
int main() {
ll h, w, n;
cin >> h >> w >> n;
ll ans = h;
for (int i = 0; i < n; i++) {
ll x, y;
cin >> x >> y;
kabe[x].push_back(y);
}
for (int i = 1; i <= h; i++) {
kabe[i].push_back(17441744);
sort(kabe[i].begin(), kabe[i].end());
}
ll c = 0;
for (int i = 1; i <= w; i++) {
if (i - c - 1 >= kabe[i][0]) {
cout << i - 1 << endl;
return 0;
} else {
ll ky = *(lower_bound(kabe[i].begin(), kabe[i].end(), i - c));
if (ky == i - c)
c++;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> kabe[200005];
int main() {
ll h, w, n;
cin >> h >> w >> n;
ll ans = h;
for (int i = 0; i < n; i++) {
ll x, y;
cin >> x >> y;
kabe[x].push_back(y);
}
for (int i = 1; i <= h; i++) {
kabe[i].push_back(17441744);
sort(kabe[i].begin(), kabe[i].end());
}
ll c = 0;
for (int i = 1; i <= h; i++) {
if (i - c - 1 >= kabe[i][0]) {
cout << i - 1 << endl;
return 0;
} else {
ll ky = *(lower_bound(kabe[i].begin(), kabe[i].end(), i - c));
if (ky == i - c)
c++;
}
}
cout << ans << endl;
}
| replace | 18 | 19 | 18 | 19 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod = 10007;
const llint big = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U> bool mineq(T &a, U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class U> bool maxeq(T &a, U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
llint gcd(llint a, llint b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
if (a == 0) {
return b;
}
return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(vector<T> &ar, T in) {
return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(vector<T> &ar, T in) {
return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int H, W, i, n;
cin >> H >> W >> n;
vector<vector<int>> zyama(W + 2);
for (i = 1; i <= H; i++) {
zyama[W + 1].pub(i);
}
for (i = 1; i <= W; i++) {
zyama[i].pub(H + 1);
}
for (i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
zyama[x].pub(y);
}
vector<bool> tka(H + 5);
tka[1] = 1;
int sta = 1;
for (int i = 1; i <= W; i++) {
for (auto it : zyama[i + 1]) {
if (tka[it]) {
cout << i << endl;
return 0;
}
}
if (find(zyama[i + 1].begin(), zyama[i + 1].end(), sta + 1) ==
zyama[i + 1].end()) {
tka[sta + 1] = 1;
sta++;
}
}
return 0;
}
| #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod = 10007;
const llint big = 2.19e15 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U> bool mineq(T &a, U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class U> bool maxeq(T &a, U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
llint gcd(llint a, llint b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
llint lcm(llint a, llint b) {
if (a == 0) {
return b;
}
return a / gcd(a, b) * b;
}
template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); }
template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); }
template <class T> llint LBI(vector<T> &ar, T in) {
return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T> llint UBI(vector<T> &ar, T in) {
return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int H, W, i, n;
cin >> W >> H >> n;
vector<vector<int>> zyama(W + 2);
for (i = 1; i <= H; i++) {
zyama[W + 1].pub(i);
}
for (i = 1; i <= W; i++) {
zyama[i].pub(H + 1);
}
for (i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
zyama[x].pub(y);
}
vector<bool> tka(H + 5);
tka[1] = 1;
int sta = 1;
for (int i = 1; i <= W; i++) {
for (auto it : zyama[i + 1]) {
if (tka[it]) {
cout << i << endl;
return 0;
}
}
if (find(zyama[i + 1].begin(), zyama[i + 1].end(), sta + 1) ==
zyama[i + 1].end()) {
tka[sta + 1] = 1;
sta++;
}
}
return 0;
}
| replace | 84 | 85 | 84 | 85 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <chrono>
#include <climits>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int H, W, N;
cin >> H >> W >> N;
vector<int> vec(H + 5);
int ans = H;
if (H == 1) {
cout << 1 << endl;
return 0;
}
rep(i, N) {
int x, y;
cin >> x >> y;
if (vec.at(x) == 0) {
vec.at(x) = y;
} else {
vec.at(x) = min(vec.at(x), y);
}
}
if (vec.at(2) == 1) {
cout << 1 << endl;
return 0;
}
int pos = 1;
for (int i = 2; i <= W; i++) {
if (vec.at(i) >= 1 && vec.at(i) <= pos) {
cout << i - 1 << endl;
return 0;
}
if (vec.at(i) == pos + 1)
continue;
pos++;
}
cout << ans << endl;
} | #include <algorithm>
#include <chrono>
#include <climits>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int H, W, N;
cin >> H >> W >> N;
vector<int> vec(H + 5);
int ans = H;
if (H == 1) {
cout << 1 << endl;
return 0;
}
rep(i, N) {
int x, y;
cin >> x >> y;
if (vec.at(x) == 0) {
vec.at(x) = y;
} else {
vec.at(x) = min(vec.at(x), y);
}
}
if (vec.at(2) == 1) {
cout << 1 << endl;
return 0;
}
int pos = 1;
for (int i = 2; i <= H; i++) {
if (vec.at(i) >= 1 && vec.at(i) <= pos) {
cout << i - 1 << endl;
return 0;
}
if (vec.at(i) == pos + 1)
continue;
pos++;
}
cout << ans << endl;
} | replace | 53 | 54 | 53 | 54 | 0 | |
p03203 | C++ | Runtime Error | #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 w, h, n;
cin >> w >> h >> n;
vector<vi> pos(h + 1);
rep(i, n) {
int x, y;
cin >> x >> y;
pos[y].pb(x);
}
rep(i, h + 1) {
pos[i].pb(w + 1);
sort(all(pos[i]));
}
int x = 1, y = 1, ans = w;
while (1) {
int k = lower_bound(all(pos[y]), x) - pos[y].begin();
ans = min(ans, pos[y][k] - 1);
if (pos[y][k] == ++x)
break;
if (!binary_search(all(pos[y + 1]), x))
y++;
}
cout << ans << 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 w, h, n;
cin >> w >> h >> n;
vector<vi> pos(h + 1);
rep(i, n) {
int x, y;
cin >> x >> y;
pos[y].pb(x);
}
rep(i, h + 1) {
pos[i].pb(w + 1);
sort(all(pos[i]));
}
int x = 1, y = 1, ans = w;
while (1) {
int k = lower_bound(all(pos[y]), x) - pos[y].begin();
ans = min(ans, pos[y][k] - 1);
if (pos[y][k] == ++x)
break;
if (y < h && !binary_search(all(pos[y + 1]), x))
y++;
}
cout << ans << endl;
return 0;
} | replace | 85 | 86 | 85 | 86 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
template <typename T> inline int Chkmax(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T> inline int Chkmin(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
template <typename T> inline T read() {
T sum = 0, fl = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
fl = -1;
for (; isdigit(ch); ch = getchar())
sum = (sum << 3) + (sum << 1) + ch - '0';
return sum * fl;
}
inline void proc_status() {
ifstream t("/proc/self/status");
cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
<< endl;
}
const int Maxn = 1e5 + 100;
int N, M, K;
pii A[Maxn];
map<pii, int> Map;
vector<int> vec[Maxn];
inline int Check(int t, int x, int y) {
for (int i = 0; i < vec[t].size(); ++i)
if (x <= vec[t][i] && vec[t][i] <= y)
return 1;
return 0;
}
inline void Solve() {
int pos = 1;
for (int i = 1; i <= N; ++i) {
if (Check(i + 1, 1, pos)) {
cout << i << endl;
return;
}
if (!Map[mp(i + 1, pos + 1)])
++pos;
}
}
inline void Input() {
N = read<int>(), M = read<int>(), K = read<int>();
for (int i = 1; i <= K; ++i) {
A[i].x = read<int>(), A[i].y = read<int>();
Map[mp(A[i].x, A[i].y)] = 1;
vec[A[i].x].pb(A[i].y);
}
for (int i = 1; i <= N; ++i)
vec[N + 1].pb(i), Map[mp(N + 1, i)] = 1;
}
int main() {
#ifdef hk_cnyali
freopen("D.in", "r", stdin);
freopen("D.out", "w", stdout);
#endif
Input();
Solve();
return 0;
}
| #include <bits/stdc++.h>
#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
template <typename T> inline int Chkmax(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T> inline int Chkmin(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
template <typename T> inline T read() {
T sum = 0, fl = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
fl = -1;
for (; isdigit(ch); ch = getchar())
sum = (sum << 3) + (sum << 1) + ch - '0';
return sum * fl;
}
inline void proc_status() {
ifstream t("/proc/self/status");
cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
<< endl;
}
const int Maxn = 2e5 + 100;
int N, M, K;
pii A[Maxn];
map<pii, int> Map;
vector<int> vec[Maxn];
inline int Check(int t, int x, int y) {
for (int i = 0; i < vec[t].size(); ++i)
if (x <= vec[t][i] && vec[t][i] <= y)
return 1;
return 0;
}
inline void Solve() {
int pos = 1;
for (int i = 1; i <= N; ++i) {
if (Check(i + 1, 1, pos)) {
cout << i << endl;
return;
}
if (!Map[mp(i + 1, pos + 1)])
++pos;
}
}
inline void Input() {
N = read<int>(), M = read<int>(), K = read<int>();
for (int i = 1; i <= K; ++i) {
A[i].x = read<int>(), A[i].y = read<int>();
Map[mp(A[i].x, A[i].y)] = 1;
vec[A[i].x].pb(A[i].y);
}
for (int i = 1; i <= N; ++i)
vec[N + 1].pb(i), Map[mp(N + 1, i)] = 1;
}
int main() {
#ifdef hk_cnyali
freopen("D.in", "r", stdin);
freopen("D.out", "w", stdout);
#endif
Input();
Solve();
return 0;
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p03203 | C++ | Runtime Error | #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 vec vector<ll>
#define mat vector<vector<ll>>
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 998244353;
const ll mod = 998244353;
signed main() {
ll h, w, n;
cin >> h >> w >> n;
vector<vector<ll>> a(w);
set<pll> st;
rep(i, n) {
ll x, y;
cin >> x >> y;
x--;
y--;
st.insert(mp(x, y));
a[y].pb(x);
}
rep(i, w) {
a[i].pb(h);
st.insert(mp(i, h));
sort(all(a[i]));
}
ll nx = 0, ny = 0;
ll ans = h;
while (nx < h) {
if (st.find(mp(nx + 1, ny)) != st.end()) {
ans = min(ans, nx + 1);
break;
}
ll p = *upper_bound(all(a[ny]), nx);
ans = min(ans, p);
nx++;
if (st.find(mp(nx, ny + 1)) == st.end()) {
ny++;
}
}
cout << ans << 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 vec vector<ll>
#define mat vector<vector<ll>>
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 998244353;
const ll mod = 998244353;
signed main() {
ll h, w, n;
cin >> h >> w >> n;
vector<vector<ll>> a(w);
set<pll> st;
rep(i, n) {
ll x, y;
cin >> x >> y;
x--;
y--;
st.insert(mp(x, y));
a[y].pb(x);
}
rep(i, w) {
a[i].pb(h);
st.insert(mp(i, h));
sort(all(a[i]));
}
ll nx = 0, ny = 0;
ll ans = h;
while (nx < h && ny < w) {
if (st.find(mp(nx + 1, ny)) != st.end()) {
ans = min(ans, nx + 1);
break;
}
ll p = *upper_bound(all(a[ny]), nx);
ans = min(ans, p);
nx++;
if (st.find(mp(nx, ny + 1)) == st.end()) {
ny++;
}
}
cout << ans << endl;
} | replace | 39 | 40 | 39 | 40 | 0 | |
p03203 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;
using pis = pair<int, string>;
using psl = pair<string, ll>;
using pls = pair<ll, string>;
using pss = pair<string, string>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> using vvvc = vector<vector<vector<T>>>;
template <typename T> using vvvvc = vector<vvvc<T>>;
template <typename T> using vvvvvc = vector<vvvvc<T>>;
template <class T, class U> inline constexpr bool chmin(T &a, const U b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> inline constexpr bool chmax(T &a, const U b) {
if (a >= b)
return false;
a = b;
return true;
}
#define bit(n, k) ((n >> k) & 1)
inline void bin101() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
}
// デバッグ
template <typename T> inline void vout(const vector<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
cout << i << " " << v[i] << '\n';
}
cout << "end\n" << endl;
}
// デバッグ
template <typename T> inline void vout(const vvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
cout << i << " " << j << " " << v[i][j] << '\n';
}
}
cout << "end\n" << endl;
}
// デバッグ(グリッド)
template <typename T> inline void gvout(const vector<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
if (i)
cout << " ";
cout << v[i];
}
cout << "end\n" << endl;
}
// デバッグ(グリッド)
template <typename T> inline void gvout(const vvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
if (j)
cout << " ";
cout << v[i][j];
}
cout << endl;
}
cout << "end\n" << endl;
}
// デバッグ
template <typename T> inline void vout(const vvvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
int sssz = v[i][j].size();
for (int k = 0; k < sssz; k++) {
cout << i << " " << j << " " << k << " " << v[i][j][k] << '\n';
}
}
}
cout << "end\n" << endl;
}
// pair cout
template <typename T, typename U>
inline ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.first << " " << p.second;
return os;
}
// pair cin
template <typename T, typename U>
inline istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
// ソート
template <typename T> inline void vsort(vector<T> &v) {
sort(v.begin(), v.end());
}
// 逆順ソート
template <typename T> inline void rvsort(vector<T> &v) {
sort(v.rbegin(), v.rend());
}
// 要素数a 初期値x
template <typename T> inline vector<T> vmake(int a, T x) {
return vector<T>(a, x);
}
// data[a][b] 初期値x
template <typename T> inline vector<vector<T>> vmake(int a, int b, T x) {
return vector<vector<T>>(a, vector<T>(b, x));
}
// data[a][b][c] 初期値x
template <typename T>
inline vector<vector<vector<T>>> vmake(int a, int b, int c, T x) {
return vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, x)));
}
// data[a][b][c][d] 初期値x
template <typename T>
inline vector<vector<vector<vector<T>>>> vmake(int a, int b, int c, int d,
T x) {
return vector<vector<vector<vector<T>>>>(a,
vvvc<T>(b, vvc<T>(c, vc<T>(d, x))));
}
// data[a][b][c][d][e] 初期値x
template <typename T>
inline vvvvvc<T> vmake(int a, int b, int c, int d, int e, T x) {
return vvvvvc<T>(a, vvvvc<T>(b, vvvc<T>(c, vvc<T>(d, vc<T>(e, x)))));
}
// 1ビットの数を返す
inline int popcount(int x) { return __builtin_popcount(x); }
// 1ビットの数を返す
inline int popcount(ll x) { return __builtin_popcountll(x); }
// queのfront() pop()
template <typename T> inline T pop(queue<T> &que) {
T x = que.front();
que.pop();
return x;
}
// priority_que top() pop()
template <typename T> inline T pop(priority_queue<T> &que) {
T x = que.top();
que.pop();
return x;
}
// stack top() pop()
template <typename T> inline T pop(stack<T> &st) {
T x = st.top();
st.pop();
return x;
}
#define intsz(x) ((int)x.size())
/*
満たすものの個数を返す
mode:0 x未満
mode:1 x以下の数
mode:2 x以上の数
mode:3 x超
mode:4 x
*/
template <typename T> inline int count_bound(vector<T> &v, T x, int mode) {
switch (mode) {
case 0:
return lower_bound(v.begin(), v.end(), x) - v.begin();
case 1:
return upper_bound(v.begin(), v.end(), x) - v.begin();
case 2:
return v.end() - lower_bound(v.begin(), v.end(), x);
case 3:
return v.end() - upper_bound(v.begin(), v.end(), x);
case 4:
return upper_bound(v.begin(), v.end(), x) -
lower_bound(v.begin(), v.end(), x);
}
}
/*
mode:0 xより小さい数で最大の数
mode:1 x以下の数で最大の数
mode:2 x以上の数で最小の数
mode:3 xより大きい数で最小の数
*/
template <typename T> inline T value_bound(vector<T> &v, T x, int mode) {
switch (mode) {
case 0:
return *(--lower_bound(v.begin(), v.end(), x));
case 1:
return *(--upper_bound(v.begin(), v.end(), x));
case 2:
return *lower_bound(v.begin(), v.end(), x);
case 3:
return *upper_bound(v.begin(), v.end(), x);
}
}
constexpr int MAX = 1 << 30;
constexpr ll INF = 1LL << 62;
constexpr ll MOD = 1e9 + 7;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
bin101();
int H, W, N;
cin >> H >> W >> N;
set<pii> S;
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
S.insert({y, x});
}
int now = 1;
int ret = H;
for (int i = 1; i <= W; i++) {
// cout<<i<<" "<<now<<endl;
auto x = S.lower_bound({i, now + 1});
auto y = *x;
if (y.first == i) {
if (chmin(ret, y.second - 1))
return 1;
// cout<<" "<<y.second-1<<endl;
}
now++;
while (S.find({i + 1, now}) != S.end()) {
now++;
}
if (ret < now)
break;
}
cout << ret << endl;
} | #pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;
using pis = pair<int, string>;
using psl = pair<string, ll>;
using pls = pair<ll, string>;
using pss = pair<string, string>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> using vvvc = vector<vector<vector<T>>>;
template <typename T> using vvvvc = vector<vvvc<T>>;
template <typename T> using vvvvvc = vector<vvvvc<T>>;
template <class T, class U> inline constexpr bool chmin(T &a, const U b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> inline constexpr bool chmax(T &a, const U b) {
if (a >= b)
return false;
a = b;
return true;
}
#define bit(n, k) ((n >> k) & 1)
inline void bin101() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
}
// デバッグ
template <typename T> inline void vout(const vector<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
cout << i << " " << v[i] << '\n';
}
cout << "end\n" << endl;
}
// デバッグ
template <typename T> inline void vout(const vvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
cout << i << " " << j << " " << v[i][j] << '\n';
}
}
cout << "end\n" << endl;
}
// デバッグ(グリッド)
template <typename T> inline void gvout(const vector<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
if (i)
cout << " ";
cout << v[i];
}
cout << "end\n" << endl;
}
// デバッグ(グリッド)
template <typename T> inline void gvout(const vvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
if (j)
cout << " ";
cout << v[i][j];
}
cout << endl;
}
cout << "end\n" << endl;
}
// デバッグ
template <typename T> inline void vout(const vvvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
int sssz = v[i][j].size();
for (int k = 0; k < sssz; k++) {
cout << i << " " << j << " " << k << " " << v[i][j][k] << '\n';
}
}
}
cout << "end\n" << endl;
}
// pair cout
template <typename T, typename U>
inline ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.first << " " << p.second;
return os;
}
// pair cin
template <typename T, typename U>
inline istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
// ソート
template <typename T> inline void vsort(vector<T> &v) {
sort(v.begin(), v.end());
}
// 逆順ソート
template <typename T> inline void rvsort(vector<T> &v) {
sort(v.rbegin(), v.rend());
}
// 要素数a 初期値x
template <typename T> inline vector<T> vmake(int a, T x) {
return vector<T>(a, x);
}
// data[a][b] 初期値x
template <typename T> inline vector<vector<T>> vmake(int a, int b, T x) {
return vector<vector<T>>(a, vector<T>(b, x));
}
// data[a][b][c] 初期値x
template <typename T>
inline vector<vector<vector<T>>> vmake(int a, int b, int c, T x) {
return vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, x)));
}
// data[a][b][c][d] 初期値x
template <typename T>
inline vector<vector<vector<vector<T>>>> vmake(int a, int b, int c, int d,
T x) {
return vector<vector<vector<vector<T>>>>(a,
vvvc<T>(b, vvc<T>(c, vc<T>(d, x))));
}
// data[a][b][c][d][e] 初期値x
template <typename T>
inline vvvvvc<T> vmake(int a, int b, int c, int d, int e, T x) {
return vvvvvc<T>(a, vvvvc<T>(b, vvvc<T>(c, vvc<T>(d, vc<T>(e, x)))));
}
// 1ビットの数を返す
inline int popcount(int x) { return __builtin_popcount(x); }
// 1ビットの数を返す
inline int popcount(ll x) { return __builtin_popcountll(x); }
// queのfront() pop()
template <typename T> inline T pop(queue<T> &que) {
T x = que.front();
que.pop();
return x;
}
// priority_que top() pop()
template <typename T> inline T pop(priority_queue<T> &que) {
T x = que.top();
que.pop();
return x;
}
// stack top() pop()
template <typename T> inline T pop(stack<T> &st) {
T x = st.top();
st.pop();
return x;
}
#define intsz(x) ((int)x.size())
/*
満たすものの個数を返す
mode:0 x未満
mode:1 x以下の数
mode:2 x以上の数
mode:3 x超
mode:4 x
*/
template <typename T> inline int count_bound(vector<T> &v, T x, int mode) {
switch (mode) {
case 0:
return lower_bound(v.begin(), v.end(), x) - v.begin();
case 1:
return upper_bound(v.begin(), v.end(), x) - v.begin();
case 2:
return v.end() - lower_bound(v.begin(), v.end(), x);
case 3:
return v.end() - upper_bound(v.begin(), v.end(), x);
case 4:
return upper_bound(v.begin(), v.end(), x) -
lower_bound(v.begin(), v.end(), x);
}
}
/*
mode:0 xより小さい数で最大の数
mode:1 x以下の数で最大の数
mode:2 x以上の数で最小の数
mode:3 xより大きい数で最小の数
*/
template <typename T> inline T value_bound(vector<T> &v, T x, int mode) {
switch (mode) {
case 0:
return *(--lower_bound(v.begin(), v.end(), x));
case 1:
return *(--upper_bound(v.begin(), v.end(), x));
case 2:
return *lower_bound(v.begin(), v.end(), x);
case 3:
return *upper_bound(v.begin(), v.end(), x);
}
}
constexpr int MAX = 1 << 30;
constexpr ll INF = 1LL << 62;
constexpr ll MOD = 1e9 + 7;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
bin101();
int H, W, N;
cin >> H >> W >> N;
set<pii> S;
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
S.insert({y, x});
}
int now = 1;
int ret = H;
for (int i = 1; i <= W; i++) {
// cout<<i<<" "<<now<<endl;
auto x = S.lower_bound({i, now + 1});
auto y = *x;
if (y.first == i) {
if (chmin(ret, y.second - 1) && ret < now)
return 1;
// cout<<" "<<y.second-1<<endl;
}
now++;
while (S.find({i + 1, now}) != S.end()) {
now++;
}
if (ret < now)
break;
}
cout << ret << endl;
} | replace | 275 | 276 | 275 | 276 | 1 | |
p03203 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;
using pis = pair<int, string>;
using psl = pair<string, ll>;
using pls = pair<ll, string>;
using pss = pair<string, string>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> using vvvc = vector<vector<vector<T>>>;
template <typename T> using vvvvc = vector<vvvc<T>>;
template <typename T> using vvvvvc = vector<vvvvc<T>>;
template <class T, class U> inline constexpr bool chmin(T &a, const U b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> inline constexpr bool chmax(T &a, const U b) {
if (a >= b)
return false;
a = b;
return true;
}
#define bit(n, k) ((n >> k) & 1)
inline void bin101() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
}
// デバッグ
template <typename T> inline void vout(const vector<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
cout << i << " " << v[i] << '\n';
}
cout << "end\n" << endl;
}
// デバッグ
template <typename T> inline void vout(const vvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
cout << i << " " << j << " " << v[i][j] << '\n';
}
}
cout << "end\n" << endl;
}
// デバッグ(グリッド)
template <typename T> inline void gvout(const vector<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
if (i)
cout << " ";
cout << v[i];
}
cout << "end\n" << endl;
}
// デバッグ(グリッド)
template <typename T> inline void gvout(const vvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
if (j)
cout << " ";
cout << v[i][j];
}
cout << endl;
}
cout << "end\n" << endl;
}
// デバッグ
template <typename T> inline void vout(const vvvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
int sssz = v[i][j].size();
for (int k = 0; k < sssz; k++) {
cout << i << " " << j << " " << k << " " << v[i][j][k] << '\n';
}
}
}
cout << "end\n" << endl;
}
// pair cout
template <typename T, typename U>
inline ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.first << " " << p.second;
return os;
}
// pair cin
template <typename T, typename U>
inline istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
// ソート
template <typename T> inline void vsort(vector<T> &v) {
sort(v.begin(), v.end());
}
// 逆順ソート
template <typename T> inline void rvsort(vector<T> &v) {
sort(v.rbegin(), v.rend());
}
// 要素数a 初期値x
template <typename T> inline vector<T> vmake(int a, T x) {
return vector<T>(a, x);
}
// data[a][b] 初期値x
template <typename T> inline vector<vector<T>> vmake(int a, int b, T x) {
return vector<vector<T>>(a, vector<T>(b, x));
}
// data[a][b][c] 初期値x
template <typename T>
inline vector<vector<vector<T>>> vmake(int a, int b, int c, T x) {
return vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, x)));
}
// data[a][b][c][d] 初期値x
template <typename T>
inline vector<vector<vector<vector<T>>>> vmake(int a, int b, int c, int d,
T x) {
return vector<vector<vector<vector<T>>>>(a,
vvvc<T>(b, vvc<T>(c, vc<T>(d, x))));
}
// data[a][b][c][d][e] 初期値x
template <typename T>
inline vvvvvc<T> vmake(int a, int b, int c, int d, int e, T x) {
return vvvvvc<T>(a, vvvvc<T>(b, vvvc<T>(c, vvc<T>(d, vc<T>(e, x)))));
}
// 1ビットの数を返す
inline int popcount(int x) { return __builtin_popcount(x); }
// 1ビットの数を返す
inline int popcount(ll x) { return __builtin_popcountll(x); }
// queのfront() pop()
template <typename T> inline T pop(queue<T> &que) {
T x = que.front();
que.pop();
return x;
}
// priority_que top() pop()
template <typename T> inline T pop(priority_queue<T> &que) {
T x = que.top();
que.pop();
return x;
}
// stack top() pop()
template <typename T> inline T pop(stack<T> &st) {
T x = st.top();
st.pop();
return x;
}
#define intsz(x) ((int)x.size())
/*
満たすものの個数を返す
mode:0 x未満
mode:1 x以下の数
mode:2 x以上の数
mode:3 x超
mode:4 x
*/
template <typename T> inline int count_bound(vector<T> &v, T x, int mode) {
switch (mode) {
case 0:
return lower_bound(v.begin(), v.end(), x) - v.begin();
case 1:
return upper_bound(v.begin(), v.end(), x) - v.begin();
case 2:
return v.end() - lower_bound(v.begin(), v.end(), x);
case 3:
return v.end() - upper_bound(v.begin(), v.end(), x);
case 4:
return upper_bound(v.begin(), v.end(), x) -
lower_bound(v.begin(), v.end(), x);
}
}
/*
mode:0 xより小さい数で最大の数
mode:1 x以下の数で最大の数
mode:2 x以上の数で最小の数
mode:3 xより大きい数で最小の数
*/
template <typename T> inline T value_bound(vector<T> &v, T x, int mode) {
switch (mode) {
case 0:
return *(--lower_bound(v.begin(), v.end(), x));
case 1:
return *(--upper_bound(v.begin(), v.end(), x));
case 2:
return *lower_bound(v.begin(), v.end(), x);
case 3:
return *upper_bound(v.begin(), v.end(), x);
}
}
constexpr int MAX = 1 << 30;
constexpr ll INF = 1LL << 62;
constexpr ll MOD = 1e9 + 7;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
bin101();
int H, W, N;
cin >> H >> W >> N;
set<pii> S;
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
S.insert({y, x});
}
int now = 1;
int ret = H;
for (int i = 1; i <= W; i++) {
// cout<<i<<" "<<now<<endl;
auto x = S.lower_bound({i, now + 1});
auto y = *x;
if (y.first == i) {
if (chmin(ret, y.second - 1) && ret < now)
return 1;
// cout<<" "<<y.second-1<<endl;
}
now++;
while (S.find({i + 1, now}) != S.end()) {
now++;
}
// if(ret<now) break;
}
cout << ret << endl;
} | #pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;
using pis = pair<int, string>;
using psl = pair<string, ll>;
using pls = pair<ll, string>;
using pss = pair<string, string>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> using vvvc = vector<vector<vector<T>>>;
template <typename T> using vvvvc = vector<vvvc<T>>;
template <typename T> using vvvvvc = vector<vvvvc<T>>;
template <class T, class U> inline constexpr bool chmin(T &a, const U b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> inline constexpr bool chmax(T &a, const U b) {
if (a >= b)
return false;
a = b;
return true;
}
#define bit(n, k) ((n >> k) & 1)
inline void bin101() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
}
// デバッグ
template <typename T> inline void vout(const vector<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
cout << i << " " << v[i] << '\n';
}
cout << "end\n" << endl;
}
// デバッグ
template <typename T> inline void vout(const vvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
cout << i << " " << j << " " << v[i][j] << '\n';
}
}
cout << "end\n" << endl;
}
// デバッグ(グリッド)
template <typename T> inline void gvout(const vector<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
if (i)
cout << " ";
cout << v[i];
}
cout << "end\n" << endl;
}
// デバッグ(グリッド)
template <typename T> inline void gvout(const vvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
if (j)
cout << " ";
cout << v[i][j];
}
cout << endl;
}
cout << "end\n" << endl;
}
// デバッグ
template <typename T> inline void vout(const vvvc<T> &v) {
cout << "\nstart\n";
const int sz = v.size();
for (int i = 0; i < sz; i++) {
int ssz = v[i].size();
for (int j = 0; j < ssz; j++) {
int sssz = v[i][j].size();
for (int k = 0; k < sssz; k++) {
cout << i << " " << j << " " << k << " " << v[i][j][k] << '\n';
}
}
}
cout << "end\n" << endl;
}
// pair cout
template <typename T, typename U>
inline ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.first << " " << p.second;
return os;
}
// pair cin
template <typename T, typename U>
inline istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
// ソート
template <typename T> inline void vsort(vector<T> &v) {
sort(v.begin(), v.end());
}
// 逆順ソート
template <typename T> inline void rvsort(vector<T> &v) {
sort(v.rbegin(), v.rend());
}
// 要素数a 初期値x
template <typename T> inline vector<T> vmake(int a, T x) {
return vector<T>(a, x);
}
// data[a][b] 初期値x
template <typename T> inline vector<vector<T>> vmake(int a, int b, T x) {
return vector<vector<T>>(a, vector<T>(b, x));
}
// data[a][b][c] 初期値x
template <typename T>
inline vector<vector<vector<T>>> vmake(int a, int b, int c, T x) {
return vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, x)));
}
// data[a][b][c][d] 初期値x
template <typename T>
inline vector<vector<vector<vector<T>>>> vmake(int a, int b, int c, int d,
T x) {
return vector<vector<vector<vector<T>>>>(a,
vvvc<T>(b, vvc<T>(c, vc<T>(d, x))));
}
// data[a][b][c][d][e] 初期値x
template <typename T>
inline vvvvvc<T> vmake(int a, int b, int c, int d, int e, T x) {
return vvvvvc<T>(a, vvvvc<T>(b, vvvc<T>(c, vvc<T>(d, vc<T>(e, x)))));
}
// 1ビットの数を返す
inline int popcount(int x) { return __builtin_popcount(x); }
// 1ビットの数を返す
inline int popcount(ll x) { return __builtin_popcountll(x); }
// queのfront() pop()
template <typename T> inline T pop(queue<T> &que) {
T x = que.front();
que.pop();
return x;
}
// priority_que top() pop()
template <typename T> inline T pop(priority_queue<T> &que) {
T x = que.top();
que.pop();
return x;
}
// stack top() pop()
template <typename T> inline T pop(stack<T> &st) {
T x = st.top();
st.pop();
return x;
}
#define intsz(x) ((int)x.size())
/*
満たすものの個数を返す
mode:0 x未満
mode:1 x以下の数
mode:2 x以上の数
mode:3 x超
mode:4 x
*/
template <typename T> inline int count_bound(vector<T> &v, T x, int mode) {
switch (mode) {
case 0:
return lower_bound(v.begin(), v.end(), x) - v.begin();
case 1:
return upper_bound(v.begin(), v.end(), x) - v.begin();
case 2:
return v.end() - lower_bound(v.begin(), v.end(), x);
case 3:
return v.end() - upper_bound(v.begin(), v.end(), x);
case 4:
return upper_bound(v.begin(), v.end(), x) -
lower_bound(v.begin(), v.end(), x);
}
}
/*
mode:0 xより小さい数で最大の数
mode:1 x以下の数で最大の数
mode:2 x以上の数で最小の数
mode:3 xより大きい数で最小の数
*/
template <typename T> inline T value_bound(vector<T> &v, T x, int mode) {
switch (mode) {
case 0:
return *(--lower_bound(v.begin(), v.end(), x));
case 1:
return *(--upper_bound(v.begin(), v.end(), x));
case 2:
return *lower_bound(v.begin(), v.end(), x);
case 3:
return *upper_bound(v.begin(), v.end(), x);
}
}
constexpr int MAX = 1 << 30;
constexpr ll INF = 1LL << 62;
constexpr ll MOD = 1e9 + 7;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
bin101();
int H, W, N;
cin >> H >> W >> N;
set<pii> S;
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
S.insert({y, x});
}
int now = 1;
int ret = H;
for (int i = 1; i <= W; i++) {
// cout<<i<<" "<<now<<endl;
auto x = S.lower_bound({i, now + 1});
auto y = *x;
if (x != S.end() && y.first == i) {
if (chmin(ret, y.second - 1) && ret < now)
return 1;
// cout<<" "<<y.second-1<<endl;
}
now++;
while (S.find({i + 1, now}) != S.end()) {
now++;
}
// if(ret<now) break;
}
cout << ret << endl;
} | replace | 274 | 275 | 274 | 275 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define MAXS 200000
int h, w, n, ans;
int x[MAXS + 3], y[MAXS + 3];
int vis[MAXS + 3];
int main() {
scanf("%d %d %d", &h, &w, &n);
ans = h;
memset(vis, 0x3f, sizeof(vis));
for (int i = 1; i <= n; i++) {
scanf("%d %d", &x[i], &y[i]);
if (x[i] >= y[i])
vis[x[i] - y[i]] = min(vis[x[i] - y[i]], x[i]);
}
for (int i = 1; i <= n; i++)
if (vis[x[i] - y[i] - 1] > x[i])
ans = min(ans, x[i] - 1);
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define MAXS 200000
int h, w, n, ans;
int x[MAXS + 3], y[MAXS + 3];
int vis[MAXS + 3];
int main() {
scanf("%d %d %d", &h, &w, &n);
ans = h;
memset(vis, 0x3f, sizeof(vis));
for (int i = 1; i <= n; i++) {
scanf("%d %d", &x[i], &y[i]);
if (x[i] >= y[i])
vis[x[i] - y[i]] = min(vis[x[i] - y[i]], x[i]);
}
for (int i = 1; i <= n; i++)
if (x[i] > y[i])
if (vis[x[i] - y[i] - 1] > x[i])
ans = min(ans, x[i] - 1);
printf("%d\n", ans);
return 0;
} | replace | 20 | 22 | 20 | 23 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
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};
int main() {
int h, w, n;
cin >> h >> w >> n;
vector<vector<int>> a(h);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
x--, y--;
a[y].pb(x);
}
int ans = w;
int x = 0;
for (int i = 0; i < h; i++) {
if (x >= w)
break;
if (a[i].size()) {
sort(ALL(a[i]));
int t = 0;
while (t < a[i].size() && a[i][t] < x) {
t++;
}
if (t < a[i].size())
ans = min(ans, a[i][t]);
}
if (i + 1 < h && a[i + 1].size()) {
int t = 0;
x++;
sort(ALL(a[i + 1]));
while (t < a[i + 1].size() && a[i + 1][t] < x) {
t++;
}
if (t < a[i + 1].size()) {
if (a[i + 1][t] == x) {
while (t < a[i + 1].size() && a[i + 1][t] == x) {
t++;
x++;
}
}
}
} else {
x++;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
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};
int main() {
int h, w, n;
cin >> w >> h >> n;
vector<vector<int>> a(h);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
x--, y--;
a[y].pb(x);
}
int ans = w;
int x = 0;
for (int i = 0; i < h; i++) {
if (x >= w)
break;
if (a[i].size()) {
sort(ALL(a[i]));
int t = 0;
while (t < a[i].size() && a[i][t] < x) {
t++;
}
if (t < a[i].size())
ans = min(ans, a[i][t]);
}
if (i + 1 < h && a[i + 1].size()) {
int t = 0;
x++;
sort(ALL(a[i + 1]));
while (t < a[i + 1].size() && a[i + 1][t] < x) {
t++;
}
if (t < a[i + 1].size()) {
if (a[i + 1][t] == x) {
while (t < a[i + 1].size() && a[i + 1][t] == x) {
t++;
x++;
}
}
}
} else {
x++;
}
}
cout << ans << endl;
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb emplace_back
#define mp make_pair
#define int long long
#define y second
#define x first
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
int h;
cin >> h;
int w;
cin >> w;
int n;
cin >> n;
std::set<pair<int, int>> v;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
v.insert({x, y});
}
std::vector<int> mw(h + 1, 0);
int x = 1, y = 1;
mw[1] = 1;
while (true) {
if (v.find({x + 1, y}) != v.end() || (x == h))
break;
x++;
if (y == w)
break;
if (v.find({x, y + 1}) == v.end())
y++;
mw[x] = y;
}
for (int i = 1; i <= w; ++i)
if (mw[i] == 0)
mw[i] = max(mw[i - 1] + 1, i + 1);
int mi = h;
for (auto r : v)
if (r.second < r.first && mw[r.first] >= r.second)
mi = min(mi, r.first - 1);
cout << mi;
} | #include <bits/stdc++.h>
#define pb emplace_back
#define mp make_pair
#define int long long
#define y second
#define x first
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
int h;
cin >> h;
int w;
cin >> w;
int n;
cin >> n;
std::set<pair<int, int>> v;
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
v.insert({x, y});
}
std::vector<int> mw(h + 1, 0);
int x = 1, y = 1;
mw[1] = 1;
while (true) {
if (v.find({x + 1, y}) != v.end() || (x == h))
break;
x++;
if (y == w)
break;
if (v.find({x, y + 1}) == v.end())
y++;
mw[x] = y;
}
for (int i = 1; i <= h; ++i)
if (mw[i] == 0)
mw[i] = max(mw[i - 1] + 1, i + 1);
int mi = h;
for (auto r : v)
if (r.second < r.first && mw[r.first] >= r.second)
mi = min(mi, r.first - 1);
cout << mi;
} | replace | 38 | 39 | 38 | 39 | 0 | |
p03203 | C++ | Runtime Error | /*
`-:://:::-
`//:-------:/:`
.+:--.......--:+`
`+:--..`````..--//`
.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 H, W, n;
vector<vector<int>> v;
signed main(signed argc, char *argv[]) {
scan H, W, n;
v.resize(H + 2);
f(i, n) {
int x, y;
scan x, y;
v[y].pb(x);
}
for (int i = 0; i <= H; i++) {
v[i].pb(W + 1);
}
for (int i = 0; i <= W; i++) {
v[H + 1].pb(i);
}
f(i, H + 1) { sort(v[i].begin(), v[i].end()); }
// print v[2];
int rez = 1e9;
int cnt = 0;
int x = 1;
int y = 1;
for (int t = 0;; t++) {
if (t % 2 == 0) {
int next = *lower_bound(v[y].begin(), v[y].end(), x);
int dist = next - x - 1;
// log(x, y, dist, next);
rez = min(rez, cnt + dist + 1);
if (dist == 0)
break;
x++;
cnt++;
} else {
if (*lower_bound(v[y + 1].begin(), v[y + 1].end(), x) != x) {
y++;
}
}
}
print rez;
}
| /*
`-:://:::-
`//:-------:/:`
.+:--.......--:+`
`+:--..`````..--//`
.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 H, W, n;
vector<vector<int>> v;
signed main(signed argc, char *argv[]) {
scan H, W, n;
swap(H, W);
v.resize(H + 2);
f(i, n) {
int x, y;
scan x, y;
v[y].pb(x);
}
for (int i = 0; i <= H; i++) {
v[i].pb(W + 1);
}
for (int i = 0; i <= W; i++) {
v[H + 1].pb(i);
}
f(i, H + 1) { sort(v[i].begin(), v[i].end()); }
// print v[2];
int rez = 1e9;
int cnt = 0;
int x = 1;
int y = 1;
for (int t = 0;; t++) {
if (t % 2 == 0) {
int next = *lower_bound(v[y].begin(), v[y].end(), x);
int dist = next - x - 1;
// log(x, y, dist, next);
rez = min(rez, cnt + dist + 1);
if (dist == 0)
break;
x++;
cnt++;
} else {
if (*lower_bound(v[y + 1].begin(), v[y + 1].end(), x) != x) {
y++;
}
}
}
print rez;
}
| insert | 320 | 320 | 320 | 321 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;
ll mod = 1e9 + 7;
int main() {
int h, w, n;
cin >> h >> w >> n;
vector<int> s(w + 1, 1e9);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
if (x - y + 1 > 0)
s[x - y + 1] = min(s[x - y + 1], y);
}
int res = h;
for (int i = 2; i <= h; i++) {
if (s[i] < s[i - 1]) {
res = min(res, i + s[i] - 2);
}
}
dump(res);
return 0;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;
ll mod = 1e9 + 7;
int main() {
int h, w, n;
cin >> h >> w >> n;
vector<int> s(h + 1, 1e9);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
if (x - y + 1 > 0)
s[x - y + 1] = min(s[x - y + 1], y);
}
int res = h;
for (int i = 2; i <= h; i++) {
if (s[i] < s[i - 1]) {
res = min(res, i + s[i] - 2);
}
}
dump(res);
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
ll gi() {
ll x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch))
f ^= ch == '-', ch = getchar();
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
return f ? x : -x;
}
int mn[100010];
int main() {
#ifdef XZZSB
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
int n = gi(), m = gi(), k = gi(), x, y;
memset(mn, 63, sizeof mn);
while (k--) {
x = gi(), y = gi();
mn[x] = std::min(mn[x], y);
}
int R = 1;
for (int i = 2; i <= n; ++i) {
if (mn[i] <= R) {
printf("%d\n", i - 1);
return 0;
}
if (mn[i] != R + 1)
++R;
}
printf("%d\n", n);
return 0;
}
| #include <bits/stdc++.h>
typedef long long ll;
ll gi() {
ll x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch))
f ^= ch == '-', ch = getchar();
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
return f ? x : -x;
}
int mn[200010];
int main() {
#ifdef XZZSB
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
int n = gi(), m = gi(), k = gi(), x, y;
memset(mn, 63, sizeof mn);
while (k--) {
x = gi(), y = gi();
mn[x] = std::min(mn[x], y);
}
int R = 1;
for (int i = 2; i <= n; ++i) {
if (mn[i] <= R) {
printf("%d\n", i - 1);
return 0;
}
if (mn[i] != R + 1)
++R;
}
printf("%d\n", n);
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int n, h, w, ans, minp[100005];
int main() {
scanf("%d%d%d", &h, &w, &n);
ans = h;
for (int i = 1; i <= h; i++)
minp[i] = w + 1;
for (int i = 1; i <= n; i++) {
int x, y;
scanf("%d%d", &x, &y);
minp[x] = min(minp[x], y);
}
int now = 0;
for (int i = 1; i <= h; i++) {
if (minp[i] <= now) {
printf("%d\n", i - 1);
return 0;
}
if (minp[i] > now + 1)
now++;
}
printf("%d\n", h);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int n, h, w, ans, minp[200005];
int main() {
scanf("%d%d%d", &h, &w, &n);
ans = h;
for (int i = 1; i <= h; i++)
minp[i] = w + 1;
for (int i = 1; i <= n; i++) {
int x, y;
scanf("%d%d", &x, &y);
minp[x] = min(minp[x], y);
}
int now = 0;
for (int i = 1; i <= h; i++) {
if (minp[i] <= now) {
printf("%d\n", i - 1);
return 0;
}
if (minp[i] > now + 1)
now++;
}
printf("%d\n", h);
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03203 | 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 main() {
int h, w;
cin >> h >> w;
int n;
cin >> n;
vector<int> a[w + 1];
rep(i, w + 1) a[i].push_back(inf);
rep(i, n) {
int x, y;
cin >> x >> y;
--x;
--y;
a[x].push_back(y);
}
a[w].push_back(0);
rep(i, w + 1) sort(a[i].begin(), a[i].end());
int H = 0;
rep(i, w) {
if (H >= a[i + 1][0]) {
cout << i + 1 << endl;
return 0;
}
int z = *lower_bound(a[i + 1].begin(), a[i + 1].end(), H + 1);
if (z != H + 1)
++H;
}
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 main() {
int h, w;
cin >> w >> h;
int n;
cin >> n;
vector<int> a[w + 1];
rep(i, w + 1) a[i].push_back(inf);
rep(i, n) {
int x, y;
cin >> x >> y;
--x;
--y;
a[x].push_back(y);
}
a[w].push_back(0);
rep(i, w + 1) sort(a[i].begin(), a[i].end());
int H = 0;
rep(i, w) {
if (H >= a[i + 1][0]) {
cout << i + 1 << endl;
return 0;
}
int z = *lower_bound(a[i + 1].begin(), a[i + 1].end(), H + 1);
if (z != H + 1)
++H;
}
return 0;
} | replace | 26 | 27 | 26 | 27 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
/**** Type Define ****/
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
/**** Const List ****/
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const ll NCK_MAX = 510000;
/**** General Functions ****/
ll ketawa(ll n) {
ll a = 0;
while (n != 0) {
a += n % 10;
n /= 10;
}
return a;
}
ll RepeatSquaring(ll N, ll P, ll M) {
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = RepeatSquaring(N, P / 2, M);
return (t % M) * (t % M) % M;
}
return (N * RepeatSquaring(N, P - 1, M)) % M;
}
bool IsPrime(ll a) { // order root a
if (a == 1)
return false;
for (int i = 2; i * i <= a; i++) {
if (a % i == 0 && a != i) {
return false;
}
}
return true;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * 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;
}
ll lmin(ll a, ll b) { return a > b ? b : a; };
ll lmax(ll a, ll b) { return a > b ? a : b; };
ll lsum(ll a, ll b) { return a + b; };
/**** Zip ****/
template <typename T> class Zip {
vector<T> d;
bool flag;
public:
Zip() { flag = false; }
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) { // T need to have operator < !!
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return (ll)d.size();
}
};
/**** Union Find ****/
class UnionFind {
vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
void init(ll n) {
par.resize(n, 1);
rank.resize(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); }
};
/**** Segment Tree ****/
class SegmentTree {
public:
vector<pair<double, double>> node; // node[0]は使用しない
ll n; // データの個数(nodeの最下層には何個並んでいるか)
pair<double, double> initial_value; // 初期値
public:
void Init(ll n_, pair<double, double> initial_value_) {
n = 1;
while (n < n_)
n *= 2;
node.resize(2 * n);
for (ll i = 0; i < 2 * n; i++) {
node[i] = initial_value_;
}
initial_value = initial_value_;
}
void Update(ll k, pair<double, double> a) {
// node[k]をaにする
// それに従って先祖も変わっていく
k += n;
node[k] = a;
while (k > 1) {
k = k / 2;
node[k] = pair<double, double>(
node[k * 2].first * node[k * 2 + 1].first,
node[k * 2].second * node[k * 2 + 1].first + node[k * 2 + 1].second);
}
}
/*void Watch(){
for(ll i=0;i<2*n;i++){
cout<<node[i]<<endl;
}
}*/
double Query() { //[a,b)
return node[1].first + node[1].second;
}
};
/**** LIS ****/
ll lis(ll *a, ll n, ll *dp) {
fill(dp, dp + n, INF); // INFを代入
for (ll i = 0; i < n; i++)
*lower_bound(dp, dp + n, a[i]) = a[i];
return (ll)(lower_bound(dp, dp + n, INF) - dp);
}
/**** main function ****/
ll h, w, n;
ll m, d;
ll ans = -9999999999999;
string s, t;
vector<P> a;
map<P, ll> mp;
ll ydokomade[100001];
ll dp[1000011][2];
int main() {
cin >> h >> w >> n;
for (ll i = 0; i < n; i++) {
ll xx, yy;
cin >> xx >> yy;
a.push_back(P(xx - 1, yy - 1));
mp[P(xx - 1, yy - 1)] = 1;
}
sort(a.begin(), a.end());
for (ll i = 1; i < h; i++) {
if (mp[P(i, ydokomade[i - 1] + 1)] == 1) {
ydokomade[i] = ydokomade[i - 1];
} else {
ydokomade[i] = ydokomade[i - 1] + 1;
}
// cout<<ydokomade[i]<<endl;
}
for (ll i = 0; i < n; i++) {
if (ydokomade[a[i].first - 1] >= a[i].second) {
cout << a[i].first << endl;
return 0;
}
}
cout << h << endl;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
/**** Type Define ****/
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
/**** Const List ****/
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const ll NCK_MAX = 510000;
/**** General Functions ****/
ll ketawa(ll n) {
ll a = 0;
while (n != 0) {
a += n % 10;
n /= 10;
}
return a;
}
ll RepeatSquaring(ll N, ll P, ll M) {
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = RepeatSquaring(N, P / 2, M);
return (t % M) * (t % M) % M;
}
return (N * RepeatSquaring(N, P - 1, M)) % M;
}
bool IsPrime(ll a) { // order root a
if (a == 1)
return false;
for (int i = 2; i * i <= a; i++) {
if (a % i == 0 && a != i) {
return false;
}
}
return true;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * 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;
}
ll lmin(ll a, ll b) { return a > b ? b : a; };
ll lmax(ll a, ll b) { return a > b ? a : b; };
ll lsum(ll a, ll b) { return a + b; };
/**** Zip ****/
template <typename T> class Zip {
vector<T> d;
bool flag;
public:
Zip() { flag = false; }
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) { // T need to have operator < !!
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return (ll)d.size();
}
};
/**** Union Find ****/
class UnionFind {
vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
void init(ll n) {
par.resize(n, 1);
rank.resize(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); }
};
/**** Segment Tree ****/
class SegmentTree {
public:
vector<pair<double, double>> node; // node[0]は使用しない
ll n; // データの個数(nodeの最下層には何個並んでいるか)
pair<double, double> initial_value; // 初期値
public:
void Init(ll n_, pair<double, double> initial_value_) {
n = 1;
while (n < n_)
n *= 2;
node.resize(2 * n);
for (ll i = 0; i < 2 * n; i++) {
node[i] = initial_value_;
}
initial_value = initial_value_;
}
void Update(ll k, pair<double, double> a) {
// node[k]をaにする
// それに従って先祖も変わっていく
k += n;
node[k] = a;
while (k > 1) {
k = k / 2;
node[k] = pair<double, double>(
node[k * 2].first * node[k * 2 + 1].first,
node[k * 2].second * node[k * 2 + 1].first + node[k * 2 + 1].second);
}
}
/*void Watch(){
for(ll i=0;i<2*n;i++){
cout<<node[i]<<endl;
}
}*/
double Query() { //[a,b)
return node[1].first + node[1].second;
}
};
/**** LIS ****/
ll lis(ll *a, ll n, ll *dp) {
fill(dp, dp + n, INF); // INFを代入
for (ll i = 0; i < n; i++)
*lower_bound(dp, dp + n, a[i]) = a[i];
return (ll)(lower_bound(dp, dp + n, INF) - dp);
}
/**** main function ****/
ll h, w, n;
ll m, d;
ll ans = -9999999999999;
string s, t;
vector<P> a;
map<P, ll> mp;
ll ydokomade[200001];
int main() {
cin >> h >> w >> n;
for (ll i = 0; i < n; i++) {
ll xx, yy;
cin >> xx >> yy;
a.push_back(P(xx - 1, yy - 1));
mp[P(xx - 1, yy - 1)] = 1;
}
sort(a.begin(), a.end());
for (ll i = 1; i < h; i++) {
if (mp[P(i, ydokomade[i - 1] + 1)] == 1) {
ydokomade[i] = ydokomade[i - 1];
} else {
ydokomade[i] = ydokomade[i - 1] + 1;
}
// cout<<ydokomade[i]<<endl;
}
for (ll i = 0; i < n; i++) {
if (ydokomade[a[i].first - 1] >= a[i].second) {
cout << a[i].first << endl;
return 0;
}
}
cout << h << endl;
}
| replace | 234 | 236 | 234 | 235 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
int h, w, n;
cin >> h >> w >> n;
if (n == 0) {
cout << h << endl;
return 0;
}
vector<pair<int, int>> a;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
if (x < y)
continue;
a.push_back(make_pair(x, y));
}
if (a.size() == 0) {
cout << h << endl;
return 0;
}
sort(a.begin(), a.end());
int ans = 0;
int pos = 0;
int j = 1;
for (int i = 1; i < h + 10; i++) {
if (i == h)
break;
bool ok = false;
bool right = true;
while (a.at(pos).first == i + 1) {
if (a.at(pos).second <= j && ok == false)
ok = true;
if (a.at(pos).second == j + 1)
right = false;
pos++;
if (pos == a.size())
break;
}
if (ok)
break;
if (right)
j++;
ans++;
}
cout << ans + 1 << endl;
}
| #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
int h, w, n;
cin >> h >> w >> n;
if (n == 0) {
cout << h << endl;
return 0;
}
vector<pair<int, int>> a;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
if (x < y)
continue;
a.push_back(make_pair(x, y));
}
if (a.size() == 0) {
cout << h << endl;
return 0;
}
sort(a.begin(), a.end());
int ans = 0;
int pos = 0;
int j = 1;
for (int i = 1; i < h + 10; i++) {
if (i == h)
break;
bool ok = false;
bool right = true;
while (pos != a.size() && a.at(pos).first == i + 1) {
if (a.at(pos).second <= j && ok == false)
ok = true;
if (a.at(pos).second == j + 1)
right = false;
pos++;
if (pos == a.size())
break;
}
if (ok)
break;
if (right)
j++;
ans++;
}
cout << ans + 1 << endl;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;
const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;
template <typename T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
double fin() {
double x;
scanf("%lf", &x);
return x;
}
Int lin() {
Int x;
scanf("%lld", &x);
return x;
}
int main() {
int H = in();
int W = in();
int N = in();
set<pair<int, int>> X;
for (int i = 0; i < N; ++i) {
int r = in() - 1;
int c = in() - 1;
X.insert(make_pair(r, c));
}
vector<int> top(W, INF);
int ar = 0, ac = 0;
while (true) {
chmin(top[ac], ar);
++ar;
if (ar >= H) {
break;
}
if (X.count(make_pair(ar, ac + 1)) == 0) {
++ac;
}
}
int res = H;
for (const auto &p : X) {
if (top[p.second] < p.first) {
chmin(res, p.first);
}
}
printf("%d\n", res);
return 0;
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;
const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;
template <typename T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
double fin() {
double x;
scanf("%lf", &x);
return x;
}
Int lin() {
Int x;
scanf("%lld", &x);
return x;
}
int main() {
int H = in();
int W = in();
int N = in();
set<pair<int, int>> X;
for (int i = 0; i < N; ++i) {
int r = in() - 1;
int c = in() - 1;
X.insert(make_pair(r, c));
}
vector<int> top(W, INF);
int ar = 0, ac = 0;
while (true) {
chmin(top[ac], ar);
++ar;
if (ar >= H) {
break;
}
if (X.count(make_pair(ar, ac + 1)) == 0 && ac + 1 < W) {
++ac;
}
}
int res = H;
for (const auto &p : X) {
if (top[p.second] < p.first) {
chmin(res, p.first);
}
}
printf("%d\n", res);
return 0;
}
| replace | 78 | 79 | 78 | 79 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << fixed;
int h, w, n;
cin >> h >> w >> n;
V<deque<int>> g(h);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
g[y].push_back(x);
}
int ans = w, er = -1;
for (int y = 0; y < h; y++) {
auto v = g[y];
sort(v.begin(), v.end());
while (v.size() && v.front() <= er)
v.pop_front();
while (v.size() && v.front() == er + 1) {
er++;
v.pop_front();
}
if (v.size())
ans = min(ans, v.front());
er++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << fixed;
int h, w, n;
cin >> w >> h >> n; // ha?
V<deque<int>> g(h);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
g[y].push_back(x);
}
int ans = w, er = -1;
for (int y = 0; y < h; y++) {
auto v = g[y];
sort(v.begin(), v.end());
while (v.size() && v.front() <= er)
v.pop_front();
while (v.size() && v.front() == er + 1) {
er++;
v.pop_front();
}
if (v.size())
ans = min(ans, v.front());
er++;
}
cout << ans << endl;
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
using namespace std;
#ifdef INPUT
#include <sstream>
stringstream input(R"(
3 3 1
3 2
)");
#define cin input
#endif
int main() {
int h, w, n;
cin >> h >> w >> n;
vector<set<int>> s(w);
REP(i, n) {
int x, y;
cin >> x >> y;
s[x - 1].insert(y - 1);
}
int x, y = 0;
for (x = 0; x < h; ++x) {
auto it = s[x].upper_bound(y);
if (it != s[x].begin())
break;
if (x && (it == s[x].end() || *it != y + 1))
++y;
}
cout << x << endl;
return 0;
}
| #include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
using namespace std;
#ifdef INPUT
#include <sstream>
stringstream input(R"(
3 3 1
3 2
)");
#define cin input
#endif
int main() {
int h, w, n;
cin >> h >> w >> n;
vector<set<int>> s(h);
REP(i, n) {
int x, y;
cin >> x >> y;
s[x - 1].insert(y - 1);
}
int x, y = 0;
for (x = 0; x < h; ++x) {
auto it = s[x].upper_bound(y);
if (it != s[x].begin())
break;
if (x && (it == s[x].end() || *it != y + 1))
++y;
}
cout << x << endl;
return 0;
}
| replace | 35 | 36 | 35 | 36 | 0 | |
p03203 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> Pii;
set<int> mp[200000];
int main() {
int h, w, n, x, y;
cin >> h >> w >> n;
for (int i = 0; i < n; ++i) {
cin >> x >> y;
mp[y].insert(x);
}
for (int i = 1; i <= w; ++i)
mp[i].insert(h + 1);
vector<Pii> v;
int j_lower_lim = 1;
for (int i = 1; i <= w; ++i) {
while (mp[i].find(j_lower_lim) != mp[i].end())
++j_lower_lim;
set<int>::iterator j_itr = mp[i].upper_bound(j_lower_lim);
if (j_itr != mp[i].end()) {
v.emplace_back(*j_itr, i);
}
++j_lower_lim;
}
sort(v.begin(), v.end());
cout << v[0].first - 1 << "\n";
} | #include <algorithm>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> Pii;
set<int> mp[200001];
int main() {
int h, w, n, x, y;
cin >> h >> w >> n;
for (int i = 0; i < n; ++i) {
cin >> x >> y;
mp[y].insert(x);
}
for (int i = 1; i <= w; ++i)
mp[i].insert(h + 1);
vector<Pii> v;
int j_lower_lim = 1;
for (int i = 1; i <= w; ++i) {
while (mp[i].find(j_lower_lim) != mp[i].end())
++j_lower_lim;
set<int>::iterator j_itr = mp[i].upper_bound(j_lower_lim);
if (j_itr != mp[i].end()) {
v.emplace_back(*j_itr, i);
}
++j_lower_lim;
}
sort(v.begin(), v.end());
cout << v[0].first - 1 << "\n";
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
int H, W, N;
cin >> H >> W >> N;
map<P, int> mp;
vector<vector<int>> g(H);
for (int i = 0; i < N; i++) {
int X, Y;
cin >> X >> Y, X--, Y--;
g[X].push_back(Y);
mp[{X, Y}] = 1;
}
for (int x = 0; x <= H; x++) {
mp[{x, W}] = 1;
}
for (int y = 0; y <= W; y++) {
mp[{H, y}] = 1;
}
int ans = 1;
int y = 0;
for (int x = 1; x <= H; x++) {
int cnt = 0;
for (auto v : g[x]) {
if (v < y)
cnt++;
}
if (cnt > 0 || mp[{x, y}])
break;
if (!mp[{x, y + 1}])
y++;
ans++;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
int H, W, N;
cin >> H >> W >> N;
map<P, int> mp;
vector<vector<int>> g(H + 1);
for (int i = 0; i < N; i++) {
int X, Y;
cin >> X >> Y, X--, Y--;
g[X].push_back(Y);
mp[{X, Y}] = 1;
}
for (int x = 0; x <= H; x++) {
mp[{x, W}] = 1;
}
for (int y = 0; y <= W; y++) {
mp[{H, y}] = 1;
}
int ans = 1;
int y = 0;
for (int x = 1; x <= H; x++) {
int cnt = 0;
for (auto v : g[x]) {
if (v < y)
cnt++;
}
if (cnt > 0 || mp[{x, y}])
break;
if (!mp[{x, y + 1}])
y++;
ans++;
}
cout << ans << endl;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p03203 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int, int> pii;
typedef pair<i64, int> pli;
typedef pair<int, i64> pil;
typedef pair<i64, i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;
template <typename T> T id(T b) { return b; };
template <class It> bool all(It f, It l) { return std::all_of(f, l, id<bool>); }
template <class It> bool any(It f, It l) { return std::any_of(f, l, id<bool>); }
const int MAX_N = 200000;
int h, w, n;
pii xy[MAX_N];
pii yx[MAX_N];
int main() {
cin >> h >> w >> n;
for (int i = 0; i < n; ++i) {
cin >> xy[i].first >> xy[i].second;
yx[i].first = xy[i].second;
yx[i].second = xy[i].first;
}
sort(xy, xy + n);
sort(yx, yx + n);
int col = 1, row = 1, m = h;
for (int i = 0; i < h; i++) {
auto it = lower_bound(yx, yx + n, mp(col, row + 1));
if (it != yx + n && it->first == col)
m = min(m, it->second - 1);
if (find(xy, xy + n, mp(row + 1, col + 1)) == xy + n && col < w) {
col++;
}
if (row < h)
row++;
}
cout << m << endl;
return 0;
}
| #include <bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int, int> pii;
typedef pair<i64, int> pli;
typedef pair<int, i64> pil;
typedef pair<i64, i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;
template <typename T> T id(T b) { return b; };
template <class It> bool all(It f, It l) { return std::all_of(f, l, id<bool>); }
template <class It> bool any(It f, It l) { return std::any_of(f, l, id<bool>); }
const int MAX_N = 200000;
int h, w, n;
pii xy[MAX_N];
pii yx[MAX_N];
int main() {
cin >> h >> w >> n;
for (int i = 0; i < n; ++i) {
cin >> xy[i].first >> xy[i].second;
yx[i].first = xy[i].second;
yx[i].second = xy[i].first;
}
sort(xy, xy + n);
sort(yx, yx + n);
int col = 1, row = 1, m = h;
for (int i = 0; i < h; i++) {
auto it = lower_bound(yx, yx + n, mp(col, row + 1));
if (it != yx + n && it->first == col)
m = min(m, it->second - 1);
if (col < w && !binary_search(xy, xy + n, mp(row + 1, col + 1))) {
col++;
}
if (row < h)
row++;
}
cout << m << endl;
return 0;
}
| replace | 41 | 42 | 41 | 42 | TLE | |
p03203 | C++ | Runtime Error | //* AuThOr GaRyMr *//
#include <bits/stdc++.h>
#define rb(a, b, c) for (int a = b; a <= c; ++a)
#define rl(a, b, c) for (int a = b; a >= c; --a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a, b) make_pair(a, b)
#define FIR first
#define SEC second
#define FREO freopen("check.out", "w", stdout)
#define rep(a, b) for (int a = 0; a < b; ++a)
#define KEEP while (1)
#define SRAND \
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng() % a
using namespace std;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> mp;
typedef pair<mp, mp> superpair;
int up_bound, low_bound;
vector<int> each[200000];
int main() {
int h, w;
cin >> h >> w;
int n;
cin >> n;
rep(i, n) {
int x, y;
scanf("%d %d", &x, &y);
each[y].PB(x);
}
int res;
low_bound = h;
up_bound = 1;
for (auto it : each[1]) {
low_bound = min(low_bound, it - 1);
}
res = low_bound;
rb(i, 2, w) {
up_bound++;
sort(each[i].begin(), each[i].end());
for (auto it : each[i]) {
if (it > low_bound)
break;
if (it < up_bound)
continue;
if (it == up_bound)
up_bound++;
else
low_bound = it - 1;
}
res = low_bound;
}
cout << res << endl;
return 0;
}
| //* AuThOr GaRyMr *//
#include <bits/stdc++.h>
#define rb(a, b, c) for (int a = b; a <= c; ++a)
#define rl(a, b, c) for (int a = b; a >= c; --a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a, b) make_pair(a, b)
#define FIR first
#define SEC second
#define FREO freopen("check.out", "w", stdout)
#define rep(a, b) for (int a = 0; a < b; ++a)
#define KEEP while (1)
#define SRAND \
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng() % a
using namespace std;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> mp;
typedef pair<mp, mp> superpair;
int up_bound, low_bound;
vector<int> each[200000 + 10];
int main() {
int h, w;
cin >> h >> w;
int n;
cin >> n;
rep(i, n) {
int x, y;
scanf("%d %d", &x, &y);
each[y].PB(x);
}
int res;
low_bound = h;
up_bound = 1;
for (auto it : each[1]) {
low_bound = min(low_bound, it - 1);
}
res = low_bound;
rb(i, 2, w) {
up_bound++;
sort(each[i].begin(), each[i].end());
for (auto it : each[i]) {
if (it > low_bound)
break;
if (it < up_bound)
continue;
if (it == up_bound)
up_bound++;
else
low_bound = it - 1;
}
res = low_bound;
}
cout << res << endl;
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
constexpr int inf = 1e9;
int main() {
int h, w, n;
cin >> h >> w >> n;
vector<vector<int>> xs(w, vector<int>(1, h + 1));
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
xs[y - 1].push_back(x);
}
for (auto &xx : xs)
sort(xx.begin(), xx.end());
auto dist = [&](int x, int y) {
return *upper_bound(xs[y].begin(), xs[y].end(), x) - x;
};
auto find_hole = [&](int x, int y) {
if (y + 1 == w)
return -1;
int res = -1;
while (x < h) {
const int nx = *lower_bound(xs[y + 1].begin(), xs[y + 1].end(), x + 1);
if (nx > x + 1) {
res = x + 1;
break;
}
x = nx;
}
return res;
};
int ans = inf, x = 1;
for (int y = 0; y < h; ++y) {
const int d = dist(x, y);
ans = min(ans, x + d - 1);
if (y + 1 != w) {
const int hole = find_hole(x, y);
if (hole == -1) {
break;
}
x = hole;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
constexpr int inf = 1e9;
int main() {
int h, w, n;
cin >> h >> w >> n;
vector<vector<int>> xs(w, vector<int>(1, h + 1));
for (int i = 0; i < n; ++i) {
int x, y;
cin >> x >> y;
xs[y - 1].push_back(x);
}
for (auto &xx : xs)
sort(xx.begin(), xx.end());
auto dist = [&](int x, int y) {
return *upper_bound(xs[y].begin(), xs[y].end(), x) - x;
};
auto find_hole = [&](int x, int y) {
if (y + 1 == w)
return -1;
int res = -1;
while (x < h) {
const int nx = *lower_bound(xs[y + 1].begin(), xs[y + 1].end(), x + 1);
if (nx > x + 1) {
res = x + 1;
break;
}
x = nx;
}
return res;
};
int ans = inf, x = 1;
for (int y = 0; y < w; ++y) {
const int d = dist(x, y);
ans = min(ans, x + d - 1);
if (y + 1 != w) {
const int hole = find_hole(x, y);
if (hole == -1) {
break;
}
x = hole;
}
}
cout << ans << endl;
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
typedef long long LL;
LL H, W, N;
typedef pair<int, int> P;
vector<int> G[200011];
int main() {
cin >> H >> W >> N;
REP(i, N) {
int X, Y;
cin >> X >> Y;
G[Y].push_back(X);
}
REP(i, 200011) { sort(G[i].begin(), G[i].end()); }
int ans = H;
LL now = 1;
REP(i, 200011) {
// if(i>W+5)break;
// cout<<now<<endl;
if (i == 0)
continue;
if (G[i].size() == 0) {
now++;
REP(j, G[i + 1].size()) {
if (now == G[i + 1][j]) {
now++;
}
}
continue;
}
if (i == 1) {
// 1より大きく始めにぶつかる場所
ans = min(ans, G[1][0] - 1);
now++;
REP(j, G[i + 1].size()) {
if (now == G[i + 1][j]) {
now++;
}
}
} else {
LL t = 300000;
REP(j, G[i].size()) {
if (now < G[i][j]) {
ans = min(ans, G[i][j] - 1);
}
}
now++;
REP(j, G[i + 1].size()) {
if (now == G[i + 1][j]) {
now++;
}
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
typedef long long LL;
LL H, W, N;
typedef pair<int, int> P;
vector<int> G[200011];
int main() {
cin >> H >> W >> N;
REP(i, N) {
int X, Y;
cin >> X >> Y;
G[Y].push_back(X);
}
REP(i, 200011) { sort(G[i].begin(), G[i].end()); }
int ans = H;
LL now = 1;
REP(i, 200009) {
// if(i>W+5)break;
// cout<<now<<endl;
if (i == 0)
continue;
if (G[i].size() == 0) {
now++;
REP(j, G[i + 1].size()) {
if (now == G[i + 1][j]) {
now++;
}
}
continue;
}
if (i == 1) {
// 1より大きく始めにぶつかる場所
ans = min(ans, G[1][0] - 1);
now++;
REP(j, G[i + 1].size()) {
if (now == G[i + 1][j]) {
now++;
}
}
} else {
LL t = 300000;
REP(j, G[i].size()) {
if (now < G[i][j]) {
ans = min(ans, G[i][j] - 1);
}
}
now++;
REP(j, G[i + 1].size()) {
if (now == G[i + 1][j]) {
now++;
}
}
}
}
cout << ans << endl;
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const int N = (int)1e5 + 9;
vector<int> P[N];
map<pii, bool> cor;
int main() {
fastIO;
int n, m, q;
cin >> n >> m >> q;
int x, y;
for (int i = 0; i < q; i++) {
cin >> x >> y;
cor[mp(y, x)] = true;
P[y].push_back(x);
}
for (int i = 1; i <= m; i++)
P[i].push_back(n + 1);
for (int i = 1; i <= m; i++)
sort(P[i].begin(), P[i].end());
int low = P[1][0];
int pos = 2;
int res = P[1][0] - 1;
int idx;
for (int i = 2; i <= m; i++) {
while (pos < low && cor[mp(i, pos)]) {
pos++;
}
if (pos >= low)
break;
idx = 0;
while (P[i][idx] < pos)
++idx;
res = min(res, P[i][idx] - 1);
pos++;
}
cout << res;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const int N = (int)2e5 + 9;
vector<int> P[N];
map<pii, bool> cor;
int main() {
fastIO;
int n, m, q;
cin >> n >> m >> q;
int x, y;
for (int i = 0; i < q; i++) {
cin >> x >> y;
cor[mp(y, x)] = true;
P[y].push_back(x);
}
for (int i = 1; i <= m; i++)
P[i].push_back(n + 1);
for (int i = 1; i <= m; i++)
sort(P[i].begin(), P[i].end());
int low = P[1][0];
int pos = 2;
int res = P[1][0] - 1;
int idx;
for (int i = 2; i <= m; i++) {
while (pos < low && cor[mp(i, pos)]) {
pos++;
}
if (pos >= low)
break;
idx = 0;
while (P[i][idx] < pos)
++idx;
res = min(res, P[i][idx] - 1);
pos++;
}
cout << res;
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p03203 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
// std::vector Declaration
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
// std::vector Declaration and Initialization
template <typename T> vector<T> make_vector(size_t a, T x) {
return vector<T>(a, x);
}
template <typename T, typename U, typename... Ts>
auto make_vector(size_t a, U b, Ts... ts) {
return vector<decltype(make_vector<T>(b, ts...))>(a,
make_vector<T>(b, ts...));
}
// std::vector Input
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v)
is >> e;
return is;
}
// std::vector Debug
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
bool a = 1;
for (auto e : v) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "]";
return os;
}
// std::array Debug
template <typename T, size_t n>
ostream &operator<<(ostream &os, const array<T, n> &v) {
os << "[";
bool a = 1;
for (auto e : v) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "]";
return os;
}
// std::deque Debug
template <typename T> ostream &operator<<(ostream &os, const deque<T> &d) {
os << "[";
bool a = 1;
for (auto e : d) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "]";
return os;
}
// std::pair Debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << " " << p.second << ")";
return os;
}
// std::set Debug
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) {
os << "{";
bool a = 1;
for (auto e : st) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "}";
return os;
}
// std::multiset Debug
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st) {
os << "{";
bool a = 1;
for (auto e : st) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "}";
return os;
}
// std::map Debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp) {
os << "{";
bool a = 1;
for (auto e : mp) {
os << (a ? "" : " ");
os << e.first << ":" << e.second;
a = 0;
}
os << "}";
return os;
}
// std::tuple Debug
template <int N, class Tuple> void out(ostream &os, const Tuple &t) {}
template <int N, class Tuple, class H, class... Ts>
void out(ostream &os, const Tuple &t) {
if (N)
os << " ";
os << get<N>(t);
out<N + 1, Tuple, Ts...>(os, t);
}
template <class... Ts> ostream &operator<<(ostream &os, const tuple<Ts...> &t) {
os << "(";
out<0, tuple<Ts...>, Ts...>(os, t);
os << ")";
return os;
}
// Debug
#define DUMP(x) cerr << #x << " = " << (x) << endl
// Weighted edge
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
friend ostream &operator<<(ostream &os, const edge &e) {
return os << "(" << e.src << "->" << e.to << ":" << e.cost << ")";
}
};
using LL = long long;
#define fs first
#define sc second
const LL MOD = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
int H, W, N;
cin >> H >> W >> N;
map<pair<int, int>, int> object;
vector<vector<int>> objectOnCol(W);
for (int i = 0; i < N; ++i) {
int x, y;
cin >> x >> y;
--x, --y;
object[make_pair(x, y)];
objectOnCol[y].emplace_back(x);
}
for (int y = 0; y < W; ++y) {
sort(objectOnCol[y].begin(), objectOnCol[y].end());
objectOnCol[y].emplace_back(H);
}
// DUMP(objectOnCol);
vector<int> reachableHeightOnCol(W, -1);
reachableHeightOnCol[0] = 0;
int x = 0, y = 0;
while (x < H) {
if (object.count({x + 1, y}) == 0) {
++x;
} else {
break;
}
if (object.count({x, y + 1}) == 0) {
++y;
if (y >= H) {
break;
} else {
reachableHeightOnCol[y] = x;
}
}
}
// DUMP(reachableHeightOnCol);
int ans = H + 1;
for (int y = 0; y < W; ++y) {
if (reachableHeightOnCol[y] == -1) {
break;
}
int r = reachableHeightOnCol[y];
auto lb = lower_bound(objectOnCol[y].begin(), objectOnCol[y].end(), r);
chmin(ans, *lb);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
// std::vector Declaration
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
// std::vector Declaration and Initialization
template <typename T> vector<T> make_vector(size_t a, T x) {
return vector<T>(a, x);
}
template <typename T, typename U, typename... Ts>
auto make_vector(size_t a, U b, Ts... ts) {
return vector<decltype(make_vector<T>(b, ts...))>(a,
make_vector<T>(b, ts...));
}
// std::vector Input
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v)
is >> e;
return is;
}
// std::vector Debug
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
bool a = 1;
for (auto e : v) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "]";
return os;
}
// std::array Debug
template <typename T, size_t n>
ostream &operator<<(ostream &os, const array<T, n> &v) {
os << "[";
bool a = 1;
for (auto e : v) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "]";
return os;
}
// std::deque Debug
template <typename T> ostream &operator<<(ostream &os, const deque<T> &d) {
os << "[";
bool a = 1;
for (auto e : d) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "]";
return os;
}
// std::pair Debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << " " << p.second << ")";
return os;
}
// std::set Debug
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) {
os << "{";
bool a = 1;
for (auto e : st) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "}";
return os;
}
// std::multiset Debug
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st) {
os << "{";
bool a = 1;
for (auto e : st) {
os << (a ? "" : " ");
os << e;
a = 0;
}
os << "}";
return os;
}
// std::map Debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp) {
os << "{";
bool a = 1;
for (auto e : mp) {
os << (a ? "" : " ");
os << e.first << ":" << e.second;
a = 0;
}
os << "}";
return os;
}
// std::tuple Debug
template <int N, class Tuple> void out(ostream &os, const Tuple &t) {}
template <int N, class Tuple, class H, class... Ts>
void out(ostream &os, const Tuple &t) {
if (N)
os << " ";
os << get<N>(t);
out<N + 1, Tuple, Ts...>(os, t);
}
template <class... Ts> ostream &operator<<(ostream &os, const tuple<Ts...> &t) {
os << "(";
out<0, tuple<Ts...>, Ts...>(os, t);
os << ")";
return os;
}
// Debug
#define DUMP(x) cerr << #x << " = " << (x) << endl
// Weighted edge
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
friend ostream &operator<<(ostream &os, const edge &e) {
return os << "(" << e.src << "->" << e.to << ":" << e.cost << ")";
}
};
using LL = long long;
#define fs first
#define sc second
const LL MOD = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
int H, W, N;
cin >> H >> W >> N;
map<pair<int, int>, int> object;
vector<vector<int>> objectOnCol(W);
for (int i = 0; i < N; ++i) {
int x, y;
cin >> x >> y;
--x, --y;
object[make_pair(x, y)];
objectOnCol[y].emplace_back(x);
}
for (int y = 0; y < W; ++y) {
sort(objectOnCol[y].begin(), objectOnCol[y].end());
objectOnCol[y].emplace_back(H);
}
// DUMP(objectOnCol);
vector<int> reachableHeightOnCol(W, -1);
reachableHeightOnCol[0] = 0;
int x = 0, y = 0;
while (x < H) {
if (object.count({x + 1, y}) == 0) {
++x;
} else {
break;
}
if (object.count({x, y + 1}) == 0) {
++y;
if (y >= W) {
break;
} else {
reachableHeightOnCol[y] = x;
}
}
}
// DUMP(reachableHeightOnCol);
int ans = H + 1;
for (int y = 0; y < W; ++y) {
if (reachableHeightOnCol[y] == -1) {
break;
}
int r = reachableHeightOnCol[y];
auto lb = lower_bound(objectOnCol[y].begin(), objectOnCol[y].end(), r);
chmin(ans, *lb);
}
cout << ans << endl;
return 0;
}
| replace | 202 | 203 | 202 | 203 | 0 | |
p03204 | C++ | Time Limit Exceeded | /**
* author: tourist
* created: 19.12.2019 15:19:08
**/
#include <bits/stdc++.h>
using namespace std;
template <typename T> class graph {
public:
struct edge {
int from;
int to;
T cost;
};
vector<edge> edges;
vector<vector<int>> g;
int n;
graph(int _n) : n(_n) { g.resize(n); }
virtual int add(int from, int to, T cost) = 0;
};
template <typename T> class forest : public graph<T> {
public:
using graph<T>::edges;
using graph<T>::g;
using graph<T>::n;
forest(int _n) : graph<T>(_n) {}
int add(int from, int to, T cost = 1) {
assert(0 <= from && from < n && 0 <= to && to < n);
int id = (int)edges.size();
assert(id < n - 1);
g[from].push_back(id);
g[to].push_back(id);
edges.push_back({from, to, cost});
return id;
}
};
template <typename T> class dfs_forest : public forest<T> {
public:
using forest<T>::edges;
using forest<T>::g;
using forest<T>::n;
vector<int> pv;
vector<int> pe;
vector<int> order;
vector<int> pos;
vector<int> end;
vector<int> sz;
vector<int> root;
vector<int> depth;
vector<T> dist;
dfs_forest(int _n) : forest<T>(_n) {}
void init() {
pv = vector<int>(n, -1);
pe = vector<int>(n, -1);
order.clear();
pos = vector<int>(n, -1);
end = vector<int>(n, -1);
sz = vector<int>(n, 0);
root = vector<int>(n, -1);
depth = vector<int>(n, -1);
dist = vector<T>(n);
}
void clear() {
pv.clear();
pe.clear();
order.clear();
pos.clear();
end.clear();
sz.clear();
root.clear();
depth.clear();
dist.clear();
}
private:
void do_dfs(int v) {
pos[v] = (int)order.size();
order.push_back(v);
sz[v] = 1;
for (int id : g[v]) {
if (id == pe[v]) {
continue;
}
auto &e = edges[id];
int to = e.from ^ e.to ^ v;
depth[to] = depth[v] + 1;
dist[to] = dist[v] + e.cost;
pv[to] = v;
pe[to] = id;
root[to] = (root[v] != -1 ? root[v] : to);
do_dfs(to);
sz[v] += sz[to];
}
end[v] = (int)order.size() - 1;
}
void do_dfs_from(int v) {
depth[v] = 0;
dist[v] = T{};
root[v] = v;
pv[v] = pe[v] = -1;
do_dfs(v);
}
public:
void dfs(int v, bool clear_order = true) {
if (pv.empty()) {
init();
} else {
if (clear_order) {
order.clear();
}
}
do_dfs_from(v);
}
void dfs_all() {
init();
for (int v = 0; v < n; v++) {
if (depth[v] == -1) {
do_dfs_from(v);
}
}
assert((int)order.size() == n);
}
};
template <typename T> class lca_forest : public dfs_forest<T> {
public:
using dfs_forest<T>::edges;
using dfs_forest<T>::g;
using dfs_forest<T>::n;
using dfs_forest<T>::pv;
using dfs_forest<T>::pos;
using dfs_forest<T>::end;
using dfs_forest<T>::depth;
int h;
vector<vector<int>> pr;
lca_forest(int _n) : dfs_forest<T>(_n) {}
inline void build_lca() {
assert(!pv.empty());
int max_depth = 0;
for (int i = 0; i < n; i++) {
max_depth = max(max_depth, depth[i]);
}
h = 1;
while ((1 << h) <= max_depth) {
h++;
}
pr.resize(n);
for (int i = 0; i < n; i++) {
pr[i].resize(h);
pr[i][0] = pv[i];
}
for (int j = 1; j < h; j++) {
for (int i = 0; i < n; i++) {
pr[i][j] = (pr[i][j - 1] == -1 ? -1 : pr[pr[i][j - 1]][j - 1]);
}
}
}
inline bool anc(int x, int y) {
return (pos[x] <= pos[y] && end[y] <= end[x]);
}
inline int go_up(int x, int up) {
assert(!pr.empty());
up = min(up, (1 << h) - 1);
for (int j = h - 1; j >= 0; j--) {
if (up & (1 << j)) {
x = pr[x][j];
if (x == -1) {
break;
}
}
}
return x;
}
inline int lca(int x, int y) {
assert(!pr.empty());
if (anc(x, y)) {
return x;
}
if (anc(y, x)) {
return y;
}
for (int j = h - 1; j >= 0; j--) {
if (pr[x][j] != -1 && !anc(pr[x][j], y)) {
x = pr[x][j];
}
}
return pr[x][0];
}
};
template <typename T> class hld_forest : public lca_forest<T> {
public:
using lca_forest<T>::edges;
using lca_forest<T>::g;
using lca_forest<T>::n;
using lca_forest<T>::pv;
using lca_forest<T>::sz;
using lca_forest<T>::pos;
using lca_forest<T>::order;
using lca_forest<T>::depth;
using lca_forest<T>::dfs;
using lca_forest<T>::dfs_all;
using lca_forest<T>::lca;
using lca_forest<T>::build_lca;
vector<int> head;
vector<int> visited;
hld_forest(int _n) : lca_forest<T>(_n) { visited.resize(n); }
void build_hld(const vector<int> &vs) {
for (int tries = 0; tries < 2; tries++) {
if (vs.empty()) {
dfs_all();
} else {
order.clear();
for (int v : vs) {
dfs(v, false);
}
assert((int)order.size() == n);
}
if (tries == 1) {
break;
}
for (int i = 0; i < n; i++) {
if (g[i].empty()) {
continue;
}
int best = -1, bid = 0;
for (int j = 0; j < (int)g[i].size(); j++) {
int id = g[i][j];
int v = edges[id].from ^ edges[id].to ^ i;
if (pv[v] != i) {
continue;
}
if (sz[v] > best) {
best = sz[v];
bid = j;
}
}
swap(g[i][0], g[i][bid]);
}
}
build_lca();
head.resize(n);
for (int i = 0; i < n; i++) {
head[i] = i;
}
for (int i = 0; i < n - 1; i++) {
int x = order[i];
int y = order[i + 1];
if (pv[y] == x) {
head[y] = head[x];
}
}
}
void build_hld(int v) { build_hld(vector<int>(1, v)); }
void build_hld_all() { build_hld(vector<int>()); }
bool apply_on_path(int x, int y, bool with_lca,
function<void(int, int, bool)> f) {
// f(x, y, up): up -- whether this part of the path goes up
assert(!head.empty());
int z = lca(x, y);
if (z == -1) {
return false;
}
{
int v = x;
while (v != z) {
if (depth[head[v]] <= depth[z]) {
f(pos[z] + 1, pos[v], true);
break;
}
f(pos[head[v]], pos[v], true);
v = pv[head[v]];
}
}
if (with_lca) {
f(pos[z], pos[z], false);
}
{
int v = y;
int cnt_visited = 0;
while (v != z) {
if (depth[head[v]] <= depth[z]) {
f(pos[z] + 1, pos[v], false);
break;
}
visited[cnt_visited++] = v;
v = pv[head[v]];
}
for (int at = cnt_visited - 1; at >= 0; at--) {
v = visited[at];
f(pos[head[v]], pos[v], false);
}
}
return true;
}
};
class segtree {
public:
struct node {
// don't forget to set default value (used for leaves)
// not necessarily neutral element!
long long sum = 0;
int add = 0;
int mx = 0;
void apply(int l, int r, int v) { mx = v; }
void apply(int l, int r, int v, bool op) {
sum += v * (r - l + 1LL);
add += v;
}
};
node unite(const node &a, const node &b) const {
node res;
res.sum = a.sum + b.sum;
res.mx = max(a.mx, b.mx);
return res;
}
inline void push(int x, int l, int r) {
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
if (tree[x].add != 0) {
tree[x + 1].apply(l, y, tree[x].add, true);
tree[z].apply(y + 1, r, tree[x].add, true);
tree[x].add = 0;
}
}
inline void pull(int x, int z) { tree[x] = unite(tree[x + 1], tree[z]); }
int n;
vector<node> tree;
void build(int x, int l, int r) {
if (l == r) {
return;
}
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
build(x + 1, l, y);
build(z, y + 1, r);
pull(x, z);
}
template <typename M> void build(int x, int l, int r, const vector<M> &v) {
if (l == r) {
tree[x].apply(l, r, v[l]);
return;
}
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
build(x + 1, l, y, v);
build(z, y + 1, r, v);
pull(x, z);
}
node get(int x, int l, int r, int ll, int rr) {
if (ll <= l && r <= rr) {
return tree[x];
}
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
push(x, l, r);
node res{};
if (rr <= y) {
res = get(x + 1, l, y, ll, rr);
} else {
if (ll > y) {
res = get(z, y + 1, r, ll, rr);
} else {
res = unite(get(x + 1, l, y, ll, rr), get(z, y + 1, r, ll, rr));
}
}
pull(x, z);
return res;
}
template <typename... M>
void modify(int x, int l, int r, int ll, int rr, const M &...v) {
if (ll <= l && r <= rr) {
tree[x].apply(l, r, v...);
return;
}
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
push(x, l, r);
if (ll <= y) {
modify(x + 1, l, y, ll, rr, v...);
}
if (rr > y) {
modify(z, y + 1, r, ll, rr, v...);
}
pull(x, z);
}
int find_first_knowingly(int x, int l, int r,
const function<bool(const node &)> &f) {
if (l == r) {
return l;
}
push(x, l, r);
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
int res;
if (f(tree[x + 1])) {
res = find_first_knowingly(x + 1, l, y, f);
} else {
res = find_first_knowingly(z, y + 1, r, f);
}
pull(x, z);
return res;
}
int find_first(int x, int l, int r, int ll, int rr,
const function<bool(const node &)> &f) {
if (ll <= l && r <= rr) {
if (!f(tree[x])) {
return -1;
}
return find_first_knowingly(x, l, r, f);
}
push(x, l, r);
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
int res = -1;
if (ll <= y) {
res = find_first(x + 1, l, y, ll, rr, f);
}
if (rr > y && res == -1) {
res = find_first(z, y + 1, r, ll, rr, f);
}
pull(x, z);
return res;
}
int find_last_knowingly(int x, int l, int r,
const function<bool(const node &)> &f) {
if (l == r) {
return l;
}
push(x, l, r);
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
int res;
if (f(tree[z])) {
res = find_last_knowingly(z, y + 1, r, f);
} else {
res = find_last_knowingly(x + 1, l, y, f);
}
pull(x, z);
return res;
}
int find_last(int x, int l, int r, int ll, int rr,
const function<bool(const node &)> &f) {
if (ll <= l && r <= rr) {
if (!f(tree[x])) {
return -1;
}
return find_last_knowingly(x, l, r, f);
}
push(x, l, r);
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
int res = -1;
if (rr > y) {
res = find_last(z, y + 1, r, ll, rr, f);
}
if (ll <= y && res == -1) {
res = find_last(x + 1, l, y, ll, rr, f);
}
pull(x, z);
return res;
}
segtree(int _n) : n(_n) {
assert(n > 0);
tree.resize(2 * n - 1);
build(0, 0, n - 1);
}
template <typename M> segtree(const vector<M> &v) {
n = v.size();
assert(n > 0);
tree.resize(2 * n - 1);
build(0, 0, n - 1, v);
}
node get(int ll, int rr) {
assert(0 <= ll && ll <= rr && rr <= n - 1);
return get(0, 0, n - 1, ll, rr);
}
node get(int p) {
assert(0 <= p && p <= n - 1);
return get(0, 0, n - 1, p, p);
}
template <typename... M> void modify(int ll, int rr, const M &...v) {
assert(0 <= ll && ll <= rr && rr <= n - 1);
modify(0, 0, n - 1, ll, rr, v...);
}
int find_first(int ll, int rr, const function<bool(const node &)> &f) {
assert(0 <= ll && ll <= rr && rr <= n - 1);
return find_first(0, 0, n - 1, ll, rr, f);
}
int find_last(int ll, int rr, const function<bool(const node &)> &f) {
assert(0 <= ll && ll <= rr && rr <= n - 1);
return find_last(0, 0, n - 1, ll, rr, f);
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
hld_forest<int> g(n);
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
--x;
--y;
g.add(x, y);
}
g.build_hld(0);
segtree st(g.order);
for (int i = 1; i < n; i++) {
int low = 0, high = g.depth[i] - 1;
while (low < high) {
int mid = (low + high + 1) >> 1;
int z = g.go_up(i, mid - 1);
int x = -1;
g.apply_on_path(i, z, true, [&](int from, int to, bool) {
x = max(x, st.get(from, to).mx);
});
int y = -1;
g.apply_on_path(g.pv[g.pv[z]], 0, true, [&](int from, int to, bool) {
y = max(y, st.get(from, to).mx);
});
if (x < y) {
low = mid;
} else {
high = mid - 1;
}
}
int z = g.go_up(i, low);
st.modify(g.pos[z], g.end[z], 1, true);
}
for (int i = 1; i < n; i++) {
if (i > 1) {
cout << " ";
}
cout << st.get(g.pos[i], g.pos[i]).sum; // + g.depth[i];
}
cout << '\n';
return 0;
}
| /**
* author: tourist
* created: 19.12.2019 15:19:08
**/
#include <bits/stdc++.h>
using namespace std;
template <typename T> class graph {
public:
struct edge {
int from;
int to;
T cost;
};
vector<edge> edges;
vector<vector<int>> g;
int n;
graph(int _n) : n(_n) { g.resize(n); }
virtual int add(int from, int to, T cost) = 0;
};
template <typename T> class forest : public graph<T> {
public:
using graph<T>::edges;
using graph<T>::g;
using graph<T>::n;
forest(int _n) : graph<T>(_n) {}
int add(int from, int to, T cost = 1) {
assert(0 <= from && from < n && 0 <= to && to < n);
int id = (int)edges.size();
assert(id < n - 1);
g[from].push_back(id);
g[to].push_back(id);
edges.push_back({from, to, cost});
return id;
}
};
template <typename T> class dfs_forest : public forest<T> {
public:
using forest<T>::edges;
using forest<T>::g;
using forest<T>::n;
vector<int> pv;
vector<int> pe;
vector<int> order;
vector<int> pos;
vector<int> end;
vector<int> sz;
vector<int> root;
vector<int> depth;
vector<T> dist;
dfs_forest(int _n) : forest<T>(_n) {}
void init() {
pv = vector<int>(n, -1);
pe = vector<int>(n, -1);
order.clear();
pos = vector<int>(n, -1);
end = vector<int>(n, -1);
sz = vector<int>(n, 0);
root = vector<int>(n, -1);
depth = vector<int>(n, -1);
dist = vector<T>(n);
}
void clear() {
pv.clear();
pe.clear();
order.clear();
pos.clear();
end.clear();
sz.clear();
root.clear();
depth.clear();
dist.clear();
}
private:
void do_dfs(int v) {
pos[v] = (int)order.size();
order.push_back(v);
sz[v] = 1;
for (int id : g[v]) {
if (id == pe[v]) {
continue;
}
auto &e = edges[id];
int to = e.from ^ e.to ^ v;
depth[to] = depth[v] + 1;
dist[to] = dist[v] + e.cost;
pv[to] = v;
pe[to] = id;
root[to] = (root[v] != -1 ? root[v] : to);
do_dfs(to);
sz[v] += sz[to];
}
end[v] = (int)order.size() - 1;
}
void do_dfs_from(int v) {
depth[v] = 0;
dist[v] = T{};
root[v] = v;
pv[v] = pe[v] = -1;
do_dfs(v);
}
public:
void dfs(int v, bool clear_order = true) {
if (pv.empty()) {
init();
} else {
if (clear_order) {
order.clear();
}
}
do_dfs_from(v);
}
void dfs_all() {
init();
for (int v = 0; v < n; v++) {
if (depth[v] == -1) {
do_dfs_from(v);
}
}
assert((int)order.size() == n);
}
};
template <typename T> class lca_forest : public dfs_forest<T> {
public:
using dfs_forest<T>::edges;
using dfs_forest<T>::g;
using dfs_forest<T>::n;
using dfs_forest<T>::pv;
using dfs_forest<T>::pos;
using dfs_forest<T>::end;
using dfs_forest<T>::depth;
int h;
vector<vector<int>> pr;
lca_forest(int _n) : dfs_forest<T>(_n) {}
inline void build_lca() {
assert(!pv.empty());
int max_depth = 0;
for (int i = 0; i < n; i++) {
max_depth = max(max_depth, depth[i]);
}
h = 1;
while ((1 << h) <= max_depth) {
h++;
}
pr.resize(n);
for (int i = 0; i < n; i++) {
pr[i].resize(h);
pr[i][0] = pv[i];
}
for (int j = 1; j < h; j++) {
for (int i = 0; i < n; i++) {
pr[i][j] = (pr[i][j - 1] == -1 ? -1 : pr[pr[i][j - 1]][j - 1]);
}
}
}
inline bool anc(int x, int y) {
return (pos[x] <= pos[y] && end[y] <= end[x]);
}
inline int go_up(int x, int up) {
assert(!pr.empty());
up = min(up, (1 << h) - 1);
for (int j = h - 1; j >= 0; j--) {
if (up & (1 << j)) {
x = pr[x][j];
if (x == -1) {
break;
}
}
}
return x;
}
inline int lca(int x, int y) {
assert(!pr.empty());
if (anc(x, y)) {
return x;
}
if (anc(y, x)) {
return y;
}
for (int j = h - 1; j >= 0; j--) {
if (pr[x][j] != -1 && !anc(pr[x][j], y)) {
x = pr[x][j];
}
}
return pr[x][0];
}
};
template <typename T> class hld_forest : public lca_forest<T> {
public:
using lca_forest<T>::edges;
using lca_forest<T>::g;
using lca_forest<T>::n;
using lca_forest<T>::pv;
using lca_forest<T>::sz;
using lca_forest<T>::pos;
using lca_forest<T>::order;
using lca_forest<T>::depth;
using lca_forest<T>::dfs;
using lca_forest<T>::dfs_all;
using lca_forest<T>::lca;
using lca_forest<T>::build_lca;
vector<int> head;
vector<int> visited;
hld_forest(int _n) : lca_forest<T>(_n) { visited.resize(n); }
void build_hld(const vector<int> &vs) {
for (int tries = 0; tries < 2; tries++) {
if (vs.empty()) {
dfs_all();
} else {
order.clear();
for (int v : vs) {
dfs(v, false);
}
assert((int)order.size() == n);
}
if (tries == 1) {
break;
}
for (int i = 0; i < n; i++) {
if (g[i].empty()) {
continue;
}
int best = -1, bid = 0;
for (int j = 0; j < (int)g[i].size(); j++) {
int id = g[i][j];
int v = edges[id].from ^ edges[id].to ^ i;
if (pv[v] != i) {
continue;
}
if (sz[v] > best) {
best = sz[v];
bid = j;
}
}
swap(g[i][0], g[i][bid]);
}
}
build_lca();
head.resize(n);
for (int i = 0; i < n; i++) {
head[i] = i;
}
for (int i = 0; i < n - 1; i++) {
int x = order[i];
int y = order[i + 1];
if (pv[y] == x) {
head[y] = head[x];
}
}
}
void build_hld(int v) { build_hld(vector<int>(1, v)); }
void build_hld_all() { build_hld(vector<int>()); }
bool apply_on_path(int x, int y, bool with_lca,
function<void(int, int, bool)> f) {
// f(x, y, up): up -- whether this part of the path goes up
assert(!head.empty());
int z = lca(x, y);
if (z == -1) {
return false;
}
{
int v = x;
while (v != z) {
if (depth[head[v]] <= depth[z]) {
f(pos[z] + 1, pos[v], true);
break;
}
f(pos[head[v]], pos[v], true);
v = pv[head[v]];
}
}
if (with_lca) {
f(pos[z], pos[z], false);
}
{
int v = y;
int cnt_visited = 0;
while (v != z) {
if (depth[head[v]] <= depth[z]) {
f(pos[z] + 1, pos[v], false);
break;
}
visited[cnt_visited++] = v;
v = pv[head[v]];
}
for (int at = cnt_visited - 1; at >= 0; at--) {
v = visited[at];
f(pos[head[v]], pos[v], false);
}
}
return true;
}
};
class segtree {
public:
struct node {
// don't forget to set default value (used for leaves)
// not necessarily neutral element!
long long sum = 0;
int add = 0;
int mx = 0;
void apply(int l, int r, int v) { mx = v; }
void apply(int l, int r, int v, bool op) {
sum += v * (r - l + 1LL);
add += v;
}
};
node unite(const node &a, const node &b) const {
node res;
res.sum = a.sum + b.sum;
res.mx = max(a.mx, b.mx);
return res;
}
inline void push(int x, int l, int r) {
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
if (tree[x].add != 0) {
tree[x + 1].apply(l, y, tree[x].add, true);
tree[z].apply(y + 1, r, tree[x].add, true);
tree[x].add = 0;
}
}
inline void pull(int x, int z) { tree[x] = unite(tree[x + 1], tree[z]); }
int n;
vector<node> tree;
void build(int x, int l, int r) {
if (l == r) {
return;
}
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
build(x + 1, l, y);
build(z, y + 1, r);
pull(x, z);
}
template <typename M> void build(int x, int l, int r, const vector<M> &v) {
if (l == r) {
tree[x].apply(l, r, v[l]);
return;
}
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
build(x + 1, l, y, v);
build(z, y + 1, r, v);
pull(x, z);
}
node get(int x, int l, int r, int ll, int rr) {
if (ll <= l && r <= rr) {
return tree[x];
}
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
push(x, l, r);
node res{};
if (rr <= y) {
res = get(x + 1, l, y, ll, rr);
} else {
if (ll > y) {
res = get(z, y + 1, r, ll, rr);
} else {
res = unite(get(x + 1, l, y, ll, rr), get(z, y + 1, r, ll, rr));
}
}
pull(x, z);
return res;
}
template <typename... M>
void modify(int x, int l, int r, int ll, int rr, const M &...v) {
if (ll <= l && r <= rr) {
tree[x].apply(l, r, v...);
return;
}
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
push(x, l, r);
if (ll <= y) {
modify(x + 1, l, y, ll, rr, v...);
}
if (rr > y) {
modify(z, y + 1, r, ll, rr, v...);
}
pull(x, z);
}
int find_first_knowingly(int x, int l, int r,
const function<bool(const node &)> &f) {
if (l == r) {
return l;
}
push(x, l, r);
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
int res;
if (f(tree[x + 1])) {
res = find_first_knowingly(x + 1, l, y, f);
} else {
res = find_first_knowingly(z, y + 1, r, f);
}
pull(x, z);
return res;
}
int find_first(int x, int l, int r, int ll, int rr,
const function<bool(const node &)> &f) {
if (ll <= l && r <= rr) {
if (!f(tree[x])) {
return -1;
}
return find_first_knowingly(x, l, r, f);
}
push(x, l, r);
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
int res = -1;
if (ll <= y) {
res = find_first(x + 1, l, y, ll, rr, f);
}
if (rr > y && res == -1) {
res = find_first(z, y + 1, r, ll, rr, f);
}
pull(x, z);
return res;
}
int find_last_knowingly(int x, int l, int r,
const function<bool(const node &)> &f) {
if (l == r) {
return l;
}
push(x, l, r);
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
int res;
if (f(tree[z])) {
res = find_last_knowingly(z, y + 1, r, f);
} else {
res = find_last_knowingly(x + 1, l, y, f);
}
pull(x, z);
return res;
}
int find_last(int x, int l, int r, int ll, int rr,
const function<bool(const node &)> &f) {
if (ll <= l && r <= rr) {
if (!f(tree[x])) {
return -1;
}
return find_last_knowingly(x, l, r, f);
}
push(x, l, r);
int y = (l + r) >> 1;
int z = x + ((y - l + 1) << 1);
int res = -1;
if (rr > y) {
res = find_last(z, y + 1, r, ll, rr, f);
}
if (ll <= y && res == -1) {
res = find_last(x + 1, l, y, ll, rr, f);
}
pull(x, z);
return res;
}
segtree(int _n) : n(_n) {
assert(n > 0);
tree.resize(2 * n - 1);
build(0, 0, n - 1);
}
template <typename M> segtree(const vector<M> &v) {
n = v.size();
assert(n > 0);
tree.resize(2 * n - 1);
build(0, 0, n - 1, v);
}
node get(int ll, int rr) {
assert(0 <= ll && ll <= rr && rr <= n - 1);
return get(0, 0, n - 1, ll, rr);
}
node get(int p) {
assert(0 <= p && p <= n - 1);
return get(0, 0, n - 1, p, p);
}
template <typename... M> void modify(int ll, int rr, const M &...v) {
assert(0 <= ll && ll <= rr && rr <= n - 1);
modify(0, 0, n - 1, ll, rr, v...);
}
int find_first(int ll, int rr, const function<bool(const node &)> &f) {
assert(0 <= ll && ll <= rr && rr <= n - 1);
return find_first(0, 0, n - 1, ll, rr, f);
}
int find_last(int ll, int rr, const function<bool(const node &)> &f) {
assert(0 <= ll && ll <= rr && rr <= n - 1);
return find_last(0, 0, n - 1, ll, rr, f);
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
hld_forest<int> g(n);
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
--x;
--y;
g.add(x, y);
}
g.build_hld(0);
segtree st(g.order);
for (int i = 1; i < n; i++) {
int z = 0;
g.apply_on_path(i, 0, true, [&](int from, int to, bool) {
z = max(z, st.get(from, to).mx);
});
int x = -1;
g.apply_on_path(i, z, false, [&](int from, int to, bool) {
x = max(x, st.get(from, to).mx);
});
int y = -1;
g.apply_on_path(g.pv[z], 0, true, [&](int from, int to, bool) {
y = max(y, st.get(from, to).mx);
});
if (x >= y) {
z = g.go_up(i, g.depth[i] - g.depth[z] - 1);
}
st.modify(g.pos[z], g.end[z], 1, true);
}
for (int i = 1; i < n; i++) {
if (i > 1) {
cout << " ";
}
cout << st.get(g.pos[i], g.pos[i]).sum; // + g.depth[i];
}
cout << '\n';
return 0;
}
| replace | 560 | 579 | 560 | 575 | TLE | |
p03204 | C++ | Runtime Error | // This amazing code is by Eric Sunli Chen.
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool get_int(T &x) {
char t = getchar();
bool neg = false;
x = 0;
for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar())
;
if (t == '-')
neg = true, t = getchar();
if (t == EOF)
return false;
for (; t <= '9' && t >= '0'; t = getchar())
x = x * 10 + t - '0';
if (neg)
x = -x;
return true;
}
template <typename T> void print_int(T x) {
if (x < 0)
putchar('-'), x = -x;
short a[20] = {}, sz = 0;
while (x > 0)
a[sz++] = x % 10, x /= 10;
if (sz == 0)
putchar('0');
for (int i = sz - 1; i >= 0; i--)
putchar('0' + a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a, b) (get1(a) && get1(b))
#define get3(a, b, c) (get1(a) && get2(b, c))
#define printendl(a) print_int(a), puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll << 61;
const double pi = acos(-1.0);
const int maxn = 100111;
vector<int> g[maxn], ng[maxn];
int n, fa[maxn], mx[maxn], sz[maxn], nsz[maxn], dt[maxn], ans[maxn];
void dfs(int x) {
sz[x] = 1;
nsz[x] = 1;
for (auto &v : g[x])
if (v != fa[x]) {
fa[v] = x;
mx[v] = max(mx[x], x);
dfs(v);
sz[x] += sz[v];
nsz[x] += nsz[v];
}
if (x > mx[x]) {
nsz[x] = 0;
if (mx[x])
ng[mx[x]].pb(x);
}
if (mx[x] == fa[x])
dt[x] = nsz[x];
}
void dfs2(int x) {
for (auto &v : g[x])
if (v != fa[x]) {
ans[v] = ans[x] + dt[v];
dfs2(v);
}
}
int f[maxn], fsz[maxn];
int gf(int x) { return x == f[x] ? x : f[x] = gf(f[x]); }
void merge(int u, int v) {
u = gf(u);
v = gf(v);
if (u == v)
return;
f[u] = v;
fsz[v] += fsz[u];
}
int main() {
get1(n);
for (int i = 1, u, v; i < n; i++) {
get2(u, v);
g[u].pb(v);
g[v].pb(u);
}
dfs(1);
for (int i = 1; i <= n; i++) {
f[i] = i;
fsz[i] = 1;
}
for (int x = 1; x <= n; x++) {
if (x > mx[x]) {
for (auto &v : ng[x]) {
int sum = 0;
for (auto &v2 : g[v])
if (v2 != fa[v] && v2 <= x) {
sum += fsz[gf(v2)];
dt[v2] -= fsz[gf(v2)];
}
dt[v] += sum + 1;
}
}
for (auto &v : g[x])
if (v <= x)
merge(x, v);
}
dfs2(1);
for (int i = 2; i <= n; i++)
printf("%d ", ans[i]);
return 0;
} | // This amazing code is by Eric Sunli Chen.
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool get_int(T &x) {
char t = getchar();
bool neg = false;
x = 0;
for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar())
;
if (t == '-')
neg = true, t = getchar();
if (t == EOF)
return false;
for (; t <= '9' && t >= '0'; t = getchar())
x = x * 10 + t - '0';
if (neg)
x = -x;
return true;
}
template <typename T> void print_int(T x) {
if (x < 0)
putchar('-'), x = -x;
short a[20] = {}, sz = 0;
while (x > 0)
a[sz++] = x % 10, x /= 10;
if (sz == 0)
putchar('0');
for (int i = sz - 1; i >= 0; i--)
putchar('0' + a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a, b) (get1(a) && get1(b))
#define get3(a, b, c) (get1(a) && get2(b, c))
#define printendl(a) print_int(a), puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll << 61;
const double pi = acos(-1.0);
const int maxn = 200111;
vector<int> g[maxn], ng[maxn];
int n, fa[maxn], mx[maxn], sz[maxn], nsz[maxn], dt[maxn], ans[maxn];
void dfs(int x) {
sz[x] = 1;
nsz[x] = 1;
for (auto &v : g[x])
if (v != fa[x]) {
fa[v] = x;
mx[v] = max(mx[x], x);
dfs(v);
sz[x] += sz[v];
nsz[x] += nsz[v];
}
if (x > mx[x]) {
nsz[x] = 0;
if (mx[x])
ng[mx[x]].pb(x);
}
if (mx[x] == fa[x])
dt[x] = nsz[x];
}
void dfs2(int x) {
for (auto &v : g[x])
if (v != fa[x]) {
ans[v] = ans[x] + dt[v];
dfs2(v);
}
}
int f[maxn], fsz[maxn];
int gf(int x) { return x == f[x] ? x : f[x] = gf(f[x]); }
void merge(int u, int v) {
u = gf(u);
v = gf(v);
if (u == v)
return;
f[u] = v;
fsz[v] += fsz[u];
}
int main() {
get1(n);
for (int i = 1, u, v; i < n; i++) {
get2(u, v);
g[u].pb(v);
g[v].pb(u);
}
dfs(1);
for (int i = 1; i <= n; i++) {
f[i] = i;
fsz[i] = 1;
}
for (int x = 1; x <= n; x++) {
if (x > mx[x]) {
for (auto &v : ng[x]) {
int sum = 0;
for (auto &v2 : g[v])
if (v2 != fa[v] && v2 <= x) {
sum += fsz[gf(v2)];
dt[v2] -= fsz[gf(v2)];
}
dt[v] += sum + 1;
}
}
for (auto &v : g[x])
if (v <= x)
merge(x, v);
}
dfs2(1);
for (int i = 2; i <= n; i++)
printf("%d ", ans[i]);
return 0;
} | replace | 45 | 46 | 45 | 46 | 0 | |
p03204 | C++ | Time Limit Exceeded |
#include <bits/stdc++.h>
#define ln '\n'
#define all(dat) dat.begin(), dat.end()
#define loop(i, to) for (int i = 0; i < to; ++i)
#define cont(i, to) for (int i = 1; i <= to; ++i)
#define circ(i, fm, to) for (int i = fm; i <= to; ++i)
#define foreach(i, dat) \
for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)
typedef long long num;
using namespace std;
const int nsz = 2e5;
int n, rt = 1, mx[nsz + 5], pr[nsz + 5], dp[nsz + 5][3], ans[nsz + 5];
vector<int> g[nsz + 5];
int inline qry0(int u, int w) {
int cnt = 1;
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u] || v > w)
continue;
cnt += qry0(v, w);
}
return cnt;
}
int inline qry1(int u, int w) {
if (u > w)
return 0;
int cnt = 1;
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
cnt += qry1(v, w);
}
return cnt;
}
void dfs(int u = rt) {
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
pr[v] = u;
mx[v] = max(mx[u], u);
dfs(v);
}
if (u > mx[u]) {
dp[u][0] = 1;
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
if (v <= mx[u]) {
dp[u][0] += dp[v][1];
}
}
} else if (u < mx[u] && pr[u] < mx[u]) {
dp[u][0] = dp[u][1] = dp[u][2] = 1;
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
if (v <= mx[u]) {
dp[u][0] += dp[v][0];
}
if (v <= mx[pr[u]]) {
dp[u][1] += dp[v][1];
}
if (v <= mx[mx[pr[u]]]) {
dp[u][2] += dp[v][2];
}
}
} else {
dp[u][0] = 1;
dp[u][1] = u <= mx[pr[u]];
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
if (v <= mx[u]) {
dp[u][0] += dp[v][0];
}
if (u <= mx[pr[u]] && v <= mx[pr[u]]) {
dp[u][1] += dp[v][2];
}
}
// dp[u][1] = qry1(u, mx[pr[u]]);
}
if (u == rt)
return;
if (u > mx[u]) {
ans[u] = dp[u][0];
// ans[u] = qry0(u, mx[u]);
} else if (pr[u] == mx[u]) {
ans[u] = dp[u][0] - dp[u][1];
// ans[u] = qry0(u, mx[u]) - qry1(u, mx[pr[u]]);
} else {
ans[u] = 0;
}
}
void pre(int u = rt) {
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
ans[v] += ans[u];
pre(v);
}
}
int main() {
// freopen("dat.in", "r", stdin);
// freopen("dat.out", "w", stdout);
scanf("%d", &n);
cont(i, n - 1) {
int u, v;
scanf("%d%d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
dfs();
cont(u, n) {
if (dp[u][0] != qry0(u, mx[u]) || dp[u][1] != qry1(u, mx[pr[u]])) {
cerr << u << ": " << dp[u][0] << ' ' << qry0(u, mx[u]) << ' ' << dp[u][1]
<< ' ' << qry1(u, mx[pr[u]]) << ln;
}
}
pre();
circ(u, 2, n) { cout << ans[u] << ' '; }
cout << ln;
} |
#include <bits/stdc++.h>
#define ln '\n'
#define all(dat) dat.begin(), dat.end()
#define loop(i, to) for (int i = 0; i < to; ++i)
#define cont(i, to) for (int i = 1; i <= to; ++i)
#define circ(i, fm, to) for (int i = fm; i <= to; ++i)
#define foreach(i, dat) \
for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)
typedef long long num;
using namespace std;
const int nsz = 2e5;
int n, rt = 1, mx[nsz + 5], pr[nsz + 5], dp[nsz + 5][3], ans[nsz + 5];
vector<int> g[nsz + 5];
int inline qry0(int u, int w) {
int cnt = 1;
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u] || v > w)
continue;
cnt += qry0(v, w);
}
return cnt;
}
int inline qry1(int u, int w) {
if (u > w)
return 0;
int cnt = 1;
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
cnt += qry1(v, w);
}
return cnt;
}
void dfs(int u = rt) {
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
pr[v] = u;
mx[v] = max(mx[u], u);
dfs(v);
}
if (u > mx[u]) {
dp[u][0] = 1;
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
if (v <= mx[u]) {
dp[u][0] += dp[v][1];
}
}
} else if (u < mx[u] && pr[u] < mx[u]) {
dp[u][0] = dp[u][1] = dp[u][2] = 1;
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
if (v <= mx[u]) {
dp[u][0] += dp[v][0];
}
if (v <= mx[pr[u]]) {
dp[u][1] += dp[v][1];
}
if (v <= mx[mx[pr[u]]]) {
dp[u][2] += dp[v][2];
}
}
} else {
dp[u][0] = 1;
dp[u][1] = u <= mx[pr[u]];
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
if (v <= mx[u]) {
dp[u][0] += dp[v][0];
}
if (u <= mx[pr[u]] && v <= mx[pr[u]]) {
dp[u][1] += dp[v][2];
}
}
// dp[u][1] = qry1(u, mx[pr[u]]);
}
if (u == rt)
return;
if (u > mx[u]) {
ans[u] = dp[u][0];
// ans[u] = qry0(u, mx[u]);
} else if (pr[u] == mx[u]) {
ans[u] = dp[u][0] - dp[u][1];
// ans[u] = qry0(u, mx[u]) - qry1(u, mx[pr[u]]);
} else {
ans[u] = 0;
}
}
void pre(int u = rt) {
loop(i, g[u].size()) {
int v = g[u][i];
if (v == pr[u])
continue;
ans[v] += ans[u];
pre(v);
}
}
int main() {
// freopen("dat.in", "r", stdin);
// freopen("dat.out", "w", stdout);
scanf("%d", &n);
cont(i, n - 1) {
int u, v;
scanf("%d%d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
dfs();
// cont (u, n) {
// if (dp[u][0] != qry0(u, mx[u]) || dp[u][1] != qry1(u, mx[pr[u]])) {
// cerr << u << ": " << dp[u][0] << ' ' << qry0(u, mx[u]) << ' ' <<
// dp[u][1] << ' ' << qry1(u, mx[pr[u]]) << ln;
// }
// }
pre();
circ(u, 2, n) { cout << ans[u] << ' '; }
cout << ln;
} | replace | 128 | 134 | 128 | 134 | TLE | |
p03204 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define N (100010)
#define P ()
#define M (N << 1)
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand()) << (15)) ^ (rand()))
#define file(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1 {
inline char read() {
static const int IN_LEN = 1000000;
static char buf[IN_LEN], *s, *t;
return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin),
(s == t ? -1 : *s++) : *s++);
}
template <class T> inline void read(T &x) {
static bool iosig;
static char c;
for (iosig = false, c = read(); !isdigit(c); c = read()) {
if (c == '-')
iosig = true;
if (c == -1)
return;
}
for (x = 0; isdigit(c); c = read())
x = ((x + (x << 2)) << 1) + (c ^ '0');
if (iosig)
x = -x;
}
inline char readc(char &c) {
for (c = read(); !isalpha(c) && !isdigit(c); c = read())
if (c == -1)
return 0;
}
const int OUT_LEN = 10000000;
char obuf[OUT_LEN], *ooh = obuf;
inline void print(char c) {
if (ooh == obuf + OUT_LEN)
fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf;
*ooh++ = c;
}
template <class T> inline void print(T x) {
static int buf[30], cnt;
if (x == 0)
print('0');
else {
if (x < 0)
print('-'), x = -x;
for (cnt = 0; x; x /= 10)
buf[++cnt] = x % 10 + 48;
while (cnt)
print((char)buf[cnt--]);
}
}
inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); }
} // namespace fastIO1
namespace fastIO2 {
template <class T> inline void read(T &x) {
static bool iosig;
static char c;
for (iosig = false, c = getchar(); !isdigit(c); c = getchar()) {
if (c == '-')
iosig = true;
if (c == -1)
return;
}
for (x = 0; isdigit(c); c = getchar())
x = ((x + (x << 2)) << 1) + (c ^ '0');
if (iosig)
x = -x;
}
} // namespace fastIO2
using namespace fastIO1;
int n, m, fi[N], ne[M], b[M], fa[N], mx[N], p[N], siz[N];
int st[N], dep[N], val[N], ans[N], top, E;
vector<int> s[N];
int ask(int x) { return p[x] == x ? x : p[x] = ask(p[x]); }
void dfs(int u, int pre) {
fa[u] = pre;
for (int i = fi[u]; i; i = ne[i]) {
int v = b[i];
if (v == pre)
continue;
mx[v] = max(mx[u], u);
dfs(v, u);
}
}
void dfs2(int u, int pre) {
st[++top] = u;
dep[u] = top;
// for(int i=1;i<=top;i++)cout<<st[i]<<" ";
// cout<<":"<<" "<<mx[u]<<st[dep[mx[u]]+1]<<"\n";
if (u > 1)
ans[u] += ans[mx[u]] - val[st[dep[mx[u]] + 1]];
for (int i = fi[u]; i; i = ne[i]) {
int v = b[i];
if (v == pre)
continue;
dfs2(v, u);
}
top--;
}
void add(int x, int y) { ne[++E] = fi[x], fi[x] = E, b[E] = y; }
int main() {
read(n);
for (int i = 1; i < n; i++) {
int x, y;
read(x), read(y);
add(x, y), add(y, x);
}
dfs(1, 0);
for (int i = 1; i <= n; i++)
p[i] = i, siz[i] = (i != 1);
for (int i = 2; i <= n; i++)
s[mx[i]].push_back(i);
// puts("faq1");
for (int i = 1; i <= n; i++) {
for (int j = 0; j < s[i].size(); j++) {
int u = s[i][j];
// cout<<i<<","<<u<<":";
if (u < i) {
ans[u] = siz[ask(u)];
// cout<<i<<" "<<u<<" "<<ask(u)<<"
//"<<siz[ask(u)]<<endl;
} else {
ans[u] = 1;
for (int t = fi[u]; t; t = ne[t]) {
int v = b[t];
if (v >= i)
continue;
if (v != fa[u])
val[v] = siz[ask(v)];
ans[u] += siz[ask(v)];
// cout<<v<<" ";
}
}
// puts("");
}
for (int j = fi[i]; j; j = ne[j]) {
int v = b[j], t = ask(i);
if (v >= i)
continue;
v = ask(v), p[v] = t, siz[t] += siz[v];
}
}
// puts("faq2");
// for(int i=1;i<=n;i++)cout<<ans[i]<<" "; puts("");
// for(int i=1;i<=n;i++)cout<<val[i]<<" "; puts("");
dfs2(1, 0);
for (int i = 2; i <= n; i++)
printf("%d ", ans[i]);
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define N (200010)
#define P ()
#define M (N << 1)
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand()) << (15)) ^ (rand()))
#define file(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1 {
inline char read() {
static const int IN_LEN = 1000000;
static char buf[IN_LEN], *s, *t;
return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin),
(s == t ? -1 : *s++) : *s++);
}
template <class T> inline void read(T &x) {
static bool iosig;
static char c;
for (iosig = false, c = read(); !isdigit(c); c = read()) {
if (c == '-')
iosig = true;
if (c == -1)
return;
}
for (x = 0; isdigit(c); c = read())
x = ((x + (x << 2)) << 1) + (c ^ '0');
if (iosig)
x = -x;
}
inline char readc(char &c) {
for (c = read(); !isalpha(c) && !isdigit(c); c = read())
if (c == -1)
return 0;
}
const int OUT_LEN = 10000000;
char obuf[OUT_LEN], *ooh = obuf;
inline void print(char c) {
if (ooh == obuf + OUT_LEN)
fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf;
*ooh++ = c;
}
template <class T> inline void print(T x) {
static int buf[30], cnt;
if (x == 0)
print('0');
else {
if (x < 0)
print('-'), x = -x;
for (cnt = 0; x; x /= 10)
buf[++cnt] = x % 10 + 48;
while (cnt)
print((char)buf[cnt--]);
}
}
inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); }
} // namespace fastIO1
namespace fastIO2 {
template <class T> inline void read(T &x) {
static bool iosig;
static char c;
for (iosig = false, c = getchar(); !isdigit(c); c = getchar()) {
if (c == '-')
iosig = true;
if (c == -1)
return;
}
for (x = 0; isdigit(c); c = getchar())
x = ((x + (x << 2)) << 1) + (c ^ '0');
if (iosig)
x = -x;
}
} // namespace fastIO2
using namespace fastIO1;
int n, m, fi[N], ne[M], b[M], fa[N], mx[N], p[N], siz[N];
int st[N], dep[N], val[N], ans[N], top, E;
vector<int> s[N];
int ask(int x) { return p[x] == x ? x : p[x] = ask(p[x]); }
void dfs(int u, int pre) {
fa[u] = pre;
for (int i = fi[u]; i; i = ne[i]) {
int v = b[i];
if (v == pre)
continue;
mx[v] = max(mx[u], u);
dfs(v, u);
}
}
void dfs2(int u, int pre) {
st[++top] = u;
dep[u] = top;
// for(int i=1;i<=top;i++)cout<<st[i]<<" ";
// cout<<":"<<" "<<mx[u]<<st[dep[mx[u]]+1]<<"\n";
if (u > 1)
ans[u] += ans[mx[u]] - val[st[dep[mx[u]] + 1]];
for (int i = fi[u]; i; i = ne[i]) {
int v = b[i];
if (v == pre)
continue;
dfs2(v, u);
}
top--;
}
void add(int x, int y) { ne[++E] = fi[x], fi[x] = E, b[E] = y; }
int main() {
read(n);
for (int i = 1; i < n; i++) {
int x, y;
read(x), read(y);
add(x, y), add(y, x);
}
dfs(1, 0);
for (int i = 1; i <= n; i++)
p[i] = i, siz[i] = (i != 1);
for (int i = 2; i <= n; i++)
s[mx[i]].push_back(i);
// puts("faq1");
for (int i = 1; i <= n; i++) {
for (int j = 0; j < s[i].size(); j++) {
int u = s[i][j];
// cout<<i<<","<<u<<":";
if (u < i) {
ans[u] = siz[ask(u)];
// cout<<i<<" "<<u<<" "<<ask(u)<<"
//"<<siz[ask(u)]<<endl;
} else {
ans[u] = 1;
for (int t = fi[u]; t; t = ne[t]) {
int v = b[t];
if (v >= i)
continue;
if (v != fa[u])
val[v] = siz[ask(v)];
ans[u] += siz[ask(v)];
// cout<<v<<" ";
}
}
// puts("");
}
for (int j = fi[i]; j; j = ne[j]) {
int v = b[j], t = ask(i);
if (v >= i)
continue;
v = ask(v), p[v] = t, siz[t] += siz[v];
}
}
// puts("faq2");
// for(int i=1;i<=n;i++)cout<<ans[i]<<" "; puts("");
// for(int i=1;i<=n;i++)cout<<val[i]<<" "; puts("");
dfs2(1, 0);
for (int i = 2; i <= n; i++)
printf("%d ", ans[i]);
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03204 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
REP(WW, n) cerr << v[WW] << ' '; \
cerr << endl << endl; \
}
#define SHOW2d(v, WW, HH) \
{ \
REP(W_, WW) { \
REP(H_, HH) cerr << v[W_][H_] << ' '; \
cerr << endl; \
} \
cerr << endl; \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
vector<vector<ll>> v(222222);
ll ma[222222];
ll ans[222222];
map<pair<int, int>, int> mp;
int seica(ll num, ll lim, ll pre) {
if (mp[MP(num, lim)] != 0)
return mp[MP(num, lim)];
ll ret = 0;
REP(i, v[num].size()) {
if (v[num][i] != pre && v[num][i] < lim) {
ret += seica(v[num][i], lim, num);
}
}
return ret + 1;
}
void dfs(ll num, ll pre) {
ll ret = ans[pre];
ma[num] = max(ma[pre], pre);
ret += seica(num, ma[num], pre);
if (ma[pre] > num)
ret -= seica(num, ma[pre], pre);
ans[num] = ret;
REP(i, v[num].size()) {
if (v[num][i] != pre) {
dfs(v[num][i], num);
}
}
}
int main() {
int n;
cin >> n;
REP(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
v[a].EB(b);
v[b].EB(a);
}
REP(i, v[0].size()) { dfs(v[0][i], 0); }
REP(i, n - 1) cout << ans[i + 1] << " ";
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
REP(WW, n) cerr << v[WW] << ' '; \
cerr << endl << endl; \
}
#define SHOW2d(v, WW, HH) \
{ \
REP(W_, WW) { \
REP(H_, HH) cerr << v[W_][H_] << ' '; \
cerr << endl; \
} \
cerr << endl; \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
vector<vector<ll>> v(222222);
ll ma[222222];
ll ans[222222];
map<pair<int, int>, int> mp;
int seica(ll num, ll lim, ll pre) {
if (mp[MP(num, lim)] != 0)
return mp[MP(num, lim)];
ll ret = 0;
REP(i, v[num].size()) {
if (v[num][i] != pre && v[num][i] < lim) {
ret += seica(v[num][i], lim, num);
}
}
return mp[MP(num, lim)] = ret + 1;
}
void dfs(ll num, ll pre) {
ll ret = ans[pre];
ma[num] = max(ma[pre], pre);
ret += seica(num, ma[num], pre);
if (ma[pre] > num)
ret -= seica(num, ma[pre], pre);
ans[num] = ret;
REP(i, v[num].size()) {
if (v[num][i] != pre) {
dfs(v[num][i], num);
}
}
}
int main() {
int n;
cin >> n;
REP(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
v[a].EB(b);
v[b].EB(a);
}
REP(i, v[0].size()) { dfs(v[0][i], 0); }
REP(i, n - 1) cout << ans[i + 1] << " ";
cout << endl;
return 0;
}
| replace | 47 | 48 | 47 | 48 | TLE |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.