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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03231 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-9;
template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T> void amin(T &a, T v) {
if (a > v)
a = v;
}
template <class T> void amax(T &a, T v) {
if (a < v)
a = v;
}
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) {
return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y)));
}
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI (acos(-1))
#define ARRAY_NUM(a) (sizeof(a) / sizeof(a[0]))
#define NG (-1)
#define BIG ((int)1e9 + 10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a) * (a))
typedef unsigned long long ull;
typedef long long ll;
ll gcd(ll x, ll y) {
if (x == 0)
return y;
if (y == 0)
return x;
ll t;
while (y != 0) {
t = x % y;
x = y;
y = t;
}
return x;
}
// 最小公倍数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
int main() {
int n, m;
string s, t;
cin >> n >> m >> s >> t;
ll gc = gcd(n, m);
ll l = lcm(n, m);
ll ans = l;
for (int i = 0; i < l; ++i) {
if (i % (l / n) == 0 && i % (l / m) == 0) {
if (s[i / (l / n)] != t[i / (l / m)]) {
ans = -1;
}
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-9;
template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T> void amin(T &a, T v) {
if (a > v)
a = v;
}
template <class T> void amax(T &a, T v) {
if (a < v)
a = v;
}
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) {
return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y)));
}
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI (acos(-1))
#define ARRAY_NUM(a) (sizeof(a) / sizeof(a[0]))
#define NG (-1)
#define BIG ((int)1e9 + 10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a) * (a))
typedef unsigned long long ull;
typedef long long ll;
ll gcd(ll x, ll y) {
if (x == 0)
return y;
if (y == 0)
return x;
ll t;
while (y != 0) {
t = x % y;
x = y;
y = t;
}
return x;
}
// 最小公倍数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
int main() {
int n, m;
string s, t;
cin >> n >> m >> s >> t;
ll gc = gcd(n, m);
ll l = lcm(n, m);
ll ans = l;
for (ll i = 0; i < l; i += l / gc) {
if (i % (l / n) == 0 && i % (l / m) == 0) {
if (s[i / (l / n)] != t[i / (l / m)]) {
ans = -1;
}
}
}
cout << ans << endl;
return 0;
}
| replace | 77 | 78 | 77 | 78 | TLE | |
p03231 | C++ | Runtime Error | #include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9 + 7))
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(v) v.begin(), v.end()
#define FIND(v, x) (binary_search(ALL(v), (x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) \
sort(ALL(v)); \
reverse(ALL(v))
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template <class A> void pr(A a) { cout << (a) << endl; }
template <class A, class B> void pr(A a, B b) {
cout << a << " ";
pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
cout << a << " ";
pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
cout << a << " ";
pr(b, c, d);
}
template <class T> inline bool chmin(T &a, T b) {
return a > b ? a = b, true : false;
}
template <class T> inline bool chmax(T &a, T b) {
return a < b ? a = b, true : false;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int main(void) {
ll N, M;
cin >> N >> M;
string S, T;
cin >> S >> T;
ll l = lcm(N, M);
ll k = gcd(N, M);
while (l <= N * M) {
bool flag = true;
for (size_t i = 0; i < min(N, M); i++) {
if (S[i * (N / k)] != T[i * (M / k)]) {
flag = false;
break;
}
}
if (flag) {
pr(l);
return 0;
}
l += lcm(N, M);
}
pr(-1);
} | #include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9 + 7))
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(v) v.begin(), v.end()
#define FIND(v, x) (binary_search(ALL(v), (x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) \
sort(ALL(v)); \
reverse(ALL(v))
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template <class A> void pr(A a) { cout << (a) << endl; }
template <class A, class B> void pr(A a, B b) {
cout << a << " ";
pr(b);
}
template <class A, class B, class C> void pr(A a, B b, C c) {
cout << a << " ";
pr(b, c);
}
template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) {
cout << a << " ";
pr(b, c, d);
}
template <class T> inline bool chmin(T &a, T b) {
return a > b ? a = b, true : false;
}
template <class T> inline bool chmax(T &a, T b) {
return a < b ? a = b, true : false;
}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int main(void) {
ll N, M;
cin >> N >> M;
string S, T;
cin >> S >> T;
ll l = lcm(N, M);
ll k = gcd(N, M);
while (l <= N * M) {
bool flag = true;
for (size_t i = 0; i < min(N, M); i++) {
if (i * (N / k) >= N || i * (M / k) >= M)
break;
if (S[i * (N / k)] != T[i * (M / k)]) {
flag = false;
break;
}
}
if (flag) {
pr(l);
return 0;
}
l += lcm(N, M);
}
pr(-1);
} | insert | 70 | 70 | 70 | 72 | 0 | |
p03231 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
ll gcd(ll m, ll n) {
ll l;
// 引数に0がある場合は0を返す
if ((0 == m) || (0 == n))
return 0;
// ユークリッドの方法
while (1) {
l = m % n;
if (l == 0)
break;
m = n;
n = l;
}
return n;
}
ll lcm(ll m, ll n) {
ll g = gcd(m, n);
if (g == 0) {
return 0;
}
return m * n / g;
}
void solve() {
ll i, j, k, r, x, y;
string S, T;
bool exit = false;
ll N, M;
cin >> N >> M;
cin >> S >> T;
ll g = gcd(M, N);
ll L = lcm(M, N);
ll l = L / g;
FOR(i, g) {
if (S[i * l] != T[i * l]) {
cout << "-1" << endl;
return;
}
}
cout << L << endl;
/*cin>>N;
vector<ll> V((N+1)*(N+1));
FOR(x,N+1) {
FOR(y,N+1) {
ll ret=1;
FOR(i,x) ret*=2;
FOR(i,y) ret*=5;
V.push_back(ret);
}
}
sort(ALL(V));
FORR(v,V) cout<<v<<endl;*/
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
ll gcd(ll m, ll n) {
ll l;
// 引数に0がある場合は0を返す
if ((0 == m) || (0 == n))
return 0;
// ユークリッドの方法
while (1) {
l = m % n;
if (l == 0)
break;
m = n;
n = l;
}
return n;
}
ll lcm(ll m, ll n) {
ll g = gcd(m, n);
if (g == 0) {
return 0;
}
return m * n / g;
}
void solve() {
ll i, j, k, r, x, y;
string S, T;
bool exit = false;
ll N, M;
cin >> N >> M;
cin >> S >> T;
ll g = gcd(M, N);
ll L = lcm(M, N);
ll l = L / g;
FOR(i, g) {
if (S[i * (N / g)] != T[i * (M / g)]) {
cout << "-1" << endl;
return;
}
}
cout << L << endl;
/*cin>>N;
vector<ll> V((N+1)*(N+1));
FOR(x,N+1) {
FOR(y,N+1) {
ll ret=1;
FOR(i,x) ret*=2;
FOR(i,y) ret*=5;
V.push_back(ret);
}
}
sort(ALL(V));
FORR(v,V) cout<<v<<endl;*/
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
| replace | 49 | 50 | 49 | 50 | 0 | |
p03231 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
char a[10005], b[10005];
map<long long, char> vis;
long long gcd(long long x, long long y) {
while (y) {
x %= y;
swap(x, y);
}
return x;
}
int main() {
long long n, m;
long long orz;
cin >> n >> m;
scanf("%s%s", a + 1, b + 1);
orz = n * m / gcd(n, m);
for (long long i = 1; i <= n; i++) {
vis[(i - 1) * orz / n + 1] = a[i];
// cout<<(i-1)*(orz/n)+1<<" ";
}
// cout<<endl;
// cout<<orz/m<<endl;
for (long long i = 1; i <= m; i++) {
// cout<<(i-1)*(orz/m)+1<<" ";
if (vis[(i - 1) * orz / m + 1]) {
if (vis[(i - 1) * orz / m + 1] != b[i]) {
printf("-1");
return 0;
}
}
}
cout << orz << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
char a[100005], b[100005];
map<long long, char> vis;
long long gcd(long long x, long long y) {
while (y) {
x %= y;
swap(x, y);
}
return x;
}
int main() {
long long n, m;
long long orz;
cin >> n >> m;
scanf("%s%s", a + 1, b + 1);
orz = n * m / gcd(n, m);
for (long long i = 1; i <= n; i++) {
vis[(i - 1) * orz / n + 1] = a[i];
// cout<<(i-1)*(orz/n)+1<<" ";
}
// cout<<endl;
// cout<<orz/m<<endl;
for (long long i = 1; i <= m; i++) {
// cout<<(i-1)*(orz/m)+1<<" ";
if (vis[(i - 1) * orz / m + 1]) {
if (vis[(i - 1) * orz / m + 1] != b[i]) {
printf("-1");
return 0;
}
}
}
cout << orz << endl;
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03231 | C++ | Runtime Error | #include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>
void print(T x) {
std::cout << x << " ";
}
template <typename T>
void println(T x) {
std::cout << x << "\n";
}
int gcd(int a, int b) {
if (a % b == 0)
return b;
else
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
signed main(void) {
int n, m;
cin >> n >> m;
string s, t;
cin >> s >> t;
int xsize = lcm(n, m);
vector<char> x(xsize, '0');
rep(i, n) { x[i * xsize / n] = s[i]; }
rep(i, m) {
if (x[i * xsize / m] != '0' && x[i * xsize / m] != t[i]) {
print("-1");
return 0;
}
}
print(xsize);
} | #include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>
void print(T x) {
std::cout << x << " ";
}
template <typename T>
void println(T x) {
std::cout << x << "\n";
}
int gcd(int a, int b) {
if (a % b == 0)
return b;
else
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
signed main(void) {
int n, m;
cin >> n >> m;
string s, t;
cin >> s >> t;
int xsize = lcm(n, m);
int a = xsize / n;
int b = xsize / m;
for (int i = 0; i * a < xsize; i++) {
if (i * a % b == 0) {
if (s[i] != t[i * a / b]) {
print("-1");
return 0;
}
}
}
print(xsize);
} | replace | 46 | 52 | 46 | 54 | 0 | |
p03232 | Python | Runtime Error | import sys
fin = sys.stdin.readline
def factorial(n, mod):
if n == 0:
return 1
else:
return n * factorial(n - 1, mod) % mod
MOD = 10**9 + 7
N = int(fin())
A_list = [int(elem) for elem in fin().split()]
fac_N = factorial(N, MOD)
inv_nums = [fac_N * pow(i, MOD - 2, MOD) % MOD for i in range(1, N + 1)]
cuml_inv_nums = [inv_nums[0]]
for inv_num in inv_nums[1:]:
cuml_inv_nums.append((cuml_inv_nums[-1] + inv_num) % MOD)
ans = 0
for i, A in enumerate(A_list):
ans += A * (cuml_inv_nums[i] + cuml_inv_nums[N - 1 - i] - cuml_inv_nums[0]) % MOD
ans %= MOD
print(ans)
| import sys
fin = sys.stdin.readline
sys.setrecursionlimit(200000)
def factorial(n, mod):
if n == 0:
return 1
else:
return n * factorial(n - 1, mod) % mod
MOD = 10**9 + 7
N = int(fin())
A_list = [int(elem) for elem in fin().split()]
fac_N = factorial(N, MOD)
inv_nums = [fac_N * pow(i, MOD - 2, MOD) % MOD for i in range(1, N + 1)]
cuml_inv_nums = [inv_nums[0]]
for inv_num in inv_nums[1:]:
cuml_inv_nums.append((cuml_inv_nums[-1] + inv_num) % MOD)
ans = 0
for i, A in enumerate(A_list):
ans += A * (cuml_inv_nums[i] + cuml_inv_nums[N - 1 - i] - cuml_inv_nums[0]) % MOD
ans %= MOD
print(ans)
| insert | 3 | 3 | 3 | 4 | 0 | |
p03232 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for ((i) = 1; (i) <= (n); (i)++)
#define foreach(c, itr) \
for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++itr)
using namespace std;
const int mod = 1e9 + 7;
int n, i, j, f[100005], inv[100005], ans;
int main() {
cin >> n;
inv[1] = f[1] = 1;
for (i = 2; i <= n; i++) {
inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
f[i] = (f[i - 1] + inv[i]) % mod;
}
rep(i, n) {
int x;
cin >> x;
ans = (ans + 1ll * x * (f[x] + f[n - x + 1] - 1)) % mod;
}
rep(i, n) { ans = 1ll * ans * i % mod; }
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for ((i) = 1; (i) <= (n); (i)++)
#define foreach(c, itr) \
for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++itr)
using namespace std;
const int mod = 1e9 + 7;
int n, i, j, f[100005], inv[100005], ans;
int main() {
cin >> n;
inv[1] = f[1] = 1;
for (i = 2; i <= n; i++) {
inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
f[i] = (f[i - 1] + inv[i]) % mod;
}
rep(i, n) {
int x;
cin >> x;
ans = (ans + 1ll * x * (f[i] + f[n - i + 1] - 1)) % mod;
}
rep(i, n) { ans = 1ll * ans * i % mod; }
cout << ans << endl;
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p03232 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
long long read() {
long long x = 0, w = 1;
char ch = getchar();
while (!isdigit(ch))
w = ch == '-' ? -1 : 1, ch = getchar();
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * w;
}
const int Max_n = 1e5 + 5, mod = 1e9 + 7;
int n, ans;
int a[Max_n], inv[Max_n];
void Mod(int &x) { x %= mod; }
int main() {
#ifndef ONLINE_JUDGE
freopen("B.in", "r", stdin);
freopen("B.out", "w", stdout);
#endif
n = read();
for (int i = 1; i <= n; i++)
a[i] = read();
inv[1] = 1;
for (int i = 2; i <= n; i++)
inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
for (int i = 2; i <= n; i++)
Mod(inv[i] += inv[i - 1]);
for (int i = 1; i <= n; i++)
Mod(ans += 1ll * a[i] * (inv[i] + inv[n - i + 1] - 1) % mod);
for (int i = 2; i <= n; i++)
ans = 1ll * ans * i % mod;
cout << ans;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
long long read() {
long long x = 0, w = 1;
char ch = getchar();
while (!isdigit(ch))
w = ch == '-' ? -1 : 1, ch = getchar();
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * w;
}
const int Max_n = 1e5 + 5, mod = 1e9 + 7;
int n, ans;
int a[Max_n], inv[Max_n];
void Mod(int &x) { x %= mod; }
int main() {
n = read();
for (int i = 1; i <= n; i++)
a[i] = read();
inv[1] = 1;
for (int i = 2; i <= n; i++)
inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
for (int i = 2; i <= n; i++)
Mod(inv[i] += inv[i - 1]);
for (int i = 1; i <= n; i++)
Mod(ans += 1ll * a[i] * (inv[i] + inv[n - i + 1] - 1) % mod);
for (int i = 2; i <= n; i++)
ans = 1ll * ans * i % mod;
cout << ans;
}
| delete | 26 | 30 | 26 | 26 | TLE | |
p03232 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define MN 1000
#define MOD 1000000007
int a[MN + 5], r[MN + 5];
inline int inv(int x) {
int y = MOD - 2, r = 1;
for (; y; y >>= 1, x = 1LL * x * x % MOD)
if (y & 1)
r = 1LL * r * x % MOD;
return r;
}
int main() {
int n, i, ans = 0;
scanf("%d", &n);
for (i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (i = 1; i <= n; ++i)
r[i] = (r[i - 1] + inv(i)) % MOD;
for (i = 1; i <= n; ++i)
ans = (ans + 1LL * a[i] * (r[i] + r[n - i + 1] - 1)) % MOD;
for (i = 1; i <= n; ++i)
ans = 1LL * ans * i % MOD;
printf("%d", ans);
} | #include <bits/stdc++.h>
using namespace std;
#define MN 100000
#define MOD 1000000007
int a[MN + 5], r[MN + 5];
inline int inv(int x) {
int y = MOD - 2, r = 1;
for (; y; y >>= 1, x = 1LL * x * x % MOD)
if (y & 1)
r = 1LL * r * x % MOD;
return r;
}
int main() {
int n, i, ans = 0;
scanf("%d", &n);
for (i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (i = 1; i <= n; ++i)
r[i] = (r[i - 1] + inv(i)) % MOD;
for (i = 1; i <= n; ++i)
ans = (ans + 1LL * a[i] * (r[i] + r[n - i + 1] - 1)) % MOD;
for (i = 1; i <= n; ++i)
ans = 1LL * ans * i % MOD;
printf("%d", ans);
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03232 | C++ | Runtime Error | //~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC
//target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") ~ #pragma
//GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define shandom_ruffle random_shuffle
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
const int nax = 1007;
const ll mod = 1000 * 1000 * 1000 + 7;
int n;
ll dp[nax];
ll wyn;
ll sil[nax];
//~ ll kom[nax][nax];
ll dziel(ll a, ll b) {
a %= mod;
b %= mod;
ll wyk = mod - 2;
while (wyk) {
if (wyk & 1)
a = (a * b) % mod;
b = (b * b) % mod;
wyk >>= 1;
}
return a;
}
ll kom(int a, int b) {
if (b > a || b < 0)
return 0;
return dziel(sil[a], sil[b] * sil[a - b]);
}
int main() {
sil[0] = 1;
for (int i = 1; i < nax; i++)
sil[i] = (sil[i - 1] * i) % mod;
scanf("%d", &n);
dp[1] = 1;
ll s = 1;
for (int i = 2; i <= n; i++) {
dp[i] = (sil[i] + sil[i - 1] * s) % mod;
s = (s + dziel(dp[i], sil[i])) % mod;
}
debug() << range(dp + 1, dp + 1 + n);
for (int i = 1; i <= n; i++) {
dp[i] = (dp[i] + mod - sil[i]) % mod;
}
debug() << range(dp + 1, dp + 1 + n);
for (int i = 1; i <= n; i++) {
ll x;
scanf("%lld", &x);
ll mno = dp[i] * sil[n - i];
mno %= mod;
mno *= kom(n, i);
mno %= mod;
wyn = (wyn + x * mno) % mod;
mno = dp[n - i + 1] * sil[i - 1];
mno %= mod;
mno *= kom(n, i - 1);
mno %= mod;
wyn = (wyn + x * mno) % mod;
wyn = (wyn + x * sil[n]) % mod;
}
wyn %= mod;
wyn += mod;
wyn %= mod;
printf("%lld\n", wyn);
return 0;
}
| //~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC
//target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") ~ #pragma
//GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define shandom_ruffle random_shuffle
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
const int nax = 1000 * 1007;
const ll mod = 1000 * 1000 * 1000 + 7;
int n;
ll dp[nax];
ll wyn;
ll sil[nax];
//~ ll kom[nax][nax];
ll dziel(ll a, ll b) {
a %= mod;
b %= mod;
ll wyk = mod - 2;
while (wyk) {
if (wyk & 1)
a = (a * b) % mod;
b = (b * b) % mod;
wyk >>= 1;
}
return a;
}
ll kom(int a, int b) {
if (b > a || b < 0)
return 0;
return dziel(sil[a], sil[b] * sil[a - b]);
}
int main() {
sil[0] = 1;
for (int i = 1; i < nax; i++)
sil[i] = (sil[i - 1] * i) % mod;
scanf("%d", &n);
dp[1] = 1;
ll s = 1;
for (int i = 2; i <= n; i++) {
dp[i] = (sil[i] + sil[i - 1] * s) % mod;
s = (s + dziel(dp[i], sil[i])) % mod;
}
debug() << range(dp + 1, dp + 1 + n);
for (int i = 1; i <= n; i++) {
dp[i] = (dp[i] + mod - sil[i]) % mod;
}
debug() << range(dp + 1, dp + 1 + n);
for (int i = 1; i <= n; i++) {
ll x;
scanf("%lld", &x);
ll mno = dp[i] * sil[n - i];
mno %= mod;
mno *= kom(n, i);
mno %= mod;
wyn = (wyn + x * mno) % mod;
mno = dp[n - i + 1] * sil[i - 1];
mno %= mod;
mno *= kom(n, i - 1);
mno %= mod;
wyn = (wyn + x * mno) % mod;
wyn = (wyn + x * sil[n]) % mod;
}
wyn %= mod;
wyn += mod;
wyn %= mod;
printf("%lld\n", wyn);
return 0;
}
| replace | 60 | 61 | 60 | 61 | 0 | |
p03232 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n;
long long a[10010], ni[100010], s[100010], ans, jie[100010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
ni[1] = 1;
for (int i = 2; i <= n; ++i)
ni[i] = (mod - mod / i) * ni[mod % i] % mod;
for (int i = 1; i <= n; ++i)
s[i] = (s[i - 1] + ni[i]) % mod;
for (int i = 1; i <= n; ++i)
ans = (ans + s[n - i + 1] * a[i] % mod + (s[i] - 1) * a[i] % mod) % mod;
jie[0] = 1;
for (int i = 1; i <= n; ++i)
jie[i] = jie[i - 1] * i % mod;
ans = (ans * jie[n]) % mod;
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n;
long long a[100010], ni[100010], s[100010], ans, jie[100010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
ni[1] = 1;
for (int i = 2; i <= n; ++i)
ni[i] = (mod - mod / i) * ni[mod % i] % mod;
for (int i = 1; i <= n; ++i)
s[i] = (s[i - 1] + ni[i]) % mod;
for (int i = 1; i <= n; ++i)
ans = (ans + s[n - i + 1] * a[i] % mod + (s[i] - 1) * a[i] % mod) % mod;
jie[0] = 1;
for (int i = 1; i <= n; ++i)
jie[i] = jie[i - 1] * i % mod;
ans = (ans * jie[n]) % mod;
printf("%lld\n", ans);
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03232 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
// #define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);
const double EPS = 1e-10;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
struct Combination {
vector<long long> _fac, _finv, _inv;
const int m = MOD;
Combination(int sz) : _fac(sz), _finv(sz), _inv(sz) {
_fac[0] = _fac[1] = 1;
_finv[0] = _finv[1] = 1;
_inv[1] = 1;
for (int i = 2; i <= sz; i++) {
_fac[i] = _fac[i - 1] * i % m;
_inv[i] = m - _inv[m % i] * (m / i) % m;
_finv[i] = _finv[i - 1] * _inv[i] % m;
}
}
inline long long fac(int n) { return _fac[n]; }
inline long long inv(int n) { return _inv[n]; }
inline long long finv(int n) { return _finv[n]; }
long long comb(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return _fac[n] * (_finv[k] * _finv[n - k] % m) % m;
}
};
int main() {
int N;
cin >> N;
vector<int> A(N);
rep(i, N) cin >> A[i];
vector<ll> sum(N + 1);
rep(i, N) {
sum[i + 1] = sum[i] + A[i];
sum[i + 1] %= MOD;
}
vector<ll> sum2(N + 2);
rep(i, N + 1) {
sum2[i + 1] = sum2[i] + sum[i];
sum2[i + 1] %= MOD;
}
ll ans = 0;
Combination C(200000);
repr(i, 1, N + 1) {
if (i == N) {
ans += sum[N];
ans %= MOD;
continue;
}
ans += sum[i] * C.inv(i + 1) % MOD;
ans %= MOD;
ans += (sum[N] - sum[N - i] + MOD) % MOD * C.inv(i + 1) % MOD;
ans %= MOD;
if (i + 2 <= N) {
ll now = 0;
now += (sum2[N] - sum2[i + 1] + MOD) % MOD;
now -= (sum2[N - i] - sum2[1] + MOD) % MOD;
if (now < 0)
now += MOD;
ans += now * C.inv(C.comb(i + 2, 2)) % MOD;
ans %= MOD;
}
}
ans *= C.fac(N);
ans %= MOD;
cout << ans << endl;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
// #define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);
const double EPS = 1e-10;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
struct Combination {
vector<long long> _fac, _finv, _inv;
const int m = MOD;
Combination(int sz) : _fac(sz), _finv(sz), _inv(sz) {
_fac[0] = _fac[1] = 1;
_finv[0] = _finv[1] = 1;
_inv[1] = 1;
for (int i = 2; i <= sz; i++) {
_fac[i] = _fac[i - 1] * i % m;
_inv[i] = m - _inv[m % i] * (m / i) % m;
_finv[i] = _finv[i - 1] * _inv[i] % m;
}
}
inline long long fac(int n) { return _fac[n]; }
inline long long inv(int n) { return _inv[n]; }
inline long long finv(int n) { return _finv[n]; }
long long comb(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return _fac[n] * (_finv[k] * _finv[n - k] % m) % m;
}
};
int main() {
int N;
cin >> N;
vector<int> A(N);
rep(i, N) cin >> A[i];
vector<ll> sum(N + 1);
rep(i, N) {
sum[i + 1] = sum[i] + A[i];
sum[i + 1] %= MOD;
}
vector<ll> sum2(N + 2);
rep(i, N + 1) {
sum2[i + 1] = sum2[i] + sum[i];
sum2[i + 1] %= MOD;
}
ll ans = 0;
Combination C(200000);
repr(i, 1, N + 1) {
if (i == N) {
ans += sum[N];
ans %= MOD;
continue;
}
ans += sum[i] * C.inv(i + 1) % MOD;
ans %= MOD;
ans += (sum[N] - sum[N - i] + MOD) % MOD * C.inv(i + 1) % MOD;
ans %= MOD;
if (i + 2 <= N) {
ll now = 0;
now += (sum2[N] - sum2[i + 1] + MOD) % MOD;
now -= (sum2[N - i] - sum2[1] + MOD) % MOD;
if (now < 0)
now += MOD;
ans += now * 2 % MOD * C.inv(i + 2) % MOD * C.inv(i + 1) % MOD;
ans %= MOD;
}
}
ans *= C.fac(N);
ans %= MOD;
cout << ans << endl;
}
| replace | 97 | 98 | 97 | 98 | 0 | |
p03232 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-')
f = 0;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f ? x : -x;
}
typedef long long LL;
const int maxn = 1e5 + 10, mod = 1e9 + 7;
int inv[maxn], a[maxn];
int main() {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
#endif
int n = read();
inv[0] = inv[1] = 1;
for (int i = 2; i <= n; ++i)
inv[i] = (LL)(mod - mod / i) * inv[mod % i] % mod;
for (int i = 1; i <= n; ++i)
a[i] = read();
for (int i = 2; i <= n; ++i)
(inv[i] += inv[i - 1]) %= mod;
int ans = 0;
for (int i = 1; i <= n; ++i)
(ans += (LL)a[i] * (inv[i] - 1 + inv[n - i + 1]) % mod) %= mod;
for (int i = 1; i <= n; ++i)
ans = (LL)ans * i % mod;
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-')
f = 0;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f ? x : -x;
}
typedef long long LL;
const int maxn = 1e5 + 10, mod = 1e9 + 7;
int inv[maxn], a[maxn];
int main() {
int n = read();
inv[0] = inv[1] = 1;
for (int i = 2; i <= n; ++i)
inv[i] = (LL)(mod - mod / i) * inv[mod % i] % mod;
for (int i = 1; i <= n; ++i)
a[i] = read();
for (int i = 2; i <= n; ++i)
(inv[i] += inv[i - 1]) %= mod;
int ans = 0;
for (int i = 1; i <= n; ++i)
(ans += (LL)a[i] * (inv[i] - 1 + inv[n - i + 1]) % mod) %= mod;
for (int i = 1; i <= n; ++i)
ans = (LL)ans * i % mod;
cout << ans << endl;
return 0;
} | delete | 27 | 31 | 27 | 27 | TLE | |
p03232 | C++ | Runtime Error | /*
_____
.' '.
/ 0 0 \
| ^ |
| \ / |
\ '---' /
'._____.'
*/
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
random_device(rd);
mt19937 rng(rd());
template <class T> void readi(T &x) {
T input = 0;
bool negative = false;
char c = ' ';
while (c < '-') {
c = getchar();
}
if (c == '-') {
negative = true;
c = getchar();
}
while (c >= '0') {
input = input * 10 + (c - '0');
c = getchar();
}
if (negative) {
input = -input;
}
x = input;
}
template <class T> void printi(T output) {
if (output == 0) {
putchar('0');
return;
}
if (output < 0) {
putchar('-');
output = -output;
}
int aout[20];
int ilen = 0;
while (output) {
aout[ilen] = ((output % 10));
output /= 10;
ilen++;
}
for (int i = ilen - 1; i >= 0; i--) {
putchar(aout[i] + '0');
}
return;
}
template <class T> void ckmin(T &a, T b) { a = min(a, b); }
template <class T> void ckmax(T &a, T b) { a = max(a, b); }
long long expo(long long a, long long e, long long mod) {
return ((e == 0)
? 1
: ((expo(a * a % mod, e >> 1, mod)) * ((e & 1) ? a : 1) % mod));
}
template <class T, class U> T nmod(T &x, U mod) {
if (x >= mod)
x -= mod;
}
template <class T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template <class T> T randomize(T mod) {
return (uniform_int_distribution<T>(0, mod - 1))(rng);
}
#define y0 ___y0
#define y1 ___y1
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define debug(x) cerr << #x << " = " << x << endl;
#define sz(x) ((int)(x.size()))
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-9;
#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 1013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
int N;
ll arr[MAXN];
ll fact[MAXN], ifact[MAXN];
// ll grid[MAXN][MAXN];
ll stirling[MAXN], coef[MAXN];
ll modinv[MAXN];
ll ans;
int32_t main() {
ios_base::sync_with_stdio(0);
// cout << fixed << setprecision(10);
// cerr << fixed << setprecision(10);
// freopen ("file.in", "r", stdin);
// freopen ("file.out", "w", stdout);
cin >> N;
fact[0] = 1;
for (int i = 1; i <= N; i++) {
fact[i] = fact[i - 1] * i % INF;
}
ifact[N] = expo(fact[N], INF - 2, INF);
for (int i = N - 1; i >= 0; i--) {
ifact[i] = ifact[i + 1] * (i + 1) % INF;
}
for (int i = 1; i <= N; i++) {
modinv[i] = expo(i, INF - 2, INF);
}
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
// grid[1][0] = 1;
// for (int i = 2; i <= N; i++)
// {
// grid[i][0] = grid[i - 1][0] * i + fact[i] * expo(i, INF - 2, INF);
// grid[i][0] %= INF; grid[i][i - 1] = grid[i][0]; for (int j = 1; j < i - 1;
// j++)
// {
// grid[i][j] = grid[j + 1][j] * fact[i] % INF * ifact[j + 1] %
// INF;
// // cerr << grid[i][j] << ' ';
// for (int k = 2; k <= i - j; k++)
// {
// grid[i][j] += fact[i] * expo(k, INF - 2, INF);
// }
// grid[i][j] %= INF;
// // cerr << grid[i][j] << ' ';
// }
// // cerr << endl;
// }
stirling[1] = 1;
for (int i = 2; i <= N; i++) {
stirling[i] = stirling[i - 1] * i % INF + fact[i - 1] % INF;
nmod(stirling[i], INF);
}
coef[0] = stirling[N];
coef[N - 1] = stirling[N];
ll sum = 0;
for (int j = N - 2; j > 0; j--) {
coef[j] = stirling[j + 1] * fact[N] % INF * ifact[j + 1] % INF;
sum += fact[N] * modinv[N - j] % INF;
nmod(sum, INF);
coef[j] += sum;
nmod(coef[j], INF);
// for (int k = 2; k <= N - j; k++)
// {
// coef[j] += fact[N] * modinv[k]; coef[j] %= INF;
// }
}
for (int i = 0; i < N; i++) {
ans += coef[i] * arr[i] % INF;
nmod(ans, INF);
}
cout << ans << '\n';
// cerr << "time elapsed = " << (clock() / (CLOCKS_PER_SEC / 1000)) << " ms"
// << endl;
return 0;
}
| /*
_____
.' '.
/ 0 0 \
| ^ |
| \ / |
\ '---' /
'._____.'
*/
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
random_device(rd);
mt19937 rng(rd());
template <class T> void readi(T &x) {
T input = 0;
bool negative = false;
char c = ' ';
while (c < '-') {
c = getchar();
}
if (c == '-') {
negative = true;
c = getchar();
}
while (c >= '0') {
input = input * 10 + (c - '0');
c = getchar();
}
if (negative) {
input = -input;
}
x = input;
}
template <class T> void printi(T output) {
if (output == 0) {
putchar('0');
return;
}
if (output < 0) {
putchar('-');
output = -output;
}
int aout[20];
int ilen = 0;
while (output) {
aout[ilen] = ((output % 10));
output /= 10;
ilen++;
}
for (int i = ilen - 1; i >= 0; i--) {
putchar(aout[i] + '0');
}
return;
}
template <class T> void ckmin(T &a, T b) { a = min(a, b); }
template <class T> void ckmax(T &a, T b) { a = max(a, b); }
long long expo(long long a, long long e, long long mod) {
return ((e == 0)
? 1
: ((expo(a * a % mod, e >> 1, mod)) * ((e & 1) ? a : 1) % mod));
}
template <class T, class U> T nmod(T &x, U mod) {
if (x >= mod)
x -= mod;
}
template <class T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template <class T> T randomize(T mod) {
return (uniform_int_distribution<T>(0, mod - 1))(rng);
}
#define y0 ___y0
#define y1 ___y1
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define debug(x) cerr << #x << " = " << x << endl;
#define sz(x) ((int)(x.size()))
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-9;
#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 100013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
int N;
ll arr[MAXN];
ll fact[MAXN], ifact[MAXN];
// ll grid[MAXN][MAXN];
ll stirling[MAXN], coef[MAXN];
ll modinv[MAXN];
ll ans;
int32_t main() {
ios_base::sync_with_stdio(0);
// cout << fixed << setprecision(10);
// cerr << fixed << setprecision(10);
// freopen ("file.in", "r", stdin);
// freopen ("file.out", "w", stdout);
cin >> N;
fact[0] = 1;
for (int i = 1; i <= N; i++) {
fact[i] = fact[i - 1] * i % INF;
}
ifact[N] = expo(fact[N], INF - 2, INF);
for (int i = N - 1; i >= 0; i--) {
ifact[i] = ifact[i + 1] * (i + 1) % INF;
}
for (int i = 1; i <= N; i++) {
modinv[i] = expo(i, INF - 2, INF);
}
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
// grid[1][0] = 1;
// for (int i = 2; i <= N; i++)
// {
// grid[i][0] = grid[i - 1][0] * i + fact[i] * expo(i, INF - 2, INF);
// grid[i][0] %= INF; grid[i][i - 1] = grid[i][0]; for (int j = 1; j < i - 1;
// j++)
// {
// grid[i][j] = grid[j + 1][j] * fact[i] % INF * ifact[j + 1] %
// INF;
// // cerr << grid[i][j] << ' ';
// for (int k = 2; k <= i - j; k++)
// {
// grid[i][j] += fact[i] * expo(k, INF - 2, INF);
// }
// grid[i][j] %= INF;
// // cerr << grid[i][j] << ' ';
// }
// // cerr << endl;
// }
stirling[1] = 1;
for (int i = 2; i <= N; i++) {
stirling[i] = stirling[i - 1] * i % INF + fact[i - 1] % INF;
nmod(stirling[i], INF);
}
coef[0] = stirling[N];
coef[N - 1] = stirling[N];
ll sum = 0;
for (int j = N - 2; j > 0; j--) {
coef[j] = stirling[j + 1] * fact[N] % INF * ifact[j + 1] % INF;
sum += fact[N] * modinv[N - j] % INF;
nmod(sum, INF);
coef[j] += sum;
nmod(coef[j], INF);
// for (int k = 2; k <= N - j; k++)
// {
// coef[j] += fact[N] * modinv[k]; coef[j] %= INF;
// }
}
for (int i = 0; i < N; i++) {
ans += coef[i] * arr[i] % INF;
nmod(ans, INF);
}
cout << ans << '\n';
// cerr << "time elapsed = " << (clock() / (CLOCKS_PER_SEC / 1000)) << " ms"
// << endl;
return 0;
}
| replace | 107 | 108 | 107 | 108 | -11 | |
p03232 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int)(u).size())
#define ALL(u) (u).begin(), (u).end()
inline void proc_status() {
ifstream t("/proc/self/status");
cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
<< endl;
}
template <typename T> inline bool chkmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
template <typename T> inline T read() {
register T sum(0), fg(1);
register char ch(getchar());
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
fg = -1;
for (; isdigit(ch); ch = getchar())
sum = sum * 10 - '0' + ch;
return sum * fg;
}
typedef long long LL;
typedef pair<int, int> pii;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5;
// Template-Libs
namespace MATH {
int inv[MAXN + 5];
inline void init() {
inv[1] = 1;
for (int i = 2; i <= MAXN; ++i)
inv[i] = (LL)MOD / i * -inv[MOD % i] % MOD;
}
} // namespace MATH
using MATH::inv;
// END
int n;
int a[MAXN + 5];
inline void input() {
n = read<int>();
for (int i = 1; i <= n; ++i)
a[i] = read<int>();
}
inline void solve() {
static int prefix[MAXN + 5];
prefix[0] = 0;
for (int i = 1; i <= n; ++i)
prefix[i] = (prefix[i - 1] + inv[i]) % MOD;
int ans = 0;
for (int i = 1; i <= n; ++i)
(ans += (LL)(prefix[i] + prefix[n - i + 1] - 1) % MOD * a[i] % MOD) %= MOD;
for (int i = 1; i <= n; ++i)
ans = (LL)ans * i % MOD;
printf("%d\n", (ans + MOD) % MOD);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("std.in", "r", stdin);
freopen("std.out", "w", stdout);
#endif
MATH::init();
input();
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int)(u).size())
#define ALL(u) (u).begin(), (u).end()
inline void proc_status() {
ifstream t("/proc/self/status");
cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
<< endl;
}
template <typename T> inline bool chkmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
template <typename T> inline T read() {
register T sum(0), fg(1);
register char ch(getchar());
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
fg = -1;
for (; isdigit(ch); ch = getchar())
sum = sum * 10 - '0' + ch;
return sum * fg;
}
typedef long long LL;
typedef pair<int, int> pii;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5;
// Template-Libs
namespace MATH {
int inv[MAXN + 5];
inline void init() {
inv[1] = 1;
for (int i = 2; i <= MAXN; ++i)
inv[i] = (LL)MOD / i * -inv[MOD % i] % MOD;
}
} // namespace MATH
using MATH::inv;
// END
int n;
int a[MAXN + 5];
inline void input() {
n = read<int>();
for (int i = 1; i <= n; ++i)
a[i] = read<int>();
}
inline void solve() {
static int prefix[MAXN + 5];
prefix[0] = 0;
for (int i = 1; i <= n; ++i)
prefix[i] = (prefix[i - 1] + inv[i]) % MOD;
int ans = 0;
for (int i = 1; i <= n; ++i)
(ans += (LL)(prefix[i] + prefix[n - i + 1] - 1) % MOD * a[i] % MOD) %= MOD;
for (int i = 1; i <= n; ++i)
ans = (LL)ans * i % MOD;
printf("%d\n", (ans + MOD) % MOD);
}
int main() {
MATH::init();
input();
solve();
return 0;
}
| delete | 81 | 86 | 81 | 81 | TLE | |
p03232 | C++ | Runtime Error | // problem:agc028_b
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
inline int read() {
int f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline ll readll() {
ll f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int MAXN = 1e5 + 5, MOD = 1e9 + 7;
inline int mod(int x) { return x < MOD ? (x < 0 ? x + MOD : x) : x - MOD; }
inline int pow_mod(int x, int i) {
int y = 1;
while (i) {
if (i & 1)
y = (ll)y * x % MOD;
x = (ll)x * x % MOD;
i >>= 1;
}
return y;
}
int n, fac[MAXN], invf[MAXN], f[MAXN], g[MAXN];
inline int comb(int n, int k) {
assert(n >= k);
return (ll)fac[n] * invf[k] % MOD * invf[n - k] % MOD;
}
namespace NTT {
const ll MODs[3] = {469762049, 998244353, 1004535809};
int MOD, n, m, P, a[MAXN], b[MAXN], f[MAXN], g[MAXN], R[MAXN], r[3][MAXN];
ll ans[MAXN];
inline int pow_mod(int x, int i) {
int y = 1;
while (i) {
if (i & 1)
y = (ll)y * x % MOD;
x = (ll)x * x % MOD;
i >>= 1;
}
return y;
}
void NTT(int *a, int n, int flag) {
for (int i = 0; i < n; ++i)
if (i < R[i])
swap(a[i], a[R[i]]);
for (int i = 1; i < n; i <<= 1) {
int T = pow_mod(3, (MOD - 1) / (i << 1));
if (flag == -1)
T = pow_mod(T, MOD - 2);
for (int j = 0; j < n; j += (i << 1)) {
int t = 1;
for (int k = 0; k < i; ++k, t = (ll)t * T % MOD) {
int Nx = a[j + k], Ny = (ll)t * a[i + j + k] % MOD;
a[j + k] = ((ll)Nx + Ny) % MOD;
a[i + j + k] = ((ll)Nx - Ny + MOD) % MOD;
}
}
}
}
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll d = exgcd(b, a % b, y, x);
y -= (a / b) * x;
return d;
}
ll mul_mod(ll a, ll b, ll p) {
a %= p;
b %= p;
ll c = (long double)a * b / p;
ll ans = a * b - c * p;
if (ans < 0)
ans += p;
if (ans >= p)
ans -= p;
return ans;
}
void solve() {
// n=read()+1;m=read()+1;P=read();
// for(int i=0;i<n;++i) a[i]=read();
// for(int i=0;i<m;++i) b[i]=read();
int lim = 1, ct = 0;
while (lim <= n + m)
lim <<= 1, ct++;
for (int i = 0; i < lim; ++i)
R[i] = (R[i >> 1] >> 1) | ((i & 1) << (ct - 1));
for (int cur = 0; cur < 3; ++cur) {
MOD = MODs[cur];
memset(f, 0, sizeof(f));
memset(g, 0, sizeof(g));
for (int i = 0; i < n; ++i)
f[i] = a[i];
for (int i = 0; i < m; ++i)
g[i] = b[i];
NTT(f, lim, 1);
NTT(g, lim, 1);
for (int i = 0; i < lim; ++i)
f[i] = (ll)f[i] * g[i] % MOD;
NTT(f, lim, -1);
int invlim = pow_mod(lim, MOD - 2);
for (int i = 0; i < lim; ++i)
r[cur][i] = (ll)f[i] * invlim % MOD;
}
const ll INV = mul_mod(pow_mod(MODs[0], MODs[2] - 2),
pow_mod(MODs[1], MODs[2] - 2), MODs[2]);
for (int i = 0; i < lim; ++i) {
ll M = MODs[0] * MODs[1];
ll m0 = MODs[0], m1 = MODs[1], m2 = MODs[2];
ll a = m0, b = m1, x, y;
ll c = (r[1][i] - r[0][i] % m1 + m1) % m1;
ll d = exgcd(a, b, x, y);
x = mul_mod(x, c, b);
ans[i] = (r[0][i] + mul_mod(x, m0, M)) % M;
ll t = ((r[2][i] - ans[i]) % MODs[2] + MODs[2]) % MODs[2];
t = mul_mod(t, INV, MODs[2]);
ans[i] = (mul_mod(t, M, P) + ans[i]) % P;
}
}
} // namespace NTT
int main() {
n = read();
fac[0] = 1;
for (int i = 1; i <= n; ++i)
fac[i] = (ll)fac[i - 1] * i % MOD;
invf[n] = pow_mod(fac[n], MOD - 2);
for (int i = n - 1; i >= 0; --i)
invf[i] = (ll)invf[i + 1] * (i + 1) % MOD;
// int ans=0;
// for(int i=1;i<=n;++i){
// int w=read();
// for(int j=1;j<=n;++j){
// for(int k=1;k<=n-abs(i-j);++k){
// ans=mod(ans+(ll)w*comb(n-abs(i-j)-1,k-1)%MOD*fac[k-1]%MOD*fac[n-k]%MOD);
// }
// }
// }
NTT::P = MOD;
NTT::n = n + 1;
NTT::m = n + 1;
for (int i = 1; i <= n; ++i)
NTT::a[i] = fac[n - i];
for (int i = 0; i <= n; ++i)
NTT::b[i] = invf[i];
NTT::solve();
for (int i = 1; i <= n; ++i)
g[i] = NTT::ans[i];
// for(int i=1;i<=n;++i){
// for(int k=1;k<=i;++k)g[i]=mod(g[i]+(ll)fac[n-k]*invf[i-k]%MOD);
// }
for (int i = 0; i < n; ++i)
f[i] = mod((ll)g[n - i] * fac[n - i - 1] % MOD + f[i - 1]);
int ans = 0;
for (int i = 1; i <= n; ++i) {
int w = read();
ans = mod(ans +
(ll)w *
mod(mod(f[min(i - 1, n - i)] + f[max(i - 1, n - i)]) - f[0]) %
MOD);
}
cout << ans << endl;
return 0;
} | // problem:agc028_b
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
inline int read() {
int f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline ll readll() {
ll f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int MAXN = 1e5 + 5, MOD = 1e9 + 7;
inline int mod(int x) { return x < MOD ? (x < 0 ? x + MOD : x) : x - MOD; }
inline int pow_mod(int x, int i) {
int y = 1;
while (i) {
if (i & 1)
y = (ll)y * x % MOD;
x = (ll)x * x % MOD;
i >>= 1;
}
return y;
}
int n, fac[MAXN], invf[MAXN], f[MAXN], g[MAXN];
inline int comb(int n, int k) {
assert(n >= k);
return (ll)fac[n] * invf[k] % MOD * invf[n - k] % MOD;
}
namespace NTT {
const int MAXN = 4e5 + 5;
const ll MODs[3] = {469762049, 998244353, 1004535809};
int MOD, n, m, P, a[MAXN], b[MAXN], f[MAXN], g[MAXN], R[MAXN], r[3][MAXN];
ll ans[MAXN];
inline int pow_mod(int x, int i) {
int y = 1;
while (i) {
if (i & 1)
y = (ll)y * x % MOD;
x = (ll)x * x % MOD;
i >>= 1;
}
return y;
}
void NTT(int *a, int n, int flag) {
for (int i = 0; i < n; ++i)
if (i < R[i])
swap(a[i], a[R[i]]);
for (int i = 1; i < n; i <<= 1) {
int T = pow_mod(3, (MOD - 1) / (i << 1));
if (flag == -1)
T = pow_mod(T, MOD - 2);
for (int j = 0; j < n; j += (i << 1)) {
int t = 1;
for (int k = 0; k < i; ++k, t = (ll)t * T % MOD) {
int Nx = a[j + k], Ny = (ll)t * a[i + j + k] % MOD;
a[j + k] = ((ll)Nx + Ny) % MOD;
a[i + j + k] = ((ll)Nx - Ny + MOD) % MOD;
}
}
}
}
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll d = exgcd(b, a % b, y, x);
y -= (a / b) * x;
return d;
}
ll mul_mod(ll a, ll b, ll p) {
a %= p;
b %= p;
ll c = (long double)a * b / p;
ll ans = a * b - c * p;
if (ans < 0)
ans += p;
if (ans >= p)
ans -= p;
return ans;
}
void solve() {
// n=read()+1;m=read()+1;P=read();
// for(int i=0;i<n;++i) a[i]=read();
// for(int i=0;i<m;++i) b[i]=read();
int lim = 1, ct = 0;
while (lim <= n + m)
lim <<= 1, ct++;
for (int i = 0; i < lim; ++i)
R[i] = (R[i >> 1] >> 1) | ((i & 1) << (ct - 1));
for (int cur = 0; cur < 3; ++cur) {
MOD = MODs[cur];
memset(f, 0, sizeof(f));
memset(g, 0, sizeof(g));
for (int i = 0; i < n; ++i)
f[i] = a[i];
for (int i = 0; i < m; ++i)
g[i] = b[i];
NTT(f, lim, 1);
NTT(g, lim, 1);
for (int i = 0; i < lim; ++i)
f[i] = (ll)f[i] * g[i] % MOD;
NTT(f, lim, -1);
int invlim = pow_mod(lim, MOD - 2);
for (int i = 0; i < lim; ++i)
r[cur][i] = (ll)f[i] * invlim % MOD;
}
const ll INV = mul_mod(pow_mod(MODs[0], MODs[2] - 2),
pow_mod(MODs[1], MODs[2] - 2), MODs[2]);
for (int i = 0; i < lim; ++i) {
ll M = MODs[0] * MODs[1];
ll m0 = MODs[0], m1 = MODs[1], m2 = MODs[2];
ll a = m0, b = m1, x, y;
ll c = (r[1][i] - r[0][i] % m1 + m1) % m1;
ll d = exgcd(a, b, x, y);
x = mul_mod(x, c, b);
ans[i] = (r[0][i] + mul_mod(x, m0, M)) % M;
ll t = ((r[2][i] - ans[i]) % MODs[2] + MODs[2]) % MODs[2];
t = mul_mod(t, INV, MODs[2]);
ans[i] = (mul_mod(t, M, P) + ans[i]) % P;
}
}
} // namespace NTT
int main() {
n = read();
fac[0] = 1;
for (int i = 1; i <= n; ++i)
fac[i] = (ll)fac[i - 1] * i % MOD;
invf[n] = pow_mod(fac[n], MOD - 2);
for (int i = n - 1; i >= 0; --i)
invf[i] = (ll)invf[i + 1] * (i + 1) % MOD;
// int ans=0;
// for(int i=1;i<=n;++i){
// int w=read();
// for(int j=1;j<=n;++j){
// for(int k=1;k<=n-abs(i-j);++k){
// ans=mod(ans+(ll)w*comb(n-abs(i-j)-1,k-1)%MOD*fac[k-1]%MOD*fac[n-k]%MOD);
// }
// }
// }
NTT::P = MOD;
NTT::n = n + 1;
NTT::m = n + 1;
for (int i = 1; i <= n; ++i)
NTT::a[i] = fac[n - i];
for (int i = 0; i <= n; ++i)
NTT::b[i] = invf[i];
NTT::solve();
for (int i = 1; i <= n; ++i)
g[i] = NTT::ans[i];
// for(int i=1;i<=n;++i){
// for(int k=1;k<=i;++k)g[i]=mod(g[i]+(ll)fac[n-k]*invf[i-k]%MOD);
// }
for (int i = 0; i < n; ++i)
f[i] = mod((ll)g[n - i] * fac[n - i - 1] % MOD + f[i - 1]);
int ans = 0;
for (int i = 1; i <= n; ++i) {
int w = read();
ans = mod(ans +
(ll)w *
mod(mod(f[min(i - 1, n - i)] + f[max(i - 1, n - i)]) - f[0]) %
MOD);
}
cout << ans << endl;
return 0;
} | insert | 63 | 63 | 63 | 64 | 0 | |
p03233 | C++ | Runtime Error | /****************************************************************
* Author: huhao
* Email: [email protected]
* Create time: 2020-02-17 15:23:07
****************************************************************/
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define fr(i, a, b) for (int i = (a), end_##i = (b); i <= end_##i; i++)
#define fd(i, a, b) for (int i = (a), end_##i = (b); i >= end_##i; i--)
int read() {
int r = 0, t = 1, c = getchar();
while (c < '0' || c > '9') {
t = c == '-' ? -1 : 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
r = (r << 3) + (r << 1) + (c ^ 48);
c = getchar();
}
return r * t;
}
#define i64 long long
const int N = 100010;
i64 n, a[N], r[N], ans, vis[N], Ans, flag;
int main() {
n = read();
Ans = 1ll << 50;
fr(i, 0, n - 1) {
a[i * 2] = read();
a[i * 2 + 1] = read();
}
fr(i, 0, n + n - 1) r[i] = i;
std::sort(r + 1, r + n + n + 1, [&](int x, int y) { return a[x] < a[y]; });
fr(i, 1, n) {
ans += a[r[i]];
vis[r[i] / 2]++;
if (vis[r[i] / 2] == 2)
Ans = 0;
flag |= 1 << (r[i] % 2);
}
if (flag == 1 || flag == 2)
Ans = 0;
if (Ans) {
fr(i, 1, n) Ans = std::min(
Ans, a[r[i] / 2 == r[n + 1] / 2 ? r[n + 2] : r[n + 1]] - a[r[i]]);
}
printf("%lld\n", ans + Ans);
return 0;
} | /****************************************************************
* Author: huhao
* Email: [email protected]
* Create time: 2020-02-17 15:23:07
****************************************************************/
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define fr(i, a, b) for (int i = (a), end_##i = (b); i <= end_##i; i++)
#define fd(i, a, b) for (int i = (a), end_##i = (b); i >= end_##i; i--)
int read() {
int r = 0, t = 1, c = getchar();
while (c < '0' || c > '9') {
t = c == '-' ? -1 : 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
r = (r << 3) + (r << 1) + (c ^ 48);
c = getchar();
}
return r * t;
}
#define i64 long long
const int N = 200010;
i64 n, a[N], r[N], ans, vis[N], Ans, flag;
int main() {
n = read();
Ans = 1ll << 50;
fr(i, 0, n - 1) {
a[i * 2] = read();
a[i * 2 + 1] = read();
}
fr(i, 0, n + n - 1) r[i] = i;
std::sort(r + 1, r + n + n + 1, [&](int x, int y) { return a[x] < a[y]; });
fr(i, 1, n) {
ans += a[r[i]];
vis[r[i] / 2]++;
if (vis[r[i] / 2] == 2)
Ans = 0;
flag |= 1 << (r[i] % 2);
}
if (flag == 1 || flag == 2)
Ans = 0;
if (Ans) {
fr(i, 1, n) Ans = std::min(
Ans, a[r[i] / 2 == r[n + 1] / 2 ? r[n + 2] : r[n + 1]] - a[r[i]]);
}
printf("%lld\n", ans + Ans);
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p03233 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#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 = (b)-1; i >= (a); --i)
#define DEBUG(x) cout << #x << ": " << x << '\n'
#define DEBUG_VEC(v) \
cout << #v << ":"; \
REP(i, v.size()) cout << ' ' << v[i]; \
cout << '\n'
#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))
const ll MOD = 1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a) % MOD + MOD) % MOD
const double EPS = 1e-11;
#define EQ0(x) (abs((x)) < EPS)
#define EQ(a, b) (abs((a) - (b)) < EPS)
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
ll a[114514], b[114514];
pair<ll, int> ab[114514];
cin >> n;
REP(i, n) {
cin >> a[i] >> b[i];
ab[i] = make_pair(a[i], i);
ab[n + i] = make_pair(b[i], n + i);
}
sort(ab, ab + n * 2);
ll ans = 0, sum1 = 0, sum2 = 0;
REP(i, n) {
ans += ab[i].first;
sum1 += a[i];
sum2 += b[i];
}
if (sum1 != ans && sum2 != ans) {
bool ok = false;
REP(i, n) {
if ((a[i] < ab[n - 1].first && b[i] < ab[n - 1].first) ||
(a[i] == ab[n - 1].first && b[i] == ab[n - 1].first &&
ab[n - 2].first == ab[n - 1].first)) {
ok = true;
break;
}
}
if (!ok) {
if (abs(ab[n - 1].second - ab[n].second) == n) {
ans = ans + min(ab[n + 1].first - ab[n - 1].first,
ab[n].first - ab[n - 2].first);
} else {
ans = ans + ab[n].first - ab[n - 1].first;
}
}
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#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 = (b)-1; i >= (a); --i)
#define DEBUG(x) cout << #x << ": " << x << '\n'
#define DEBUG_VEC(v) \
cout << #v << ":"; \
REP(i, v.size()) cout << ' ' << v[i]; \
cout << '\n'
#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))
const ll MOD = 1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a) % MOD + MOD) % MOD
const double EPS = 1e-11;
#define EQ0(x) (abs((x)) < EPS)
#define EQ(a, b) (abs((a) - (b)) < EPS)
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
ll a[114514], b[114514];
pair<ll, int> ab[214514];
cin >> n;
REP(i, n) {
cin >> a[i] >> b[i];
ab[i] = make_pair(a[i], i);
ab[n + i] = make_pair(b[i], n + i);
}
sort(ab, ab + n * 2);
ll ans = 0, sum1 = 0, sum2 = 0;
REP(i, n) {
ans += ab[i].first;
sum1 += a[i];
sum2 += b[i];
}
if (sum1 != ans && sum2 != ans) {
bool ok = false;
REP(i, n) {
if ((a[i] < ab[n - 1].first && b[i] < ab[n - 1].first) ||
(a[i] == ab[n - 1].first && b[i] == ab[n - 1].first &&
ab[n - 2].first == ab[n - 1].first)) {
ok = true;
break;
}
}
if (!ok) {
if (abs(ab[n - 1].second - ab[n].second) == n) {
ans = ans + min(ab[n + 1].first - ab[n - 1].first,
ab[n].first - ab[n - 2].first);
} else {
ans = ans + ab[n].first - ab[n - 1].first;
}
}
}
cout << ans << '\n';
return 0;
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p03233 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, b) for (register ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (register ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (register int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast<t>(x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((int)x.size())
#define file(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef queue<int> qi;
typedef queue<pii> qii;
typedef set<int> si;
typedef map<int, int> mii;
typedef map<string, int> msi;
const int maxn = 5e3 + 5;
const int inf = 0x3f3f3f3f;
const int iinf = 1 << 30;
const ll linf = 2e18;
const ll mod = 1e9 + 7;
const double eps = 1e-7;
template <class T = int> T read() {
T f = 1, a = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
a = (a << 3) + (a << 1) + ch - '0';
ch = getchar();
}
return a * f;
}
ll n, ans;
ll a[maxn], b[maxn], suma, sumb;
pair<ll, pair<ll, ll>> c[maxn];
ll pre[maxn];
ll rnka[maxn], rnkb[maxn];
signed main() {
scanf("%lld", &n);
rep(i, 1, n) scanf("%lld %lld", &a[i], &b[i]), suma += a[i], sumb += b[i],
c[i] = mp(a[i], mp(i, 0)), c[n + i] = mp(b[i], mp(i, 1));
ans = min(suma, sumb);
sort(c + 1, c + 2 * n + 1);
rep(i, 1, 2 * n) pre[i] = pre[i - 1] + c[i].fi;
rep(i, 1, n) {
rnka[i] = lb(c + 1, c + n + n + 1, mp(a[i], mp(i, 0ll))) - c;
rnkb[i] = lb(c + 1, c + n + n + 1, mp(b[i], mp(i, 1ll))) - c;
}
rep(i, 1, n) {
ll x = rnka[i], y = rnkb[i];
if (x > y)
swap(x, y);
ll sum = pre[n - 2] + a[i] + b[i];
if (x <= n - 2) {
sum += c[n - 1].fi;
sum -= c[x].fi;
if (y <= n - 1)
sum += c[n].fi, sum -= c[y].fi;
}
ans = min(ans, sum);
}
printf("%lld\n", ans);
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, b) for (register ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (register ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (register int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast<t>(x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((int)x.size())
#define file(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef queue<int> qi;
typedef queue<pii> qii;
typedef set<int> si;
typedef map<int, int> mii;
typedef map<string, int> msi;
const int maxn = 2e6 + 5;
const int inf = 0x3f3f3f3f;
const int iinf = 1 << 30;
const ll linf = 2e18;
const ll mod = 1e9 + 7;
const double eps = 1e-7;
template <class T = int> T read() {
T f = 1, a = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
a = (a << 3) + (a << 1) + ch - '0';
ch = getchar();
}
return a * f;
}
ll n, ans;
ll a[maxn], b[maxn], suma, sumb;
pair<ll, pair<ll, ll>> c[maxn];
ll pre[maxn];
ll rnka[maxn], rnkb[maxn];
signed main() {
scanf("%lld", &n);
rep(i, 1, n) scanf("%lld %lld", &a[i], &b[i]), suma += a[i], sumb += b[i],
c[i] = mp(a[i], mp(i, 0)), c[n + i] = mp(b[i], mp(i, 1));
ans = min(suma, sumb);
sort(c + 1, c + 2 * n + 1);
rep(i, 1, 2 * n) pre[i] = pre[i - 1] + c[i].fi;
rep(i, 1, n) {
rnka[i] = lb(c + 1, c + n + n + 1, mp(a[i], mp(i, 0ll))) - c;
rnkb[i] = lb(c + 1, c + n + n + 1, mp(b[i], mp(i, 1ll))) - c;
}
rep(i, 1, n) {
ll x = rnka[i], y = rnkb[i];
if (x > y)
swap(x, y);
ll sum = pre[n - 2] + a[i] + b[i];
if (x <= n - 2) {
sum += c[n - 1].fi;
sum -= c[x].fi;
if (y <= n - 1)
sum += c[n].fi, sum -= c[y].fi;
}
ans = min(ans, sum);
}
printf("%lld\n", ans);
return 0;
} | replace | 56 | 57 | 56 | 57 | 0 | |
p03233 | C++ | Runtime Error | /*input
3
1 5
4 2
6 3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i, n) for (int i = 0; i < ((int)n); i++)
#define pb push_back
#define MP(a, b) make_pair(a, b)
#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())
#ifdef leowang
#define debug(...) \
do { \
fprintf(stderr, "%s - %d : (%s) = ", __PRETTY_FUNCTION__, __LINE__, \
#__VA_ARGS__); \
_DO(__VA_ARGS__); \
} while (0)
template <typename I> void _DO(I &&x) { cerr << x << endl; }
template <typename I, typename... T> void _DO(I &&x, T &&...tail) {
cerr << x << ", ";
_DO(tail...);
}
#else
#define debug(...)
#endif
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> P) {
out << '(' << P.F << ',' << P.S << ')';
return out;
}
//}}}
const ll maxn = 300005;
const ll maxlg = __lg(maxn) + 2;
const ll INF64 = 8000000000000000000LL;
const int INF = 0x3f3f3f3f;
const ll MOD = ll(1e9 + 7);
const double PI = acos(-1);
// const ll p=880301;
// const ll P=31;
ll mypow(ll a, ll b) {
ll res = 1LL;
while (b) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
ll a[maxn], b[maxn];
multiset<ll> mn, mx;
int main() {
IOS;
int n;
cin >> n;
REP(i, n) cin >> a[i] >> b[i];
REP(i, n) mx.insert(a[i]);
REP(i, n) mx.insert(b[i]);
ll ans = INF64;
{
ll cur = 0;
REP(i, n) cur += a[i];
ans = min(ans, cur);
}
{
ll cur = 0;
REP(i, n) cur += b[i];
ans = min(ans, cur);
}
REP(i, n - 2) {
mn.insert(*mx.begin());
mx.erase(mx.begin());
}
ll cur = 0;
for (ll i : mn)
cur += i;
REP(i, n) {
if (mn.count(a[i]))
mn.erase(mn.lower_bound(a[i])), cur -= a[i];
else
mx.erase(mx.lower_bound(a[i]));
if (mn.count(b[i]))
mn.erase(mn.lower_bound(b[i])), cur -= b[i];
else
mx.erase(mx.lower_bound(b[i]));
while (SZ(mn) < n - 2) {
mn.insert(*mx.begin());
cur += *mx.begin();
mx.erase(mx.begin());
}
while (SZ(mn) > n - 2) {
mx.insert(*prev(mn.end()));
cur -= *prev(mn.end());
mn.erase(prev(mn.end()));
}
ans = min(ans, cur + a[i] + b[i]);
// cout<<i<<' '<<cur+a[i]+b[i]<<'\n';
// for(ll i:mn) cout<<i<<' ';
// cout<<'\n';
mx.insert(a[i]);
mx.insert(b[i]);
while (*prev(mn.end()) > *mx.begin()) {
ll x = *prev(mn.end()), y = *mx.begin();
mn.erase(prev(mn.end()));
mx.erase(mx.begin());
mn.insert(y);
mx.insert(x);
cur = cur - x + y;
}
}
cout << ans << '\n';
} | /*input
3
1 5
4 2
6 3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i, n) for (int i = 0; i < ((int)n); i++)
#define pb push_back
#define MP(a, b) make_pair(a, b)
#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())
#ifdef leowang
#define debug(...) \
do { \
fprintf(stderr, "%s - %d : (%s) = ", __PRETTY_FUNCTION__, __LINE__, \
#__VA_ARGS__); \
_DO(__VA_ARGS__); \
} while (0)
template <typename I> void _DO(I &&x) { cerr << x << endl; }
template <typename I, typename... T> void _DO(I &&x, T &&...tail) {
cerr << x << ", ";
_DO(tail...);
}
#else
#define debug(...)
#endif
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> P) {
out << '(' << P.F << ',' << P.S << ')';
return out;
}
//}}}
const ll maxn = 300005;
const ll maxlg = __lg(maxn) + 2;
const ll INF64 = 8000000000000000000LL;
const int INF = 0x3f3f3f3f;
const ll MOD = ll(1e9 + 7);
const double PI = acos(-1);
// const ll p=880301;
// const ll P=31;
ll mypow(ll a, ll b) {
ll res = 1LL;
while (b) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
ll a[maxn], b[maxn];
multiset<ll> mn, mx;
int main() {
IOS;
int n;
cin >> n;
REP(i, n) cin >> a[i] >> b[i];
if (n == 2) {
cout << min(a[0], b[1]) + min(a[1], b[0]) << '\n';
return 0;
}
REP(i, n) mx.insert(a[i]);
REP(i, n) mx.insert(b[i]);
ll ans = INF64;
{
ll cur = 0;
REP(i, n) cur += a[i];
ans = min(ans, cur);
}
{
ll cur = 0;
REP(i, n) cur += b[i];
ans = min(ans, cur);
}
REP(i, n - 2) {
mn.insert(*mx.begin());
mx.erase(mx.begin());
}
ll cur = 0;
for (ll i : mn)
cur += i;
REP(i, n) {
if (mn.count(a[i]))
mn.erase(mn.lower_bound(a[i])), cur -= a[i];
else
mx.erase(mx.lower_bound(a[i]));
if (mn.count(b[i]))
mn.erase(mn.lower_bound(b[i])), cur -= b[i];
else
mx.erase(mx.lower_bound(b[i]));
while (SZ(mn) < n - 2) {
mn.insert(*mx.begin());
cur += *mx.begin();
mx.erase(mx.begin());
}
while (SZ(mn) > n - 2) {
mx.insert(*prev(mn.end()));
cur -= *prev(mn.end());
mn.erase(prev(mn.end()));
}
ans = min(ans, cur + a[i] + b[i]);
// cout<<i<<' '<<cur+a[i]+b[i]<<'\n';
// for(ll i:mn) cout<<i<<' ';
// cout<<'\n';
mx.insert(a[i]);
mx.insert(b[i]);
while (*prev(mn.end()) > *mx.begin()) {
ll x = *prev(mn.end()), y = *mx.begin();
mn.erase(prev(mn.end()));
mx.erase(mx.begin());
mn.insert(y);
mx.insert(x);
cur = cur - x + y;
}
}
cout << ans << '\n';
} | insert | 76 | 76 | 76 | 82 | 0 | |
p03233 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define vi vector<int>
#define vpi vector<pii>
#define IT iterator
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking
#define fi first
#define se second
#define BG begin
#define ED end
#define For(i, j, k) for (int i = (int)(j); i <= (int)(k); i++)
#define Rep(i, j, k) for (int i = (int)(j); i >= (int)(k); i--)
#define UPD(x, y) (((x) += (y)) >= mo ? (x) -= mo : 233)
#define CLR(a, v) memset(a, v, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define sqr(x) (1ll * x * x)
#define LS3 k * 2, l, mid
#define RS3 k * 2 + 1, mid + 1, r
#define LS5 k * 2, l, mid, x, y
#define RS5 k * 2 + 1, mid + 1, r, x, y
#define GET \
pushdown(k); \
int mid = (l + r) / 2
#define INF (1 << 29)
using namespace std;
const int N = 100005;
int a[N], b[N], n, tot;
int sum[N], val[N];
ll ans1, ans2, ans3;
pii q[N * 2];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i], &b[i]);
ans1 = 0, ans2 = 0, ans3 = 0;
for (int i = 1; i <= n; i++)
ans1 += a[i], ans2 += b[i];
for (int i = 1; i <= n; i++)
q[++tot] = pii(a[i], i), q[++tot] = pii(b[i], -i);
sort(q + 1, q + tot + 1);
int ok = 0;
for (int i = 1; i <= n; i++) {
ok += (sum[abs(q[i].se)] != 0);
ans3 += q[i].fi;
sum[abs(q[i].se)] += q[i].se;
val[abs(q[i].se)] = q[i].fi;
}
if (!ok) {
int del = 1 << 30;
for (int i = n + 1; i <= tot; i++)
del = min(del, q[i].fi - (val[abs(q[i].fi)] == q[n].fi ? q[n - 1].fi
: q[n].fi));
ans3 += del;
}
printf("%lld\n", min(min(ans1, ans2), ans3));
}
| #include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define vi vector<int>
#define vpi vector<pii>
#define IT iterator
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking
#define fi first
#define se second
#define BG begin
#define ED end
#define For(i, j, k) for (int i = (int)(j); i <= (int)(k); i++)
#define Rep(i, j, k) for (int i = (int)(j); i >= (int)(k); i--)
#define UPD(x, y) (((x) += (y)) >= mo ? (x) -= mo : 233)
#define CLR(a, v) memset(a, v, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define sqr(x) (1ll * x * x)
#define LS3 k * 2, l, mid
#define RS3 k * 2 + 1, mid + 1, r
#define LS5 k * 2, l, mid, x, y
#define RS5 k * 2 + 1, mid + 1, r, x, y
#define GET \
pushdown(k); \
int mid = (l + r) / 2
#define INF (1 << 29)
using namespace std;
const int N = 100005;
int a[N], b[N], n, tot;
int sum[N], val[N];
ll ans1, ans2, ans3;
pii q[N * 2];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i], &b[i]);
ans1 = 0, ans2 = 0, ans3 = 0;
for (int i = 1; i <= n; i++)
ans1 += a[i], ans2 += b[i];
for (int i = 1; i <= n; i++)
q[++tot] = pii(a[i], i), q[++tot] = pii(b[i], -i);
sort(q + 1, q + tot + 1);
int ok = 0;
for (int i = 1; i <= n; i++) {
ok += (sum[abs(q[i].se)] != 0);
ans3 += q[i].fi;
sum[abs(q[i].se)] += q[i].se;
val[abs(q[i].se)] = q[i].fi;
}
if (!ok) {
int del = 1 << 30;
for (int i = n + 1; i <= tot; i++)
del = min(del, q[i].fi - (val[abs(q[i].se)] == q[n].fi ? q[n - 1].fi
: q[n].fi));
ans3 += del;
}
printf("%lld\n", min(min(ans1, ans2), ans3));
}
| replace | 63 | 64 | 63 | 64 | 0 | |
p03233 | C++ | Runtime Error | // In the Name of God
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)
#define itr iterator
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define ub upper_bound
#define lb lower_bound
const int N = 1e5 + 5;
const ll mod = 8;
const ll inf = 1e18 + 1;
const double eps = 1e-15;
const int pw = 257;
int n;
pair<int, int> p[N];
ll ans = inf, X, Y, res;
set<int> s;
int main() {
#ifdef Madi
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
cin >> n;
rep(i, 1, n) {
cin >> p[i].fi >> p[n + i].fi;
X += p[i].fi;
Y += p[n + i].fi;
p[i].se = p[i + n].se = i;
}
sort(p + 1, p + 1 + n + n);
rep(i, 1, n) s.insert(p[i].se);
rep(i, 1, n) res += p[i].fi;
if (sz(s) == n) {
rep(i, n + 1, n + n) {
if (p[n].se == p[i].se)
ans = min(ans, res - p[n - 1].fi + p[i].fi);
else
ans = min(ans, res - p[n].fi + p[i].fi);
}
} else
ans = res;
cout << min(ans, min(X, Y));
#ifdef Madi
cerr << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
} | // In the Name of God
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)
#define itr iterator
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define ub upper_bound
#define lb lower_bound
const int N = 2e5 + 5;
const ll mod = 8;
const ll inf = 1e18 + 1;
const double eps = 1e-15;
const int pw = 257;
int n;
pair<int, int> p[N];
ll ans = inf, X, Y, res;
set<int> s;
int main() {
#ifdef Madi
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
cin >> n;
rep(i, 1, n) {
cin >> p[i].fi >> p[n + i].fi;
X += p[i].fi;
Y += p[n + i].fi;
p[i].se = p[i + n].se = i;
}
sort(p + 1, p + 1 + n + n);
rep(i, 1, n) s.insert(p[i].se);
rep(i, 1, n) res += p[i].fi;
if (sz(s) == n) {
rep(i, n + 1, n + n) {
if (p[n].se == p[i].se)
ans = min(ans, res - p[n - 1].fi + p[i].fi);
else
ans = min(ans, res - p[n].fi + p[i].fi);
}
} else
ans = res;
cout << min(ans, min(X, Y));
#ifdef Madi
cerr << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p03233 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#define int long long
const int Maxv = 100010;
int sum[Maxv], val[Maxv], a[Maxv], b[Maxv], suma, sumb, ans;
inline char fgc() {
static char buf[1 << 15], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 15, stdin), p1 == p2)
? EOF
: *p1++;
}
inline int read() {
static int x, ch;
x = 0, ch = fgc();
while (ch < '0' || ch > '9')
ch = fgc();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = fgc();
return x;
}
signed main() {
int n = read();
for (int i = 1; i <= n; i++) {
a[i] = read();
suma += a[i];
b[i] = read();
sumb += b[i];
val[(i << 1) - 1] = a[i];
val[i << 1] = b[i];
}
ans = std::min(suma, sumb);
std::sort(val + 1, val + (n << 1) + 1);
for (int i = 1; i <= (n << 1); i++)
sum[i] += sum[i - 1] + val[i];
for (int i = 1; i <= n; i++) {
int idx = n, tmp = 0;
if (a[i] <= val[idx - 1])
idx++;
else
tmp += a[i];
if (b[i] <= val[idx - 1])
idx++;
else
tmp += b[i];
ans = std::min(ans, tmp + sum[idx - 2]);
}
printf("%lld\n", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#define int long long
const int Maxv = 300010;
int sum[Maxv], val[Maxv], a[Maxv], b[Maxv], suma, sumb, ans;
inline char fgc() {
static char buf[1 << 15], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 15, stdin), p1 == p2)
? EOF
: *p1++;
}
inline int read() {
static int x, ch;
x = 0, ch = fgc();
while (ch < '0' || ch > '9')
ch = fgc();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = fgc();
return x;
}
signed main() {
int n = read();
for (int i = 1; i <= n; i++) {
a[i] = read();
suma += a[i];
b[i] = read();
sumb += b[i];
val[(i << 1) - 1] = a[i];
val[i << 1] = b[i];
}
ans = std::min(suma, sumb);
std::sort(val + 1, val + (n << 1) + 1);
for (int i = 1; i <= (n << 1); i++)
sum[i] += sum[i - 1] + val[i];
for (int i = 1; i <= n; i++) {
int idx = n, tmp = 0;
if (a[i] <= val[idx - 1])
idx++;
else
tmp += a[i];
if (b[i] <= val[idx - 1])
idx++;
else
tmp += b[i];
ans = std::min(ans, tmp + sum[idx - 2]);
}
printf("%lld\n", ans);
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03233 | 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, A[Maxn], B[Maxn];
vector<pii> C;
vector<int> Pos[Maxn];
LL Sum[Maxn];
inline void Solve() {
LL sum = 0, ans = LLONG_MAX;
for (int i = 1; i <= N; ++i)
sum += A[i];
Chkmin(ans, sum);
sum = 0;
for (int i = 1; i <= N; ++i)
sum += B[i];
Chkmin(ans, sum);
C.pb(mp(0, 0));
for (int i = 1; i <= N; ++i)
C.pb(mp(A[i], i)), C.pb(mp(B[i], i));
sort(C.begin(), C.end());
for (int i = 1; i <= 2 * N; ++i) {
Pos[C[i].y].pb(i);
Sum[i] = Sum[i - 1] + C[i].x;
}
for (int i = 1; i <= N; ++i) {
sort(Pos[i].begin(), Pos[i].end());
if (Pos[i][1] <= N) {
Chkmin(ans, Sum[N]);
cout << ans << endl;
return;
}
}
for (int i = 1; i <= N; ++i) {
if (Pos[i][1] == N + 1)
Chkmin(ans, Sum[N + 2] - A[i] - B[i]);
else
Chkmin(ans, Sum[N + 1] - C[Pos[i][0]].x);
}
cout << ans << endl;
}
inline void Input() {
N = read<int>();
for (int i = 1; i <= N; ++i)
A[i] = read<int>(), B[i] = read<int>();
}
int main() {
#ifdef hk_cnyali
freopen("C.in", "r", stdin);
freopen("C.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, A[Maxn], B[Maxn];
vector<pii> C;
vector<int> Pos[Maxn];
LL Sum[Maxn];
inline void Solve() {
LL sum = 0, ans = LLONG_MAX;
for (int i = 1; i <= N; ++i)
sum += A[i];
Chkmin(ans, sum);
sum = 0;
for (int i = 1; i <= N; ++i)
sum += B[i];
Chkmin(ans, sum);
C.pb(mp(0, 0));
for (int i = 1; i <= N; ++i)
C.pb(mp(A[i], i)), C.pb(mp(B[i], i));
sort(C.begin(), C.end());
for (int i = 1; i <= 2 * N; ++i) {
Pos[C[i].y].pb(i);
Sum[i] = Sum[i - 1] + C[i].x;
}
for (int i = 1; i <= N; ++i) {
sort(Pos[i].begin(), Pos[i].end());
if (Pos[i][1] <= N) {
Chkmin(ans, Sum[N]);
cout << ans << endl;
return;
}
}
for (int i = 1; i <= N; ++i) {
if (Pos[i][1] == N + 1)
Chkmin(ans, Sum[N + 2] - A[i] - B[i]);
else
Chkmin(ans, Sum[N + 1] - C[Pos[i][0]].x);
}
cout << ans << endl;
}
inline void Input() {
N = read<int>();
for (int i = 1; i <= N; ++i)
A[i] = read<int>(), B[i] = read<int>();
}
int main() {
#ifdef hk_cnyali
freopen("C.in", "r", stdin);
freopen("C.out", "w", stdout);
#endif
Input();
Solve();
return 0;
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p03233 | 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 n;
cin >> n;
vi v(2 * n);
vector<pi> p;
rep(i, 2 * n) {
cin >> v[i];
p.emplace_back(v[i], i);
}
sort(all(p));
vi use(n), use2(2);
bool ok = 0;
rep(i, n) {
if (++use[p[i].second / 2] == 2)
ok = 1;
if (++use2[p[i].second % 2] == n)
ok = 1;
}
dbg(use2);
if (ok) {
cerr << "1" << endl;
ll sum = 0;
rep(i, n) sum += p[i].first;
cout << sum << endl;
} else if ((p[n - 1].second ^ 1) != p[n].second) {
cerr << "2" << endl;
ll sum = p[n].first;
rep(i, n - 1) sum += p[i].first;
cout << sum << endl;
} else {
assert(0);
cerr << "3" << endl;
ll sum = 0;
rep(i, n - 2) sum += p[i].first;
sum += min(p[n - 2].first + p[n + 1].first, p[n - 1].first + p[n].first);
cout << sum << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define dbg(...) \
do { \
cerr << __LINE__ << ": "; \
dbgprint(#__VA_ARGS__, __VA_ARGS__); \
} while (0);
using namespace std;
namespace std {
template <class S, class T> struct hash<pair<S, T>> {
size_t operator()(const pair<S, T> &p) const {
return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second);
}
};
template <class T> struct hash<vector<T>> {
size_t operator()(const vector<T> &v) const {
size_t h = 0;
for (auto i : v)
h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1;
return h;
}
};
} // namespace std
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[ ";
rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", ");
return os;
}
template <class T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "{ ";
for (const auto &i : v)
os << i << ", ";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &v) {
os << "{";
for (const auto &i : v)
os << " " << i.first << ": " << i.second << ",";
return os << "}";
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
void dbgprint(const string &fmt) { cerr << endl; }
template <class H, class... T>
void dbgprint(const string &fmt, const H &h, const T &...r) {
cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " ";
dbgprint(fmt.substr(fmt.find(",") + 1), r...);
}
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n;
cin >> n;
vi v(2 * n);
vector<pi> p;
rep(i, 2 * n) {
cin >> v[i];
p.emplace_back(v[i], i);
}
sort(all(p));
vi use(n), use2(2);
bool ok = 0;
rep(i, n) {
if (++use[p[i].second / 2] == 2)
ok = 1;
if (++use2[p[i].second % 2] == n)
ok = 1;
}
dbg(use2);
if (ok) {
cerr << "1" << endl;
ll sum = 0;
rep(i, n) sum += p[i].first;
cout << sum << endl;
} else if ((p[n - 1].second ^ 1) != p[n].second) {
cerr << "2" << endl;
ll sum = p[n].first;
rep(i, n - 1) sum += p[i].first;
cout << sum << endl;
} else {
cerr << "3" << endl;
ll sum = 0;
rep(i, n - 2) sum += p[i].first;
sum += min(p[n - 2].first + p[n + 1].first, p[n - 1].first + p[n].first);
cout << sum << endl;
}
return 0;
} | delete | 97 | 98 | 97 | 97 | 0 | 32: use2= [ 1, 2 ]
2
|
p03233 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
const int N = 1e5 + 10;
int n, a[N], b[N];
ll tot, suma, sumb, sum, res;
pli all[N];
bool vis[N];
int main() {
cin >> n;
rep(i, 1, n) {
scanf("%d%d", &a[i], &b[i]);
tot += a[i] + b[i];
suma += a[i], sumb += b[i];
all[i << 1] = make_pair(a[i], i);
all[i << 1 | 1] = make_pair(b[i], i);
}
sort(all + 1, all + (n << 1) + 2, greater<pli>());
bool ff = 0;
res = max(suma, sumb);
rep(i, 1, n) {
if (vis[all[i].second]) {
ff = 1;
}
vis[all[i].second] = 1;
sum += all[i].first;
}
if (ff) {
res = max(res, sum);
} else {
rep(i, n + 1, n << 1) {
if (all[n].second == all[i].second)
res = max(res, sum + all[i].first - all[n - 1].first);
else
res = max(res, sum + all[i].first - all[n].first);
}
}
printf("%lld\n", tot - res);
return 0;
} | #include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
const int N = 2e5 + 10;
int n, a[N], b[N];
ll tot, suma, sumb, sum, res;
pli all[N];
bool vis[N];
int main() {
cin >> n;
rep(i, 1, n) {
scanf("%d%d", &a[i], &b[i]);
tot += a[i] + b[i];
suma += a[i], sumb += b[i];
all[i << 1] = make_pair(a[i], i);
all[i << 1 | 1] = make_pair(b[i], i);
}
sort(all + 1, all + (n << 1) + 2, greater<pli>());
bool ff = 0;
res = max(suma, sumb);
rep(i, 1, n) {
if (vis[all[i].second]) {
ff = 1;
}
vis[all[i].second] = 1;
sum += all[i].first;
}
if (ff) {
res = max(res, sum);
} else {
rep(i, n + 1, n << 1) {
if (all[n].second == all[i].second)
res = max(res, sum + all[i].first - all[n - 1].first);
else
res = max(res, sum + all[i].first - all[n].first);
}
}
printf("%lld\n", tot - res);
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03233 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
struct T {
ll value;
int id;
bool isB;
};
int main(void) {
int n;
cin >> n;
vector<T> t;
rep(i, n) {
ll a, b;
cin >> a >> b;
t.push_back({a, i, false});
t.push_back({b, i, true});
}
sort(all(t), [](T x, T y) {
return x.value != y.value ? x.value < y.value : x.id < y.id;
});
vector<vector<bool>> low(n, {0, 0});
rep(i, n) { low[t[i].id][t[i].isB] = true; }
int HH = 0, LL = 0, HL = 0, LH = 0;
ll sum = 0;
rep(i, n) {
if (low[i][0] && low[i][1])
LL++;
if (!low[i][0] && !low[i][1])
HH++;
if (!low[i][0] && low[i][1])
HL++;
if (low[i][0] && !low[i][1])
LH++;
sum += t[i].value;
}
if (LL > 0 || LH == n || HL == n) {
cout << sum << endl;
} else if (t[n].id != t[n - 1].id) {
assert(false);
cout << sum - t[n - 1].value + t[n].value << endl;
} else if (sum - t[n - 2].value + t[n].value <
sum - t[n - 1].value + t[n + 1].value) {
cout << sum - t[n - 2].value + t[n].value << endl;
} else {
cout << sum - t[n - 1].value + t[n + 1].value << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
struct T {
ll value;
int id;
bool isB;
};
int main(void) {
int n;
cin >> n;
vector<T> t;
rep(i, n) {
ll a, b;
cin >> a >> b;
t.push_back({a, i, false});
t.push_back({b, i, true});
}
sort(all(t), [](T x, T y) {
return x.value != y.value ? x.value < y.value : x.id < y.id;
});
vector<vector<bool>> low(n, {0, 0});
rep(i, n) { low[t[i].id][t[i].isB] = true; }
int HH = 0, LL = 0, HL = 0, LH = 0;
ll sum = 0;
rep(i, n) {
if (low[i][0] && low[i][1])
LL++;
if (!low[i][0] && !low[i][1])
HH++;
if (!low[i][0] && low[i][1])
HL++;
if (low[i][0] && !low[i][1])
LH++;
sum += t[i].value;
}
if (LL > 0 || LH == n || HL == n) {
cout << sum << endl;
} else if (t[n].id != t[n - 1].id) {
cout << sum - t[n - 1].value + t[n].value << endl;
} else if (sum - t[n - 2].value + t[n].value <
sum - t[n - 1].value + t[n + 1].value) {
cout << sum - t[n - 2].value + t[n].value << endl;
} else {
cout << sum - t[n - 1].value + t[n + 1].value << endl;
}
return 0;
}
| delete | 47 | 48 | 47 | 47 | -6 | 2add7d32-9f3a-4329-9dbe-1592b7fe741c.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03233/C++/s311358863.cpp:48: int main(): Assertion `false' failed.
|
p03233 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
#define LL long long
#define mp(x, y) make_pair(x, y)
#define pll pair<long long, long long>
#define pii pair<int, int>
#define SZ(x) ((int)x.size())
#define VI vector<int>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read() {
LL f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int stack[20];
template <typename T> inline void write(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (!x) {
putchar('0');
return;
}
int top = 0;
while (x)
stack[++top] = x % 10, x /= 10;
while (top)
putchar(stack[top--] + '0');
}
template <typename T> inline void pr1(T x) {
write(x);
putchar(' ');
}
template <typename T> inline void pr2(T x) {
write(x);
putchar('\n');
}
template <typename T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }
template <typename T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }
const int MAXN = 100005;
int n, a[MAXN], b[MAXN];
int L[MAXN], R[MAXN];
vector<pii> vec;
LL pres[MAXN];
int main() {
#ifdef Rose
double BeginJudgeTime = clock();
#endif
n = read();
for (int i = 1; i <= n; i++) {
a[i] = read(), b[i] = read();
vec.emplace_back(mp(a[i], i));
vec.emplace_back(mp(b[i], i));
}
sort(vec.begin(), vec.end());
LL ans = 1e18, sum = 0;
for (int i = 1; i <= n; i++)
sum += a[i];
chkmin(ans, sum);
sum = 0;
for (int i = 1; i <= n; i++)
sum += b[i];
chkmin(ans, sum);
sum = 0;
int t = 0;
for (auto p : vec) {
if (L[p.second])
R[p.second] = ++t;
else
L[p.second] = ++t;
pres[t] = pres[t - 1] + p.first;
}
for (int i = 1; i <= n; i++) {
if (L[i] > n - 2)
chkmin(ans, a[i] + b[i] + pres[n - 2]);
else if (R[i] > n - 1)
chkmin(ans, pres[n - 1] + pres[R[i]] - pres[R[i] - 1]);
else
chkmin(ans, pres[n]);
}
pr2(ans);
#ifdef Rose
double EndJudgeTime = clock();
cerr << "JudgeTime is"
<< " ";
cerr << (EndJudgeTime - BeginJudgeTime) / CLOCKS_PER_SEC << endl;
#endif
return 0;
}
| #include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
#define LL long long
#define mp(x, y) make_pair(x, y)
#define pll pair<long long, long long>
#define pii pair<int, int>
#define SZ(x) ((int)x.size())
#define VI vector<int>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read() {
LL f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int stack[20];
template <typename T> inline void write(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (!x) {
putchar('0');
return;
}
int top = 0;
while (x)
stack[++top] = x % 10, x /= 10;
while (top)
putchar(stack[top--] + '0');
}
template <typename T> inline void pr1(T x) {
write(x);
putchar(' ');
}
template <typename T> inline void pr2(T x) {
write(x);
putchar('\n');
}
template <typename T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }
template <typename T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }
const int MAXN = 200005;
int n, a[MAXN], b[MAXN];
int L[MAXN], R[MAXN];
vector<pii> vec;
LL pres[MAXN];
int main() {
#ifdef Rose
double BeginJudgeTime = clock();
#endif
n = read();
for (int i = 1; i <= n; i++) {
a[i] = read(), b[i] = read();
vec.emplace_back(mp(a[i], i));
vec.emplace_back(mp(b[i], i));
}
sort(vec.begin(), vec.end());
LL ans = 1e18, sum = 0;
for (int i = 1; i <= n; i++)
sum += a[i];
chkmin(ans, sum);
sum = 0;
for (int i = 1; i <= n; i++)
sum += b[i];
chkmin(ans, sum);
sum = 0;
int t = 0;
for (auto p : vec) {
if (L[p.second])
R[p.second] = ++t;
else
L[p.second] = ++t;
pres[t] = pres[t - 1] + p.first;
}
for (int i = 1; i <= n; i++) {
if (L[i] > n - 2)
chkmin(ans, a[i] + b[i] + pres[n - 2]);
else if (R[i] > n - 1)
chkmin(ans, pres[n - 1] + pres[R[i]] - pres[R[i] - 1]);
else
chkmin(ans, pres[n]);
}
pr2(ans);
#ifdef Rose
double EndJudgeTime = clock();
cerr << "JudgeTime is"
<< " ";
cerr << (EndJudgeTime - BeginJudgeTime) / CLOCKS_PER_SEC << endl;
#endif
return 0;
}
| replace | 63 | 64 | 63 | 64 | 0 | |
p03233 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PI;
const LL N = 100005;
LL n;
LL a[N], b[N];
LL ans = 0, sum = 0;
PI c[N];
LL tot;
bool cmp(PI x, PI y) { return x.first > y.first; }
bool in[N];
int main() {
scanf("%lld", &n);
for (LL u = 1; u <= n; u++) {
scanf("%lld%lld", &a[u], &b[u]);
ans = ans + a[u] + b[u];
sum = sum + a[u];
c[++tot] = {a[u], u};
c[++tot] = {b[u], u};
}
sort(c + 1, c + 1 + tot, cmp);
LL mx = 0;
mx = max(sum, ans - sum);
sum = 0;
bool tf = false;
memset(in, false, sizeof(in));
for (LL u = 1; u <= n; u++) {
if (in[c[u].second])
tf = true;
sum = sum + c[u].first;
in[c[u].second] = true;
}
if (tf)
mx = max(mx, sum);
else {
for (LL i = n + 1; i <= tot; i++) {
if (c[i].second != c[n].second)
mx = max(mx, sum + c[i].first - c[n].first);
else
mx = max(mx, sum + c[i].first - c[n - 1].first);
}
}
printf("%lld\n", ans - mx);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PI;
const LL N = 200005;
LL n;
LL a[N], b[N];
LL ans = 0, sum = 0;
PI c[N];
LL tot;
bool cmp(PI x, PI y) { return x.first > y.first; }
bool in[N];
int main() {
scanf("%lld", &n);
for (LL u = 1; u <= n; u++) {
scanf("%lld%lld", &a[u], &b[u]);
ans = ans + a[u] + b[u];
sum = sum + a[u];
c[++tot] = {a[u], u};
c[++tot] = {b[u], u};
}
sort(c + 1, c + 1 + tot, cmp);
LL mx = 0;
mx = max(sum, ans - sum);
sum = 0;
bool tf = false;
memset(in, false, sizeof(in));
for (LL u = 1; u <= n; u++) {
if (in[c[u].second])
tf = true;
sum = sum + c[u].first;
in[c[u].second] = true;
}
if (tf)
mx = max(mx, sum);
else {
for (LL i = n + 1; i <= tot; i++) {
if (c[i].second != c[n].second)
mx = max(mx, sum + c[i].first - c[n].first);
else
mx = max(mx, sum + c[i].first - c[n - 1].first);
}
}
printf("%lld\n", ans - mx);
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03233 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define double long double
#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 repeq(i, n) for (int i = 0; i <= (int)(n); ++i)
#define rep1eq(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n)-1; i > 0; --i)
#define rrepeq(i, n) for (int i = (int)(n); i >= 0; --i)
#define rrep1eq(i, n) for (int i = (int)(n); i > 0; --i)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template <typename T> using Graph = vector<vector<T>>;
template <typename T> using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
// const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string interval[2] = {" ", "\n"}; // {" ", "\n"}
template <typename T> struct is_plural : false_type {};
template <typename T1, typename T2>
struct is_plural<pair<T1, T2>> : true_type {};
template <typename T> struct is_plural<vector<T>> : true_type {};
template <typename T> struct is_plural<complex<T>> : true_type {};
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
return is >> p.first >> p.second;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << p.first << " " << p.second;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto itr = vec.begin(); itr != vec.end(); ++itr)
is >> *itr;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
if (vec.empty())
return os;
bool pl = is_plural<T>();
os << vec.front();
for (auto itr = ++vec.begin(); itr != vec.end(); ++itr)
os << interval[pl] << *itr;
return os;
}
bool CoutYN(bool a, string y = "Yes", string n = "No") {
cout << (a ? y : n) << "\n";
return a;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
long long modpow(int a, long long n, int mod = MOD) {
long long ret = 1;
do {
if (n & 1)
ret = ret * a % mod;
a = 1LL * a * a % mod;
} while (n >>= 1);
return ret;
}
template <typename T> T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template <typename T> T LCM(T a, T b) { return a / GCD(a, b) * b; }
template <typename T1, typename T2>
bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) {
return a.second != b.second ? a.second < b.second : a.first < b.first;
}
template <typename T1, typename T2>
bool CompareByInverse(pair<T1, T2> a, pair<T1, T2> b) {
return a.first != b.first ? a.first < b.first : a.second > b.second;
}
/* -------- <templates end> -------- */
void solve() {
int n;
cin >> n;
vi arr(2 * n);
cin >> arr;
vi num(2 * n);
iota(ALL(num), 0);
sort(ALL(num), [&](int a, int b) { return arr[a] < arr[b]; });
vb det(2, false);
vi cnt(n, 0);
bool ok = false;
ll ans = 0;
rep(i, n) {
ans += arr[num[i]];
det[num[i] & 1] = true;
ok |= cnt[num[i] >> 1]++;
}
if (det[0] && det[1] && !ok) {
if ((num[n] ^ num[n - 1]) != 1) {
ans += arr[num[n]] - arr[num[n - 1]];
} else {
ans +=
min(arr[num[n]] - arr[num[n - 2]], arr[num[n + 1] - arr[num[n - 1]]]);
}
}
cout << ans << endl;
}
/* -------- <programs end> -------- */
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define double long double
#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 repeq(i, n) for (int i = 0; i <= (int)(n); ++i)
#define rep1eq(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n)-1; i > 0; --i)
#define rrepeq(i, n) for (int i = (int)(n); i >= 0; --i)
#define rrep1eq(i, n) for (int i = (int)(n); i > 0; --i)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template <typename T> using Graph = vector<vector<T>>;
template <typename T> using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
// const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string interval[2] = {" ", "\n"}; // {" ", "\n"}
template <typename T> struct is_plural : false_type {};
template <typename T1, typename T2>
struct is_plural<pair<T1, T2>> : true_type {};
template <typename T> struct is_plural<vector<T>> : true_type {};
template <typename T> struct is_plural<complex<T>> : true_type {};
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
return is >> p.first >> p.second;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << p.first << " " << p.second;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto itr = vec.begin(); itr != vec.end(); ++itr)
is >> *itr;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
if (vec.empty())
return os;
bool pl = is_plural<T>();
os << vec.front();
for (auto itr = ++vec.begin(); itr != vec.end(); ++itr)
os << interval[pl] << *itr;
return os;
}
bool CoutYN(bool a, string y = "Yes", string n = "No") {
cout << (a ? y : n) << "\n";
return a;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
long long modpow(int a, long long n, int mod = MOD) {
long long ret = 1;
do {
if (n & 1)
ret = ret * a % mod;
a = 1LL * a * a % mod;
} while (n >>= 1);
return ret;
}
template <typename T> T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template <typename T> T LCM(T a, T b) { return a / GCD(a, b) * b; }
template <typename T1, typename T2>
bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) {
return a.second != b.second ? a.second < b.second : a.first < b.first;
}
template <typename T1, typename T2>
bool CompareByInverse(pair<T1, T2> a, pair<T1, T2> b) {
return a.first != b.first ? a.first < b.first : a.second > b.second;
}
/* -------- <templates end> -------- */
void solve() {
int n;
cin >> n;
vi arr(2 * n);
cin >> arr;
vi num(2 * n);
iota(ALL(num), 0);
sort(ALL(num), [&](int a, int b) { return arr[a] < arr[b]; });
vb det(2, false);
vi cnt(n, 0);
bool ok = false;
ll ans = 0;
rep(i, n) {
ans += arr[num[i]];
det[num[i] & 1] = true;
ok |= cnt[num[i] >> 1]++;
}
if (det[0] && det[1] && !ok) {
if ((num[n] ^ num[n - 1]) != 1) {
ans += arr[num[n]] - arr[num[n - 1]];
} else {
ans +=
min(arr[num[n]] - arr[num[n - 2]], arr[num[n + 1]] - arr[num[n - 1]]);
}
}
cout << ans << endl;
}
/* -------- <programs end> -------- */
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
solve();
return 0;
}
| replace | 118 | 119 | 118 | 119 | 0 | |
p03233 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long LL;
const int N = 100005;
int n;
bool vis[N];
LL A, B, ans;
std::pair<int, int> a[N];
int main() {
std::ios::sync_with_stdio(0), std::cin.tie(0);
std::cin >> n;
for (int i = 0, x, y; i < n; ++i)
std::cin >> x >> y, a[i] = {x, i}, a[i + n] = {y, i}, A += x, B += y;
ans = std::min(A, B), std::sort(a, a + n + n);
for (int i = 0; i < n; ++i)
vis[a[i].second] = 1;
LL sum = 0;
for (int i = 0; i < n; ++i)
sum += a[i].first;
for (int i = 0; i < n; ++i)
if (!vis[i])
return std::cout << std::min(ans, sum) << '\n', 0;
if (a[n - 1].second != a[n].second)
std::cout << std::min(ans, sum - a[n - 1].first + a[n].first) << '\n';
else
std::cout << std::min(ans, sum + std::min(a[n].first - a[n - 2].first,
a[n + 1].first - a[n - 1].first))
<< '\n';
return 0;
} | #include <bits/stdc++.h>
typedef long long LL;
const int N = 200005;
int n;
bool vis[N];
LL A, B, ans;
std::pair<int, int> a[N];
int main() {
std::ios::sync_with_stdio(0), std::cin.tie(0);
std::cin >> n;
for (int i = 0, x, y; i < n; ++i)
std::cin >> x >> y, a[i] = {x, i}, a[i + n] = {y, i}, A += x, B += y;
ans = std::min(A, B), std::sort(a, a + n + n);
for (int i = 0; i < n; ++i)
vis[a[i].second] = 1;
LL sum = 0;
for (int i = 0; i < n; ++i)
sum += a[i].first;
for (int i = 0; i < n; ++i)
if (!vis[i])
return std::cout << std::min(ans, sum) << '\n', 0;
if (a[n - 1].second != a[n].second)
std::cout << std::min(ans, sum - a[n - 1].first + a[n].first) << '\n';
else
std::cout << std::min(ans, sum + std::min(a[n].first - a[n - 2].first,
a[n + 1].first - a[n - 1].first))
<< '\n';
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03233 | C++ | Runtime Error | /*
author: JioFell
ahihi
*/
#include <bits/stdc++.h>
using namespace std;
#define FOR(a, b, c) for (int a = b; a <= c; ++a)
#define pb push_back
#define fi first
#define se second
#define int long long
typedef pair<int, int> ii;
typedef pair<ii, int> pii;
const int N = 4e5 + 10;
int n, suma, sumb;
int a[N], b[N], pre[N], posa[N], posb[N];
vector<pii> tmp;
signed main() {
freopen("test.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
FOR(i, 1, n) {
cin >> a[i] >> b[i];
tmp.pb({{a[i], i}, 0});
tmp.pb({{b[i], i}, 1});
suma += a[i];
sumb += b[i];
}
int ans = min(suma, sumb);
sort(tmp.begin(), tmp.end());
FOR(i, 0, tmp.size() - 1) {
if (tmp[i].se == 0)
posa[tmp[i].fi.se] = i;
else
posb[tmp[i].fi.se] = i;
pre[i] = tmp[i].fi.fi;
if (i > 0)
pre[i] += pre[i - 1];
}
FOR(i, 1, n) {
int sum = pre[n - 1];
int cur = n - 1;
if (posa[i] > cur) {
if (tmp[cur].fi.se != i) {
sum -= tmp[cur].fi.fi;
sum += a[i];
cur--;
} else {
sum -= tmp[cur - 1].fi.fi;
sum += a[i];
}
}
if (posb[i] > cur) {
if (tmp[cur].fi.se != i) {
sum -= tmp[cur].fi.fi;
sum += b[i];
} else {
sum -= tmp[cur - 1].fi.fi;
sum += b[i];
}
}
ans = min(ans, sum);
}
cout << ans;
}
| /*
author: JioFell
ahihi
*/
#include <bits/stdc++.h>
using namespace std;
#define FOR(a, b, c) for (int a = b; a <= c; ++a)
#define pb push_back
#define fi first
#define se second
#define int long long
typedef pair<int, int> ii;
typedef pair<ii, int> pii;
const int N = 4e5 + 10;
int n, suma, sumb;
int a[N], b[N], pre[N], posa[N], posb[N];
vector<pii> tmp;
signed main() {
// freopen("test.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
FOR(i, 1, n) {
cin >> a[i] >> b[i];
tmp.pb({{a[i], i}, 0});
tmp.pb({{b[i], i}, 1});
suma += a[i];
sumb += b[i];
}
int ans = min(suma, sumb);
sort(tmp.begin(), tmp.end());
FOR(i, 0, tmp.size() - 1) {
if (tmp[i].se == 0)
posa[tmp[i].fi.se] = i;
else
posb[tmp[i].fi.se] = i;
pre[i] = tmp[i].fi.fi;
if (i > 0)
pre[i] += pre[i - 1];
}
FOR(i, 1, n) {
int sum = pre[n - 1];
int cur = n - 1;
if (posa[i] > cur) {
if (tmp[cur].fi.se != i) {
sum -= tmp[cur].fi.fi;
sum += a[i];
cur--;
} else {
sum -= tmp[cur - 1].fi.fi;
sum += a[i];
}
}
if (posb[i] > cur) {
if (tmp[cur].fi.se != i) {
sum -= tmp[cur].fi.fi;
sum += b[i];
} else {
sum -= tmp[cur - 1].fi.fi;
sum += b[i];
}
}
ans = min(ans, sum);
}
cout << ans;
}
| replace | 21 | 22 | 21 | 22 | -11 | |
p03234 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
os << "[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &pa) {
os << "(" << pa.first << "," << pa.second << ")";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
#define dbg(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
int N, K;
vector<int> con;
int avi[602];
constexpr lint MOD = 1000000007;
int leftmost[602][602], rightmost[602][602];
lint dp[602][602];
lint extgcd(lint a, lint b, lint &x, lint &y) {
lint d = a;
if (b != 0)
d = extgcd(b, a % b, y, x), y -= (a / b) * x;
else
x = 1, y = 0;
return d;
}
vector<lint> fac, facInv, inv;
void facInit(int nmax) {
fac = facInv = inv = vector<lint>(nmax + 1, 1);
for (int i = 2; i <= nmax; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
facInv[i] = facInv[i - 1] * inv[i] % MOD;
}
}
lint nCr(int n, int r) {
if (n < r || r < 0)
return 0;
return (fac[n] * facInv[r] % MOD) * facInv[n - r] % MOD;
}
lint power(lint x, lint n, lint mod = MOD) {
lint ans = 1;
while (n > 0) {
if (n & 1)
(ans *= x) %= mod;
(x *= x) %= mod;
n >>= 1;
}
return ans;
}
lint modinv(lint x, lint mod = MOD) {
lint ans, y;
extgcd(x, mod, ans, y);
ans %= mod;
return ans < 0 ? ans + mod : ans;
}
lint doublefac(lint n) {
lint k = (n + 1) / 2;
if (n & 1)
return fac[k * 2] * power(facInv[2], k) % MOD * modinv(fac[k]) % MOD;
else
return fac[k] * power(facInv[2], k) % MOD;
}
lint solve(int l, int r) {
lint ans = 0;
int ca = avi[r] - avi[l - 1];
if (leftmost[l][r] < l || rightmost[l][r] > r || (ca & 1))
return ans;
ans = doublefac(max(ca - 1, 0));
FOR(i, l + 1, r) // lからiまでが連結
{
if (rightmost[l][i] > i)
continue;
int c2 = avi[r] - avi[i];
if (c2 & 1)
continue;
ans += MOD - dp[l][i] * doublefac(max(c2 - 1, 0)) % MOD;
}
ans %= MOD;
dp[l][r] = ans;
return ans * doublefac(max(avi[l - 1] + avi[N * 2] - avi[r] - 1, 0)) % MOD;
}
int main() {
memset(dp, 0, sizeof(dp));
cin >> N >> K;
con.resize(N * 2 + 1);
facInit(N * 3);
avi[0] = 0;
FOR(i, 1, N * 2 + 1) avi[i] = 1;
REP(i, 2 * N + 1) REP(j, 2 * N + 1) {
leftmost[i][j] = i;
rightmost[i][j] = j;
}
REP(_, K) {
int A, B;
cin >> A >> B;
con[A] = B;
con[B] = A;
avi[A] = avi[B] = 0;
if (B < A)
swap(A, B);
FOR(i, 1, A + 1)
FOR(j, A, 2 * N + 1) leftmost[i][j] = min(leftmost[i][j], B),
rightmost[i][j] = max(rightmost[i][j], B);
FOR(i, 1, B + 1)
FOR(j, B, 2 * N + 1) leftmost[i][j] = min(leftmost[i][j], A),
rightmost[i][j] = max(rightmost[i][j], A);
}
REP(i, N * 2) avi[i + 1] += avi[i];
lint ans = 0;
FOR(l, 1, 2 * N) FOR(r, l + 1, 2 * N + 1) ans = (ans + solve(l, r)) % MOD;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
os << "[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &pa) {
os << "(" << pa.first << "," << pa.second << ")";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
#define dbg(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
int N, K;
vector<int> con;
int avi[602];
constexpr lint MOD = 1000000007;
int leftmost[602][602], rightmost[602][602];
lint dp[602][602];
lint extgcd(lint a, lint b, lint &x, lint &y) {
lint d = a;
if (b != 0)
d = extgcd(b, a % b, y, x), y -= (a / b) * x;
else
x = 1, y = 0;
return d;
}
vector<lint> fac, facInv, inv;
void facInit(int nmax) {
fac = facInv = inv = vector<lint>(nmax + 1, 1);
for (int i = 2; i <= nmax; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
facInv[i] = facInv[i - 1] * inv[i] % MOD;
}
}
lint nCr(int n, int r) {
if (n < r || r < 0)
return 0;
return (fac[n] * facInv[r] % MOD) * facInv[n - r] % MOD;
}
lint power(lint x, lint n, lint mod = MOD) {
lint ans = 1;
while (n > 0) {
if (n & 1)
(ans *= x) %= mod;
(x *= x) %= mod;
n >>= 1;
}
return ans;
}
lint modinv(lint x, lint mod = MOD) {
lint ans, y;
extgcd(x, mod, ans, y);
ans %= mod;
return ans < 0 ? ans + mod : ans;
}
lint doublefac(lint n) {
lint k = (n + 1) / 2;
if (n & 1)
return fac[k * 2] * power(facInv[2], k) % MOD * power(fac[k], MOD - 2) %
MOD;
else
return fac[k] * power(facInv[2], k) % MOD;
}
lint solve(int l, int r) {
lint ans = 0;
int ca = avi[r] - avi[l - 1];
if (leftmost[l][r] < l || rightmost[l][r] > r || (ca & 1))
return ans;
ans = doublefac(max(ca - 1, 0));
FOR(i, l + 1, r) // lからiまでが連結
{
if (rightmost[l][i] > i)
continue;
int c2 = avi[r] - avi[i];
if (c2 & 1)
continue;
ans += MOD - dp[l][i] * doublefac(max(c2 - 1, 0)) % MOD;
}
ans %= MOD;
dp[l][r] = ans;
return ans * doublefac(max(avi[l - 1] + avi[N * 2] - avi[r] - 1, 0)) % MOD;
}
int main() {
memset(dp, 0, sizeof(dp));
cin >> N >> K;
con.resize(N * 2 + 1);
facInit(N * 3);
avi[0] = 0;
FOR(i, 1, N * 2 + 1) avi[i] = 1;
REP(i, 2 * N + 1) REP(j, 2 * N + 1) {
leftmost[i][j] = i;
rightmost[i][j] = j;
}
REP(_, K) {
int A, B;
cin >> A >> B;
con[A] = B;
con[B] = A;
avi[A] = avi[B] = 0;
if (B < A)
swap(A, B);
FOR(i, 1, A + 1)
FOR(j, A, 2 * N + 1) leftmost[i][j] = min(leftmost[i][j], B),
rightmost[i][j] = max(rightmost[i][j], B);
FOR(i, 1, B + 1)
FOR(j, B, 2 * N + 1) leftmost[i][j] = min(leftmost[i][j], A),
rightmost[i][j] = max(rightmost[i][j], A);
}
REP(i, N * 2) avi[i + 1] += avi[i];
lint ans = 0;
FOR(l, 1, 2 * N) FOR(r, l + 1, 2 * N + 1) ans = (ans + solve(l, r)) % MOD;
cout << ans << endl;
}
| replace | 102 | 103 | 102 | 104 | TLE | |
p03234 | C++ | Runtime Error | // problem:agc028_d
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
inline int read() {
int f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline ll readll() {
ll f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int MAXN = 305, MOD = 1e9 + 7;
inline int mod(int x) { return x < MOD ? (x < 0 ? x + MOD : x) : x - MOD; }
int n, K, p[MAXN], cnt[MAXN][MAXN], dp[MAXN][MAXN], g[MAXN];
int DP(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
if (l == r)
return dp[l][r] = 0;
if (l + 1 == r)
return dp[l][r] = (p[l] == r || (!p[l] && !p[r])) ? 1 : 0;
if (cnt[l][r] == -1 || cnt[l][r] & 1)
return dp[l][r] = 0;
else
dp[l][r] = g[cnt[l][r]];
for (int i = l + 1; i < r; ++i) {
if (cnt[i + 1][r] != -1)
dp[l][r] = mod(dp[l][r] - (ll)DP(l, i) * g[cnt[i + 1][r]] % MOD);
}
return dp[l][r];
}
int main() {
n = read() * 2;
K = read();
g[0] = 1;
for (int i = 2; i <= n; i += 2)
g[i] = (ll)g[i - 2] * (i - 1) % MOD;
for (int i = 1, a, b; i <= K; ++i)
a = read(), b = read(), p[a] = b, p[b] = a;
for (int l = 1; l <= n; ++l) {
for (int r = l; r <= n; ++r) {
cnt[l][r] = r - l + 1;
for (int i = l; i <= r; ++i) {
if (!p[i])
continue;
if (p[i] < l || p[i] > r) {
cnt[l][r] = -1;
break;
}
cnt[l][r]--;
}
}
}
memset(dp, -1, sizeof(dp));
// int l,r;while(cin>>l>>r)cout<<DP(l,r)<<endl;
int ans = 0;
for (int l = 1; l <= n; ++l) {
for (int r = l; r <= n; ++r) {
int c = n - (r - l + 1), ok = 1;
for (int i = 1; i < l; ++i) {
if (!p[i])
continue;
if (p[i] >= l && p[i] <= r) {
ok = 0;
break;
}
c--;
}
if (!ok)
continue;
for (int i = r + 1; i <= n; ++i) {
if (!p[i])
continue;
if (p[i] >= l && p[i] <= r) {
ok = 0;
break;
}
c--;
}
if (!ok)
continue;
ans = mod(ans + (ll)DP(l, r) * g[c] % MOD);
}
}
cout << ans << endl;
return 0;
} | // problem:agc028_d
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
inline int read() {
int f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline ll readll() {
ll f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-')
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int MAXN = 605, MOD = 1e9 + 7;
inline int mod(int x) { return x < MOD ? (x < 0 ? x + MOD : x) : x - MOD; }
int n, K, p[MAXN], cnt[MAXN][MAXN], dp[MAXN][MAXN], g[MAXN];
int DP(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
if (l == r)
return dp[l][r] = 0;
if (l + 1 == r)
return dp[l][r] = (p[l] == r || (!p[l] && !p[r])) ? 1 : 0;
if (cnt[l][r] == -1 || cnt[l][r] & 1)
return dp[l][r] = 0;
else
dp[l][r] = g[cnt[l][r]];
for (int i = l + 1; i < r; ++i) {
if (cnt[i + 1][r] != -1)
dp[l][r] = mod(dp[l][r] - (ll)DP(l, i) * g[cnt[i + 1][r]] % MOD);
}
return dp[l][r];
}
int main() {
n = read() * 2;
K = read();
g[0] = 1;
for (int i = 2; i <= n; i += 2)
g[i] = (ll)g[i - 2] * (i - 1) % MOD;
for (int i = 1, a, b; i <= K; ++i)
a = read(), b = read(), p[a] = b, p[b] = a;
for (int l = 1; l <= n; ++l) {
for (int r = l; r <= n; ++r) {
cnt[l][r] = r - l + 1;
for (int i = l; i <= r; ++i) {
if (!p[i])
continue;
if (p[i] < l || p[i] > r) {
cnt[l][r] = -1;
break;
}
cnt[l][r]--;
}
}
}
memset(dp, -1, sizeof(dp));
// int l,r;while(cin>>l>>r)cout<<DP(l,r)<<endl;
int ans = 0;
for (int l = 1; l <= n; ++l) {
for (int r = l; r <= n; ++r) {
int c = n - (r - l + 1), ok = 1;
for (int i = 1; i < l; ++i) {
if (!p[i])
continue;
if (p[i] >= l && p[i] <= r) {
ok = 0;
break;
}
c--;
}
if (!ok)
continue;
for (int i = r + 1; i <= n; ++i) {
if (!p[i])
continue;
if (p[i] >= l && p[i] <= r) {
ok = 0;
break;
}
c--;
}
if (!ok)
continue;
ans = mod(ans + (ll)DP(l, r) * g[c] % MOD);
}
}
cout << ans << endl;
return 0;
} | replace | 45 | 46 | 45 | 46 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 305;
const int MOD = 1e9 + 7;
int to[N], sum[N];
ll dp[N][N], g[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
to[u] = v;
to[v] = u;
sum[u]++;
sum[v]++;
}
n *= 2;
g[0] = 1;
for (int i = 1; i <= n; i++)
sum[i] += sum[i - 1];
for (int i = 2; i <= n; i += 2)
g[i] = g[i - 2] * (i - 1) % MOD;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j += 2) {
bool flag = 0;
for (int k = i; k <= j; k++)
if (to[k] && (to[k] < i || to[k] > j))
flag = 1;
if (flag)
continue;
dp[i][j] = g[j - i + 1 - sum[j] + sum[i - 1]];
for (int k = i + 1; k < j; k += 2)
(dp[i][j] -= dp[i][k] * g[j - k - sum[j] + sum[k]]) %= MOD;
}
m *= 2;
ll res = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j += 2)
(res += dp[i][j] * g[n - j + i - 1 - m + sum[j] - sum[i - 1]]) %= MOD;
cout << (res + MOD) % MOD << '\n';
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 605;
const int MOD = 1e9 + 7;
int to[N], sum[N];
ll dp[N][N], g[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
to[u] = v;
to[v] = u;
sum[u]++;
sum[v]++;
}
n *= 2;
g[0] = 1;
for (int i = 1; i <= n; i++)
sum[i] += sum[i - 1];
for (int i = 2; i <= n; i += 2)
g[i] = g[i - 2] * (i - 1) % MOD;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j += 2) {
bool flag = 0;
for (int k = i; k <= j; k++)
if (to[k] && (to[k] < i || to[k] > j))
flag = 1;
if (flag)
continue;
dp[i][j] = g[j - i + 1 - sum[j] + sum[i - 1]];
for (int k = i + 1; k < j; k += 2)
(dp[i][j] -= dp[i][k] * g[j - k - sum[j] + sum[k]]) %= MOD;
}
m *= 2;
ll res = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j += 2)
(res += dp[i][j] * g[n - j + i - 1 - m + sum[j] - sum[i - 1]]) %= MOD;
cout << (res + MOD) % MOD << '\n';
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03234 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#define w(i, j) (c[j] - c[(i)-1])
typedef long long L;
const int N = 3e2 + 23, P = 1e9 + 7;
struct mod_t {
static int norm(int x) { return x + (x >> 31 & P); }
static void norm2(int &x) { x += x >> 31 & P; }
int x;
mod_t() {}
mod_t(int v) : x(v) {}
mod_t(long long v) : x(v) {}
mod_t(char v) : x(v) {}
mod_t operator+(const mod_t &rhs) const { return norm(x + rhs.x - P); }
mod_t operator-(const mod_t &rhs) const { return norm(x - rhs.x); }
mod_t operator*(const mod_t &rhs) const { return (L)x * rhs.x % P; }
void operator+=(const mod_t &rhs) { norm2(x += rhs.x - P); }
void operator-=(const mod_t &rhs) { norm2(x -= rhs.x); }
void operator*=(const mod_t &rhs) { x = (L)x * rhs.x % P; }
};
mod_t f[N][N], g[N], ans;
int p[N], c[N];
int n, k;
int h(int l, int r) { return (r - l + 1) - w(l, r); }
int main() {
scanf("%d%d", &n, &k);
for (int i = 1, x, y; i <= k; i++) {
scanf("%d%d", &x, &y);
x[p] = y, y[p] = x, x[c] = y[c] = 1;
}
g[0] = g[1] = 1;
for (int i = 2; i <= 2 * n; i++)
g[i] = g[i - 2] * (i - 1);
for (int i = 1; i <= 2 * n; i++)
c[i] += c[i - 1];
for (int l = 1; l <= 2 * n; l++)
for (int r = l + 1; r <= 2 * n; r++)
if ((l ^ r) & 1) {
for (int x = l; x <= r; x++)
if (x[p] && (x[p] < l || x[p] > r))
goto end;
f[l][r] = g[h(l, r)];
for (int x = l + 1; x < r; x++)
f[l][r] -= f[l][x] * g[h(x + 1, r)];
ans += f[l][r] * g[(n << 1) - (r - l + 1) - ((k << 1) - w(l, r))];
end:;
}
printf("%d", ans.x);
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#define w(i, j) (c[j] - c[(i)-1])
typedef long long L;
const int N = 6e2 + 26, P = 1e9 + 7;
struct mod_t {
static int norm(int x) { return x + (x >> 31 & P); }
static void norm2(int &x) { x += x >> 31 & P; }
int x;
mod_t() {}
mod_t(int v) : x(v) {}
mod_t(long long v) : x(v) {}
mod_t(char v) : x(v) {}
mod_t operator+(const mod_t &rhs) const { return norm(x + rhs.x - P); }
mod_t operator-(const mod_t &rhs) const { return norm(x - rhs.x); }
mod_t operator*(const mod_t &rhs) const { return (L)x * rhs.x % P; }
void operator+=(const mod_t &rhs) { norm2(x += rhs.x - P); }
void operator-=(const mod_t &rhs) { norm2(x -= rhs.x); }
void operator*=(const mod_t &rhs) { x = (L)x * rhs.x % P; }
};
mod_t f[N][N], g[N], ans;
int p[N], c[N];
int n, k;
int h(int l, int r) { return (r - l + 1) - w(l, r); }
int main() {
scanf("%d%d", &n, &k);
for (int i = 1, x, y; i <= k; i++) {
scanf("%d%d", &x, &y);
x[p] = y, y[p] = x, x[c] = y[c] = 1;
}
g[0] = g[1] = 1;
for (int i = 2; i <= 2 * n; i++)
g[i] = g[i - 2] * (i - 1);
for (int i = 1; i <= 2 * n; i++)
c[i] += c[i - 1];
for (int l = 1; l <= 2 * n; l++)
for (int r = l + 1; r <= 2 * n; r++)
if ((l ^ r) & 1) {
for (int x = l; x <= r; x++)
if (x[p] && (x[p] < l || x[p] > r))
goto end;
f[l][r] = g[h(l, r)];
for (int x = l + 1; x < r; x++)
f[l][r] -= f[l][x] * g[h(x + 1, r)];
ans += f[l][r] * g[(n << 1) - (r - l + 1) - ((k << 1) - w(l, r))];
end:;
}
printf("%d", ans.x);
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03234 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define LL long long
#define fgx cerr << "--------------" << endl;
#define dgx cerr << "==============" << endl;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 100010;
const int INF = 2147483600;
const LL Mod = 1000000007;
int N, K;
int a[MAXN + 1], b[MAXN + 1];
int sum[MAXN + 1];
LL f[310][310];
LL g[MAXN + 1];
inline int S(int l, int r) { return sum[r] - sum[l - 1]; }
inline bool In(int x, int l, int r) { return x >= l && x <= r; }
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
N = read() * 2, K = read();
for (int i = 1; i <= K; i++) {
a[i] = read(), b[i] = read();
sum[a[i]] = sum[b[i]] = 1;
}
LL ans = 0;
g[0] = 1;
for (int i = 1; i <= N; i++) {
if (i & 1)
g[i] = 0;
else
g[i] = g[i - 2] * (i - 1) % Mod;
}
for (int i = 1; i <= N; i++)
sum[i] += sum[i - 1];
for (int len = 1; len <= N; len++) {
if (len & 1)
continue;
for (int i = 1; i + len - 1 <= N; i++) {
int j = i + len - 1;
bool flag = 0;
for (int k = 1; k <= K; k++) {
if (In(a[k], i, j) && !In(b[k], i, j)) {
flag = 1;
break;
}
if (!In(a[k], i, j) && In(b[k], i, j)) {
flag = 1;
break;
}
}
if (flag) {
f[i][j] = 0;
continue;
}
f[i][j] = g[len - S(i, j)];
for (int k = i; k < j; k++)
f[i][j] =
(f[i][j] - g[j - k - S(k + 1, j)] * f[i][k] % Mod + Mod) % Mod;
(ans += f[i][j] * g[N - len - 2 * K + S(i, j)] % Mod) %= Mod;
}
}
printf("%lld\n", ans);
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define LL long long
#define fgx cerr << "--------------" << endl;
#define dgx cerr << "==============" << endl;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 100010;
const int INF = 2147483600;
const LL Mod = 1000000007;
int N, K;
int a[MAXN + 1], b[MAXN + 1];
int sum[MAXN + 1];
LL f[610][610];
LL g[MAXN + 1];
inline int S(int l, int r) { return sum[r] - sum[l - 1]; }
inline bool In(int x, int l, int r) { return x >= l && x <= r; }
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
N = read() * 2, K = read();
for (int i = 1; i <= K; i++) {
a[i] = read(), b[i] = read();
sum[a[i]] = sum[b[i]] = 1;
}
LL ans = 0;
g[0] = 1;
for (int i = 1; i <= N; i++) {
if (i & 1)
g[i] = 0;
else
g[i] = g[i - 2] * (i - 1) % Mod;
}
for (int i = 1; i <= N; i++)
sum[i] += sum[i - 1];
for (int len = 1; len <= N; len++) {
if (len & 1)
continue;
for (int i = 1; i + len - 1 <= N; i++) {
int j = i + len - 1;
bool flag = 0;
for (int k = 1; k <= K; k++) {
if (In(a[k], i, j) && !In(b[k], i, j)) {
flag = 1;
break;
}
if (!In(a[k], i, j) && In(b[k], i, j)) {
flag = 1;
break;
}
}
if (flag) {
f[i][j] = 0;
continue;
}
f[i][j] = g[len - S(i, j)];
for (int k = i; k < j; k++)
f[i][j] =
(f[i][j] - g[j - k - S(k + 1, j)] * f[i][k] % Mod + Mod) % Mod;
(ans += f[i][j] * g[N - len - 2 * K + S(i, j)] % Mod) %= Mod;
}
}
printf("%lld\n", ans);
return 0;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mod 1000000007
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 f[310], s[310], R[310], lnk[310], F[310][310];
int main() {
#ifdef XZZSB
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
int n = gi() * 2, k = gi(), A, B;
for (int i = 1; i <= n; ++i)
s[i] = 1;
while (k--) {
A = gi(), B = gi();
if (A > B)
std::swap(A, B);
s[A] = s[B] = 0;
R[A] = B;
lnk[A] = B, lnk[B] = A;
}
for (int i = 1; i <= n; ++i)
s[i] += s[i - 1];
int ans = 0;
f[0] = 1;
for (int i = 2; i <= n; i += 2)
f[i] = 1ll * f[i - 2] * (i - 1) % mod;
for (int sz = 2; sz <= n; ++sz) {
for (int l = 1, r = sz; r <= n; ++l, ++r) {
if (R[l] && R[l] > r)
continue;
bool flg = 0;
for (int i = l; i <= r; ++i)
if (lnk[i] && (lnk[i] < l || lnk[i] > r)) {
flg = 1;
break;
}
if (flg)
continue;
F[l][r] = f[s[r] - s[l - 1]];
for (int i = R[l]; i < r; ++i)
F[l][r] = (F[l][r] - 1ll * F[l][i] * f[s[r] - s[i]] % mod + mod) % mod;
ans = (ans + 1ll * F[l][r] * f[s[n] - s[r] + s[l - 1]]) % mod;
}
}
printf("%d\n", ans);
return 0;
}
| #include <bits/stdc++.h>
#define mod 1000000007
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 f[610], s[610], R[610], lnk[610], F[610][610];
int main() {
#ifdef XZZSB
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
int n = gi() * 2, k = gi(), A, B;
for (int i = 1; i <= n; ++i)
s[i] = 1;
while (k--) {
A = gi(), B = gi();
if (A > B)
std::swap(A, B);
s[A] = s[B] = 0;
R[A] = B;
lnk[A] = B, lnk[B] = A;
}
for (int i = 1; i <= n; ++i)
s[i] += s[i - 1];
int ans = 0;
f[0] = 1;
for (int i = 2; i <= n; i += 2)
f[i] = 1ll * f[i - 2] * (i - 1) % mod;
for (int sz = 2; sz <= n; ++sz) {
for (int l = 1, r = sz; r <= n; ++l, ++r) {
if (R[l] && R[l] > r)
continue;
bool flg = 0;
for (int i = l; i <= r; ++i)
if (lnk[i] && (lnk[i] < l || lnk[i] > r)) {
flg = 1;
break;
}
if (flg)
continue;
F[l][r] = f[s[r] - s[l - 1]];
for (int i = R[l]; i < r; ++i)
F[l][r] = (F[l][r] - 1ll * F[l][i] * f[s[r] - s[i]] % mod + mod) % mod;
ans = (ans + 1ll * F[l][r] * f[s[n] - s[r] + s[l - 1]]) % mod;
}
}
printf("%d\n", ans);
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 4e2, mod = 1e9 + 7;
ll n, m, k, f[maxn][maxn], g[maxn] = {1}, match[maxn], vis[maxn], pre[maxn],
ans, u, v;
signed main() {
scanf("%lld%lld", &n, &m), n <<= 1;
for (ll i = 1; i <= m; ++i) {
scanf("%lld%lld", &u, &v);
vis[match[u] = v] = vis[match[v] = u] = 1;
}
for (ll i = 1; i <= n; ++i)
pre[i] = pre[i - 1] + (!vis[i]);
for (ll i = 2; i <= n; i += 2)
g[i] = g[i - 2] * (i - 1) % mod;
for (ll i = 2; i <= n; i += 2)
for (ll l = 1; l <= n - i + 1; ++l) {
ll r = l + i - 1;
for (ll j = l; j <= r; ++j)
if (match[j] && (match[j] < l || match[j] > r))
goto end;
f[l][r] = g[pre[r] - pre[l - 1]];
for (ll j = l + 1; j < r; j += 2)
(f[l][r] += (mod - f[l][j] * g[pre[r] - pre[j]] % mod)) %= mod;
(ans += g[(pre[n] - pre[r] + pre[l - 1])] * f[l][r] % mod) %= mod;
end:;
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3, mod = 1e9 + 7;
ll n, m, k, f[maxn][maxn], g[maxn] = {1}, match[maxn], vis[maxn], pre[maxn],
ans, u, v;
signed main() {
scanf("%lld%lld", &n, &m), n <<= 1;
for (ll i = 1; i <= m; ++i) {
scanf("%lld%lld", &u, &v);
vis[match[u] = v] = vis[match[v] = u] = 1;
}
for (ll i = 1; i <= n; ++i)
pre[i] = pre[i - 1] + (!vis[i]);
for (ll i = 2; i <= n; i += 2)
g[i] = g[i - 2] * (i - 1) % mod;
for (ll i = 2; i <= n; i += 2)
for (ll l = 1; l <= n - i + 1; ++l) {
ll r = l + i - 1;
for (ll j = l; j <= r; ++j)
if (match[j] && (match[j] < l || match[j] > r))
goto end;
f[l][r] = g[pre[r] - pre[l - 1]];
for (ll j = l + 1; j < r; j += 2)
(f[l][r] += (mod - f[l][j] * g[pre[r] - pre[j]] % mod)) %= mod;
(ans += g[(pre[n] - pre[r] + pre[l - 1])] * f[l][r] % mod) %= mod;
end:;
}
printf("%lld\n", ans);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout << x << '\n', 0;
using namespace std;
const int N = 3e2 + 10, mod = 1e9 + 7;
ll dp[N][N];
ll pd[N][N];
ll t[N][N];
ll nxt[N];
int32_t main() {
ll n, m;
cin >> n >> m;
n *= 2;
for (int i = 1; i <= m; i++) {
ll u, v;
cin >> u >> v;
nxt[u] = v;
nxt[v] = u;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n + 1; j++) {
if ((j - i) % 2 == 1)
continue;
ll p1 = 0;
ll ts = 0;
for (int k = i; k < j; k++) {
if (nxt[k] != 0) {
if (nxt[k] < i || nxt[k] >= j)
p1 = 1;
} else
ts++;
}
if (p1)
continue;
ll ans = 1;
ll z = ts;
z--;
while (z > 0) {
ans *= z;
z -= 2;
ans %= mod;
}
pd[i][j] = ans;
}
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n + 1; j++) {
if ((j - i) % 2 == 1)
continue;
ll p1 = 0;
ll ts = 0;
for (int k = i; k < j; k++) {
if (nxt[k] != 0) {
if (nxt[k] < i && nxt[k] >= j)
p1 = 1;
}
}
if (p1)
continue;
for (int k = 1; k < i; k++)
if (nxt[k] == 0)
ts++;
for (int k = j; k <= n; k++) {
if (nxt[k] == 0)
ts++;
}
ll ans = 1;
ll z = ts;
z--;
while (z > 0) {
ans *= z;
z -= 2;
ans %= mod;
}
t[i][j] = ans;
}
}
for (int i = n - 1; i > 0; i--) {
for (int j = i + 2; j <= n + 1; j += 2) {
ll p1 = 0;
ll ts = 0;
for (int k = i; k < j; k++) {
if (nxt[k] != 0) {
if (nxt[k] < i || nxt[k] >= j)
p1 = 1;
} else
ts++;
}
if (p1)
continue;
dp[i][j] = pd[i][j];
for (int k = i + 1; k < j - 1; k++) {
dp[i][j] -= dp[i][k] * pd[k][j] % mod;
dp[i][j] += mod;
dp[i][j] %= mod;
}
// cout << i << " " << j << " " << dp[i][j] << " " << pd[i][j] << endl;
}
}
ll ans = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
ans += dp[i][j] * t[i][j] % mod;
cout << ans % mod << endl;
}
| #include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout << x << '\n', 0;
using namespace std;
const int N = 6e2 + 10, mod = 1e9 + 7;
ll dp[N][N];
ll pd[N][N];
ll t[N][N];
ll nxt[N];
int32_t main() {
ll n, m;
cin >> n >> m;
n *= 2;
for (int i = 1; i <= m; i++) {
ll u, v;
cin >> u >> v;
nxt[u] = v;
nxt[v] = u;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n + 1; j++) {
if ((j - i) % 2 == 1)
continue;
ll p1 = 0;
ll ts = 0;
for (int k = i; k < j; k++) {
if (nxt[k] != 0) {
if (nxt[k] < i || nxt[k] >= j)
p1 = 1;
} else
ts++;
}
if (p1)
continue;
ll ans = 1;
ll z = ts;
z--;
while (z > 0) {
ans *= z;
z -= 2;
ans %= mod;
}
pd[i][j] = ans;
}
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n + 1; j++) {
if ((j - i) % 2 == 1)
continue;
ll p1 = 0;
ll ts = 0;
for (int k = i; k < j; k++) {
if (nxt[k] != 0) {
if (nxt[k] < i && nxt[k] >= j)
p1 = 1;
}
}
if (p1)
continue;
for (int k = 1; k < i; k++)
if (nxt[k] == 0)
ts++;
for (int k = j; k <= n; k++) {
if (nxt[k] == 0)
ts++;
}
ll ans = 1;
ll z = ts;
z--;
while (z > 0) {
ans *= z;
z -= 2;
ans %= mod;
}
t[i][j] = ans;
}
}
for (int i = n - 1; i > 0; i--) {
for (int j = i + 2; j <= n + 1; j += 2) {
ll p1 = 0;
ll ts = 0;
for (int k = i; k < j; k++) {
if (nxt[k] != 0) {
if (nxt[k] < i || nxt[k] >= j)
p1 = 1;
} else
ts++;
}
if (p1)
continue;
dp[i][j] = pd[i][j];
for (int k = i + 1; k < j - 1; k++) {
dp[i][j] -= dp[i][k] * pd[k][j] % mod;
dp[i][j] += mod;
dp[i][j] %= mod;
}
// cout << i << " " << j << " " << dp[i][j] << " " << pd[i][j] << endl;
}
}
ll ans = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
ans += dp[i][j] * t[i][j] % mod;
cout << ans % mod << endl;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p03234 | C++ | Runtime Error | #include <cstdio>
const int MaxN = 310, mod = 1000000007;
int N, K, to[MaxN], pre[MaxN], f[MaxN * 2][MaxN * 2], fac[MaxN];
int main() {
scanf("%d%d", &N, &K);
for (int i = 0, a, b; i < K; i++)
scanf("%d%d", &a, &b), to[a] = b, to[b] = a;
for (int i = 1; i <= N * 2; i++)
pre[i] = pre[i - 1] + !to[i];
fac[0] = 1;
for (int i = 2; i <= N * 2; i++)
fac[i] = 1ll * (i - 1) * fac[i - 2] % mod;
f[N * 2 + 1][N * 2] = 1;
int ans = 0;
for (int l = N * 2; l; l--) {
int mn = 1 << 30, mx = -1, c = 0;
f[l][l - 1] = 1;
for (int r = l; r <= N * 2; r++) {
if (!to[r])
c++;
else {
if (to[r] < mn)
mn = to[r];
if (to[r] > mx)
mx = to[r];
}
// printf("l=%d r=%d mn=%d mx=%d c=%d\n",l,r,mn,mx,c);
if ((r - l & 1) && mn >= l && mx <= r && c % 2 == 0) {
f[l][r] = fac[c];
for (int m = l, ml = 1 << 30, mr = -1, d = 0; m < r - 1; m++) {
if (!to[m])
d++;
else {
if (to[m] < ml)
ml = to[m];
if (to[m] > mr)
mr = to[m];
}
if ((m - l & 1) && ml >= l && mr <= m && d % 2 == 0)
f[l][r] = (f[l][r] + 1ll * (mod - f[m + 1][r]) * fac[d]) % mod;
}
ans = (ans + 1ll * f[l][r] * fac[pre[N * 2] - c]) % mod;
// printf("f(%d,%d)=%d\n",l,r,f[l][r]);
}
}
}
printf("%d\n", ans);
} | #include <cstdio>
const int MaxN = 310, mod = 1000000007;
int N, K, to[MaxN * 2], pre[MaxN * 2], f[MaxN * 2][MaxN * 2], fac[MaxN * 2];
int main() {
scanf("%d%d", &N, &K);
for (int i = 0, a, b; i < K; i++)
scanf("%d%d", &a, &b), to[a] = b, to[b] = a;
for (int i = 1; i <= N * 2; i++)
pre[i] = pre[i - 1] + !to[i];
fac[0] = 1;
for (int i = 2; i <= N * 2; i++)
fac[i] = 1ll * (i - 1) * fac[i - 2] % mod;
f[N * 2 + 1][N * 2] = 1;
int ans = 0;
for (int l = N * 2; l; l--) {
int mn = 1 << 30, mx = -1, c = 0;
f[l][l - 1] = 1;
for (int r = l; r <= N * 2; r++) {
if (!to[r])
c++;
else {
if (to[r] < mn)
mn = to[r];
if (to[r] > mx)
mx = to[r];
}
// printf("l=%d r=%d mn=%d mx=%d c=%d\n",l,r,mn,mx,c);
if ((r - l & 1) && mn >= l && mx <= r && c % 2 == 0) {
f[l][r] = fac[c];
for (int m = l, ml = 1 << 30, mr = -1, d = 0; m < r - 1; m++) {
if (!to[m])
d++;
else {
if (to[m] < ml)
ml = to[m];
if (to[m] > mr)
mr = to[m];
}
if ((m - l & 1) && ml >= l && mr <= m && d % 2 == 0)
f[l][r] = (f[l][r] + 1ll * (mod - f[m + 1][r]) * fac[d]) % mod;
}
ans = (ans + 1ll * f[l][r] * fac[pre[N * 2] - c]) % mod;
// printf("f(%d,%d)=%d\n",l,r,f[l][r]);
}
}
}
printf("%d\n", ans);
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr << #x << "=" << x << endl
#define fgx cerr << "-------------" << endl
#define N 333
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
int go[N], mx[N][N], mn[N][N], s[N], f[N][N], g[N];
int main() {
int n, k, x, y, ans = 0;
cin >> n >> k;
n *= 2;
for (rint i = 1; i <= k; i++)
scanf("%d%d", &x, &y), go[x] = y, go[y] = x;
for (rint i = 1; i <= n; i++)
s[i] = s[i - 1] + (!go[i]);
for (rint i = 1; i <= n; i++) {
mx[i][i - 1] = 0;
mn[i][i - 1] = 1e9;
for (rint j = i; j <= n; j++) {
mx[i][j] = mx[i][j - 1];
mn[i][j] = mn[i][j - 1];
if (go[j])
mx[i][j] = max(mx[i][j], go[j]), mn[i][j] = min(mn[i][j], go[j]);
}
}
g[0] = 1;
for (rint i = 2; i <= n; i++)
g[i] = (ll)g[i - 2] * (i - 1) % mod;
for (rint i = 2; i <= n; i += 2) {
for (rint l = 1; l + i - 1 <= n; l++) {
int r = l + i - 1;
if (mn[l][r] < l || mx[l][r] > r)
continue;
f[l][r] = g[s[r] - s[l - 1]];
for (rint k = l + 1; k < r; k += 2)
f[l][r] = (f[l][r] - (ll)f[l][k] * g[s[r] - s[k]] % mod + mod) % mod;
(ans += (ll)f[l][r] * g[s[l - 1] + s[n] - s[r]] % mod) %= mod;
}
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr << #x << "=" << x << endl
#define fgx cerr << "-------------" << endl
#define N 666
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
int go[N], mx[N][N], mn[N][N], s[N], f[N][N], g[N];
int main() {
int n, k, x, y, ans = 0;
cin >> n >> k;
n *= 2;
for (rint i = 1; i <= k; i++)
scanf("%d%d", &x, &y), go[x] = y, go[y] = x;
for (rint i = 1; i <= n; i++)
s[i] = s[i - 1] + (!go[i]);
for (rint i = 1; i <= n; i++) {
mx[i][i - 1] = 0;
mn[i][i - 1] = 1e9;
for (rint j = i; j <= n; j++) {
mx[i][j] = mx[i][j - 1];
mn[i][j] = mn[i][j - 1];
if (go[j])
mx[i][j] = max(mx[i][j], go[j]), mn[i][j] = min(mn[i][j], go[j]);
}
}
g[0] = 1;
for (rint i = 2; i <= n; i++)
g[i] = (ll)g[i - 2] * (i - 1) % mod;
for (rint i = 2; i <= n; i += 2) {
for (rint l = 1; l + i - 1 <= n; l++) {
int r = l + i - 1;
if (mn[l][r] < l || mx[l][r] > r)
continue;
f[l][r] = g[s[r] - s[l - 1]];
for (rint k = l + 1; k < r; k += 2)
f[l][r] = (f[l][r] - (ll)f[l][k] * g[s[r] - s[k]] % mod + mod) % mod;
(ans += (ll)f[l][r] * g[s[l - 1] + s[n] - s[r]] % mod) %= mod;
}
}
cout << ans;
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 404, MOD = 1e9 + 7;
namespace {
int Mul(int x, int y) { return 1LL * x * y % MOD; }
int Dec(int x, int y) { return (x -= y) < 0 ? x + MOD : x; }
int Add(int x, int y) { return (x += y) >= MOD ? x - MOD : x; }
int Kissme(int x, int y) {
int c = 1;
while (y) {
if (y & 1)
c = Mul(c, x);
x = Mul(x, x);
y >>= 1;
}
return c;
}
} // namespace
struct Segment {
int u, v;
bool Intersect(const Segment &rhs) const {
return ((rhs.u > u) & (rhs.u < v)) ^ ((rhs.v > u) & (rhs.v < v));
}
} seg[N];
int fa[N], n, K, mi[N], mx[N], G[N], f[N][N], vis[N], Ans, IG[N];
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
void Merge(int x, int y) {
int fx = Find(x), fy = Find(y);
if (fx != fy) {
fa[fx] = fy;
mx[fy] = max(mx[fy], mx[fx]);
mi[fy] = min(mi[fy], mi[fx]);
}
}
int main(void) {
scanf("%d%d", &n, &K);
for (int i = 1; i <= 2 * n; i++)
fa[i] = mx[i] = mi[i] = i;
for (int i = 1; i <= K; i++) {
scanf("%d%d", &seg[i].u, &seg[i].v);
vis[seg[i].u] = vis[seg[i].v] = 1;
if (seg[i].u > seg[i].v)
swap(seg[i].u, seg[i].v);
Merge(seg[i].u, seg[i].v);
for (int j = 1; j < i; j++)
if (seg[i].Intersect(seg[j]))
Merge(seg[i].u, seg[j].u);
}
G[0] = 1;
IG[0] = 1;
for (int i = 2; i <= 2 * n; i += 2) {
G[i] = Mul(G[i - 2], i - 1);
IG[i] = Kissme(G[i], MOD - 2);
}
for (int l = 0; l < 2 * n; l++)
for (int i = 1, j = 1 + l; j <= 2 * n; i++, j++) {
if (mx[Find(i)] > j || mi[Find(i)] < i || mx[Find(j)] > j ||
mi[Find(j)] < i)
continue;
bool flg = 0;
for (int k = 1; k <= K; k++)
if (seg[k].Intersect({i, j}))
flg = 1;
if (flg)
continue;
int X = 0, Y = 0;
for (int k = 1; k < i; k++)
X += !vis[k];
for (int k = j + 1; k <= 2 * n; k++)
X += !vis[k];
for (int k = i; k <= j; k++)
Y += !vis[k];
f[i][j] = Mul(G[X], G[Y]);
// printf("f[%d][%d] = %d\n", i, j, f[i][j]);
for (int k = j - 1, Z = !vis[j]; k > i; Z += !vis[k--])
if (f[i][k]) {
assert(~(X + Z) & 1);
f[i][j] = Dec(f[i][j], Mul(f[i][k], Mul(IG[X + Z], Mul(G[Z], G[X]))));
}
// printf("f[%d][%d] = %d\n", i, j, f[i][j]);
Ans = Add(Ans, f[i][j]);
}
cout << Ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 604, MOD = 1e9 + 7;
namespace {
int Mul(int x, int y) { return 1LL * x * y % MOD; }
int Dec(int x, int y) { return (x -= y) < 0 ? x + MOD : x; }
int Add(int x, int y) { return (x += y) >= MOD ? x - MOD : x; }
int Kissme(int x, int y) {
int c = 1;
while (y) {
if (y & 1)
c = Mul(c, x);
x = Mul(x, x);
y >>= 1;
}
return c;
}
} // namespace
struct Segment {
int u, v;
bool Intersect(const Segment &rhs) const {
return ((rhs.u > u) & (rhs.u < v)) ^ ((rhs.v > u) & (rhs.v < v));
}
} seg[N];
int fa[N], n, K, mi[N], mx[N], G[N], f[N][N], vis[N], Ans, IG[N];
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
void Merge(int x, int y) {
int fx = Find(x), fy = Find(y);
if (fx != fy) {
fa[fx] = fy;
mx[fy] = max(mx[fy], mx[fx]);
mi[fy] = min(mi[fy], mi[fx]);
}
}
int main(void) {
scanf("%d%d", &n, &K);
for (int i = 1; i <= 2 * n; i++)
fa[i] = mx[i] = mi[i] = i;
for (int i = 1; i <= K; i++) {
scanf("%d%d", &seg[i].u, &seg[i].v);
vis[seg[i].u] = vis[seg[i].v] = 1;
if (seg[i].u > seg[i].v)
swap(seg[i].u, seg[i].v);
Merge(seg[i].u, seg[i].v);
for (int j = 1; j < i; j++)
if (seg[i].Intersect(seg[j]))
Merge(seg[i].u, seg[j].u);
}
G[0] = 1;
IG[0] = 1;
for (int i = 2; i <= 2 * n; i += 2) {
G[i] = Mul(G[i - 2], i - 1);
IG[i] = Kissme(G[i], MOD - 2);
}
for (int l = 0; l < 2 * n; l++)
for (int i = 1, j = 1 + l; j <= 2 * n; i++, j++) {
if (mx[Find(i)] > j || mi[Find(i)] < i || mx[Find(j)] > j ||
mi[Find(j)] < i)
continue;
bool flg = 0;
for (int k = 1; k <= K; k++)
if (seg[k].Intersect({i, j}))
flg = 1;
if (flg)
continue;
int X = 0, Y = 0;
for (int k = 1; k < i; k++)
X += !vis[k];
for (int k = j + 1; k <= 2 * n; k++)
X += !vis[k];
for (int k = i; k <= j; k++)
Y += !vis[k];
f[i][j] = Mul(G[X], G[Y]);
// printf("f[%d][%d] = %d\n", i, j, f[i][j]);
for (int k = j - 1, Z = !vis[j]; k > i; Z += !vis[k--])
if (f[i][k]) {
assert(~(X + Z) & 1);
f[i][j] = Dec(f[i][j], Mul(f[i][k], Mul(IG[X + Z], Mul(G[Z], G[X]))));
}
// printf("f[%d][%d] = %d\n", i, j, f[i][j]);
Ans = Add(Ans, f[i][j]);
}
cout << Ans << endl;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
#define N 310
using namespace std;
typedef long long ll;
const int mod = 1000000007;
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 to[N], sum[N], dp[N][N], g[N];
int main() {
int n = rd(), k = rd();
for (int i = 1; i <= k; i++) {
int x = rd(), y = rd();
to[x] = y, to[y] = x;
sum[x]++, sum[y]++;
}
n *= 2;
for (int i = 1; i <= n; i++) {
sum[i] += sum[i - 1];
}
// init_g
g[0] = 1;
for (int i = 2; i <= n; i += 2) {
g[i] = (ll)g[i - 2] * (i - 1) % mod;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j += 2) {
bool flag = false;
for (int k = i; k <= j; k++) {
if (to[k] && (to[k] < i || to[k] > j)) {
flag = true;
break;
}
}
if (flag) {
continue;
}
dp[i][j] = g[j - i + 1 - sum[j] + sum[i - 1]];
for (int l = i + 1; l < j; l += 2) {
dp[i][j] = ((ll)dp[i][j] + mod -
(ll)dp[i][l] * g[j - l - sum[j] + sum[l]] % mod) %
mod;
}
}
}
k <<= 1;
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j += 2) {
ans = (ans + (ll)dp[i][j] *
g[n - (j - i + 1) - (k - (sum[j] - sum[i - 1]))] % mod) %
mod;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define N 1010
using namespace std;
typedef long long ll;
const int mod = 1000000007;
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 to[N], sum[N], dp[N][N], g[N];
int main() {
int n = rd(), k = rd();
for (int i = 1; i <= k; i++) {
int x = rd(), y = rd();
to[x] = y, to[y] = x;
sum[x]++, sum[y]++;
}
n *= 2;
for (int i = 1; i <= n; i++) {
sum[i] += sum[i - 1];
}
// init_g
g[0] = 1;
for (int i = 2; i <= n; i += 2) {
g[i] = (ll)g[i - 2] * (i - 1) % mod;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j += 2) {
bool flag = false;
for (int k = i; k <= j; k++) {
if (to[k] && (to[k] < i || to[k] > j)) {
flag = true;
break;
}
}
if (flag) {
continue;
}
dp[i][j] = g[j - i + 1 - sum[j] + sum[i - 1]];
for (int l = i + 1; l < j; l += 2) {
dp[i][j] = ((ll)dp[i][j] + mod -
(ll)dp[i][l] * g[j - l - sum[j] + sum[l]] % mod) %
mod;
}
}
}
k <<= 1;
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j += 2) {
ans = (ans + (ll)dp[i][j] *
g[n - (j - i + 1) - (k - (sum[j] - sum[i - 1]))] % mod) %
mod;
}
}
cout << ans << endl;
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
ll dpL[301][301];
ll dpM[301][301];
ll dpR[301][301];
int main() {
int n, k;
cin >> n >> k;
vector<int> a(k), b(k);
for (int i = 0; i < k; i++)
cin >> a[i] >> b[i], a[i]--, b[i]--;
n = n * 2;
vector<int> c(n, -1);
for (int i = 0; i < k; i++)
c[a[i]] = b[i], c[b[i]] = a[i];
auto circleMax = [&](int from, int x, int y) {
int tmpx = x - from, tmpy = y - from;
if (x < from)
tmpx = x + n - from;
if (y < from)
tmpy = y + n - from;
return tmpx < tmpy ? y : x;
};
vector<ll> res(n);
// cerr<<circleMax(1,0,7)<<endl;
// cerr<<"#DP Start"<<endl;
int half = n / 2;
for (int i = 0; i < n; i++) {
bool b = (c[i] != -1 && c[i] < i);
if (b)
continue;
for (int j = 0; j < n; j++)
for (int k = 0; k <= half; k++)
dpL[j][k] = dpM[j][k] = dpR[j][k] = 0;
dpL[0][0] = 1;
int cmax = i;
for (int j = 0; j + 1 < n; j++) {
int id = (i + j + 1) % n;
if (c[id] == -1) {
for (int k = 0; k + 1 <= half; k++) {
dpL[j + 1][k + 1] += dpL[j][k];
dpM[j + 1][k + 1] += dpM[j][k];
dpR[j + 1][k + 1] += dpR[j][k];
}
for (int k = 1; k <= half; k++) {
dpL[j + 1][k - 1] += dpL[j][k] * k;
dpM[j + 1][k - 1] += dpM[j][k] * k;
dpR[j + 1][k - 1] += dpR[j][k] * k;
}
} else {
cmax = circleMax(i, cmax, c[id]);
for (int k = 0; k <= half; k++) {
dpL[j + 1][k] += dpL[j][k];
dpM[j + 1][k] += dpM[j][k];
dpR[j + 1][k] += dpR[j][k];
}
}
if (c[id] == -1 && c[i] == -1 || c[id] == i) {
for (int k = 0; k <= half; k++)
dpM[j + 1][k] += dpL[j][k];
}
if (i < id && circleMax(i, id, cmax) == id) {
dpR[j + 1][0] += dpM[j + 1][0];
dpM[j + 1][0] = 0;
}
for (int k = 0; k <= half; k++)
dpL[j + 1][k] %= MOD, dpM[j + 1][k] %= MOD, dpR[j + 1][k] %= MOD;
}
res[i] = dpR[n - 1][0];
}
// cerr<<"#DP END"<<endl;
// for(int i=0;i<n;i++){
// cerr<<"$"<<i<<" "<<res[i]<<endl;
// }
cout << accumulate(res.begin(), res.end(), 0LL) % MOD << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
ll dpL[601][601];
ll dpM[601][601];
ll dpR[601][601];
int main() {
int n, k;
cin >> n >> k;
vector<int> a(k), b(k);
for (int i = 0; i < k; i++)
cin >> a[i] >> b[i], a[i]--, b[i]--;
n = n * 2;
vector<int> c(n, -1);
for (int i = 0; i < k; i++)
c[a[i]] = b[i], c[b[i]] = a[i];
auto circleMax = [&](int from, int x, int y) {
int tmpx = x - from, tmpy = y - from;
if (x < from)
tmpx = x + n - from;
if (y < from)
tmpy = y + n - from;
return tmpx < tmpy ? y : x;
};
vector<ll> res(n);
// cerr<<circleMax(1,0,7)<<endl;
// cerr<<"#DP Start"<<endl;
int half = n / 2;
for (int i = 0; i < n; i++) {
bool b = (c[i] != -1 && c[i] < i);
if (b)
continue;
for (int j = 0; j < n; j++)
for (int k = 0; k <= half; k++)
dpL[j][k] = dpM[j][k] = dpR[j][k] = 0;
dpL[0][0] = 1;
int cmax = i;
for (int j = 0; j + 1 < n; j++) {
int id = (i + j + 1) % n;
if (c[id] == -1) {
for (int k = 0; k + 1 <= half; k++) {
dpL[j + 1][k + 1] += dpL[j][k];
dpM[j + 1][k + 1] += dpM[j][k];
dpR[j + 1][k + 1] += dpR[j][k];
}
for (int k = 1; k <= half; k++) {
dpL[j + 1][k - 1] += dpL[j][k] * k;
dpM[j + 1][k - 1] += dpM[j][k] * k;
dpR[j + 1][k - 1] += dpR[j][k] * k;
}
} else {
cmax = circleMax(i, cmax, c[id]);
for (int k = 0; k <= half; k++) {
dpL[j + 1][k] += dpL[j][k];
dpM[j + 1][k] += dpM[j][k];
dpR[j + 1][k] += dpR[j][k];
}
}
if (c[id] == -1 && c[i] == -1 || c[id] == i) {
for (int k = 0; k <= half; k++)
dpM[j + 1][k] += dpL[j][k];
}
if (i < id && circleMax(i, id, cmax) == id) {
dpR[j + 1][0] += dpM[j + 1][0];
dpM[j + 1][0] = 0;
}
for (int k = 0; k <= half; k++)
dpL[j + 1][k] %= MOD, dpM[j + 1][k] %= MOD, dpR[j + 1][k] %= MOD;
}
res[i] = dpR[n - 1][0];
}
// cerr<<"#DP END"<<endl;
// for(int i=0;i<n;i++){
// cerr<<"$"<<i<<" "<<res[i]<<endl;
// }
cout << accumulate(res.begin(), res.end(), 0LL) % MOD << endl;
return 0;
} | replace | 6 | 9 | 6 | 9 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;
namespace modular {
const int MOD = 1000000007;
inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
inline int mul(int x, int y) { return 1LL * x * y % MOD; }
inline int qpow(int x, int y) {
int ans = 1;
for (; y; y >>= 1, x = mul(x, x))
if (y & 1)
ans = mul(ans, x);
return ans;
}
}; // namespace modular
using namespace modular;
namespace Base {
template <typename Tp> inline Tp input() {
Tp x = 0, y = 1;
char c = getchar();
while ((c < '0' || '9' < c) && c != EOF) {
if (c == '-')
y = -1;
c = getchar();
}
if (c == EOF)
return 0;
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x *= y;
}
template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); }
template <typename Tp> inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; }
template <typename Tp> inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; }
}; // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/
#define MAX_N 607
int N, M;
int mc[MAX_N], g[MAX_N], f[MAX_N][MAX_N], su[MAX_N][MAX_N];
inline bool check(int l, int r) {
if ((r ^ l ^ 1) & 1)
return false;
rep(i, l, r) if (mc[i] && (mc[i] < l || mc[i] > r)) return false;
return true;
}
void solve() {
read(N), read(M);
N <<= 1;
Rep(i, N) mc[i] = 0;
int x, y;
Rep(i, M) {
read(x), read(y);
mc[mc[y] = x] = y;
}
g[0] = 1;
for (int i = 2; i <= N; i += 2)
g[i] = mul(g[i - 2], i - 1);
Rep(i, N) { rep(j, i, N) su[i][j] = su[i][j - 1] + (mc[j] ? 0 : 1); }
int res = 0;
Rep(i, N) {
rep(j, i, N) if (check(i, j)) {
int &fx = f[i][j];
fx = g[su[i][j]];
lep(k, i + 1, j) { inc(fx, MOD - mul(f[i][k], g[su[k + 1][j]])); }
inc(res, mul(fx, g[su[1][i - 1] + su[j + 1][N]]));
}
}
Rep(i, N) rep(j, i, N) f[i][j] = 0;
printf("%d\n", res);
}
int main() {
int T = input<int>();
while (T--)
solve();
return 0;
}
| #include <bits/stdc++.h>
#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;
namespace modular {
const int MOD = 1000000007;
inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
inline int mul(int x, int y) { return 1LL * x * y % MOD; }
inline int qpow(int x, int y) {
int ans = 1;
for (; y; y >>= 1, x = mul(x, x))
if (y & 1)
ans = mul(ans, x);
return ans;
}
}; // namespace modular
using namespace modular;
namespace Base {
template <typename Tp> inline Tp input() {
Tp x = 0, y = 1;
char c = getchar();
while ((c < '0' || '9' < c) && c != EOF) {
if (c == '-')
y = -1;
c = getchar();
}
if (c == EOF)
return 0;
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x *= y;
}
template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); }
template <typename Tp> inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; }
template <typename Tp> inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; }
}; // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/
#define MAX_N 607
int N, M;
int mc[MAX_N], g[MAX_N], f[MAX_N][MAX_N], su[MAX_N][MAX_N];
inline bool check(int l, int r) {
if ((r ^ l ^ 1) & 1)
return false;
rep(i, l, r) if (mc[i] && (mc[i] < l || mc[i] > r)) return false;
return true;
}
void solve() {
read(N), read(M);
N <<= 1;
Rep(i, N) mc[i] = 0;
int x, y;
Rep(i, M) {
read(x), read(y);
mc[mc[y] = x] = y;
}
g[0] = 1;
for (int i = 2; i <= N; i += 2)
g[i] = mul(g[i - 2], i - 1);
Rep(i, N) { rep(j, i, N) su[i][j] = su[i][j - 1] + (mc[j] ? 0 : 1); }
int res = 0;
Rep(i, N) {
rep(j, i, N) if (check(i, j)) {
int &fx = f[i][j];
fx = g[su[i][j]];
lep(k, i + 1, j) { inc(fx, MOD - mul(f[i][k], g[su[k + 1][j]])); }
inc(res, mul(fx, g[su[1][i - 1] + su[j + 1][N]]));
}
}
Rep(i, N) rep(j, i, N) f[i][j] = 0;
printf("%d\n", res);
}
int main() {
solve();
return 0;
}
| replace | 96 | 99 | 96 | 97 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, st, ed) for (register int i = st, i##end = ed; i <= i##end; ++i)
#define DREP(i, st, ed) for (register int i = st, i##end = ed; i >= i##end; --i)
typedef long long ll;
template <typename T> inline bool chkmin(T &x, T y) {
return (y < x) ? (x = y, 1) : 0;
}
template <typename T> inline bool chkmax(T &x, T y) {
return (y > x) ? (x = y, 1) : 0;
}
inline int read() {
int x;
char c;
int f = 1;
while ((c = getchar()) != '-' && (c > '9' || c < '0'))
;
if (c == '-')
f = -1, c = getchar();
x = c ^ '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ '0');
return x * f;
}
inline ll readll() {
ll x;
char c;
int f = 1;
while ((c = getchar()) != '-' && (c > '9' || c < '0'))
;
if (c == '-')
f = -1, c = getchar();
x = c ^ '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 1ll) + (x << 3ll) + (c ^ '0');
return x * f;
}
const int maxn = 300 + 10, mod = 1e9 + 7;
int n, m, g[maxn], dp[maxn][maxn], a[maxn], b[maxn], sum[maxn], ans;
inline bool check(int l, int r) {
REP(i, 1, m)
if ((l <= a[i] && a[i] <= r) ^ (l <= b[i] && b[i] <= r)) return 0;
return 1;
}
int main() {
n = read() * 2, m = read();
REP(i, 1, n) sum[i] = 1;
REP(i, 1, m) {
a[i] = read(), b[i] = read();
if (a[i] > b[i])
swap(a[i], b[i]);
sum[a[i]] = sum[b[i]] = 0;
}
REP(i, 1, n) sum[i] += sum[i - 1];
g[0] = 1;
REP(i, 2, n) g[i] = (ll)g[i - 2] * (i - 1) % mod;
for (int l = 2; l <= n; l += 2)
REP(i, 1, n - l + 1) {
int j = i + l - 1;
if (!check(i, j))
continue;
dp[i][j] = g[sum[j] - sum[i - 1]];
for (int k = i - 1; k < j; k += 2)
dp[i][j] = (dp[i][j] - (ll)dp[i][k] * g[sum[j] - sum[k]]) % mod;
ans = (ans + (ll)dp[i][j] * g[sum[n] - sum[j] + sum[i - 1]]) % mod;
}
ans = (ans + mod) % mod;
printf("%d\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, st, ed) for (register int i = st, i##end = ed; i <= i##end; ++i)
#define DREP(i, st, ed) for (register int i = st, i##end = ed; i >= i##end; --i)
typedef long long ll;
template <typename T> inline bool chkmin(T &x, T y) {
return (y < x) ? (x = y, 1) : 0;
}
template <typename T> inline bool chkmax(T &x, T y) {
return (y > x) ? (x = y, 1) : 0;
}
inline int read() {
int x;
char c;
int f = 1;
while ((c = getchar()) != '-' && (c > '9' || c < '0'))
;
if (c == '-')
f = -1, c = getchar();
x = c ^ '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ '0');
return x * f;
}
inline ll readll() {
ll x;
char c;
int f = 1;
while ((c = getchar()) != '-' && (c > '9' || c < '0'))
;
if (c == '-')
f = -1, c = getchar();
x = c ^ '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 1ll) + (x << 3ll) + (c ^ '0');
return x * f;
}
const int maxn = 600 + 10, mod = 1e9 + 7;
int n, m, g[maxn], dp[maxn][maxn], a[maxn], b[maxn], sum[maxn], ans;
inline bool check(int l, int r) {
REP(i, 1, m)
if ((l <= a[i] && a[i] <= r) ^ (l <= b[i] && b[i] <= r)) return 0;
return 1;
}
int main() {
n = read() * 2, m = read();
REP(i, 1, n) sum[i] = 1;
REP(i, 1, m) {
a[i] = read(), b[i] = read();
if (a[i] > b[i])
swap(a[i], b[i]);
sum[a[i]] = sum[b[i]] = 0;
}
REP(i, 1, n) sum[i] += sum[i - 1];
g[0] = 1;
REP(i, 2, n) g[i] = (ll)g[i - 2] * (i - 1) % mod;
for (int l = 2; l <= n; l += 2)
REP(i, 1, n - l + 1) {
int j = i + l - 1;
if (!check(i, j))
continue;
dp[i][j] = g[sum[j] - sum[i - 1]];
for (int k = i - 1; k < j; k += 2)
dp[i][j] = (dp[i][j] - (ll)dp[i][k] * g[sum[j] - sum[k]]) % mod;
ans = (ans + (ll)dp[i][j] * g[sum[n] - sum[j] + sum[i - 1]]) % mod;
}
ans = (ans + mod) % mod;
printf("%d\n", ans);
return 0;
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p03234 | C++ | Runtime Error | #include <cstdio>
#include <cstring>
#include <iostream>
#define N 510
#define ll long long
#define mod 1000000007
using namespace std;
int link[N], tot[N][N];
ll f[N][N], h[N << 1];
int main() {
int n, k;
scanf("%d%d", &n, &k);
n <<= 1;
for (int i = 1; i <= k; i++) {
int u, v;
scanf("%d%d", &u, &v);
link[u] = v;
link[v] = u;
}
h[0] = 1, h[1] = 0;
for (int i = 2; i <= n; i += 2)
h[i] = h[i - 2] * (i - 1) % mod;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++)
tot[i][j] = tot[i][j - 1] + (!link[j]);
}
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++) {
bool have = false;
for (int l = i; l <= j; l++)
if (link[l] && (link[l] > j || link[l] < i))
have = true;
if (have)
continue;
f[i][j] = h[tot[i][j]];
for (int l = i + 1; l <= j - 1; l++)
f[i][j] = (f[i][j] - f[i][l] * h[tot[l + 1][j]] % mod + mod) % mod;
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++)
ans = (ans + f[i][j] * h[n - k * 2 - tot[i][j]] % mod) % mod;
}
printf("%lld\n", ans);
return 0;
}
| #include <cstdio>
#include <cstring>
#include <iostream>
#define N 610
#define ll long long
#define mod 1000000007
using namespace std;
int link[N], tot[N][N];
ll f[N][N], h[N << 1];
int main() {
int n, k;
scanf("%d%d", &n, &k);
n <<= 1;
for (int i = 1; i <= k; i++) {
int u, v;
scanf("%d%d", &u, &v);
link[u] = v;
link[v] = u;
}
h[0] = 1, h[1] = 0;
for (int i = 2; i <= n; i += 2)
h[i] = h[i - 2] * (i - 1) % mod;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++)
tot[i][j] = tot[i][j - 1] + (!link[j]);
}
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++) {
bool have = false;
for (int l = i; l <= j; l++)
if (link[l] && (link[l] > j || link[l] < i))
have = true;
if (have)
continue;
f[i][j] = h[tot[i][j]];
for (int l = i + 1; l <= j - 1; l++)
f[i][j] = (f[i][j] - f[i][l] * h[tot[l + 1][j]] % mod + mod) % mod;
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++)
ans = (ans + f[i][j] * h[n - k * 2 - tot[i][j]] % mod) % mod;
}
printf("%lld\n", ans);
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03234 | 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 fi first
#define se 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;
typedef vector<int> vi;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll << 61;
const double pi = acos(-1.0);
const int maxn = 311;
const int mod = 1e9 + 7;
int n, k, a[maxn], b[maxn], match[maxn], ff[maxn];
bool ok[maxn][maxn];
int dp[maxn][maxn], sum[maxn][maxn];
int main() {
ff[0] = 1;
for (int i = 2; i < maxn; i += 2)
ff[i] = (LL)ff[i - 2] * (i - 1) % mod;
get2(n, k);
for (int i = 1; i <= k; i++) {
get2(a[i], b[i]);
match[a[i]] = b[i];
match[b[i]] = a[i];
}
n *= 2;
for (int l = 1; l <= n; l++)
for (int r = l; r <= n; r++) {
ok[l][r] = 1;
for (int i = l; i <= r; i++)
if (match[i] && (match[i] < l || match[i] > r))
ok[l][r] = 0;
else if (!match[i])
sum[l][r]++;
if (sum[l][r] % 2)
ok[l][r] = 0;
}
int ans = 0;
for (int l = n; l >= 1; l--)
for (int r = l; r <= n; r++)
if (ok[l][r]) {
dp[l][r] = ff[sum[l][r]];
for (int i = l; i < r; i++)
dp[l][r] =
(dp[l][r] + (LL)(mod - dp[l][i]) * ff[sum[i + 1][r]]) % mod;
ans = (ans + (LL)dp[l][r] * ff[n - k - k - sum[l][r]]) % mod;
}
printendl(ans);
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 fi first
#define se 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;
typedef vector<int> vi;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll << 61;
const double pi = acos(-1.0);
const int maxn = 611;
const int mod = 1e9 + 7;
int n, k, a[maxn], b[maxn], match[maxn], ff[maxn];
bool ok[maxn][maxn];
int dp[maxn][maxn], sum[maxn][maxn];
int main() {
ff[0] = 1;
for (int i = 2; i < maxn; i += 2)
ff[i] = (LL)ff[i - 2] * (i - 1) % mod;
get2(n, k);
for (int i = 1; i <= k; i++) {
get2(a[i], b[i]);
match[a[i]] = b[i];
match[b[i]] = a[i];
}
n *= 2;
for (int l = 1; l <= n; l++)
for (int r = l; r <= n; r++) {
ok[l][r] = 1;
for (int i = l; i <= r; i++)
if (match[i] && (match[i] < l || match[i] > r))
ok[l][r] = 0;
else if (!match[i])
sum[l][r]++;
if (sum[l][r] % 2)
ok[l][r] = 0;
}
int ans = 0;
for (int l = n; l >= 1; l--)
for (int r = l; r <= n; r++)
if (ok[l][r]) {
dp[l][r] = ff[sum[l][r]];
for (int i = l; i < r; i++)
dp[l][r] =
(dp[l][r] + (LL)(mod - dp[l][i]) * ff[sum[i + 1][r]]) % mod;
ans = (ans + (LL)dp[l][r] * ff[n - k - k - sum[l][r]]) % mod;
}
printendl(ans);
return 0;
} | replace | 46 | 47 | 46 | 47 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
#define M 1000000007
#define maxn 303
using namespace std;
typedef long long ll;
inline ll add(ll a, ll b) { return a + b < M ? a + b : a + b - M; }
inline ll sub(ll a, ll b) { return a - b < 0 ? a - b + M : a - b; }
inline ll mult(ll a, ll b) { return a * b % M; }
int n, k;
int a[maxn], b[maxn];
ll d[maxn][maxn];
int s[maxn][maxn];
ll g[maxn];
int main() {
#define TASK "ABC"
// freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
ios_base::sync_with_stdio(0);
cin >> n >> k;
n *= 2;
for (int i = 0; i < k; ++i) {
int a, b;
cin >> a >> b;
::a[i] = min(a, b);
::b[i] = max(a, b);
s[a][a] = s[b][b] = 1;
}
g[0] = 1;
for (int i = 2; i <= n; i += 2)
g[i] = mult(g[i - 2], i - 1);
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
s[i][j] = s[i][j - 1] + s[j][j];
ll ans = 0;
for (int l = 1; l < n; l += 2)
for (int i = 1; i + l <= n; ++i) {
int j = i + l;
bool flag = 0;
for (int ik = 0; ik < k; ++ik)
if ((i <= a[ik] && a[ik] <= j) ^ (i <= b[ik] && b[ik] <= j))
flag = 1;
if (flag)
continue;
d[i][j] = g[l + 1 - s[i][j]];
for (int ik = i + 1; ik < j; ik += 2)
d[i][j] = sub(d[i][j], mult(d[i][ik], g[j - ik - s[ik + 1][j]]));
ans = add(ans, mult(d[i][j], g[n - 2 * k + s[i][j] - l - 1]));
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
#define M 1000000007
#define maxn 603
using namespace std;
typedef long long ll;
inline ll add(ll a, ll b) { return a + b < M ? a + b : a + b - M; }
inline ll sub(ll a, ll b) { return a - b < 0 ? a - b + M : a - b; }
inline ll mult(ll a, ll b) { return a * b % M; }
int n, k;
int a[maxn], b[maxn];
ll d[maxn][maxn];
int s[maxn][maxn];
ll g[maxn];
int main() {
#define TASK "ABC"
// freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
ios_base::sync_with_stdio(0);
cin >> n >> k;
n *= 2;
for (int i = 0; i < k; ++i) {
int a, b;
cin >> a >> b;
::a[i] = min(a, b);
::b[i] = max(a, b);
s[a][a] = s[b][b] = 1;
}
g[0] = 1;
for (int i = 2; i <= n; i += 2)
g[i] = mult(g[i - 2], i - 1);
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
s[i][j] = s[i][j - 1] + s[j][j];
ll ans = 0;
for (int l = 1; l < n; l += 2)
for (int i = 1; i + l <= n; ++i) {
int j = i + l;
bool flag = 0;
for (int ik = 0; ik < k; ++ik)
if ((i <= a[ik] && a[ik] <= j) ^ (i <= b[ik] && b[ik] <= j))
flag = 1;
if (flag)
continue;
d[i][j] = g[l + 1 - s[i][j]];
for (int ik = i + 1; ik < j; ik += 2)
d[i][j] = sub(d[i][j], mult(d[i][ik], g[j - ik - s[ik + 1][j]]));
ans = add(ans, mult(d[i][j], g[n - 2 * k + s[i][j] - l - 1]));
}
cout << ans;
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mp make_pair
#define fs first
#define sc second
#define pb push_back
#define mod 1000000007
using namespace std;
int n, k;
int match[305];
long long f[305];
long long dp[305][305];
long long dp2[305][305];
long long cnt[305][305];
long long solve(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
if ((r - l) % 2 == 0)
return 0;
long long ans = 0;
cnt[l][r] = r - l + 1;
for (int i = l; i <= r; i++) {
if (match[i] != -1) {
int v = match[i];
if (v >= l && v <= r) {
cnt[l][r]--;
} else {
return dp[l][r] = 0;
}
}
}
// assert(cnt[l][r] % 2 == 0);
ans = f[cnt[l][r]];
return (dp[l][r] = ans);
}
long long solve2(int l, int r) {
if (dp2[l][r] != -1)
return dp2[l][r];
if ((r - l) % 2 == 0)
return 0;
long long ans = solve(l, r);
for (int i = l; i < r; i++) {
long long ini = (solve2(l, i) * solve(i + 1, r)) % mod;
ans = (ans + mod - ini) % mod;
}
return (dp2[l][r] = ans);
}
int main() {
cin >> n >> k;
n *= 2;
int aktif = n - 2 * k;
memset(match, -1, sizeof(match));
for (int i = 1; i <= k; i++) {
int u, v;
cin >> u >> v;
match[u] = v;
match[v] = u;
}
memset(f, 0, sizeof(f));
f[0] = 1;
for (int i = 2; i <= n; i++) {
f[i] = (f[i - 2] * (i - 1)) % mod;
}
memset(dp, -1, sizeof(dp));
memset(dp2, -1, sizeof(dp2));
long long ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if ((j + i) % 2 == 0)
continue;
solve(i, j);
long long x = (solve2(i, j) * f[aktif - cnt[i][j]]) % mod;
ans = (ans + x) % mod;
}
}
cout << ans << "\n";
} | #include <bits/stdc++.h>
#define mp make_pair
#define fs first
#define sc second
#define pb push_back
#define mod 1000000007
using namespace std;
int n, k;
int match[610];
long long f[610];
long long dp[610][610];
long long dp2[610][610];
long long cnt[610][610];
long long solve(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
if ((r - l) % 2 == 0)
return 0;
long long ans = 0;
cnt[l][r] = r - l + 1;
for (int i = l; i <= r; i++) {
if (match[i] != -1) {
int v = match[i];
if (v >= l && v <= r) {
cnt[l][r]--;
} else {
return dp[l][r] = 0;
}
}
}
// assert(cnt[l][r] % 2 == 0);
ans = f[cnt[l][r]];
return (dp[l][r] = ans);
}
long long solve2(int l, int r) {
if (dp2[l][r] != -1)
return dp2[l][r];
if ((r - l) % 2 == 0)
return 0;
long long ans = solve(l, r);
for (int i = l; i < r; i++) {
long long ini = (solve2(l, i) * solve(i + 1, r)) % mod;
ans = (ans + mod - ini) % mod;
}
return (dp2[l][r] = ans);
}
int main() {
cin >> n >> k;
n *= 2;
int aktif = n - 2 * k;
memset(match, -1, sizeof(match));
for (int i = 1; i <= k; i++) {
int u, v;
cin >> u >> v;
match[u] = v;
match[v] = u;
}
memset(f, 0, sizeof(f));
f[0] = 1;
for (int i = 2; i <= n; i++) {
f[i] = (f[i - 2] * (i - 1)) % mod;
}
memset(dp, -1, sizeof(dp));
memset(dp2, -1, sizeof(dp2));
long long ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if ((j + i) % 2 == 0)
continue;
solve(i, j);
long long x = (solve2(i, j) * f[aktif - cnt[i][j]]) % mod;
ans = (ans + x) % mod;
}
}
cout << ans << "\n";
} | replace | 9 | 14 | 9 | 14 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int Maxn = 305, mod = 1e9 + 7;
int p[Maxn], g[Maxn], f[Maxn][Maxn], cnt[Maxn][Maxn];
int main() {
int n, k, ans = 0;
cin >> n >> k;
g[0] = 1;
for (int i = 2; i <= 2 * n; i += 2)
g[i] = 1ll * g[i - 2] * (i - 1) % mod;
for (int i = 1; i <= k; i++) {
int x, y;
cin >> x >> y;
p[x] = y;
p[y] = x;
}
for (int i = 1; i <= 2 * n; i++)
for (int j = i; j <= 2 * n; j++)
cnt[i][j] = cnt[i][j - 1] + (!p[j]);
for (int len = 1; len <= 2 * n; len++)
for (int l = 1, r = len; r <= 2 * n; l++, r++) {
bool succ = true;
for (int k = l; k <= r; k++)
if (p[k] && (p[k] < l || p[k] > r))
succ = false;
if (!succ)
continue;
f[l][r] = g[cnt[l][r]];
for (int k = l + 1; k < r; k++)
f[l][r] = (f[l][r] - 1ll * f[l][k] * g[cnt[k + 1][r]]) % mod;
ans = (ans + 1ll * f[l][r] * g[cnt[1][l - 1] + cnt[r + 1][2 * n]]) % mod;
}
cout << (ans + mod) % mod << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int Maxn = 605, mod = 1e9 + 7;
int p[Maxn], g[Maxn], f[Maxn][Maxn], cnt[Maxn][Maxn];
int main() {
int n, k, ans = 0;
cin >> n >> k;
g[0] = 1;
for (int i = 2; i <= 2 * n; i += 2)
g[i] = 1ll * g[i - 2] * (i - 1) % mod;
for (int i = 1; i <= k; i++) {
int x, y;
cin >> x >> y;
p[x] = y;
p[y] = x;
}
for (int i = 1; i <= 2 * n; i++)
for (int j = i; j <= 2 * n; j++)
cnt[i][j] = cnt[i][j - 1] + (!p[j]);
for (int len = 1; len <= 2 * n; len++)
for (int l = 1, r = len; r <= 2 * n; l++, r++) {
bool succ = true;
for (int k = l; k <= r; k++)
if (p[k] && (p[k] < l || p[k] > r))
succ = false;
if (!succ)
continue;
f[l][r] = g[cnt[l][r]];
for (int k = l + 1; k < r; k++)
f[l][r] = (f[l][r] - 1ll * f[l][k] * g[cnt[k + 1][r]]) % mod;
ans = (ans + 1ll * f[l][r] * g[cnt[1][l - 1] + cnt[r + 1][2 * n]]) % mod;
}
cout << (ans + mod) % mod << "\n";
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03234 | C++ | Time Limit Exceeded | /********************************************************************************
Code by a weak man who named CYJian, and he hopes the code can get more
scores.
Algorithm:
********************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//{{{ FAST IO
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;
#define ge \
(iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), \
(iS == iT ? EOF : *iS++)) \
: *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
template <typename T> inline void read(T &x) {
char ch, t = 0;
x = 0;
while (!isdigit(ch = ge))
t |= ch == '-';
while (isdigit(ch))
x = x * 10 + (ch ^ 48), ch = ge;
x = t ? -x : x;
}
inline int read_int() {
int x;
return read(x), x;
}
inline ll read_ll() {
ll x;
return read(x), x;
}
template <typename T> inline void chkmin(T &a, T b) { a = a < b ? a : b; }
template <typename T> inline void chkmax(T &a, T b) { a = a > b ? a : b; }
//}}}
const int mod = 1e9 + 7;
inline int Mod(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }
inline int fsp(int x, int k = mod - 2) {
int s = 1;
while (k) {
if (k & 1)
s = 1LL * s * x % mod;
x = 1LL * x * x % mod, k >>= 1;
}
return s;
}
int F[610];
int pw[610];
int fac[610];
int ifac[610];
int to[610];
int cnt[610];
int f[610][610];
int main() {
#ifndef ONLINE_JUDGE
FILE("count");
#endif
fac[0] = pw[0] = 1;
for (int i = 1; i <= 600; i++)
fac[i] = 1LL * fac[i - 1] * i % mod;
ifac[600] = fsp(fac[600]);
for (int i = 600; i >= 1; i--)
ifac[i - 1] = 1LL * ifac[i] * i % mod;
int iv = fsp(2);
for (int i = 1; i <= 600; i++)
pw[i] = 1LL * pw[i - 1] * iv % mod;
for (int i = 0; i <= 600; i += 2)
F[i] = 1LL * fac[i] * ifac[i >> 1] % mod * pw[i >> 1] % mod;
int Case = 1;
while (Case--) {
int n = ri, m = ri;
for (int i = 1; i <= m; i++) {
int u = ri, v = ri;
to[u] = v, to[v] = u;
}
n <<= 1;
for (int i = 1; i <= n; i++)
cnt[i] = cnt[i - 1] + (!to[i]);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j += 2) {
int flag = 0;
for (int k = i; k <= j && !flag; k++)
flag |= to[k] && (to[k] < i || to[k] > j);
if (flag)
continue;
int &G = f[i][j] = F[cnt[j] - cnt[i - 1]];
for (int k = i + 1; k < j; k++)
G = (G + 1LL * (mod - f[i][k]) * F[cnt[j] - cnt[k]]) % mod;
}
int res = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j += 2)
res = (res + 1LL * F[cnt[n] - cnt[j] + cnt[i - 1]] * f[i][j]) % mod;
cout << res << endl;
for (int i = 1; i <= n; i++)
to[i] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
f[i][j] = 0;
}
return 0;
} | /********************************************************************************
Code by a weak man who named CYJian, and he hopes the code can get more
scores.
Algorithm:
********************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//{{{ FAST IO
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;
#define ge \
(iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), \
(iS == iT ? EOF : *iS++)) \
: *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
template <typename T> inline void read(T &x) {
char ch, t = 0;
x = 0;
while (!isdigit(ch = ge))
t |= ch == '-';
while (isdigit(ch))
x = x * 10 + (ch ^ 48), ch = ge;
x = t ? -x : x;
}
inline int read_int() {
int x;
return read(x), x;
}
inline ll read_ll() {
ll x;
return read(x), x;
}
template <typename T> inline void chkmin(T &a, T b) { a = a < b ? a : b; }
template <typename T> inline void chkmax(T &a, T b) { a = a > b ? a : b; }
//}}}
const int mod = 1e9 + 7;
inline int Mod(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }
inline int fsp(int x, int k = mod - 2) {
int s = 1;
while (k) {
if (k & 1)
s = 1LL * s * x % mod;
x = 1LL * x * x % mod, k >>= 1;
}
return s;
}
int F[610];
int pw[610];
int fac[610];
int ifac[610];
int to[610];
int cnt[610];
int f[610][610];
int main() {
fac[0] = pw[0] = 1;
for (int i = 1; i <= 600; i++)
fac[i] = 1LL * fac[i - 1] * i % mod;
ifac[600] = fsp(fac[600]);
for (int i = 600; i >= 1; i--)
ifac[i - 1] = 1LL * ifac[i] * i % mod;
int iv = fsp(2);
for (int i = 1; i <= 600; i++)
pw[i] = 1LL * pw[i - 1] * iv % mod;
for (int i = 0; i <= 600; i += 2)
F[i] = 1LL * fac[i] * ifac[i >> 1] % mod * pw[i >> 1] % mod;
int Case = 1;
while (Case--) {
int n = ri, m = ri;
for (int i = 1; i <= m; i++) {
int u = ri, v = ri;
to[u] = v, to[v] = u;
}
n <<= 1;
for (int i = 1; i <= n; i++)
cnt[i] = cnt[i - 1] + (!to[i]);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j += 2) {
int flag = 0;
for (int k = i; k <= j && !flag; k++)
flag |= to[k] && (to[k] < i || to[k] > j);
if (flag)
continue;
int &G = f[i][j] = F[cnt[j] - cnt[i - 1]];
for (int k = i + 1; k < j; k++)
G = (G + 1LL * (mod - f[i][k]) * F[cnt[j] - cnt[k]]) % mod;
}
int res = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j += 2)
res = (res + 1LL * F[cnt[n] - cnt[j] + cnt[i - 1]] * f[i][j]) % mod;
cout << res << endl;
for (int i = 1; i <= n; i++)
to[i] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
f[i][j] = 0;
}
return 0;
} | delete | 73 | 77 | 73 | 73 | TLE | |
p03234 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long LL;
using namespace std;
const int maxn = 310, mod = 1e9 + 7;
int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-')
f = 0;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f ? x : -x;
}
int g[maxn], cnt[maxn][maxn], dp[maxn][maxn], a[maxn];
int main() {
int n = read() * 2, K = read();
for (int i = 1; i <= K; ++i) {
int x = read(), y = read();
a[x] = y;
a[y] = x;
}
g[0] = 1;
for (int i = 2; i <= n; i += 2)
g[i] = (LL)g[i - 2] * (i - 1) % mod;
for (int i = 1; i <= n; ++i)
for (int j = i; j <= n; ++j)
cnt[i][j] = cnt[i][j - 1] + (a[j] ? 0 : 1);
int ans = 0;
for (int i = 1; i <= n; ++i)
for (int j = i; j <= n; ++j) {
if ((j - i + 1) & 1)
continue;
for (int k = i; k <= j; ++k)
if (a[k] && (a[k] < i || a[k] > j))
goto nxt;
dp[i][j] = g[cnt[i][j]];
for (int k = i; k < j; ++k)
(dp[i][j] -= (LL)dp[i][k] * g[cnt[k + 1][j]] % mod) %= mod;
(ans += (LL)dp[i][j] * g[cnt[1][i - 1] + cnt[j + 1][n]] % mod) %= mod;
nxt:;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
typedef long long LL;
using namespace std;
const int maxn = 610, mod = 1e9 + 7;
int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-')
f = 0;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f ? x : -x;
}
int g[maxn], cnt[maxn][maxn], dp[maxn][maxn], a[maxn];
int main() {
int n = read() * 2, K = read();
for (int i = 1; i <= K; ++i) {
int x = read(), y = read();
a[x] = y;
a[y] = x;
}
g[0] = 1;
for (int i = 2; i <= n; i += 2)
g[i] = (LL)g[i - 2] * (i - 1) % mod;
for (int i = 1; i <= n; ++i)
for (int j = i; j <= n; ++j)
cnt[i][j] = cnt[i][j - 1] + (a[j] ? 0 : 1);
int ans = 0;
for (int i = 1; i <= n; ++i)
for (int j = i; j <= n; ++j) {
if ((j - i + 1) & 1)
continue;
for (int k = i; k <= j; ++k)
if (a[k] && (a[k] < i || a[k] > j))
goto nxt;
dp[i][j] = g[cnt[i][j]];
for (int k = i; k < j; ++k)
(dp[i][j] -= (LL)dp[i][k] * g[cnt[k + 1][j]] % mod) %= mod;
(ans += (LL)dp[i][j] * g[cnt[1][i - 1] + cnt[j + 1][n]] % mod) %= mod;
nxt:;
}
cout << ans << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p03234 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, x, y) for (int i = (x); i <= (y); i++)
#define ll long long
using namespace std;
const int N = 305, mod = 1e9 + 7;
int n, m, a, b, f[N][N], cnt[N][N], p[N], g[N], ans;
void upd(int &x, int y) {
x += y;
x -= x >= mod ? mod : 0;
}
int main() {
scanf("%d%d", &n, &m);
n *= 2;
rep(i, 1, m) scanf("%d%d", &a, &b), p[a] = b, p[b] = a;
rep(i, 1, n) rep(j, i, n) cnt[i][j] =
cnt[i][j - 1] + (!p[j]); // i~j中未连过的点数
g[0] = 1;
rep(i, 1, n) if (!(i & 1)) g[i] =
(ll)g[i - 2] * (i - 1) %
mod; // 两个点可以自成一个匹配或拆散i-2个点中的一个匹配,i-2+1
rep(i, 1, n) rep(j, i, n) {
bool flag = 1;
rep(k, i, j) if (p[k] && (p[k] > j || p[k] < i)) flag = 0; // 不能连到外面
if (!flag)
continue;
f[i][j] = g[cnt[i][j]]; // 容斥
rep(k, i + 1, j - 1)
upd(f[i][j], mod - (ll)f[i][k] * g[cnt[k + 1][j]] % mod);
}
rep(i, 1, n) rep(j, 1, n)
upd(ans, (ll)f[i][j] * g[n - 2 * m - cnt[i][j]] % mod);
printf("%d\n", ans);
return 0;
}
// 果然很神啊……我好菜 | #include <bits/stdc++.h>
#define rep(i, x, y) for (int i = (x); i <= (y); i++)
#define ll long long
using namespace std;
const int N = 605, mod = 1e9 + 7;
int n, m, a, b, f[N][N], cnt[N][N], p[N], g[N], ans;
void upd(int &x, int y) {
x += y;
x -= x >= mod ? mod : 0;
}
int main() {
scanf("%d%d", &n, &m);
n *= 2;
rep(i, 1, m) scanf("%d%d", &a, &b), p[a] = b, p[b] = a;
rep(i, 1, n) rep(j, i, n) cnt[i][j] =
cnt[i][j - 1] + (!p[j]); // i~j中未连过的点数
g[0] = 1;
rep(i, 1, n) if (!(i & 1)) g[i] =
(ll)g[i - 2] * (i - 1) %
mod; // 两个点可以自成一个匹配或拆散i-2个点中的一个匹配,i-2+1
rep(i, 1, n) rep(j, i, n) {
bool flag = 1;
rep(k, i, j) if (p[k] && (p[k] > j || p[k] < i)) flag = 0; // 不能连到外面
if (!flag)
continue;
f[i][j] = g[cnt[i][j]]; // 容斥
rep(k, i + 1, j - 1)
upd(f[i][j], mod - (ll)f[i][k] * g[cnt[k + 1][j]] % mod);
}
rep(i, 1, n) rep(j, 1, n)
upd(ans, (ll)f[i][j] * g[n - 2 * m - cnt[i][j]] % mod);
printf("%d\n", ans);
return 0;
}
// 果然很神啊……我好菜 | replace | 4 | 5 | 4 | 5 | 0 | |
p03235 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
int read() {
char ch;
for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
;
int x = ch - '0';
for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
x = x * 10 + ch - '0';
return x;
}
const int N = 2e5 + 5, inf = 0x7fffffff;
struct Segment_Tree {
int mx[N << 2];
void modify(int v, int l, int r, int x, int y) {
if (l == r) {
mx[v] = y;
return;
}
int mid = l + r >> 1;
if (x <= mid)
modify(v << 1, l, mid, x, y);
else
modify(v << 1 | 1, mid + 1, r, x, y);
mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
}
int query(int v, int l, int r, int x, int y) {
if (x > y)
return 0;
if (x <= l && r <= y)
return mx[v];
int mid = l + r >> 1, tmp = -inf;
if (x <= mid)
tmp = max(tmp, query(v << 1, l, mid, x, y));
if (y > mid)
tmp = max(tmp, query(v << 1 | 1, mid + 1, r, x, y));
return tmp;
}
} tr[2];
int n, p[N], cnt[N], mx;
bool chk(int x, int mx0, int c0, int mx1, int c1) {
int v0 = c0 + cnt[x] - c1, v1 = c1 + cnt[x] - c0;
if (v0 >= 0 && tr[v0 & 1].query(1, 1, n, mx1 + 1, n) >= v0)
return 1;
if (v1 >= 0 && tr[v1 & 1].query(1, 1, n, mx0 + 1, n) >= v1)
return 1;
return 0;
}
void print(string s) {
int n = s.length();
fo(i, 0, n - 1) putchar(s[i]);
}
int main() {
freopen("pty.in", "r", stdin);
n = read();
fo(i, 1, n) {
p[i] = read();
if (p[i] > mx)
mx = p[i], cnt[i] = 1;
}
fo(i, 1, n << 2) tr[1].mx[i] = -inf;
fd(i, n, 1) {
int f0 = tr[0].query(1, 1, n, p[i], n);
int f1 = tr[1].query(1, 1, n, p[i], n);
if (cnt[i]) {
tr[0].modify(1, 1, n, p[i], f0 + 2);
tr[1].modify(1, 1, n, p[i], f1 + 2);
} else {
tr[1].modify(1, 1, n, p[i], f0 + 1);
tr[0].modify(1, 1, n, p[i], f1 + 1);
}
}
fd(i, n, 1) cnt[i] += cnt[i + 1];
string s = "";
int mx0 = 0, mx1 = 0, c0 = 0, c1 = 0;
fo(i, 1, n) {
tr[0].modify(1, 1, n, p[i], 0);
tr[1].modify(1, 1, n, p[i], -inf);
if (chk(i + 1, max(mx0, p[i]), c0 + (p[i] > mx0), mx1, c1)) {
c0 += p[i] > mx0;
mx0 = max(mx0, p[i]);
s.push_back('0');
} else {
c1 += p[i] > mx1;
mx1 = max(mx1, p[i]);
s.push_back('1');
}
}
if (c0 == c1)
print(s);
else
puts("-1");
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
int read() {
char ch;
for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
;
int x = ch - '0';
for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
x = x * 10 + ch - '0';
return x;
}
const int N = 2e5 + 5, inf = 0x7fffffff;
struct Segment_Tree {
int mx[N << 2];
void modify(int v, int l, int r, int x, int y) {
if (l == r) {
mx[v] = y;
return;
}
int mid = l + r >> 1;
if (x <= mid)
modify(v << 1, l, mid, x, y);
else
modify(v << 1 | 1, mid + 1, r, x, y);
mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
}
int query(int v, int l, int r, int x, int y) {
if (x > y)
return 0;
if (x <= l && r <= y)
return mx[v];
int mid = l + r >> 1, tmp = -inf;
if (x <= mid)
tmp = max(tmp, query(v << 1, l, mid, x, y));
if (y > mid)
tmp = max(tmp, query(v << 1 | 1, mid + 1, r, x, y));
return tmp;
}
} tr[2];
int n, p[N], cnt[N], mx;
bool chk(int x, int mx0, int c0, int mx1, int c1) {
int v0 = c0 + cnt[x] - c1, v1 = c1 + cnt[x] - c0;
if (v0 >= 0 && tr[v0 & 1].query(1, 1, n, mx1 + 1, n) >= v0)
return 1;
if (v1 >= 0 && tr[v1 & 1].query(1, 1, n, mx0 + 1, n) >= v1)
return 1;
return 0;
}
void print(string s) {
int n = s.length();
fo(i, 0, n - 1) putchar(s[i]);
}
int main() {
n = read();
fo(i, 1, n) {
p[i] = read();
if (p[i] > mx)
mx = p[i], cnt[i] = 1;
}
fo(i, 1, n << 2) tr[1].mx[i] = -inf;
fd(i, n, 1) {
int f0 = tr[0].query(1, 1, n, p[i], n);
int f1 = tr[1].query(1, 1, n, p[i], n);
if (cnt[i]) {
tr[0].modify(1, 1, n, p[i], f0 + 2);
tr[1].modify(1, 1, n, p[i], f1 + 2);
} else {
tr[1].modify(1, 1, n, p[i], f0 + 1);
tr[0].modify(1, 1, n, p[i], f1 + 1);
}
}
fd(i, n, 1) cnt[i] += cnt[i + 1];
string s = "";
int mx0 = 0, mx1 = 0, c0 = 0, c1 = 0;
fo(i, 1, n) {
tr[0].modify(1, 1, n, p[i], 0);
tr[1].modify(1, 1, n, p[i], -inf);
if (chk(i + 1, max(mx0, p[i]), c0 + (p[i] > mx0), mx1, c1)) {
c0 += p[i] > mx0;
mx0 = max(mx0, p[i]);
s.push_back('0');
} else {
c1 += p[i] > mx1;
mx1 = max(mx1, p[i]);
s.push_back('1');
}
}
if (c0 == c1)
print(s);
else
puts("-1");
return 0;
} | delete | 65 | 66 | 65 | 65 | TLE | |
p03235 | C++ | Runtime Error | #include <bits/stdc++.h>
#define il inline
#define vd void
typedef long long ll;
il 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 n, p[200010];
int f[2][200010], ismx[200010];
struct segtree {
#define mid ((l + r) >> 1)
int rt[200010], ls[3000010], rs[3000010], mx[3000010], cnt;
il vd update(int &x, int l, int r, const int &p, const int &d) {
++cnt;
ls[cnt] = ls[x], rs[cnt] = rs[x], mx[cnt] = mx[x];
x = cnt;
if (l == r) {
mx[x] = d;
return;
}
if (d > mx[x])
mx[x] = d;
if (p <= mid)
update(ls[x], l, mid, p, d);
else
update(rs[x], mid + 1, r, p, d);
}
il int query(int x, int l, int r, const int &L) {
if (L <= l)
return mx[x];
if (L <= mid)
return std::max(query(ls[x], l, mid, L), query(rs[x], mid + 1, r, L));
else
return query(rs[x], mid + 1, r, L);
}
#undef mid
} T0, T1;
char ans1[200010], ans2[200010];
il int Query(int c, int l, int p) {
if (l > n)
return c ? -1e9 : 0;
if (!c)
return T0.query(T0.rt[l], 1, n, p);
else
return T1.query(T1.rt[l], 1, n, p);
}
int main() {
#ifdef XZZSB
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
n = gi();
for (int i = 1; i <= n; ++i)
p[i] = gi();
int la1 = 0, lb1 = 0, la2 = 0, lb2 = 0, mxa1 = 0, mxa2 = 0, mxb1 = 0,
mxb2 = 0, rest = 0;
for (int i = 1, mx = 0; i <= n; ++i)
if (p[i] > mx)
mx = p[i], ismx[i] = 1, ++rest;
memset(T1.mx, -63, sizeof T1.mx);
for (int i = n; i; --i) {
T0.rt[i] = T0.rt[i + 1];
T1.rt[i] = T1.rt[i + 1];
if (ismx[i])
f[0][i] = T0.query(T0.rt[i], 1, n, p[i]) + 2,
f[1][i] = T1.query(T1.rt[i], 1, n, p[i]) + 2;
else
f[0][i] = T1.query(T1.rt[i], 1, n, p[i]) + 1,
f[1][i] = T0.query(T0.rt[i], 1, n, p[i]) + 1;
T0.update(T0.rt[i], 1, n, p[i], f[0][i]);
T1.update(T1.rt[i], 1, n, p[i], f[1][i]);
}
auto adda1 = [&](int x) {
if (x > mxa1)
++la1, mxa1 = x;
};
auto adda2 = [&](int x) {
if (x > mxa2)
++la2, mxa2 = x;
};
auto addb1 = [&](int x) {
if (x > mxb1)
++lb1, mxb1 = x;
};
auto addb2 = [&](int x) {
if (x > mxb2)
++lb2, mxb2 = x;
};
for (int i = 1; i <= n; ++i) {
int c = la1 + rest - lb1 + (p[i] > mxa1) - ismx[i];
if (c >= 0 && Query(c & 1, i + 1, mxb1) >= c)
ans1[i] = '0', adda1(p[i]);
else
ans1[i] = '1', addb1(p[i]);
c = la2 + rest - lb2 - (p[i] > mxb2) - ismx[i];
if (c >= 0 && Query(c & 1, i + 1, std::max(p[i], mxb2)) >= c)
ans2[i] = '0', addb2(p[i]);
else
ans2[i] = '1', adda2(p[i]);
if (ismx[i])
--rest;
}
if (la1 == lb1 && la2 == lb2) {
if (strcmp(ans1 + 1, ans2 + 1) < 0)
printf("%s", ans1 + 1);
else
printf("%s", ans2 + 1);
} else if (la1 == lb1)
printf("%s", ans1 + 1);
else if (la2 == lb2)
printf("%s", ans2 + 1);
else
puts("-1");
return 0;
}
| #include <bits/stdc++.h>
#define il inline
#define vd void
typedef long long ll;
il 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 n, p[200010];
int f[2][200010], ismx[200010];
struct segtree {
#define mid ((l + r) >> 1)
int rt[200010], ls[6000010], rs[6000010], mx[6000010], cnt;
il vd update(int &x, int l, int r, const int &p, const int &d) {
++cnt;
ls[cnt] = ls[x], rs[cnt] = rs[x], mx[cnt] = mx[x];
x = cnt;
if (l == r) {
mx[x] = d;
return;
}
if (d > mx[x])
mx[x] = d;
if (p <= mid)
update(ls[x], l, mid, p, d);
else
update(rs[x], mid + 1, r, p, d);
}
il int query(int x, int l, int r, const int &L) {
if (L <= l)
return mx[x];
if (L <= mid)
return std::max(query(ls[x], l, mid, L), query(rs[x], mid + 1, r, L));
else
return query(rs[x], mid + 1, r, L);
}
#undef mid
} T0, T1;
char ans1[200010], ans2[200010];
il int Query(int c, int l, int p) {
if (l > n)
return c ? -1e9 : 0;
if (!c)
return T0.query(T0.rt[l], 1, n, p);
else
return T1.query(T1.rt[l], 1, n, p);
}
int main() {
#ifdef XZZSB
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
n = gi();
for (int i = 1; i <= n; ++i)
p[i] = gi();
int la1 = 0, lb1 = 0, la2 = 0, lb2 = 0, mxa1 = 0, mxa2 = 0, mxb1 = 0,
mxb2 = 0, rest = 0;
for (int i = 1, mx = 0; i <= n; ++i)
if (p[i] > mx)
mx = p[i], ismx[i] = 1, ++rest;
memset(T1.mx, -63, sizeof T1.mx);
for (int i = n; i; --i) {
T0.rt[i] = T0.rt[i + 1];
T1.rt[i] = T1.rt[i + 1];
if (ismx[i])
f[0][i] = T0.query(T0.rt[i], 1, n, p[i]) + 2,
f[1][i] = T1.query(T1.rt[i], 1, n, p[i]) + 2;
else
f[0][i] = T1.query(T1.rt[i], 1, n, p[i]) + 1,
f[1][i] = T0.query(T0.rt[i], 1, n, p[i]) + 1;
T0.update(T0.rt[i], 1, n, p[i], f[0][i]);
T1.update(T1.rt[i], 1, n, p[i], f[1][i]);
}
auto adda1 = [&](int x) {
if (x > mxa1)
++la1, mxa1 = x;
};
auto adda2 = [&](int x) {
if (x > mxa2)
++la2, mxa2 = x;
};
auto addb1 = [&](int x) {
if (x > mxb1)
++lb1, mxb1 = x;
};
auto addb2 = [&](int x) {
if (x > mxb2)
++lb2, mxb2 = x;
};
for (int i = 1; i <= n; ++i) {
int c = la1 + rest - lb1 + (p[i] > mxa1) - ismx[i];
if (c >= 0 && Query(c & 1, i + 1, mxb1) >= c)
ans1[i] = '0', adda1(p[i]);
else
ans1[i] = '1', addb1(p[i]);
c = la2 + rest - lb2 - (p[i] > mxb2) - ismx[i];
if (c >= 0 && Query(c & 1, i + 1, std::max(p[i], mxb2)) >= c)
ans2[i] = '0', addb2(p[i]);
else
ans2[i] = '1', adda2(p[i]);
if (ismx[i])
--rest;
}
if (la1 == lb1 && la2 == lb2) {
if (strcmp(ans1 + 1, ans2 + 1) < 0)
printf("%s", ans1 + 1);
else
printf("%s", ans2 + 1);
} else if (la1 == lb1)
printf("%s", ans1 + 1);
else if (la2 == lb2)
printf("%s", ans2 + 1);
else
puts("-1");
return 0;
}
| replace | 17 | 18 | 17 | 18 | 0 | |
p03235 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 200100;
struct Node {
int mx[2];
Node *lch, *rch;
Node() : mx(), lch(0), rch(0) {}
} node[maxn * 20];
typedef Node *pnode;
int tot = 0;
pnode root[maxn];
void update(pnode r) {
r->mx[0] = max(r->lch->mx[0], r->rch->mx[0]);
r->mx[1] = max(r->lch->mx[1], r->rch->mx[1]);
}
void build(pnode &r, int st, int ed) {
r = &node[++tot];
if (st == ed)
return;
int mid = (st + ed) >> 1;
build(r->lch, st, mid);
build(r->rch, mid + 1, ed);
}
int ask(pnode r, int ll, int rr, int asd, int st, int ed) {
if (ll > rr)
return 0;
if (ll == st && rr == ed)
return r->mx[asd];
int ans = 0;
int mid = (st + ed) >> 1;
if (ll <= mid)
ans = max(ans, ask(r->lch, ll, min(mid, rr), asd, st, mid));
if (mid < rr)
ans = max(ans, ask(r->rch, max(ll, mid + 1), rr, asd, mid + 1, ed));
return ans;
}
void change(pnode &r, pnode nxt, int x, int y, int st, int ed) {
r = &node[++tot];
*r = *nxt;
if (st == ed) {
r->mx[y & 1] = max(r->mx[y & 1], y);
return;
}
int mid = (st + ed) >> 1;
if (x <= mid) {
r->lch = 0;
change(r->lch, nxt->lch, x, y, st, mid);
} else {
r->rch = 0;
change(r->rch, nxt->rch, x, y, mid + 1, ed);
}
update(r);
}
void out(pnode r, int st, int ed) {
cout << st << " " << ed << " " << r->mx[0] << " " << r->mx[1] << endl;
if (st == ed)
return;
int mid = (st + ed) >> 1;
out(r->lch, st, mid);
out(r->rch, mid + 1, ed);
}
int p[maxn], v[maxn], num[maxn];
int n;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
int mx = -1;
num[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> p[i];
if (p[i] > mx) {
v[i] = 2;
mx = p[i];
} else
v[i] = 1;
num[i] = num[i - 1] + v[i] - 1;
}
build(root[n + 1], 1, n);
for (int i = n; i >= 1; i--) {
// cerr << i << " ---------------------- " << endl;
int a = ask(root[i + 1], p[i] + 1, n, 0, 1, n);
int b = ask(root[i + 1], p[i] + 1, n, 1, 1, n);
// cout << a << " " << b << endl;
// cout << a + v[i] << " " << b + v[i] << endl;
change(root[i], root[i + 1], p[i], a + v[i], 1, n);
change(root[i], root[i], p[i], b + v[i], 1, n);
// out(root[i], 1, n);
}
string s = "";
int c1 = 0, c2 = 0, mx1 = 0, mx2 = 0;
// cout << num[n] << endl;
// cout << ask(root[1], mx2 + 1, n, num[n] & 1, 1, n) << " " << ask(root[1],
// mx1 + 1, n, num[n] & 1, 1, n) << endl;
if (ask(root[1], mx2 + 1, n, num[n] & 1, 1, n) < c1 - c2 + num[n] &&
ask(root[1], mx1 + 1, n, num[n] & 1, 1, n) < c2 - c1 + num[n]) {
cout << -1 << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
// cerr << i << " ----------- " << endl;
int a = num[n] - num[i];
int nxt1 = mx1, nxtc = c1;
if (p[i] > mx1) {
mx1 = p[i];
c1++;
}
int asd = (c1 - c2 + a) & 1;
// cout << c1 << " " << mx1 << " " << c2 << " " << mx2 << " " << a << " " <<
// c1 - c2 + a << " " << asd << endl; out(root[i + 1], 1, n); cout <<
// ask(root[i + 1], mx2 + 1, n, asd, 1, n) << " " << ask(root[i + 1], mx1 +
// 1, n, asd, 1, n) << endl;
if ((c1 - c2 + a >= 0 &&
ask(root[i + 1], mx2 + 1, n, asd, 1, n) >= c1 - c2 + a) ||
(c2 - c1 + a >= 0 &&
ask(root[i + 1], mx1 + 1, n, asd, 1, n) >= c2 - c1 + a))
s += '0';
else {
mx1 = nxt1;
c1 = nxtc;
if (p[i] > mx2) {
mx2 = p[i];
c2++;
}
s += '1';
}
}
cout << s << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 200100;
struct Node {
int mx[2];
Node *lch, *rch;
Node() : mx(), lch(0), rch(0) {}
} node[maxn * 41];
typedef Node *pnode;
int tot = 0;
pnode root[maxn];
void update(pnode r) {
r->mx[0] = max(r->lch->mx[0], r->rch->mx[0]);
r->mx[1] = max(r->lch->mx[1], r->rch->mx[1]);
}
void build(pnode &r, int st, int ed) {
r = &node[++tot];
if (st == ed)
return;
int mid = (st + ed) >> 1;
build(r->lch, st, mid);
build(r->rch, mid + 1, ed);
}
int ask(pnode r, int ll, int rr, int asd, int st, int ed) {
if (ll > rr)
return 0;
if (ll == st && rr == ed)
return r->mx[asd];
int ans = 0;
int mid = (st + ed) >> 1;
if (ll <= mid)
ans = max(ans, ask(r->lch, ll, min(mid, rr), asd, st, mid));
if (mid < rr)
ans = max(ans, ask(r->rch, max(ll, mid + 1), rr, asd, mid + 1, ed));
return ans;
}
void change(pnode &r, pnode nxt, int x, int y, int st, int ed) {
r = &node[++tot];
*r = *nxt;
if (st == ed) {
r->mx[y & 1] = max(r->mx[y & 1], y);
return;
}
int mid = (st + ed) >> 1;
if (x <= mid) {
r->lch = 0;
change(r->lch, nxt->lch, x, y, st, mid);
} else {
r->rch = 0;
change(r->rch, nxt->rch, x, y, mid + 1, ed);
}
update(r);
}
void out(pnode r, int st, int ed) {
cout << st << " " << ed << " " << r->mx[0] << " " << r->mx[1] << endl;
if (st == ed)
return;
int mid = (st + ed) >> 1;
out(r->lch, st, mid);
out(r->rch, mid + 1, ed);
}
int p[maxn], v[maxn], num[maxn];
int n;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
int mx = -1;
num[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> p[i];
if (p[i] > mx) {
v[i] = 2;
mx = p[i];
} else
v[i] = 1;
num[i] = num[i - 1] + v[i] - 1;
}
build(root[n + 1], 1, n);
for (int i = n; i >= 1; i--) {
// cerr << i << " ---------------------- " << endl;
int a = ask(root[i + 1], p[i] + 1, n, 0, 1, n);
int b = ask(root[i + 1], p[i] + 1, n, 1, 1, n);
// cout << a << " " << b << endl;
// cout << a + v[i] << " " << b + v[i] << endl;
change(root[i], root[i + 1], p[i], a + v[i], 1, n);
change(root[i], root[i], p[i], b + v[i], 1, n);
// out(root[i], 1, n);
}
string s = "";
int c1 = 0, c2 = 0, mx1 = 0, mx2 = 0;
// cout << num[n] << endl;
// cout << ask(root[1], mx2 + 1, n, num[n] & 1, 1, n) << " " << ask(root[1],
// mx1 + 1, n, num[n] & 1, 1, n) << endl;
if (ask(root[1], mx2 + 1, n, num[n] & 1, 1, n) < c1 - c2 + num[n] &&
ask(root[1], mx1 + 1, n, num[n] & 1, 1, n) < c2 - c1 + num[n]) {
cout << -1 << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
// cerr << i << " ----------- " << endl;
int a = num[n] - num[i];
int nxt1 = mx1, nxtc = c1;
if (p[i] > mx1) {
mx1 = p[i];
c1++;
}
int asd = (c1 - c2 + a) & 1;
// cout << c1 << " " << mx1 << " " << c2 << " " << mx2 << " " << a << " " <<
// c1 - c2 + a << " " << asd << endl; out(root[i + 1], 1, n); cout <<
// ask(root[i + 1], mx2 + 1, n, asd, 1, n) << " " << ask(root[i + 1], mx1 +
// 1, n, asd, 1, n) << endl;
if ((c1 - c2 + a >= 0 &&
ask(root[i + 1], mx2 + 1, n, asd, 1, n) >= c1 - c2 + a) ||
(c2 - c1 + a >= 0 &&
ask(root[i + 1], mx1 + 1, n, asd, 1, n) >= c2 - c1 + a))
s += '0';
else {
mx1 = nxt1;
c1 = nxtc;
if (p[i] > mx2) {
mx2 = p[i];
c2++;
}
s += '1';
}
}
cout << s << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | 127 | /tmp/0dbcc59b-4c12-42ff-93ed-bf440029a0d2.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object
|
p03235 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
namespace io {
const int l = 1 << 20;
char buf[l], *s, *t, c;
inline void gc() {
if (s == t) {
t = (s = buf) + fread(buf, 1, l, stdin);
c = s == t ? EOF : *s++;
} else
c = *s++;
}
template <class IT> inline void gi(IT &x) {
x = 0;
gc();
while (c < '0' || c > '9')
gc();
while ('0' <= c && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ 48);
gc();
}
}
char buf0[20];
int a;
template <class IT> inline void pi(IT x) {
if (x < 0) {
putchar('-');
x = -x;
}
do
buf0[++a] = x % 10 + 48;
while (x /= 10);
while (a)
putchar(buf0[a--]);
putchar('\n');
}
}; // namespace io
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pque priority_queue
#define rep(i, l, r) for (i = (l); i <= (r); ++i)
#define per(i, l, r) for (i = (l); i >= (r); --i)
#define REP(i, l, r) for (i = (l); i < (r); ++i)
#define PER(i, l, r) for (i = (l); i > (r); --i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template <class IT> inline void cmax(IT &a, IT b) {
if (a < b)
a = b;
}
template <class IT> inline void cmin(IT &a, IT b) {
if (b < a)
a = b;
}
const int N = 200005;
struct node {
pii v;
int lc, rc;
} tre[N * 18];
int tot;
inline pii aww(pii a, int b) {
return (b & 1) ? mp(max(a.fi, a.se + b), max(a.se, a.fi + b))
: mp(a.fi + b, a.se + b);
}
inline bool get(pii a, int b) {
return b >= 0 && ((b & 1) ? (b <= a.se) : (b <= a.fi));
}
inline pii pmax(pii a, const pii &b) {
cmax(a.fi, b.fi);
cmax(a.se, b.se);
return a;
}
#define mid ((l + r) >> 1)
#define ls tre[o].lc, l, mid
#define rs tre[o].rc, mid + 1, r
void add(int O, int &o, int l, int r, int x, pii y) {
tre[o = ++tot].v = pmax(tre[O].v, y);
if (l == r)
return;
if (x <= mid) {
tre[o].rc = tre[O].rc;
add(tre[O].lc, ls, x, y);
} else {
tre[o].lc = tre[O].lc;
add(tre[O].rc, rs, x, y);
}
}
pii que(int o, int l, int r, int x) {
if (l == r)
return tre[o].v;
if (x <= mid)
return pmax(que(ls, x), tre[tre[o].rc].v);
return que(rs, x);
}
int rt[N], a[N], h[N], s[N];
int main() {
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
tre[0].v.se = -(N << 1 | 1);
int n, i, cx = 0, mx = 0, cy = 0, my = 0, C, M, b;
scanf("%d", &n);
rep(i, 1, n) {
scanf("%d", &a[i]);
if (a[i] > mx) {
mx = a[i];
h[i] = 1;
}
}
mx = 0;
per(i, n, 1) add(rt[i + 1], rt[i], 1, n, a[i],
aww(que(rt[i + 1], 1, n, a[i]), 1 + h[i]));
per(i, n, 1) s[i] = h[i] + s[i + 1];
if (!get(tre[rt[1]].v, s[1])) {
puts("-1");
return 0;
}
rep(i, 1, n) {
C = cx + (a[i] > mx);
M = max(mx, a[i]);
// printf("Y (%d,%d)
// %d\n",que(rt[i+1],1,n,my).fi,que(rt[i+1],1,n,my).se,C-cy+s[i+1]);
// printf("X (%d,%d) %d\n",que(rt[i+1],1,n,M ).fi,que(rt[i+1],1,n,M
// ).se,cy-C+s[i+1]);
if (get(que(rt[i + 1], 1, n, my), C - cy + s[i + 1]) ||
get(que(rt[i + 1], 1, n, M), cy - C + s[i + 1])) {
cx = C;
mx = M;
putchar('0');
} else {
cy += (a[i] > my);
cmax(my, a[i]);
putchar('1');
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
namespace io {
const int l = 1 << 20;
char buf[l], *s, *t, c;
inline void gc() {
if (s == t) {
t = (s = buf) + fread(buf, 1, l, stdin);
c = s == t ? EOF : *s++;
} else
c = *s++;
}
template <class IT> inline void gi(IT &x) {
x = 0;
gc();
while (c < '0' || c > '9')
gc();
while ('0' <= c && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ 48);
gc();
}
}
char buf0[20];
int a;
template <class IT> inline void pi(IT x) {
if (x < 0) {
putchar('-');
x = -x;
}
do
buf0[++a] = x % 10 + 48;
while (x /= 10);
while (a)
putchar(buf0[a--]);
putchar('\n');
}
}; // namespace io
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pque priority_queue
#define rep(i, l, r) for (i = (l); i <= (r); ++i)
#define per(i, l, r) for (i = (l); i >= (r); --i)
#define REP(i, l, r) for (i = (l); i < (r); ++i)
#define PER(i, l, r) for (i = (l); i > (r); --i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template <class IT> inline void cmax(IT &a, IT b) {
if (a < b)
a = b;
}
template <class IT> inline void cmin(IT &a, IT b) {
if (b < a)
a = b;
}
const int N = 200005;
struct node {
pii v;
int lc, rc;
} tre[N * 19];
int tot;
inline pii aww(pii a, int b) {
return (b & 1) ? mp(max(a.fi, a.se + b), max(a.se, a.fi + b))
: mp(a.fi + b, a.se + b);
}
inline bool get(pii a, int b) {
return b >= 0 && ((b & 1) ? (b <= a.se) : (b <= a.fi));
}
inline pii pmax(pii a, const pii &b) {
cmax(a.fi, b.fi);
cmax(a.se, b.se);
return a;
}
#define mid ((l + r) >> 1)
#define ls tre[o].lc, l, mid
#define rs tre[o].rc, mid + 1, r
void add(int O, int &o, int l, int r, int x, pii y) {
tre[o = ++tot].v = pmax(tre[O].v, y);
if (l == r)
return;
if (x <= mid) {
tre[o].rc = tre[O].rc;
add(tre[O].lc, ls, x, y);
} else {
tre[o].lc = tre[O].lc;
add(tre[O].rc, rs, x, y);
}
}
pii que(int o, int l, int r, int x) {
if (l == r)
return tre[o].v;
if (x <= mid)
return pmax(que(ls, x), tre[tre[o].rc].v);
return que(rs, x);
}
int rt[N], a[N], h[N], s[N];
int main() {
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
tre[0].v.se = -(N << 1 | 1);
int n, i, cx = 0, mx = 0, cy = 0, my = 0, C, M, b;
scanf("%d", &n);
rep(i, 1, n) {
scanf("%d", &a[i]);
if (a[i] > mx) {
mx = a[i];
h[i] = 1;
}
}
mx = 0;
per(i, n, 1) add(rt[i + 1], rt[i], 1, n, a[i],
aww(que(rt[i + 1], 1, n, a[i]), 1 + h[i]));
per(i, n, 1) s[i] = h[i] + s[i + 1];
if (!get(tre[rt[1]].v, s[1])) {
puts("-1");
return 0;
}
rep(i, 1, n) {
C = cx + (a[i] > mx);
M = max(mx, a[i]);
// printf("Y (%d,%d)
// %d\n",que(rt[i+1],1,n,my).fi,que(rt[i+1],1,n,my).se,C-cy+s[i+1]);
// printf("X (%d,%d) %d\n",que(rt[i+1],1,n,M ).fi,que(rt[i+1],1,n,M
// ).se,cy-C+s[i+1]);
if (get(que(rt[i + 1], 1, n, my), C - cy + s[i + 1]) ||
get(que(rt[i + 1], 1, n, M), cy - C + s[i + 1])) {
cx = C;
mx = M;
putchar('0');
} else {
cy += (a[i] > my);
cmax(my, a[i]);
putchar('1');
}
}
return 0;
} | replace | 72 | 73 | 72 | 73 | 0 | |
p03235 | C++ | Runtime Error | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ET cout << "\n"
#define MEM(i, j) memset(i, j, sizeof i)
#define ALL(v) v.begin(), v.end()
#define DB(a, s, e) \
{ \
for (int i = s; i < e; ++i) \
cerr << a[i] << " "; \
ET; \
}
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int arr[200005], seg[2][200005];
bitset<200005> high;
string ans;
void modify(int x, int l, int r, int rt, int t, int v) {
if (l == r)
return seg[t][rt] = v, void();
int m = l + r >> 1;
if (x <= m)
modify(x, l, m, rt << 1, t, v);
else
modify(x, m + 1, r, rt << 1 | 1, t, v);
seg[t][rt] = max(seg[t][rt << 1], seg[t][rt << 1 | 1]);
}
int query(int L, int R, int l, int r, int rt, int t) {
if (L <= l && R >= r)
return seg[t][rt];
int m = l + r >> 1;
if (R <= m)
return query(L, R, l, m, rt << 1, t);
if (L > m)
return query(L, R, m + 1, r, rt << 1 | 1, t);
return max(query(L, R, l, m, rt << 1, t),
query(L, R, m + 1, r, rt << 1 | 1, t));
}
int main() {
jizz int n, mx = 0, a, b, ma, mb, cnt;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> arr[i], high[i] = (arr[i] > mx), mx = max(mx, arr[i]);
for (int i = n; i >= 1; --i) {
a = query(arr[i] + 1, n + 1, 1, n + 1, 1, 0) + high[i] + 1,
b = query(arr[i] + 1, n + 1, 1, n + 1, 1, 1);
if (b & 1)
b += high[i] + 1, modify(arr[i], 1, n + 1, 1, b & 1, b);
modify(arr[i], 1, n + 1, 1, a & 1, a);
}
cnt = high.count();
if (seg[cnt & 1][1] < cnt)
return cout << "-1\n", 0;
a = b = ma = mb = 0;
for (int i = 1; i <= n; ++i) {
modify(arr[i], 1, n + 1, 1, 0, 0), modify(arr[i], 1, n + 1, 1, 1, 0);
cnt -= high[i];
int t = a - b + cnt + (arr[i] > ma);
if (t >= 0 && query(mb + 1, n + 1, 1, n + 1, 1, t & 1) >= t)
a += (arr[i] > ma), ma = max(ma, arr[i]), ans.pb('0');
else if (t = b - a + cnt - (arr[i] > ma),
t >= 0 &&
query(max(ma, arr[i]) + 1, n + 1, 1, n + 1, 1, t & 1) >= t)
a += (arr[i] > ma), ma = max(ma, arr[i]), ans.pb('0');
else
b += (arr[i] > mb), mb = max(mb, arr[i]), ans.pb('1');
}
cout << ans << "\n";
} | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ET cout << "\n"
#define MEM(i, j) memset(i, j, sizeof i)
#define ALL(v) v.begin(), v.end()
#define DB(a, s, e) \
{ \
for (int i = s; i < e; ++i) \
cerr << a[i] << " "; \
ET; \
}
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int arr[200005], seg[2][800005];
bitset<200005> high;
string ans;
void modify(int x, int l, int r, int rt, int t, int v) {
if (l == r)
return seg[t][rt] = v, void();
int m = l + r >> 1;
if (x <= m)
modify(x, l, m, rt << 1, t, v);
else
modify(x, m + 1, r, rt << 1 | 1, t, v);
seg[t][rt] = max(seg[t][rt << 1], seg[t][rt << 1 | 1]);
}
int query(int L, int R, int l, int r, int rt, int t) {
if (L <= l && R >= r)
return seg[t][rt];
int m = l + r >> 1;
if (R <= m)
return query(L, R, l, m, rt << 1, t);
if (L > m)
return query(L, R, m + 1, r, rt << 1 | 1, t);
return max(query(L, R, l, m, rt << 1, t),
query(L, R, m + 1, r, rt << 1 | 1, t));
}
int main() {
jizz int n, mx = 0, a, b, ma, mb, cnt;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> arr[i], high[i] = (arr[i] > mx), mx = max(mx, arr[i]);
for (int i = n; i >= 1; --i) {
a = query(arr[i] + 1, n + 1, 1, n + 1, 1, 0) + high[i] + 1,
b = query(arr[i] + 1, n + 1, 1, n + 1, 1, 1);
if (b & 1)
b += high[i] + 1, modify(arr[i], 1, n + 1, 1, b & 1, b);
modify(arr[i], 1, n + 1, 1, a & 1, a);
}
cnt = high.count();
if (seg[cnt & 1][1] < cnt)
return cout << "-1\n", 0;
a = b = ma = mb = 0;
for (int i = 1; i <= n; ++i) {
modify(arr[i], 1, n + 1, 1, 0, 0), modify(arr[i], 1, n + 1, 1, 1, 0);
cnt -= high[i];
int t = a - b + cnt + (arr[i] > ma);
if (t >= 0 && query(mb + 1, n + 1, 1, n + 1, 1, t & 1) >= t)
a += (arr[i] > ma), ma = max(ma, arr[i]), ans.pb('0');
else if (t = b - a + cnt - (arr[i] > ma),
t >= 0 &&
query(max(ma, arr[i]) + 1, n + 1, 1, n + 1, 1, t & 1) >= t)
a += (arr[i] > ma), ma = max(ma, arr[i]), ans.pb('0');
else
b += (arr[i] > mb), mb = max(mb, arr[i]), ans.pb('1');
}
cout << ans << "\n";
} | replace | 21 | 22 | 21 | 22 | 0 | |
p03235 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int Q = 1 << 18;
int tl = 0;
int ls[Q * 18], rs[Q * 18];
int mx[Q * 18];
void MDF(int lst, int &now, int l, int r, int x, int v) {
now = ++tl;
mx[now] = -998244353;
if (l == r) {
mx[now] = max(mx[now], v);
return;
}
ls[now] = ls[lst], rs[now] = rs[lst];
int mid = (l + r) >> 1;
if (x <= mid)
MDF(ls[lst], ls[now], l, mid, x, v);
else
MDF(rs[lst], rs[now], mid + 1, r, x, v);
mx[now] = max(mx[ls[now]], mx[rs[now]]);
}
int GM(int now, int l, int r, int x, int y) {
if (x <= l && y >= r)
return mx[now];
int mid = (l + r) >> 1;
if (y <= mid)
return GM(ls[now], l, mid, x, y);
if (x > mid)
return GM(rs[now], mid + 1, r, x, y);
return max(GM(ls[now], l, mid, x, y), GM(rs[now], mid + 1, r, x, y));
}
int rt0[Q], rt1[Q];
int p[Q];
int imp[Q];
int n;
int c0 = 0, c1 = 0;
int res = 0;
int mxa, mxb;
int Ch(int st) {
int ra = c0 - c1 + res, rb = c1 - c0 + res;
int pa = GM((ra & 1 ? rt1 : rt0)[st], 1, n, mxb, n),
pb = GM((rb & 1 ? rt1 : rt0)[st], 1, n, mxa, n);
if (ra >= 0 && pa >= ra)
return 1;
if (rb >= 0 && pb >= rb)
return 1;
return 0;
}
void Ga(int x) {
if (imp[x])
--res;
}
int main() {
mx[0] = -998244353;
scanf("%d", &n);
for (int i = 1, mx = 0; i <= n; i++) {
scanf("%d", &p[i]);
if (mx < p[i])
mx = p[i], imp[i] = 1, ++res;
}
MDF(rt0[n + 1], rt0[n + 1], 1, n, n, 0);
for (int i = n; i; --i) {
int f0 = GM(rt0[i + 1], 1, n, p[i], n) + imp[i] + 1;
int f1 = GM(rt1[i + 1], 1, n, p[i], n) + imp[i] + 1;
// printf("%d %d ???\n",imp[i]?f0:f1,imp[i]?f1:f0);
MDF(rt0[i + 1], rt0[i], 1, n, p[i], imp[i] ? f0 : f1);
MDF(rt1[i + 1], rt1[i], 1, n, p[i], imp[i] ? f1 : f0);
}
if (!Ch(1))
return puts("-1") & 0;
mxb = 0, mxa = 0;
for (int i = 1; i <= n; i++) {
int cc = c0, ra = mxa;
if (imp[i])
--res;
if (p[i] > mxa)
++c0, mxa = p[i];
int fin = Ch(i + 1);
if (!fin) {
c0 = cc;
mxa = ra;
if (p[i] > mxb)
mxb = p[i], ++c1;
putchar('1');
} else
putchar('0');
}
return 0;
}
/*
c0+(tl-k)==c1+k+had
c0-c1+tl==2*k+had;
*/ | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int Q = 1 << 18;
int tl = 0;
int ls[Q * 36], rs[Q * 36];
int mx[Q * 36];
void MDF(int lst, int &now, int l, int r, int x, int v) {
now = ++tl;
mx[now] = -998244353;
if (l == r) {
mx[now] = max(mx[now], v);
return;
}
ls[now] = ls[lst], rs[now] = rs[lst];
int mid = (l + r) >> 1;
if (x <= mid)
MDF(ls[lst], ls[now], l, mid, x, v);
else
MDF(rs[lst], rs[now], mid + 1, r, x, v);
mx[now] = max(mx[ls[now]], mx[rs[now]]);
}
int GM(int now, int l, int r, int x, int y) {
if (x <= l && y >= r)
return mx[now];
int mid = (l + r) >> 1;
if (y <= mid)
return GM(ls[now], l, mid, x, y);
if (x > mid)
return GM(rs[now], mid + 1, r, x, y);
return max(GM(ls[now], l, mid, x, y), GM(rs[now], mid + 1, r, x, y));
}
int rt0[Q], rt1[Q];
int p[Q];
int imp[Q];
int n;
int c0 = 0, c1 = 0;
int res = 0;
int mxa, mxb;
int Ch(int st) {
int ra = c0 - c1 + res, rb = c1 - c0 + res;
int pa = GM((ra & 1 ? rt1 : rt0)[st], 1, n, mxb, n),
pb = GM((rb & 1 ? rt1 : rt0)[st], 1, n, mxa, n);
if (ra >= 0 && pa >= ra)
return 1;
if (rb >= 0 && pb >= rb)
return 1;
return 0;
}
void Ga(int x) {
if (imp[x])
--res;
}
int main() {
mx[0] = -998244353;
scanf("%d", &n);
for (int i = 1, mx = 0; i <= n; i++) {
scanf("%d", &p[i]);
if (mx < p[i])
mx = p[i], imp[i] = 1, ++res;
}
MDF(rt0[n + 1], rt0[n + 1], 1, n, n, 0);
for (int i = n; i; --i) {
int f0 = GM(rt0[i + 1], 1, n, p[i], n) + imp[i] + 1;
int f1 = GM(rt1[i + 1], 1, n, p[i], n) + imp[i] + 1;
// printf("%d %d ???\n",imp[i]?f0:f1,imp[i]?f1:f0);
MDF(rt0[i + 1], rt0[i], 1, n, p[i], imp[i] ? f0 : f1);
MDF(rt1[i + 1], rt1[i], 1, n, p[i], imp[i] ? f1 : f0);
}
if (!Ch(1))
return puts("-1") & 0;
mxb = 0, mxa = 0;
for (int i = 1; i <= n; i++) {
int cc = c0, ra = mxa;
if (imp[i])
--res;
if (p[i] > mxa)
++c0, mxa = p[i];
int fin = Ch(i + 1);
if (!fin) {
c0 = cc;
mxa = ra;
if (p[i] > mxb)
mxb = p[i], ++c1;
putchar('1');
} else
putchar('0');
}
return 0;
}
/*
c0+(tl-k)==c1+k+had
c0-c1+tl==2*k+had;
*/ | replace | 7 | 9 | 7 | 9 | 0 | |
p03235 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#define FILL(a, n, x) memset((a), (x), sizeof((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof(a))
#define COPY(a, n, b) memcpy((b), (a), sizeof((a)[0]) * (n))
#define COPYA(a, b) memcpy((b), (a), sizeof(a))
using namespace std;
typedef pair<int, int> pii;
typedef long long li;
typedef unsigned long long lu;
const int inf = ~0U >> 2;
const li infl = ~0LLU >> 2;
template <class T> inline void Min(T &x, T y) {
if (y < x)
x = y;
}
template <class T> inline void Max(T &x, T y) {
if (y > x)
x = y;
}
// ----------------------------------------
const int maxn = 2e5;
struct Data {
int maxv[2];
void operator+=(const Data &b) {
Max(maxv[0], b.maxv[0]);
Max(maxv[1], b.maxv[1]);
}
Data operator+(const Data &b) const {
return {max(maxv[0], b.maxv[0]), max(maxv[1], b.maxv[1])};
}
};
int n, P[maxn];
bool old[maxn];
namespace seg {
const int max_node = 2e5 * 19;
struct Node {
int lc, rc;
Data dat;
} node[max_node];
int nd;
void Build(int u, int l, int r) {
if (r - l == 1) {
node[u] = {-1, -1, {0, -inf}};
} else {
node[u] = {nd, nd + 1, {0, -inf}};
nd += 2;
int mid = l + r >> 1;
Build(node[u].lc, l, mid);
Build(node[u].rc, mid, r);
}
}
int Init(void) {
nd = 1;
Build(0, 0, n);
return 0;
}
int ql, qr;
Data qx;
void QQuery(int u, int l, int r) {
if (ql <= l && qr >= r) {
qx += node[u].dat;
return;
}
int mid = l + r >> 1;
if (ql < mid)
QQuery(node[u].lc, l, mid);
if (qr > mid)
QQuery(node[u].rc, mid, r);
}
Data Query(int root, int l, int r) {
if (l >= r)
return {0, -inf};
qx = {0, -inf};
ql = l;
qr = r;
QQuery(root, 0, n);
return qx;
}
void Copy(int &u) {
int v = nd++;
node[v] = node[u];
u = v;
}
void UUpdate(int &u, int l, int r) {
Copy(u);
if (r - l == 1) {
node[u].dat += qx;
return;
}
int mid = l + r >> 1;
if (ql < mid) {
UUpdate(node[u].lc, l, mid);
} else {
UUpdate(node[u].rc, mid, r);
}
node[u].dat = node[node[u].lc].dat + node[node[u].rc].dat;
}
int Update(int root, int i, const Data &x) {
ql = i;
qx = x;
UUpdate(root, 0, n);
return root;
}
} // namespace seg
int root[maxn + 1];
int dire[maxn];
int tail[2];
int suf_old[maxn + 1];
bool Check(int i, int prev, int tail) {
prev += suf_old[i];
if (prev < 0)
return false;
int tar = prev;
Data res = seg::Query(root[i], tail, n);
// printf("Check(%d, %d, %d) = %d %d\n", i, prev, tail,
// res.maxv[0], res.maxv[1]);
return res.maxv[tar & 1] >= tar;
}
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", P + i);
--P[i];
}
int maxv = -1;
FILL(old, n, 0);
for (int i = 0; i < n; ++i) {
if (P[i] > maxv) {
maxv = P[i];
old[i] = true;
}
}
suf_old[n] = 0;
for (int i = n - 1; i >= 0; --i) {
suf_old[i] = suf_old[i + 1] + old[i];
}
root[n] = seg::Init();
for (int i = n - 1; i >= 0; --i) {
Data res = seg::Query(root[i + 1], P[i], n);
Data now;
if (old[i]) {
now = (Data){res.maxv[0] + 2, res.maxv[1] + 2};
} else {
now = (Data){res.maxv[1] + 1, res.maxv[0] + 1};
}
root[i] = seg::Update(root[i + 1], P[i], now);
}
if (!Check(0, 0, 0)) {
puts("-1");
return 0;
}
tail[0] = tail[1] = -1;
int lambda = 0;
for (int i = 0; i < n; ++i) {
// Try 0
int tail_0 = tail[0];
int lambda_0 = lambda;
if (P[i] > tail[0]) {
tail[0] = P[i];
++lambda;
}
if (Check(i + 1, lambda, tail[1]) || Check(i + 1, -lambda, tail[0])) {
dire[i] = 0;
continue;
}
lambda = lambda_0;
tail[0] = tail_0;
// Set 1
if (P[i] > tail[1]) {
tail[1] = P[i];
--lambda;
}
dire[i] = 1;
}
for (int i = 0; i < n; ++i) {
putchar('0' + dire[i]);
}
putchar('\n');
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#define FILL(a, n, x) memset((a), (x), sizeof((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof(a))
#define COPY(a, n, b) memcpy((b), (a), sizeof((a)[0]) * (n))
#define COPYA(a, b) memcpy((b), (a), sizeof(a))
using namespace std;
typedef pair<int, int> pii;
typedef long long li;
typedef unsigned long long lu;
const int inf = ~0U >> 2;
const li infl = ~0LLU >> 2;
template <class T> inline void Min(T &x, T y) {
if (y < x)
x = y;
}
template <class T> inline void Max(T &x, T y) {
if (y > x)
x = y;
}
// ----------------------------------------
const int maxn = 2e5;
struct Data {
int maxv[2];
void operator+=(const Data &b) {
Max(maxv[0], b.maxv[0]);
Max(maxv[1], b.maxv[1]);
}
Data operator+(const Data &b) const {
return {max(maxv[0], b.maxv[0]), max(maxv[1], b.maxv[1])};
}
};
int n, P[maxn];
bool old[maxn];
namespace seg {
const int max_node = 4e5 + 2e5 * 19;
struct Node {
int lc, rc;
Data dat;
} node[max_node];
int nd;
void Build(int u, int l, int r) {
if (r - l == 1) {
node[u] = {-1, -1, {0, -inf}};
} else {
node[u] = {nd, nd + 1, {0, -inf}};
nd += 2;
int mid = l + r >> 1;
Build(node[u].lc, l, mid);
Build(node[u].rc, mid, r);
}
}
int Init(void) {
nd = 1;
Build(0, 0, n);
return 0;
}
int ql, qr;
Data qx;
void QQuery(int u, int l, int r) {
if (ql <= l && qr >= r) {
qx += node[u].dat;
return;
}
int mid = l + r >> 1;
if (ql < mid)
QQuery(node[u].lc, l, mid);
if (qr > mid)
QQuery(node[u].rc, mid, r);
}
Data Query(int root, int l, int r) {
if (l >= r)
return {0, -inf};
qx = {0, -inf};
ql = l;
qr = r;
QQuery(root, 0, n);
return qx;
}
void Copy(int &u) {
int v = nd++;
node[v] = node[u];
u = v;
}
void UUpdate(int &u, int l, int r) {
Copy(u);
if (r - l == 1) {
node[u].dat += qx;
return;
}
int mid = l + r >> 1;
if (ql < mid) {
UUpdate(node[u].lc, l, mid);
} else {
UUpdate(node[u].rc, mid, r);
}
node[u].dat = node[node[u].lc].dat + node[node[u].rc].dat;
}
int Update(int root, int i, const Data &x) {
ql = i;
qx = x;
UUpdate(root, 0, n);
return root;
}
} // namespace seg
int root[maxn + 1];
int dire[maxn];
int tail[2];
int suf_old[maxn + 1];
bool Check(int i, int prev, int tail) {
prev += suf_old[i];
if (prev < 0)
return false;
int tar = prev;
Data res = seg::Query(root[i], tail, n);
// printf("Check(%d, %d, %d) = %d %d\n", i, prev, tail,
// res.maxv[0], res.maxv[1]);
return res.maxv[tar & 1] >= tar;
}
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", P + i);
--P[i];
}
int maxv = -1;
FILL(old, n, 0);
for (int i = 0; i < n; ++i) {
if (P[i] > maxv) {
maxv = P[i];
old[i] = true;
}
}
suf_old[n] = 0;
for (int i = n - 1; i >= 0; --i) {
suf_old[i] = suf_old[i + 1] + old[i];
}
root[n] = seg::Init();
for (int i = n - 1; i >= 0; --i) {
Data res = seg::Query(root[i + 1], P[i], n);
Data now;
if (old[i]) {
now = (Data){res.maxv[0] + 2, res.maxv[1] + 2};
} else {
now = (Data){res.maxv[1] + 1, res.maxv[0] + 1};
}
root[i] = seg::Update(root[i + 1], P[i], now);
}
if (!Check(0, 0, 0)) {
puts("-1");
return 0;
}
tail[0] = tail[1] = -1;
int lambda = 0;
for (int i = 0; i < n; ++i) {
// Try 0
int tail_0 = tail[0];
int lambda_0 = lambda;
if (P[i] > tail[0]) {
tail[0] = P[i];
++lambda;
}
if (Check(i + 1, lambda, tail[1]) || Check(i + 1, -lambda, tail[0])) {
dire[i] = 0;
continue;
}
lambda = lambda_0;
tail[0] = tail_0;
// Set 1
if (P[i] > tail[1]) {
tail[1] = P[i];
--lambda;
}
dire[i] = 1;
}
for (int i = 0; i < n; ++i) {
putchar('0' + dire[i]);
}
putchar('\n');
return 0;
}
| replace | 46 | 47 | 46 | 47 | 0 | |
p03235 | C++ | Runtime Error | #include <algorithm>
#include <stdio.h>
using namespace std;
int n;
int p[131072];
bool mx[131072];
int c1[131072], c2[131072];
int wz1[2097152], wz2[2097152], pre1[2097152], pre2[2097152], tim1[2097152],
tim2[2097152], num1 = 0, num2 = 0;
void add(int wz, int val1, int val2, int tim) {
for (int i = wz; i > 0; i -= (i & (-i))) {
if (val1 > c1[i]) {
wz1[num1] = i;
pre1[num1] = c1[i];
tim1[num1] = tim;
num1++;
c1[i] = val1;
}
if (val2 > c2[i]) {
wz2[num2] = i;
pre2[num2] = c2[i];
tim2[num2] = tim;
num2++;
c2[i] = val2;
}
}
}
void query(int wz, int &val1, int &val2) {
val1 = -999999;
val2 = 0;
for (int i = wz; i <= n; i += (i & (-i))) {
if (c1[i] > val1) {
val1 = c1[i];
}
if (c2[i] > val2) {
val2 = c2[i];
}
}
}
void del(int tim) {
while (num1) {
if (tim1[num1 - 1] != tim) {
break;
}
num1--;
c1[wz1[num1]] = pre1[num1];
}
while (num2) {
if (tim2[num2 - 1] != tim) {
break;
}
num2--;
c2[wz2[num2]] = pre2[num2];
}
}
bool chk2(int val, int val1, int val2) {
if (val < 0) {
return false;
}
if (val & 1) {
return val <= val1;
}
return val <= val2;
}
bool chk(int numx, int numy, int mxx, int mxy, int m) {
int val1, val2;
query(mxx, val1, val2);
if (chk2(numy - numx + m, val1, val2)) {
return true;
}
query(mxy, val1, val2);
return chk2(numx - numy + m, val1, val2);
}
int main() {
int last = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &p[i]);
if (p[i] > last) {
mx[i] = true;
last = p[i];
}
c1[i] = -999999;
c2[i] = 0;
}
int m = 0;
for (int i = n; i >= 1; i--) {
int val1, val2;
query(p[i], val1, val2);
if (mx[i]) {
m++;
add(p[i], val1 + 2, val2 + 2, i);
} else {
add(p[i], val2 + 1, val1 + 1, i);
}
}
int numx = 0, numy = 0, mxx = 1, mxy = 1;
if (!chk(numx, numy, mxx, mxy, m)) {
printf("-1\n");
return 0;
}
for (int i = 1; i <= n; i++) {
del(i);
if (mx[i]) {
m--;
}
int numx2 = numx, numy2 = numy, mxx2 = mxx, mxy2 = mxy;
if (p[i] >= mxx) {
mxx2 = p[i];
numx2++;
}
if (p[i] >= mxy) {
mxy2 = p[i];
numy2++;
}
if (chk(numx2, numy, mxx2, mxy, m)) {
putchar('0');
numx = numx2;
mxx = mxx2;
} else {
putchar('1');
numy = numy2;
mxy = mxy2;
}
}
putchar('\n');
return 0;
} | #include <algorithm>
#include <stdio.h>
using namespace std;
int n;
int p[262144];
bool mx[262144];
int c1[262144], c2[262144];
int wz1[4194304], wz2[4194304], pre1[4194304], pre2[4194304], tim1[4194304],
tim2[4194304], num1 = 0, num2 = 0;
void add(int wz, int val1, int val2, int tim) {
for (int i = wz; i > 0; i -= (i & (-i))) {
if (val1 > c1[i]) {
wz1[num1] = i;
pre1[num1] = c1[i];
tim1[num1] = tim;
num1++;
c1[i] = val1;
}
if (val2 > c2[i]) {
wz2[num2] = i;
pre2[num2] = c2[i];
tim2[num2] = tim;
num2++;
c2[i] = val2;
}
}
}
void query(int wz, int &val1, int &val2) {
val1 = -999999;
val2 = 0;
for (int i = wz; i <= n; i += (i & (-i))) {
if (c1[i] > val1) {
val1 = c1[i];
}
if (c2[i] > val2) {
val2 = c2[i];
}
}
}
void del(int tim) {
while (num1) {
if (tim1[num1 - 1] != tim) {
break;
}
num1--;
c1[wz1[num1]] = pre1[num1];
}
while (num2) {
if (tim2[num2 - 1] != tim) {
break;
}
num2--;
c2[wz2[num2]] = pre2[num2];
}
}
bool chk2(int val, int val1, int val2) {
if (val < 0) {
return false;
}
if (val & 1) {
return val <= val1;
}
return val <= val2;
}
bool chk(int numx, int numy, int mxx, int mxy, int m) {
int val1, val2;
query(mxx, val1, val2);
if (chk2(numy - numx + m, val1, val2)) {
return true;
}
query(mxy, val1, val2);
return chk2(numx - numy + m, val1, val2);
}
int main() {
int last = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &p[i]);
if (p[i] > last) {
mx[i] = true;
last = p[i];
}
c1[i] = -999999;
c2[i] = 0;
}
int m = 0;
for (int i = n; i >= 1; i--) {
int val1, val2;
query(p[i], val1, val2);
if (mx[i]) {
m++;
add(p[i], val1 + 2, val2 + 2, i);
} else {
add(p[i], val2 + 1, val1 + 1, i);
}
}
int numx = 0, numy = 0, mxx = 1, mxy = 1;
if (!chk(numx, numy, mxx, mxy, m)) {
printf("-1\n");
return 0;
}
for (int i = 1; i <= n; i++) {
del(i);
if (mx[i]) {
m--;
}
int numx2 = numx, numy2 = numy, mxx2 = mxx, mxy2 = mxy;
if (p[i] >= mxx) {
mxx2 = p[i];
numx2++;
}
if (p[i] >= mxy) {
mxy2 = p[i];
numy2++;
}
if (chk(numx2, numy, mxx2, mxy, m)) {
putchar('0');
numx = numx2;
mxx = mxx2;
} else {
putchar('1');
numy = numy2;
mxy = mxy2;
}
}
putchar('\n');
return 0;
} | replace | 4 | 9 | 4 | 9 | 0 | |
p03235 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
struct Tree {
int mx;
int lch, rch;
} T[6400010];
int tot;
void update(int root) {
int lc = T[root].lch;
int rc = T[root].rch;
T[root].mx = max(T[lc].mx, T[rc].mx);
return;
}
void insert(int lstroot, int &nowroot, int l, int r, int x, int y) {
nowroot = ++tot;
if (l == r) {
T[nowroot].mx = max(T[lstroot].mx, y);
return;
}
int mid = (l + r) >> 1;
if (x <= mid) {
T[nowroot].rch = T[lstroot].rch;
insert(T[lstroot].lch, T[nowroot].lch, l, mid, x, y);
} else {
T[nowroot].lch = T[lstroot].lch;
insert(T[lstroot].rch, T[nowroot].rch, mid + 1, r, x, y);
}
update(nowroot);
return;
}
int query(int root, int l, int r, int x, int y) {
if (x <= l && r <= y)
return T[root].mx;
int mid = (l + r) >> 1;
if (x <= mid) {
if (y > mid)
return max(query(T[root].lch, l, mid, x, y),
query(T[root].rch, mid + 1, r, x, y));
return query(T[root].lch, l, mid, x, y);
}
return query(T[root].rch, mid + 1, r, x, y);
}
int rt[200010][2];
int n, p[200010], c[200010], f[200010];
void init() {
int mx = 0;
for (int i = 1; i <= n; i++)
if (p[i] > mx) {
mx = p[i];
c[i] = 2;
} else
c[i] = 1;
for (int i = n; i >= 1; i--)
f[i] = f[i + 1] + c[i] - 1;
for (int i = n; i >= 1; i--)
for (int j = 0; j < 2; j++) {
rt[i][j] = rt[i + 1][j];
int val = query(rt[i + 1][(j + c[i]) & 1], 1, n, p[i], n) + c[i];
if (val % 2 == j) {
// printf("%d,%d:%d\n",i,j,val);
insert(rt[i + 1][j], rt[i][j], 1, n, p[i], val);
}
}
return;
}
bool check(int H1, int C1, int H2, int C2, int opt, int i) {
if (opt == 0) {
C1 += (p[i] > H1);
H1 = max(H1, p[i]);
} else {
C2 += (p[i] > H2);
H2 = max(H2, p[i]);
}
int need;
// in 2
need = C1 - C2 + f[i + 1];
if (need >= 0 && query(rt[i + 1][need & 1], 1, n, H2, n) >= need)
return true;
// in 1
need = C2 - C1 + f[i + 1];
if (need >= 0 && query(rt[i + 1][need & 1], 1, n, H1, n) >= need)
return true;
return false;
}
char ans[200010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &p[i]);
init();
int H1 = 0, C1 = 0, H2 = 0, C2 = 0;
for (int i = 1; i <= n; i++) {
if (check(H1, C1, H2, C2, 0, i)) {
C1 += (p[i] > H1);
H1 = max(H1, p[i]);
ans[i] = '0';
} else if (check(H1, C1, H2, C2, 1, i)) {
C2 += (p[i] > H2);
H2 = max(H2, p[i]);
ans[i] = '1';
} else {
printf("-1\n");
return 0;
}
}
printf("%s\n", ans + 1);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
struct Tree {
int mx;
int lch, rch;
} T[12800010];
int tot;
void update(int root) {
int lc = T[root].lch;
int rc = T[root].rch;
T[root].mx = max(T[lc].mx, T[rc].mx);
return;
}
void insert(int lstroot, int &nowroot, int l, int r, int x, int y) {
nowroot = ++tot;
if (l == r) {
T[nowroot].mx = max(T[lstroot].mx, y);
return;
}
int mid = (l + r) >> 1;
if (x <= mid) {
T[nowroot].rch = T[lstroot].rch;
insert(T[lstroot].lch, T[nowroot].lch, l, mid, x, y);
} else {
T[nowroot].lch = T[lstroot].lch;
insert(T[lstroot].rch, T[nowroot].rch, mid + 1, r, x, y);
}
update(nowroot);
return;
}
int query(int root, int l, int r, int x, int y) {
if (x <= l && r <= y)
return T[root].mx;
int mid = (l + r) >> 1;
if (x <= mid) {
if (y > mid)
return max(query(T[root].lch, l, mid, x, y),
query(T[root].rch, mid + 1, r, x, y));
return query(T[root].lch, l, mid, x, y);
}
return query(T[root].rch, mid + 1, r, x, y);
}
int rt[200010][2];
int n, p[200010], c[200010], f[200010];
void init() {
int mx = 0;
for (int i = 1; i <= n; i++)
if (p[i] > mx) {
mx = p[i];
c[i] = 2;
} else
c[i] = 1;
for (int i = n; i >= 1; i--)
f[i] = f[i + 1] + c[i] - 1;
for (int i = n; i >= 1; i--)
for (int j = 0; j < 2; j++) {
rt[i][j] = rt[i + 1][j];
int val = query(rt[i + 1][(j + c[i]) & 1], 1, n, p[i], n) + c[i];
if (val % 2 == j) {
// printf("%d,%d:%d\n",i,j,val);
insert(rt[i + 1][j], rt[i][j], 1, n, p[i], val);
}
}
return;
}
bool check(int H1, int C1, int H2, int C2, int opt, int i) {
if (opt == 0) {
C1 += (p[i] > H1);
H1 = max(H1, p[i]);
} else {
C2 += (p[i] > H2);
H2 = max(H2, p[i]);
}
int need;
// in 2
need = C1 - C2 + f[i + 1];
if (need >= 0 && query(rt[i + 1][need & 1], 1, n, H2, n) >= need)
return true;
// in 1
need = C2 - C1 + f[i + 1];
if (need >= 0 && query(rt[i + 1][need & 1], 1, n, H1, n) >= need)
return true;
return false;
}
char ans[200010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &p[i]);
init();
int H1 = 0, C1 = 0, H2 = 0, C2 = 0;
for (int i = 1; i <= n; i++) {
if (check(H1, C1, H2, C2, 0, i)) {
C1 += (p[i] > H1);
H1 = max(H1, p[i]);
ans[i] = '0';
} else if (check(H1, C1, H2, C2, 1, i)) {
C2 += (p[i] > H2);
H2 = max(H2, p[i]);
ans[i] = '1';
} else {
printf("-1\n");
return 0;
}
}
printf("%s\n", ans + 1);
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p03235 | C++ | Runtime Error | #ifndef BZ
#pragma GCC optimize "Ofast"
#endif
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;
const int MAXN = 200228;
int a[MAXN];
bool must[MAXN];
int mustcnt[MAXN];
int bef[MAXN][2];
int n;
int fn;
struct Fen {
Fen() { fill(begin(fen), end(fen), -MAXN); }
int fen[MAXN];
vector<pair<int, int>> changes;
void upd(int x, int y) {
for (int i = x; i <= fn + 1; i |= (i + 1)) {
changes.emplace_back(i, fen[i]);
fen[i] = max(fen[i], y);
}
}
int gt(int x) {
int ans = -MAXN;
for (int i = x + 1; --i >= 0; i &= (i + 1)) {
ans = max(ans, fen[i]);
}
return ans;
}
void pop(int sz) {
while (changes.size() > sz) {
fen[changes.back().first] = changes.back().second;
changes.pop_back();
}
}
};
Fen fens[2];
bool good(int id, int x, int y, int d) {
if (fens[0].gt(x) + d - mustcnt[id] < 0 ||
fens[0].gt(y) - d - mustcnt[id] < 0) {
return false;
}
if (mustcnt[id] == d % 2) {
return true;
}
return fens[1].gt(x) + d - mustcnt[id] >= 0 ||
fens[1].gt(y) - d - mustcnt[id] >= 0;
}
int main() {
#ifdef BZ
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout.setf(ios::fixed);
cout.precision(20);
cin >> n;
fn = n + 2;
int cm = n + 2;
for (int i = 0; i < n; ++i) {
cin >> a[i];
a[i] = n + 1 - a[i];
must[i] = a[i] < cm;
cm = min(cm, a[i]);
}
fens[0].upd(0, 0);
for (int i = n - 1; i >= 0; --i) {
mustcnt[i] = mustcnt[i + 1] + must[i];
for (int j = 0; j < 2; ++j) {
bef[i][j] = fens[j].changes.size();
}
for (int j = 0; j < 2; ++j) {
for (int k = j; k < 2; ++k) {
int cur = fens[j].gt(a[i] - 1);
++cur;
cur += must[i];
if (must[i] && k > j) {
continue;
}
fens[k].upd(a[i], cur);
}
}
}
if (!good(0, n, n, 0)) {
cout << "-1\n";
return 0;
}
int x = fn + 2, y = fn + 2, d = 0;
for (int i = 0; i < n; ++i) {
int id = i + 1;
for (int j = 0; j < 2; ++j) {
fens[j].pop(bef[i][j]);
}
{
int nx = x, ny = y, nd = d;
if (a[i] < nx) {
nx = a[i];
++nd;
}
if (good(id, nx, ny, nd)) {
cout << 0;
x = nx;
y = ny;
d = nd;
continue;
}
}
{
int nx = x, ny = y, nd = d;
if (a[i] < ny) {
ny = a[i];
--nd;
}
if (good(id, nx, ny, nd)) {
cout << 1;
x = nx;
y = ny;
d = nd;
continue;
}
}
assert(false);
}
assert(d == 0);
cout << "\n";
}
| #ifndef BZ
#pragma GCC optimize "Ofast"
#endif
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;
const int MAXN = 200228;
int a[MAXN];
bool must[MAXN];
int mustcnt[MAXN];
int bef[MAXN][2];
int n;
int fn;
struct Fen {
Fen() { fill(begin(fen), end(fen), -MAXN); }
int fen[MAXN];
vector<pair<int, int>> changes;
void upd(int x, int y) {
for (int i = x; i <= fn + 1; i |= (i + 1)) {
changes.emplace_back(i, fen[i]);
fen[i] = max(fen[i], y);
}
}
int gt(int x) {
int ans = -MAXN;
for (int i = x + 1; --i >= 0; i &= (i + 1)) {
ans = max(ans, fen[i]);
}
return ans;
}
void pop(int sz) {
while (changes.size() > sz) {
fen[changes.back().first] = changes.back().second;
changes.pop_back();
}
}
};
Fen fens[2];
bool good(int id, int x, int y, int d) {
if (fens[0].gt(x) + d - mustcnt[id] < 0 ||
fens[0].gt(y) - d - mustcnt[id] < 0) {
return false;
}
if (mustcnt[id] % 2 == d % 2) {
return true;
}
return fens[1].gt(x) + d - mustcnt[id] >= 0 ||
fens[1].gt(y) - d - mustcnt[id] >= 0;
}
int main() {
#ifdef BZ
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout.setf(ios::fixed);
cout.precision(20);
cin >> n;
fn = n + 2;
int cm = n + 2;
for (int i = 0; i < n; ++i) {
cin >> a[i];
a[i] = n + 1 - a[i];
must[i] = a[i] < cm;
cm = min(cm, a[i]);
}
fens[0].upd(0, 0);
for (int i = n - 1; i >= 0; --i) {
mustcnt[i] = mustcnt[i + 1] + must[i];
for (int j = 0; j < 2; ++j) {
bef[i][j] = fens[j].changes.size();
}
for (int j = 0; j < 2; ++j) {
for (int k = j; k < 2; ++k) {
int cur = fens[j].gt(a[i] - 1);
++cur;
cur += must[i];
if (must[i] && k > j) {
continue;
}
fens[k].upd(a[i], cur);
}
}
}
if (!good(0, n, n, 0)) {
cout << "-1\n";
return 0;
}
int x = fn + 2, y = fn + 2, d = 0;
for (int i = 0; i < n; ++i) {
int id = i + 1;
for (int j = 0; j < 2; ++j) {
fens[j].pop(bef[i][j]);
}
{
int nx = x, ny = y, nd = d;
if (a[i] < nx) {
nx = a[i];
++nd;
}
if (good(id, nx, ny, nd)) {
cout << 0;
x = nx;
y = ny;
d = nd;
continue;
}
}
{
int nx = x, ny = y, nd = d;
if (a[i] < ny) {
ny = a[i];
--nd;
}
if (good(id, nx, ny, nd)) {
cout << 1;
x = nx;
y = ny;
d = nd;
continue;
}
}
assert(false);
}
assert(d == 0);
cout << "\n";
}
| replace | 59 | 60 | 59 | 60 | 0 | |
p03235 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define LL long long
#define LD long double
using namespace std;
const int NN = 200000 + 117;
const int MM = 200000 + 117;
int read() {
int fl = 1, x;
char c;
for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
;
if (c == '-') {
fl = -1;
c = getchar();
}
for (x = 0; c >= '0' && c <= '9'; c = getchar())
x = (x << 3) + (x << 1) + c - '0';
return x * fl;
}
void open() {
freopen("a.in", "r", stdin);
// freopen("a.out","w",stdout);
}
void close() {
fclose(stdin);
fclose(stdout);
}
int m, n;
bool mark[NN] = {};
int suf[NN] = {};
struct seg {
int ev, od;
int s[2];
} t[20 * NN] = {};
int tcnt = 0;
int a[NN] = {};
int rt[NN] = {};
int op[NN] = {};
void push_up(int pos) {
int ls = t[pos].s[0];
int rs = t[pos].s[1];
t[pos].ev = max(t[ls].ev, t[rs].ev);
t[pos].od = max(t[ls].od, t[rs].od);
}
int build(int l, int r) {
int pos = ++tcnt;
if (l == r) {
t[pos].ev = 0;
t[pos].od = -1e9 + 1;
return pos;
}
int mid = (l + r) >> 1;
t[pos].s[0] = build(l, mid);
t[pos].s[1] = build(mid + 1, r);
push_up(pos);
return pos;
}
int find(int l, int r, int pos, int x, int kd) {
if (l >= x) {
if (kd)
return t[pos].od;
else
return t[pos].ev;
}
if (r < x)
return -1e9;
int mid = (l + r) >> 1;
int ret = find(l, mid, t[pos].s[0], x, kd);
ret = max(ret, find(mid + 1, r, t[pos].s[1], x, kd));
return ret;
}
int modify(int l, int r, int pos, int tar, int v1, int v2) {
int cur = ++tcnt;
if (l == r) {
t[cur].ev = v1;
t[cur].od = v2;
return cur;
}
int mid = (l + r) >> 1;
if (tar <= mid) {
t[cur].s[0] = modify(l, mid, t[pos].s[0], tar, v1, v2);
t[cur].s[1] = t[pos].s[1];
} else {
t[cur].s[0] = t[pos].s[0];
t[cur].s[1] = modify(mid + 1, r, t[pos].s[1], tar, v1, v2);
}
push_up(cur);
return cur;
}
bool chk(int h1, int c1, int h2, int c2, int len) {
int t = c1 - c2 + suf[len + 1];
if (t >= 0) {
int res = find(1, n + 1, rt[len + 1], h2 + 1, t & 1);
;
return res >= t;
} else
return false;
}
void preproc() {
rt[n + 1] = build(1, n + 1);
for (int i = n; i >= 1; --i) {
int ev = find(1, n + 1, rt[i + 1], a[i] + 1, 0);
int od = find(1, n + 1, rt[i + 1], a[i] + 1, 1);
ev += 1 + mark[i];
od += 1 + mark[i];
if (ev & 1)
swap(ev, od);
rt[i] = modify(1, n + 1, rt[i + 1], a[i], ev, od);
}
}
int main() {
// open();
n = read();
int pre = -1;
for (int i = 1; i <= n; ++i) {
a[i] = read();
if (a[i] > pre) {
pre = a[i];
mark[i] = 1;
}
}
for (int i = n; i >= 1; --i) {
if (mark[i])
suf[i] = suf[i + 1] + 1;
else
suf[i] = suf[i + 1];
}
preproc();
int pre1 = -1, pre2 = -1;
int pc1 = 0, pc2 = 0;
bool fail = 0;
for (int i = 1; i <= n; ++i) {
op[i] = 0;
int h1 = pre1, h2 = pre2, cnt1 = pc1, cnt2 = pc2;
if (a[i] > pre1) {
h1 = a[i];
++cnt1;
}
if (chk(h1, cnt1, h2, cnt2, i) || chk(h2, cnt2, h1, cnt1, i)) {
pre1 = h1, pre2 = h2, pc1 = cnt1, pc2 = cnt2;
continue;
}
op[i] = 1;
h1 = pre1, h2 = pre2, cnt1 = pc1, cnt2 = pc2;
if (a[i] > pre2) {
h2 = a[i];
++cnt2;
}
if (chk(h1, cnt1, h2, cnt2, i) || chk(h2, cnt2, h1, cnt1, i)) {
pre1 = h1, pre2 = h2, pc1 = cnt1, pc2 = cnt2;
continue;
}
fail = 1;
break;
}
if (fail) {
printf("-1\n");
} else {
for (int i = 1; i <= n; ++i) {
putchar('0' + op[i]);
}
putchar('\n');
}
close();
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define LL long long
#define LD long double
using namespace std;
const int NN = 200000 + 117;
const int MM = 200000 + 117;
int read() {
int fl = 1, x;
char c;
for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
;
if (c == '-') {
fl = -1;
c = getchar();
}
for (x = 0; c >= '0' && c <= '9'; c = getchar())
x = (x << 3) + (x << 1) + c - '0';
return x * fl;
}
void open() {
freopen("a.in", "r", stdin);
// freopen("a.out","w",stdout);
}
void close() {
fclose(stdin);
fclose(stdout);
}
int m, n;
bool mark[NN] = {};
int suf[NN] = {};
struct seg {
int ev, od;
int s[2];
} t[30 * NN] = {};
int tcnt = 0;
int a[NN] = {};
int rt[NN] = {};
int op[NN] = {};
void push_up(int pos) {
int ls = t[pos].s[0];
int rs = t[pos].s[1];
t[pos].ev = max(t[ls].ev, t[rs].ev);
t[pos].od = max(t[ls].od, t[rs].od);
}
int build(int l, int r) {
int pos = ++tcnt;
if (l == r) {
t[pos].ev = 0;
t[pos].od = -1e9 + 1;
return pos;
}
int mid = (l + r) >> 1;
t[pos].s[0] = build(l, mid);
t[pos].s[1] = build(mid + 1, r);
push_up(pos);
return pos;
}
int find(int l, int r, int pos, int x, int kd) {
if (l >= x) {
if (kd)
return t[pos].od;
else
return t[pos].ev;
}
if (r < x)
return -1e9;
int mid = (l + r) >> 1;
int ret = find(l, mid, t[pos].s[0], x, kd);
ret = max(ret, find(mid + 1, r, t[pos].s[1], x, kd));
return ret;
}
int modify(int l, int r, int pos, int tar, int v1, int v2) {
int cur = ++tcnt;
if (l == r) {
t[cur].ev = v1;
t[cur].od = v2;
return cur;
}
int mid = (l + r) >> 1;
if (tar <= mid) {
t[cur].s[0] = modify(l, mid, t[pos].s[0], tar, v1, v2);
t[cur].s[1] = t[pos].s[1];
} else {
t[cur].s[0] = t[pos].s[0];
t[cur].s[1] = modify(mid + 1, r, t[pos].s[1], tar, v1, v2);
}
push_up(cur);
return cur;
}
bool chk(int h1, int c1, int h2, int c2, int len) {
int t = c1 - c2 + suf[len + 1];
if (t >= 0) {
int res = find(1, n + 1, rt[len + 1], h2 + 1, t & 1);
;
return res >= t;
} else
return false;
}
void preproc() {
rt[n + 1] = build(1, n + 1);
for (int i = n; i >= 1; --i) {
int ev = find(1, n + 1, rt[i + 1], a[i] + 1, 0);
int od = find(1, n + 1, rt[i + 1], a[i] + 1, 1);
ev += 1 + mark[i];
od += 1 + mark[i];
if (ev & 1)
swap(ev, od);
rt[i] = modify(1, n + 1, rt[i + 1], a[i], ev, od);
}
}
int main() {
// open();
n = read();
int pre = -1;
for (int i = 1; i <= n; ++i) {
a[i] = read();
if (a[i] > pre) {
pre = a[i];
mark[i] = 1;
}
}
for (int i = n; i >= 1; --i) {
if (mark[i])
suf[i] = suf[i + 1] + 1;
else
suf[i] = suf[i + 1];
}
preproc();
int pre1 = -1, pre2 = -1;
int pc1 = 0, pc2 = 0;
bool fail = 0;
for (int i = 1; i <= n; ++i) {
op[i] = 0;
int h1 = pre1, h2 = pre2, cnt1 = pc1, cnt2 = pc2;
if (a[i] > pre1) {
h1 = a[i];
++cnt1;
}
if (chk(h1, cnt1, h2, cnt2, i) || chk(h2, cnt2, h1, cnt1, i)) {
pre1 = h1, pre2 = h2, pc1 = cnt1, pc2 = cnt2;
continue;
}
op[i] = 1;
h1 = pre1, h2 = pre2, cnt1 = pc1, cnt2 = pc2;
if (a[i] > pre2) {
h2 = a[i];
++cnt2;
}
if (chk(h1, cnt1, h2, cnt2, i) || chk(h2, cnt2, h1, cnt1, i)) {
pre1 = h1, pre2 = h2, pc1 = cnt1, pc2 = cnt2;
continue;
}
fail = 1;
break;
}
if (fail) {
printf("-1\n");
} else {
for (int i = 1; i <= n; ++i) {
putchar('0' + op[i]);
}
putchar('\n');
}
close();
return 0;
} | replace | 41 | 42 | 41 | 42 | 0 | |
p03235 | C++ | Runtime Error | #include <cstdio>
#include <vector>
#define N 700001
#include <cstring>
using namespace std;
vector<int> pans0[N], pans1[N];
int a[N], ans[N], ls1[N], ls2[N], rs1[N], rs2[N], hz[N], wei[N];
int f0l[N], f1l[N], f0r[N], f1r[N];
bool bz[N], used[N];
int X, Y, numX, numY, maxs, anss, newX, newY, n;
int max(int x, int y) {
if (x < y)
return y;
return x;
}
int min(int x, int y) {
if (x < y)
return x;
return y;
}
int find_ans1(int ma, int l, int r, int s) {
if (pans1[ma].size() >= 1)
while (pans1[ma][0] > 0 && used[pans1[ma][pans1[ma][0]]] == false)
pans1[ma][0]--;
if (l == r)
return pans1[ma][pans1[ma][0]];
int mid = (l + r) / 2;
int t1 = 0;
if (s <= mid)
t1 = find_ans1(ma * 2, l, mid, s);
else
t1 = find_ans1(ma * 2 + 1, mid + 1, r, s);
return max(t1, pans1[ma][pans1[ma][0]]);
}
int find_ans0(int ma, int l, int r, int s) {
if (pans0[ma].size() >= 1)
while (pans0[ma][0] > 0 && used[pans0[ma][pans0[ma][0]]] == false)
pans0[ma][0]--;
if (l == r)
return pans0[ma][pans0[ma][0]];
int mid = (l + r) / 2;
int t1 = 0;
if (s <= mid)
t1 = find_ans0(ma * 2, l, mid, s);
else
t1 = find_ans0(ma * 2 + 1, mid + 1, r, s);
return max(t1, pans0[ma][pans0[ma][0]]);
}
bool pd(int k, int p) {
int newX = X, newY = Y, p1 = numX, p2 = numY;
if (p == 0) {
if (a[k] > X)
p1++;
newX = max(a[k], X);
} else {
if (a[k] > Y)
p2++;
newY = max(a[k], Y);
}
// if (k>=n) return true;
if (k == n) {
if (p1 != p2)
return false;
return true;
}
int daijia = p1 - p2 + hz[k + 1], sp1;
if (daijia >= 0) {
if (daijia % 2 == 0) {
sp1 = find_ans0(1, 1, 2 * n, daijia);
if (sp1 > newY)
return true;
} else {
sp1 = find_ans1(1, 1, 2 * n, daijia);
if (sp1 > newY)
return true;
}
}
daijia = p2 - p1 + hz[k + 1];
if (daijia >= 0) {
if (daijia == 0)
return true;
if (daijia % 2 == 0) {
sp1 = find_ans0(1, 1, 2 * n, daijia);
if (sp1 > newX)
return true;
} else {
sp1 = find_ans1(1, 1, 2 * n, daijia);
if (sp1 > newX)
return true;
}
}
return false;
}
void update(int ma, int l, int r, int s, int l1, int r1, int l2, int r2) {
if (l == r) {
f0l[ma] = l2;
f0r[ma] = r2;
f1l[ma] = l1;
f1r[ma] = r1;
return;
}
int mid = (l + r) / 2;
if (s <= mid)
update(ma * 2, l, mid, s, l1, r1, l2, r2);
else
update(ma * 2 + 1, mid + 1, r, s, l1, r1, l2, r2);
f0l[ma] = min(f0l[ma * 2], f0l[ma * 2 + 1]);
f1l[ma] = min(f1l[ma * 2], f1l[ma * 2 + 1]);
f0r[ma] = max(f0r[ma * 2], f0r[ma * 2 + 1]);
f1r[ma] = max(f1r[ma * 2], f1r[ma * 2 + 1]);
}
int find_ans(int type, int ma, int l, int r, int l1, int r1) {
if (l == l1 && r == r1) {
if (type == 1)
return f1l[ma];
if (type == 2)
return f1r[ma];
if (type == 3)
return f0l[ma];
if (type == 4)
return f0r[ma];
}
int mid = (l + r) / 2;
if (r1 <= mid)
return find_ans(type, ma * 2, l, mid, l1, r1);
if (mid < l1)
return find_ans(type, ma * 2 + 1, mid + 1, r, l1, r1);
int s1 = find_ans(type, ma * 2, l, mid, l1, mid);
int s2 = find_ans(type, ma * 2 + 1, mid + 1, r, mid + 1, r1);
if (type == 1 || type == 3)
return min(s1, s2);
return max(s1, s2);
}
void update1(int ma, int l, int r, int s, int l1, int r1) {
if (l == l1 && r == r1) {
if (pans1[ma].size() == 0)
pans1[ma].resize(1);
pans1[ma][0]++;
pans1[ma].resize(pans1[ma][0] + 1);
pans1[ma][pans1[ma][0]] = s;
return;
}
int mid = (l + r) / 2;
if (r1 <= mid)
update1(ma * 2, l, mid, s, l1, r1);
else if (mid < l1)
update1(ma * 2 + 1, mid + 1, r, s, l1, r1);
else {
update1(ma * 2, l, mid, s, l1, mid);
update1(ma * 2 + 1, mid + 1, r, s, mid + 1, r1);
}
}
void update0(int ma, int l, int r, int s, int l1, int r1) {
if (l == l1 && r == r1) {
if (pans0[ma].size() == 0)
pans0[ma].resize(1);
pans0[ma][0]++;
pans0[ma].resize(pans0[ma][0] + 1);
pans0[ma][pans0[ma][0]] = s;
return;
}
int mid = (l + r) / 2;
if (r1 <= mid)
update0(ma * 2, l, mid, s, l1, r1);
else if (mid < l1)
update0(ma * 2 + 1, mid + 1, r, s, l1, r1);
else {
update0(ma * 2, l, mid, s, l1, mid);
update0(ma * 2 + 1, mid + 1, r, s, mid + 1, r1);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
int maxs = 0;
memset(bz, false, sizeof(bz));
for (int i = 1; i <= n; i++) {
maxs = max(maxs, a[i]);
if (a[i] == maxs)
bz[i] = true;
}
for (int i = 1; i < N; i++)
f0l[i] = f1l[i] = 1e9;
for (int i = 1; i < N; i++)
pans0[i].resize(1);
for (int i = 1; i < N; i++)
pans1[i].resize(1);
update(1, 1, n + 1, n + 1, 1e9, 0, 0, 0);
for (int i = n; i >= 1; i--) {
if (i == 3) {
n++;
n--;
}
if (bz[i]) {
ls1[i] = find_ans(1, 1, 1, n + 1, a[i], n + 1) + 2;
if (ls1[i] < 0)
ls1[i] = 1;
rs1[i] = find_ans(2, 1, 1, n + 1, a[i], n + 1) + 2;
if (rs1[i] < 0)
rs1[i] = 1;
} else {
ls1[i] = find_ans(3, 1, 1, n + 1, a[i], n + 1) + 1;
rs1[i] = find_ans(4, 1, 1, n + 1, a[i], n + 1) + 1;
ls1[i] = 1;
if (rs1[i] < 0)
rs1[i] = 1;
}
if (bz[i]) {
ls2[i] = find_ans(3, 1, 1, n + 1, a[i], n + 1) + 2;
rs2[i] = find_ans(4, 1, 1, n + 1, a[i], n + 1) + 2;
if (ls2[i] <= 0)
ls2[i] = 2;
if (rs2[i] <= 0)
rs2[i] = 2;
ls2[i] = 2;
} else {
ls2[i] = find_ans(1, 1, 1, n + 1, a[i], n + 1) + 1;
rs2[i] = find_ans(2, 1, 1, n + 1, a[i], n + 1) + 1;
if (ls2[i] <= 0)
ls2[i] = 2;
if (rs2[i] <= 0)
rs2[i] = 2;
}
if (ls1[i] > rs1[i])
ls1[i] = 1e9, rs1[i] = 0;
if (ls2[i] > rs2[i])
ls2[i] = 1e9, rs2[i] = 0;
update(1, 1, n + 1, a[i], ls1[i], rs1[i], ls2[i], rs2[i]);
}
hz[n + 1] = 0;
for (int i = n; i >= 1; i--)
if (bz[i])
hz[i] = hz[i + 1] + 1;
else
hz[i] = hz[i + 1];
// for (int i=1;i<=n;i++) update(1,1,n,i,a[i]);
X = 0, Y = 0, numX = 0, numY = 0;
for (int i = 1; i <= n; i++)
wei[a[i]] = i;
for (int i = 1; i <= n; i++)
if (ls1[wei[i]] != 1e9)
update1(1, 1, 2 * n, i, ls1[wei[i]], rs1[wei[i]]);
for (int i = 1; i <= n; i++)
if (ls2[wei[i]] != 1e9)
update0(1, 1, 2 * n, i, ls2[wei[i]], rs2[wei[i]]);
memset(used, true, sizeof(used));
for (int i = 1; i <= n; i++) {
if (i == 9) {
n++;
n--;
}
used[a[i]] = false;
if (pd(i, 0))
ans[i] = 0;
else if (pd(i, 1))
ans[i] = 1;
else {
printf("-1\n");
return 0;
}
if (ans[i] == 0) {
if (X < a[i])
numX++;
X = max(X, a[i]);
} else {
if (Y < a[i])
numY++;
Y = max(Y, a[i]);
}
}
for (int i = 1; i <= n; i++)
printf("%d", ans[i]);
} | #include <cstdio>
#include <vector>
#define N 3000001
#include <cstring>
using namespace std;
vector<int> pans0[N], pans1[N];
int a[N], ans[N], ls1[N], ls2[N], rs1[N], rs2[N], hz[N], wei[N];
int f0l[N], f1l[N], f0r[N], f1r[N];
bool bz[N], used[N];
int X, Y, numX, numY, maxs, anss, newX, newY, n;
int max(int x, int y) {
if (x < y)
return y;
return x;
}
int min(int x, int y) {
if (x < y)
return x;
return y;
}
int find_ans1(int ma, int l, int r, int s) {
if (pans1[ma].size() >= 1)
while (pans1[ma][0] > 0 && used[pans1[ma][pans1[ma][0]]] == false)
pans1[ma][0]--;
if (l == r)
return pans1[ma][pans1[ma][0]];
int mid = (l + r) / 2;
int t1 = 0;
if (s <= mid)
t1 = find_ans1(ma * 2, l, mid, s);
else
t1 = find_ans1(ma * 2 + 1, mid + 1, r, s);
return max(t1, pans1[ma][pans1[ma][0]]);
}
int find_ans0(int ma, int l, int r, int s) {
if (pans0[ma].size() >= 1)
while (pans0[ma][0] > 0 && used[pans0[ma][pans0[ma][0]]] == false)
pans0[ma][0]--;
if (l == r)
return pans0[ma][pans0[ma][0]];
int mid = (l + r) / 2;
int t1 = 0;
if (s <= mid)
t1 = find_ans0(ma * 2, l, mid, s);
else
t1 = find_ans0(ma * 2 + 1, mid + 1, r, s);
return max(t1, pans0[ma][pans0[ma][0]]);
}
bool pd(int k, int p) {
int newX = X, newY = Y, p1 = numX, p2 = numY;
if (p == 0) {
if (a[k] > X)
p1++;
newX = max(a[k], X);
} else {
if (a[k] > Y)
p2++;
newY = max(a[k], Y);
}
// if (k>=n) return true;
if (k == n) {
if (p1 != p2)
return false;
return true;
}
int daijia = p1 - p2 + hz[k + 1], sp1;
if (daijia >= 0) {
if (daijia % 2 == 0) {
sp1 = find_ans0(1, 1, 2 * n, daijia);
if (sp1 > newY)
return true;
} else {
sp1 = find_ans1(1, 1, 2 * n, daijia);
if (sp1 > newY)
return true;
}
}
daijia = p2 - p1 + hz[k + 1];
if (daijia >= 0) {
if (daijia == 0)
return true;
if (daijia % 2 == 0) {
sp1 = find_ans0(1, 1, 2 * n, daijia);
if (sp1 > newX)
return true;
} else {
sp1 = find_ans1(1, 1, 2 * n, daijia);
if (sp1 > newX)
return true;
}
}
return false;
}
void update(int ma, int l, int r, int s, int l1, int r1, int l2, int r2) {
if (l == r) {
f0l[ma] = l2;
f0r[ma] = r2;
f1l[ma] = l1;
f1r[ma] = r1;
return;
}
int mid = (l + r) / 2;
if (s <= mid)
update(ma * 2, l, mid, s, l1, r1, l2, r2);
else
update(ma * 2 + 1, mid + 1, r, s, l1, r1, l2, r2);
f0l[ma] = min(f0l[ma * 2], f0l[ma * 2 + 1]);
f1l[ma] = min(f1l[ma * 2], f1l[ma * 2 + 1]);
f0r[ma] = max(f0r[ma * 2], f0r[ma * 2 + 1]);
f1r[ma] = max(f1r[ma * 2], f1r[ma * 2 + 1]);
}
int find_ans(int type, int ma, int l, int r, int l1, int r1) {
if (l == l1 && r == r1) {
if (type == 1)
return f1l[ma];
if (type == 2)
return f1r[ma];
if (type == 3)
return f0l[ma];
if (type == 4)
return f0r[ma];
}
int mid = (l + r) / 2;
if (r1 <= mid)
return find_ans(type, ma * 2, l, mid, l1, r1);
if (mid < l1)
return find_ans(type, ma * 2 + 1, mid + 1, r, l1, r1);
int s1 = find_ans(type, ma * 2, l, mid, l1, mid);
int s2 = find_ans(type, ma * 2 + 1, mid + 1, r, mid + 1, r1);
if (type == 1 || type == 3)
return min(s1, s2);
return max(s1, s2);
}
void update1(int ma, int l, int r, int s, int l1, int r1) {
if (l == l1 && r == r1) {
if (pans1[ma].size() == 0)
pans1[ma].resize(1);
pans1[ma][0]++;
pans1[ma].resize(pans1[ma][0] + 1);
pans1[ma][pans1[ma][0]] = s;
return;
}
int mid = (l + r) / 2;
if (r1 <= mid)
update1(ma * 2, l, mid, s, l1, r1);
else if (mid < l1)
update1(ma * 2 + 1, mid + 1, r, s, l1, r1);
else {
update1(ma * 2, l, mid, s, l1, mid);
update1(ma * 2 + 1, mid + 1, r, s, mid + 1, r1);
}
}
void update0(int ma, int l, int r, int s, int l1, int r1) {
if (l == l1 && r == r1) {
if (pans0[ma].size() == 0)
pans0[ma].resize(1);
pans0[ma][0]++;
pans0[ma].resize(pans0[ma][0] + 1);
pans0[ma][pans0[ma][0]] = s;
return;
}
int mid = (l + r) / 2;
if (r1 <= mid)
update0(ma * 2, l, mid, s, l1, r1);
else if (mid < l1)
update0(ma * 2 + 1, mid + 1, r, s, l1, r1);
else {
update0(ma * 2, l, mid, s, l1, mid);
update0(ma * 2 + 1, mid + 1, r, s, mid + 1, r1);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
int maxs = 0;
memset(bz, false, sizeof(bz));
for (int i = 1; i <= n; i++) {
maxs = max(maxs, a[i]);
if (a[i] == maxs)
bz[i] = true;
}
for (int i = 1; i < N; i++)
f0l[i] = f1l[i] = 1e9;
for (int i = 1; i < N; i++)
pans0[i].resize(1);
for (int i = 1; i < N; i++)
pans1[i].resize(1);
update(1, 1, n + 1, n + 1, 1e9, 0, 0, 0);
for (int i = n; i >= 1; i--) {
if (i == 3) {
n++;
n--;
}
if (bz[i]) {
ls1[i] = find_ans(1, 1, 1, n + 1, a[i], n + 1) + 2;
if (ls1[i] < 0)
ls1[i] = 1;
rs1[i] = find_ans(2, 1, 1, n + 1, a[i], n + 1) + 2;
if (rs1[i] < 0)
rs1[i] = 1;
} else {
ls1[i] = find_ans(3, 1, 1, n + 1, a[i], n + 1) + 1;
rs1[i] = find_ans(4, 1, 1, n + 1, a[i], n + 1) + 1;
ls1[i] = 1;
if (rs1[i] < 0)
rs1[i] = 1;
}
if (bz[i]) {
ls2[i] = find_ans(3, 1, 1, n + 1, a[i], n + 1) + 2;
rs2[i] = find_ans(4, 1, 1, n + 1, a[i], n + 1) + 2;
if (ls2[i] <= 0)
ls2[i] = 2;
if (rs2[i] <= 0)
rs2[i] = 2;
ls2[i] = 2;
} else {
ls2[i] = find_ans(1, 1, 1, n + 1, a[i], n + 1) + 1;
rs2[i] = find_ans(2, 1, 1, n + 1, a[i], n + 1) + 1;
if (ls2[i] <= 0)
ls2[i] = 2;
if (rs2[i] <= 0)
rs2[i] = 2;
}
if (ls1[i] > rs1[i])
ls1[i] = 1e9, rs1[i] = 0;
if (ls2[i] > rs2[i])
ls2[i] = 1e9, rs2[i] = 0;
update(1, 1, n + 1, a[i], ls1[i], rs1[i], ls2[i], rs2[i]);
}
hz[n + 1] = 0;
for (int i = n; i >= 1; i--)
if (bz[i])
hz[i] = hz[i + 1] + 1;
else
hz[i] = hz[i + 1];
// for (int i=1;i<=n;i++) update(1,1,n,i,a[i]);
X = 0, Y = 0, numX = 0, numY = 0;
for (int i = 1; i <= n; i++)
wei[a[i]] = i;
for (int i = 1; i <= n; i++)
if (ls1[wei[i]] != 1e9)
update1(1, 1, 2 * n, i, ls1[wei[i]], rs1[wei[i]]);
for (int i = 1; i <= n; i++)
if (ls2[wei[i]] != 1e9)
update0(1, 1, 2 * n, i, ls2[wei[i]], rs2[wei[i]]);
memset(used, true, sizeof(used));
for (int i = 1; i <= n; i++) {
if (i == 9) {
n++;
n--;
}
used[a[i]] = false;
if (pd(i, 0))
ans[i] = 0;
else if (pd(i, 1))
ans[i] = 1;
else {
printf("-1\n");
return 0;
}
if (ans[i] == 0) {
if (X < a[i])
numX++;
X = max(X, a[i]);
} else {
if (Y < a[i])
numY++;
Y = max(Y, a[i]);
}
}
for (int i = 1; i <= n; i++)
printf("%d", ans[i]);
} | replace | 2 | 3 | 2 | 3 | -6 | terminate called after throwing an instance of 'St9bad_alloc'
what(): std::bad_alloc
|
p03235 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
#define mod 998244353
using namespace std;
typedef pair<int, int> pii;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
inline int read() {
int x = 0;
char c = getchar();
while (!isdigit(c))
c = getchar();
while (isdigit(c))
x = (x << 1) + (x << 3) + c - '0', c = getchar();
return x;
}
inline void write(int x) {
if (!x) {
ptc('0');
return;
}
int dg[20], len = 0;
while (x)
dg[len++] = x % 10, x /= 10;
while (len--)
ptc(dg[len] + '0');
}
inline void writeln(int x) {
write(x);
ptc('\n');
}
inline int add(int x, int y) {
x += y;
if (x >= mod)
x -= mod;
return x;
}
inline int sub(int x, int y) {
x -= y;
if (x < 0)
x += mod;
return x;
}
inline int qpow(int x, int y) {
int res = 1;
while (y) {
if (y & 1)
res = 1ll * res * x % mod;
x = 1ll * x * x % mod;
y >>= 1;
}
return res;
}
const int N = 1e5 + 10;
int n, a[N], premax[N], sufsumpremaxcnt[N];
struct Node {
int maxn, ls, rs;
} tr[N * 50];
int tcnt;
struct Segment_Tree {
int rt[N];
void up(int x) {
if (!tr[x].ls)
tr[x].maxn = tr[tr[x].rs].maxn;
else if (!tr[x].rs)
tr[x].maxn = tr[tr[x].ls].maxn;
else
tr[x].maxn = max(tr[tr[x].ls].maxn, tr[tr[x].rs].maxn);
}
void insert(int &x, int prex, int l, int r, int pos, int v) {
x = ++tcnt;
if (l == r) {
tr[x].maxn = v;
return;
}
int mid = l + r >> 1;
if (pos <= mid) {
tr[x].rs = tr[prex].rs;
insert(tr[x].ls, tr[prex].ls, l, mid, pos, v);
} else {
tr[x].ls = tr[prex].ls;
insert(tr[x].rs, tr[prex].rs, mid + 1, r, pos, v);
}
up(x);
}
int query(int x, int l, int r, int ql, int qr) {
if (!x || ql > qr)
return 0;
if (ql <= l && r <= qr)
return tr[x].maxn;
int mid = l + r >> 1, res = 0;
if (ql <= mid)
res = max(res, query(tr[x].ls, l, mid, ql, qr));
if (mid < qr)
res = max(res, query(tr[x].rs, mid + 1, r, ql, qr));
return res;
}
} T[2];
int s[2][N], maxn[2][N], len[2], sum[2];
int res[N];
int check(int id, int pos) { //[pos , n]
int need = sum[id] - sum[id ^ 1] + sufsumpremaxcnt[pos];
if (need < 0)
return 0;
int most = T[need & 1].query(T[need & 1].rt[pos], 1, n,
maxn[id ^ 1][len[id ^ 1]] + 1, n);
return most >= need;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
premax[i] = max(premax[i - 1], a[i]);
}
for (int i = n; i >= 1; i--) {
sufsumpremaxcnt[i] = sufsumpremaxcnt[i + 1] + (premax[i] == a[i]);
}
for (int i = n; i >= 1; i--) {
int d0max = T[0].query(T[0].rt[i + 1], 1, n, a[i] + 1, n),
d1max = T[1].query(T[1].rt[i + 1], 1, n, a[i] + 1, n);
if (premax[i] == a[i]) {
T[0].insert(T[0].rt[i], T[0].rt[i + 1], 1, n, a[i], d0max + 2);
if (d1max)
T[1].insert(T[1].rt[i], T[1].rt[i + 1], 1, n, a[i], d1max + 2);
else
T[1].rt[i] = T[1].rt[i + 1];
} else {
T[1].insert(T[1].rt[i], T[1].rt[i + 1], 1, n, a[i], d0max + 1);
if (d1max)
T[0].insert(T[0].rt[i], T[0].rt[i + 1], 1, n, a[i], d1max + 1);
else
T[0].rt[i] = T[0].rt[i + 1];
}
/*
printf("This is %d [%d %d]\n",i,d0max,d1max);
printf("ou:\n");
for (int j = 1;j <= n;j++) printf("%d
",T[0].query(T[0].rt[i],1,n,j,j));enter; printf("ji:\n"); for (int j = 1;j
<= n;j++) printf("%d ",T[1].query(T[1].rt[i],1,n,j,j));enter;*/
}
memset(res, -1, sizeof res);
for (int i = 1; i <= n; i++) {
for (int d = 0; d < 2; d++) {
s[d][++len[d]] = a[i];
maxn[d][len[d]] = max(maxn[d][len[d] - 1], a[i]);
sum[d] += maxn[d][len[d]] == s[d][len[d]];
if (check(0, i + 1)) {
res[i] = d;
break;
}
if (check(1, i + 1)) {
res[i] = d;
break;
}
sum[d] -= maxn[d][len[d]] == s[d][len[d]];
--len[d];
}
if (res[i] == -1)
return puts("-1"), 0;
}
for (int i = 1; i <= n; i++)
printf("%d", res[i]);
return 0;
}
| #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
#define mod 998244353
using namespace std;
typedef pair<int, int> pii;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
inline int read() {
int x = 0;
char c = getchar();
while (!isdigit(c))
c = getchar();
while (isdigit(c))
x = (x << 1) + (x << 3) + c - '0', c = getchar();
return x;
}
inline void write(int x) {
if (!x) {
ptc('0');
return;
}
int dg[20], len = 0;
while (x)
dg[len++] = x % 10, x /= 10;
while (len--)
ptc(dg[len] + '0');
}
inline void writeln(int x) {
write(x);
ptc('\n');
}
inline int add(int x, int y) {
x += y;
if (x >= mod)
x -= mod;
return x;
}
inline int sub(int x, int y) {
x -= y;
if (x < 0)
x += mod;
return x;
}
inline int qpow(int x, int y) {
int res = 1;
while (y) {
if (y & 1)
res = 1ll * res * x % mod;
x = 1ll * x * x % mod;
y >>= 1;
}
return res;
}
const int N = 2e5 + 10;
int n, a[N], premax[N], sufsumpremaxcnt[N];
struct Node {
int maxn, ls, rs;
} tr[N * 50];
int tcnt;
struct Segment_Tree {
int rt[N];
void up(int x) {
if (!tr[x].ls)
tr[x].maxn = tr[tr[x].rs].maxn;
else if (!tr[x].rs)
tr[x].maxn = tr[tr[x].ls].maxn;
else
tr[x].maxn = max(tr[tr[x].ls].maxn, tr[tr[x].rs].maxn);
}
void insert(int &x, int prex, int l, int r, int pos, int v) {
x = ++tcnt;
if (l == r) {
tr[x].maxn = v;
return;
}
int mid = l + r >> 1;
if (pos <= mid) {
tr[x].rs = tr[prex].rs;
insert(tr[x].ls, tr[prex].ls, l, mid, pos, v);
} else {
tr[x].ls = tr[prex].ls;
insert(tr[x].rs, tr[prex].rs, mid + 1, r, pos, v);
}
up(x);
}
int query(int x, int l, int r, int ql, int qr) {
if (!x || ql > qr)
return 0;
if (ql <= l && r <= qr)
return tr[x].maxn;
int mid = l + r >> 1, res = 0;
if (ql <= mid)
res = max(res, query(tr[x].ls, l, mid, ql, qr));
if (mid < qr)
res = max(res, query(tr[x].rs, mid + 1, r, ql, qr));
return res;
}
} T[2];
int s[2][N], maxn[2][N], len[2], sum[2];
int res[N];
int check(int id, int pos) { //[pos , n]
int need = sum[id] - sum[id ^ 1] + sufsumpremaxcnt[pos];
if (need < 0)
return 0;
int most = T[need & 1].query(T[need & 1].rt[pos], 1, n,
maxn[id ^ 1][len[id ^ 1]] + 1, n);
return most >= need;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
premax[i] = max(premax[i - 1], a[i]);
}
for (int i = n; i >= 1; i--) {
sufsumpremaxcnt[i] = sufsumpremaxcnt[i + 1] + (premax[i] == a[i]);
}
for (int i = n; i >= 1; i--) {
int d0max = T[0].query(T[0].rt[i + 1], 1, n, a[i] + 1, n),
d1max = T[1].query(T[1].rt[i + 1], 1, n, a[i] + 1, n);
if (premax[i] == a[i]) {
T[0].insert(T[0].rt[i], T[0].rt[i + 1], 1, n, a[i], d0max + 2);
if (d1max)
T[1].insert(T[1].rt[i], T[1].rt[i + 1], 1, n, a[i], d1max + 2);
else
T[1].rt[i] = T[1].rt[i + 1];
} else {
T[1].insert(T[1].rt[i], T[1].rt[i + 1], 1, n, a[i], d0max + 1);
if (d1max)
T[0].insert(T[0].rt[i], T[0].rt[i + 1], 1, n, a[i], d1max + 1);
else
T[0].rt[i] = T[0].rt[i + 1];
}
/*
printf("This is %d [%d %d]\n",i,d0max,d1max);
printf("ou:\n");
for (int j = 1;j <= n;j++) printf("%d
",T[0].query(T[0].rt[i],1,n,j,j));enter; printf("ji:\n"); for (int j = 1;j
<= n;j++) printf("%d ",T[1].query(T[1].rt[i],1,n,j,j));enter;*/
}
memset(res, -1, sizeof res);
for (int i = 1; i <= n; i++) {
for (int d = 0; d < 2; d++) {
s[d][++len[d]] = a[i];
maxn[d][len[d]] = max(maxn[d][len[d] - 1], a[i]);
sum[d] += maxn[d][len[d]] == s[d][len[d]];
if (check(0, i + 1)) {
res[i] = d;
break;
}
if (check(1, i + 1)) {
res[i] = d;
break;
}
sum[d] -= maxn[d][len[d]] == s[d][len[d]];
--len[d];
}
if (res[i] == -1)
return puts("-1"), 0;
}
for (int i = 1; i <= n; i++)
printf("%d", res[i]);
return 0;
}
| replace | 59 | 60 | 59 | 60 | 0 | |
p03235 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int, int>
#define mk(x, y) make_pair(x, y)
#define fir first
#define sec second
#define Rep(x, y, z) for (int x = y; x <= z; x++)
#define Red(x, y, z) for (int x = y; x >= z; x--)
using namespace std;
const int MAXN = 1e5 + 5;
char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;
int ny;
inline char gc() {
return pp1 == pp2 &&
(pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2)
? EOF
: *pp1++;
}
// inline char gc(){return getchar();}
inline int read() {
int x = 0;
for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;)
if (nc == 45)
ny = -1;
if (nc < 0)
return nc;
for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF;
x = (x << 3) + (x << 1) + (nc ^ 48))
;
return x * ny;
}
int n, a[MAXN], val[MAXN], cnt[MAXN], Mx;
char s[MAXN];
struct SegTree {
#define ls x << 1
#define rs x << 1 | 1
int Mx[MAXN << 2];
inline void pushup(int x) { Mx[x] = max(Mx[ls], Mx[rs]); }
void Change(int x, int l, int r, int p, int v) {
if (l == r) {
Mx[x] = v;
return;
}
int mid = l + r >> 1;
if (p <= mid)
Change(ls, l, mid, p, v);
else
Change(rs, mid + 1, r, p, v);
pushup(x);
}
int Ask(int x, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr)
return Mx[x];
int mid = l + r >> 1;
if (qr <= mid)
return Ask(ls, l, mid, ql, qr);
else if (ql > mid)
return Ask(rs, mid + 1, r, ql, qr);
else
return max(Ask(ls, l, mid, ql, mid), Ask(rs, mid + 1, r, mid + 1, qr));
}
void Build(int x, int l, int r) {
Mx[x] = 1 - 1e9;
if (l == r)
return;
int mid = l + r >> 1;
Build(ls, l, mid), Build(rs, mid + 1, r);
}
} Odd, Even;
inline bool chk(int mx, int Q) {
if (Q < 0)
return 0;
return Q & 1 ? Odd.Ask(1, 1, n, mx, n) >= Q : Even.Ask(1, 1, n, mx, n) >= Q;
}
int main() {
n = read();
Rep(i, 1, n) a[i] = read(), a[i] > Mx ? Mx = a[i], val[i] = 2 : val[i] = 1;
Odd.Build(1, 1, n);
Red(i, n, 1) {
int Mx1 = Odd.Ask(1, 1, n, a[i], n), Mx0 = Even.Ask(1, 1, n, a[i], n);
if (val[i] == 1)
Odd.Change(1, 1, n, a[i], Mx0 + 1), Even.Change(1, 1, n, a[i], Mx1 + 1);
else
Odd.Change(1, 1, n, a[i], Mx1 + 2), Even.Change(1, 1, n, a[i], Mx0 + 2);
}
Red(i, n, 1) cnt[i] = cnt[i + 1] + val[i] - 1;
int cntX = 0, cntY = 0, mxX = 0, mxY = 0;
Rep(i, 1, n) {
Odd.Change(1, 1, n, a[i], 1 - 1e9), Even.Change(1, 1, n, a[i], 0);
if (chk(mxY, cntX + cnt[i + 1] - cntY + (a[i] > mxX)))
s[i] = '0', cntX += a[i] > mxX, mxX = max(mxX, a[i]);
else if (chk(max(mxX, a[i]), cntY + cnt[i + 1] - cntX - (a[i] > mxX)))
s[i] = '0', cntX += a[i] > mxX, mxX = max(mxX, a[i]);
else
s[i] = '1', cntY += a[i] > mxY, mxY = max(mxY, a[i]);
}
if (cntX == cntY)
cout << s + 1 << '\n';
else
puts("-1");
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int, int>
#define mk(x, y) make_pair(x, y)
#define fir first
#define sec second
#define Rep(x, y, z) for (int x = y; x <= z; x++)
#define Red(x, y, z) for (int x = y; x >= z; x--)
using namespace std;
const int MAXN = 2e5 + 5;
char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;
int ny;
inline char gc() {
return pp1 == pp2 &&
(pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2)
? EOF
: *pp1++;
}
// inline char gc(){return getchar();}
inline int read() {
int x = 0;
for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;)
if (nc == 45)
ny = -1;
if (nc < 0)
return nc;
for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF;
x = (x << 3) + (x << 1) + (nc ^ 48))
;
return x * ny;
}
int n, a[MAXN], val[MAXN], cnt[MAXN], Mx;
char s[MAXN];
struct SegTree {
#define ls x << 1
#define rs x << 1 | 1
int Mx[MAXN << 2];
inline void pushup(int x) { Mx[x] = max(Mx[ls], Mx[rs]); }
void Change(int x, int l, int r, int p, int v) {
if (l == r) {
Mx[x] = v;
return;
}
int mid = l + r >> 1;
if (p <= mid)
Change(ls, l, mid, p, v);
else
Change(rs, mid + 1, r, p, v);
pushup(x);
}
int Ask(int x, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr)
return Mx[x];
int mid = l + r >> 1;
if (qr <= mid)
return Ask(ls, l, mid, ql, qr);
else if (ql > mid)
return Ask(rs, mid + 1, r, ql, qr);
else
return max(Ask(ls, l, mid, ql, mid), Ask(rs, mid + 1, r, mid + 1, qr));
}
void Build(int x, int l, int r) {
Mx[x] = 1 - 1e9;
if (l == r)
return;
int mid = l + r >> 1;
Build(ls, l, mid), Build(rs, mid + 1, r);
}
} Odd, Even;
inline bool chk(int mx, int Q) {
if (Q < 0)
return 0;
return Q & 1 ? Odd.Ask(1, 1, n, mx, n) >= Q : Even.Ask(1, 1, n, mx, n) >= Q;
}
int main() {
n = read();
Rep(i, 1, n) a[i] = read(), a[i] > Mx ? Mx = a[i], val[i] = 2 : val[i] = 1;
Odd.Build(1, 1, n);
Red(i, n, 1) {
int Mx1 = Odd.Ask(1, 1, n, a[i], n), Mx0 = Even.Ask(1, 1, n, a[i], n);
if (val[i] == 1)
Odd.Change(1, 1, n, a[i], Mx0 + 1), Even.Change(1, 1, n, a[i], Mx1 + 1);
else
Odd.Change(1, 1, n, a[i], Mx1 + 2), Even.Change(1, 1, n, a[i], Mx0 + 2);
}
Red(i, n, 1) cnt[i] = cnt[i + 1] + val[i] - 1;
int cntX = 0, cntY = 0, mxX = 0, mxY = 0;
Rep(i, 1, n) {
Odd.Change(1, 1, n, a[i], 1 - 1e9), Even.Change(1, 1, n, a[i], 0);
if (chk(mxY, cntX + cnt[i + 1] - cntY + (a[i] > mxX)))
s[i] = '0', cntX += a[i] > mxX, mxX = max(mxX, a[i]);
else if (chk(max(mxX, a[i]), cntY + cnt[i + 1] - cntX - (a[i] > mxX)))
s[i] = '0', cntX += a[i] > mxX, mxX = max(mxX, a[i]);
else
s[i] = '1', cntY += a[i] > mxY, mxY = max(mxY, a[i]);
}
if (cntX == cntY)
cout << s + 1 << '\n';
else
puts("-1");
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p03235 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n;
int nu[200200];
struct SEG {
int ma[200200];
void build(int rt, int l, int r) {
ma[rt] = -inf;
if (l == r)
return;
int mid = (l + r) / 2;
build(rt * 2, l, mid);
build(rt * 2 + 1, mid + 1, r);
}
void change(int rt, int l, int r, int p, int v) {
if (l == r) {
ma[rt] = v;
return;
}
int mid = (l + r) / 2;
if (mid >= p)
change(rt * 2, l, mid, p, v);
else
change(rt * 2 + 1, mid + 1, r, p, v);
ma[rt] = max(ma[rt * 2], ma[rt * 2 + 1]);
}
int query(int rt, int l, int r, int st, int ed) {
if (l > ed || r < st)
return -inf;
if (l >= st && r <= ed)
return ma[rt];
int mid = (l + r) / 2;
return max(query(rt * 2, l, mid, st, ed),
query(rt * 2 + 1, mid + 1, r, st, ed));
}
} seg[2];
int val[200200];
int cnt[200200];
char ans[200200];
bool check(int v, int c) {
if (c < 0)
return 0;
return seg[c & 1].query(1, 1, n, v, n) >= c;
}
int main() {
scanf("%d", &n);
int mx = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", &nu[i]);
val[i] = 1;
if (nu[i] > mx)
val[i]++, mx = nu[i];
}
seg[1].build(1, 1, n);
int m0, m1;
for (int i = n; i; --i) {
cnt[i] = cnt[i + 1] + val[i] - 1;
m0 = seg[0].query(1, 1, n, nu[i], n);
m1 = seg[1].query(1, 1, n, nu[i], n);
if (val[i] == 2) {
seg[0].change(1, 1, n, nu[i], m0 + 2);
seg[1].change(1, 1, n, nu[i], m1 + 2);
} else {
seg[0].change(1, 1, n, nu[i], m1 + 1);
seg[1].change(1, 1, n, nu[i], m0 + 1);
}
}
int lx = 0, ly = 0;
mx = 0;
int my = 0;
for (int i = 1; i <= n; ++i) {
seg[0].change(1, 1, n, nu[i], 0);
seg[1].change(1, 1, n, nu[i], -inf);
if (check(my, lx + (nu[i] > mx) + cnt[i + 1] - ly))
ans[i] = '0';
else if (check(max(mx, nu[i]), ly + cnt[i + 1] - lx - (nu[i] > mx)))
ans[i] = '0';
else
ans[i] = '1';
if (ans[i] == '0')
lx += (nu[i] > mx), mx = max(mx, nu[i]);
else
ly += (nu[i] > my), my = max(my, nu[i]);
}
if (lx != ly) {
puts("-1");
return 0;
}
printf("%s\n", ans + 1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n;
int nu[200200];
struct SEG {
int ma[2000200];
void build(int rt, int l, int r) {
ma[rt] = -inf;
if (l == r)
return;
int mid = (l + r) / 2;
build(rt * 2, l, mid);
build(rt * 2 + 1, mid + 1, r);
}
void change(int rt, int l, int r, int p, int v) {
if (l == r) {
ma[rt] = v;
return;
}
int mid = (l + r) / 2;
if (mid >= p)
change(rt * 2, l, mid, p, v);
else
change(rt * 2 + 1, mid + 1, r, p, v);
ma[rt] = max(ma[rt * 2], ma[rt * 2 + 1]);
}
int query(int rt, int l, int r, int st, int ed) {
if (l > ed || r < st)
return -inf;
if (l >= st && r <= ed)
return ma[rt];
int mid = (l + r) / 2;
return max(query(rt * 2, l, mid, st, ed),
query(rt * 2 + 1, mid + 1, r, st, ed));
}
} seg[2];
int val[200200];
int cnt[200200];
char ans[200200];
bool check(int v, int c) {
if (c < 0)
return 0;
return seg[c & 1].query(1, 1, n, v, n) >= c;
}
int main() {
scanf("%d", &n);
int mx = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", &nu[i]);
val[i] = 1;
if (nu[i] > mx)
val[i]++, mx = nu[i];
}
seg[1].build(1, 1, n);
int m0, m1;
for (int i = n; i; --i) {
cnt[i] = cnt[i + 1] + val[i] - 1;
m0 = seg[0].query(1, 1, n, nu[i], n);
m1 = seg[1].query(1, 1, n, nu[i], n);
if (val[i] == 2) {
seg[0].change(1, 1, n, nu[i], m0 + 2);
seg[1].change(1, 1, n, nu[i], m1 + 2);
} else {
seg[0].change(1, 1, n, nu[i], m1 + 1);
seg[1].change(1, 1, n, nu[i], m0 + 1);
}
}
int lx = 0, ly = 0;
mx = 0;
int my = 0;
for (int i = 1; i <= n; ++i) {
seg[0].change(1, 1, n, nu[i], 0);
seg[1].change(1, 1, n, nu[i], -inf);
if (check(my, lx + (nu[i] > mx) + cnt[i + 1] - ly))
ans[i] = '0';
else if (check(max(mx, nu[i]), ly + cnt[i + 1] - lx - (nu[i] > mx)))
ans[i] = '0';
else
ans[i] = '1';
if (ans[i] == '0')
lx += (nu[i] > mx), mx = max(mx, nu[i]);
else
ly += (nu[i] > my), my = max(my, nu[i]);
}
if (lx != ly) {
puts("-1");
return 0;
}
printf("%s\n", ans + 1);
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03236 | 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とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう?
#define N 514
string ma[N];
int dp[N][N]; // どこまで戻れるか
int mx[N][N], mn[N][N]; // ある層への最高・最低着地点(毎回計算する)
lint num[N], sum[N];
int main() {
lint out = 0;
int n;
cin >> n;
rep(i, n) cin >> ma[i];
rep(i, n) rep(j, n) {
dp[i][j] = N * 2;
if (ma[i][j] == '#')
continue;
dp[i][j] = i + j;
if (i > 0)
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
if (j > 0)
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
}
for (int i = n * 2 - 2; i >= 0; i--) {
// cout<<i<<endl;
rep(j, n + 5) rep(k, n + 5) mx[j][k] = -N, mn[j][k] = N;
for (int j = n - 1; j >= 0; j--)
for (int k = n - 1; k >= 0; k--) {
if (j + k == i)
mx[j][k] = mn[j][k] = j;
if (j + k < i) {
if (ma[j][k] != '#') {
if (j < n - 1)
mx[j][k] = max(mx[j][k], mx[j + 1][k]),
mn[j][k] = min(mn[j][k], mn[j + 1][k]);
if (k < n - 1)
mx[j][k] = max(mx[j][k], mx[j][k + 1]),
mn[j][k] = min(mn[j][k], mn[j][k + 1]);
}
}
// cout<<i<<j<<k<<mx[j][k]<<mn[j][k]<<endl;
}
for (int j = i - 1; j >= 0; j--) {
memset(num, 0, sizeof(num));
memset(sum, 0, sizeof(sum));
rep(k, n) {
int l = i - k;
if (l >= 0 && l < n && dp[k][l] <= j && ma[k][l] != '#')
num[k] = (ma[k][l] - '0');
sum[k + 1] = sum[k] + num[k];
}
rep(k, n) {
int l = j - k;
if (l >= 0 && l < n && mx[k][l] >= mn[k][l] && ma[k][l] != '#') {
// cout<<i<<' '<<k<<' '<<l<<' '<<mx[k][l]<<' '<<mn[k][l]<<'
// '<<(sum[mx[k][l]+1]-sum[mn[k][l]])<<endl;
out += (ma[k][l] - '0') * (sum[mx[k][l] + 1] - sum[mn[k][l]]);
}
}
}
}
cout << out << 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とかかもしれないし、重要な制約・条件を見落としているかも
// とりあえずサンプルを読んでから解法を考えよう?
#define N 514
string ma[N];
int dp[N][N]; // どこまで戻れるか
int mx[N][N], mn[N][N]; // ある層への最高・最低着地点(毎回計算する)
lint num[N], sum[N];
int main() {
lint out = 0;
int n;
cin >> n;
rep(i, n) cin >> ma[i];
rep(i, n) rep(j, n) {
dp[i][j] = N * 2;
if (ma[i][j] == '#')
continue;
dp[i][j] = i + j;
if (i > 0)
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
if (j > 0)
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
}
for (int i = n * 2 - 2; i >= 0; i--) {
// cout<<i<<endl;
rep(j, n + 5) rep(k, min(n, i - j) + 5) mx[j][k] = -N, mn[j][k] = N;
for (int j = n - 1; j >= 0; j--)
for (int k = n - 1; k >= 0; k--) {
if (j + k == i)
mx[j][k] = mn[j][k] = j;
if (j + k < i) {
if (ma[j][k] != '#') {
if (j < n - 1)
mx[j][k] = max(mx[j][k], mx[j + 1][k]),
mn[j][k] = min(mn[j][k], mn[j + 1][k]);
if (k < n - 1)
mx[j][k] = max(mx[j][k], mx[j][k + 1]),
mn[j][k] = min(mn[j][k], mn[j][k + 1]);
}
}
// cout<<i<<j<<k<<mx[j][k]<<mn[j][k]<<endl;
}
for (int j = i - 1; j >= 0; j--) {
memset(num, 0, sizeof(num));
memset(sum, 0, sizeof(sum));
rep(k, n) {
int l = i - k;
if (l >= 0 && l < n && dp[k][l] <= j && ma[k][l] != '#')
num[k] = (ma[k][l] - '0');
sum[k + 1] = sum[k] + num[k];
}
rep(k, n) {
int l = j - k;
if (l >= 0 && l < n && mx[k][l] >= mn[k][l] && ma[k][l] != '#') {
// cout<<i<<' '<<k<<' '<<l<<' '<<mx[k][l]<<' '<<mn[k][l]<<'
// '<<(sum[mx[k][l]+1]-sum[mn[k][l]])<<endl;
out += (ma[k][l] - '0') * (sum[mx[k][l] + 1] - sum[mn[k][l]]);
}
}
}
}
cout << out << endl;
}
| replace | 58 | 59 | 58 | 59 | TLE | |
p03236 | C++ | Time Limit Exceeded | // 無理。
#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>>;
const int MN = 1550;
int N;
using B = array<ull, MN / 64 + 1>;
int g[MN][MN];
B used[MN][MN];
namespace std {
bool operator<(const B &l, const B &r) {
for (int i = 0; i < MN / 64 + 1; i++) {
if (l[i] != r[i])
return l[i] < r[i];
}
return false;
}
bool operator>(const B &l, const B &r) { return r < l; }
bool operator==(const B &l, const B &r) {
for (int i = 0; i < MN / 64 + 1; i++) {
if (l[i] != r[i])
return false;
}
return true;
}
} // namespace std
bool sam(const B &l, const B &r) {
for (int i = 0; i < MN / 64 + 1; i++) {
if (l[i] & r[i])
return true;
}
return false;
}
bool gt(const B &b, int id) { return (b[id / 64] & (1ULL << (id % 64))) != 0; }
void st(B &b, int id) { b[id / 64] |= 1ULL << (id % 64); }
int L, R, D, U;
void dfs_up(int a, int b, int id) {
if (!(L <= a && a <= R && D <= b && b <= U))
return;
// if (g[a][b] == 0 || used[a][b][id]) return;
if (g[a][b] == 0 || gt(used[a][b], id))
return;
st(used[a][b], id);
// used[a][b][id] = true;
dfs_up(a - 1, b, id);
dfs_up(a, b - 1, id);
}
void dfs_dw(int a, int b, int id) {
if (!(L <= a && a <= R && D <= b && b <= U))
return;
if (g[a][b] == 0 || gt(used[a][b], id))
return;
st(used[a][b], id);
// if (g[a][b] == 0 || used[a][b][id]) return;
// used[a][b][id] = true;
dfs_dw(a + 1, b, id);
dfs_dw(a, b + 1, id);
}
ll ans = 0;
using P = pair<B, int>;
V<P> uni(V<P> v) {
sort(v.begin(), v.end());
V<P> res;
for (auto &p : v) {
if (res.size() && res.back().first == p.first) {
res.back().second += p.second;
continue;
}
res.push_back(p);
}
return res;
}
void solve(int l, int r, int d, int u) {
if (r < l || u < d)
return;
if (l == r && d == u)
return;
L = l;
R = r;
D = d;
U = u;
for (int x = l; x <= r; x++) {
for (int y = d; y <= u; y++) {
used[x][y] = B();
}
}
if (r - l > u - d) {
int m = (l + r) / 2;
for (int y = d; y <= u; y++) {
dfs_up(m, y, y);
}
for (int y = u; y >= d; y--) {
dfs_dw(m + 1, y, y);
}
V<P> mp1, mp2;
for (int x = l; x <= r; x++) {
for (int y = d; y <= u; y++) {
if (x <= m)
mp1.push_back(P(used[x][y], g[x][y]));
else
mp2.push_back(P(used[x][y], g[x][y]));
}
}
mp1 = uni(mp1);
mp2 = uni(mp2);
for (auto &p1 : mp1) {
for (auto &p2 : mp2) {
// if ((p1.first & p2.first).count()) ans += ll(p1.second) * p2.second;
if (sam(p1.first, p2.first))
ans += ll(p1.second) * p2.second;
}
}
solve(l, m, d, u);
solve(m + 1, r, d, u);
} else {
int m = (d + u) / 2;
for (int x = l; x <= r; x++) {
dfs_up(x, m, x);
}
for (int x = r; x >= l; x--) {
dfs_dw(x, m + 1, x);
}
using P = pair<B, int>;
V<P> mp1, mp2;
for (int x = l; x <= r; x++) {
for (int y = d; y <= u; y++) {
if (y <= m)
mp1.push_back(P(used[x][y], g[x][y]));
else
mp2.push_back(P(used[x][y], g[x][y]));
}
}
mp1 = uni(mp1);
mp2 = uni(mp2);
/* map<B, int> mp1, mp2;
for (int x = l; x <= r; x++) {
for (int y = d; y <= u; y++) {
if (y <= m) mp1[used[x][y]] += g[x][y];
else mp2[used[x][y]] += g[x][y];
}
}*/
for (auto &p1 : mp1) {
for (auto &p2 : mp2) {
if (sam(p1.first, p2.first))
ans += ll(p1.second) * p2.second;
}
}
solve(l, r, d, m);
solve(l, r, m + 1, u);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(20) << fixed;
cin >> N;
for (int i = 1; i <= N; i++) {
string s;
cin >> s;
for (int j = 1; j <= N; j++) {
int d = 0;
if (isdigit(s[j - 1]))
d = s[j - 1] - '0';
g[i][j] = d;
// ans -= d*d;
}
}
solve(1, N, 1, N);
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>>;
const int MN = 550;
int N;
using B = array<ull, MN / 64 + 1>;
int g[MN][MN];
B used[MN][MN];
namespace std {
bool operator<(const B &l, const B &r) {
for (int i = 0; i < MN / 64 + 1; i++) {
if (l[i] != r[i])
return l[i] < r[i];
}
return false;
}
bool operator>(const B &l, const B &r) { return r < l; }
bool operator==(const B &l, const B &r) {
for (int i = 0; i < MN / 64 + 1; i++) {
if (l[i] != r[i])
return false;
}
return true;
}
} // namespace std
bool sam(const B &l, const B &r) {
for (int i = 0; i < MN / 64 + 1; i++) {
if (l[i] & r[i])
return true;
}
return false;
}
bool gt(const B &b, int id) { return (b[id / 64] & (1ULL << (id % 64))) != 0; }
void st(B &b, int id) { b[id / 64] |= 1ULL << (id % 64); }
int L, R, D, U;
void dfs_up(int a, int b, int id) {
if (!(L <= a && a <= R && D <= b && b <= U))
return;
// if (g[a][b] == 0 || used[a][b][id]) return;
if (g[a][b] == 0 || gt(used[a][b], id))
return;
st(used[a][b], id);
// used[a][b][id] = true;
dfs_up(a - 1, b, id);
dfs_up(a, b - 1, id);
}
void dfs_dw(int a, int b, int id) {
if (!(L <= a && a <= R && D <= b && b <= U))
return;
if (g[a][b] == 0 || gt(used[a][b], id))
return;
st(used[a][b], id);
// if (g[a][b] == 0 || used[a][b][id]) return;
// used[a][b][id] = true;
dfs_dw(a + 1, b, id);
dfs_dw(a, b + 1, id);
}
ll ans = 0;
using P = pair<B, int>;
V<P> uni(V<P> v) {
sort(v.begin(), v.end());
V<P> res;
for (auto &p : v) {
if (res.size() && res.back().first == p.first) {
res.back().second += p.second;
continue;
}
res.push_back(p);
}
return res;
}
void solve(int l, int r, int d, int u) {
if (r < l || u < d)
return;
if (l == r && d == u)
return;
L = l;
R = r;
D = d;
U = u;
for (int x = l; x <= r; x++) {
for (int y = d; y <= u; y++) {
used[x][y] = B();
}
}
if (r - l > u - d) {
int m = (l + r) / 2;
for (int y = d; y <= u; y++) {
dfs_up(m, y, y);
}
for (int y = u; y >= d; y--) {
dfs_dw(m + 1, y, y);
}
V<P> mp1, mp2;
for (int x = l; x <= r; x++) {
for (int y = d; y <= u; y++) {
if (x <= m)
mp1.push_back(P(used[x][y], g[x][y]));
else
mp2.push_back(P(used[x][y], g[x][y]));
}
}
mp1 = uni(mp1);
mp2 = uni(mp2);
for (auto &p1 : mp1) {
for (auto &p2 : mp2) {
// if ((p1.first & p2.first).count()) ans += ll(p1.second) * p2.second;
if (sam(p1.first, p2.first))
ans += ll(p1.second) * p2.second;
}
}
solve(l, m, d, u);
solve(m + 1, r, d, u);
} else {
int m = (d + u) / 2;
for (int x = l; x <= r; x++) {
dfs_up(x, m, x);
}
for (int x = r; x >= l; x--) {
dfs_dw(x, m + 1, x);
}
using P = pair<B, int>;
V<P> mp1, mp2;
for (int x = l; x <= r; x++) {
for (int y = d; y <= u; y++) {
if (y <= m)
mp1.push_back(P(used[x][y], g[x][y]));
else
mp2.push_back(P(used[x][y], g[x][y]));
}
}
mp1 = uni(mp1);
mp2 = uni(mp2);
/* map<B, int> mp1, mp2;
for (int x = l; x <= r; x++) {
for (int y = d; y <= u; y++) {
if (y <= m) mp1[used[x][y]] += g[x][y];
else mp2[used[x][y]] += g[x][y];
}
}*/
for (auto &p1 : mp1) {
for (auto &p2 : mp2) {
if (sam(p1.first, p2.first))
ans += ll(p1.second) * p2.second;
}
}
solve(l, r, d, m);
solve(l, r, m + 1, u);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(20) << fixed;
cin >> N;
for (int i = 1; i <= N; i++) {
string s;
cin >> s;
for (int j = 1; j <= N; j++) {
int d = 0;
if (isdigit(s[j - 1]))
d = s[j - 1] - '0';
g[i][j] = d;
// ans -= d*d;
}
}
solve(1, N, 1, N);
cout << ans << endl;
return 0;
}
| replace | 12 | 13 | 12 | 13 | TLE | |
p03237 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
namespace io {
const int l = 1 << 20;
char buf[l], *s, *t, c;
inline void gc() {
if (s == t) {
t = (s = buf) + fread(buf, 1, l, stdin);
c = s == t ? EOF : *s++;
} else
c = *s++;
}
template <class IT> inline void gi(IT &x) {
x = 0;
gc();
while (c < '0' || c > '9')
gc();
while ('0' <= c && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ 48);
gc();
}
}
char buf0[20];
int a;
template <class IT> inline void pi(IT x) {
if (x < 0) {
putchar('-');
x = -x;
}
do
buf0[++a] = x % 10 + 48;
while (x /= 10);
while (a)
putchar(buf0[a--]);
putchar('\n');
}
}; // namespace io
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pque priority_queue
#define rep(i, l, r) for (i = (l); i <= (r); ++i)
#define per(i, l, r) for (i = (l); i >= (r); --i)
#define REP(i, l, r) for (i = (l); i < (r); ++i)
#define PER(i, l, r) for (i = (l); i > (r); --i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template <class IT> inline void cmax(IT &a, IT b) {
if (a < b)
a = b;
}
template <class IT> inline void cmin(IT &a, IT b) {
if (b < a)
a = b;
}
const int N = 1505;
int a[N][N], f[N][N];
short l[N][N], r[N][N];
char c[N];
int main() {
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
int n, i, j, k, t;
short m;
ll ans = 0ll;
scanf("%d", &n);
rep(i, 1, n) {
scanf("%s", c + 1);
rep(j, 1, n) a[i][j] = ((c[j] == '#') ? 0 : (c[j] ^ 48));
}
per(i, n, 1) per(j, n, 1) {
if (a[i][j]) {
if (a[i + 1][j]) {
if (a[i][j + 1]) {
l[j][i] = j;
r[j][i] = r[j + 1][i];
t = f[i][j + 1] + f[i + 1][j];
m = 0;
rep(k, i + 1, t) {
if (r[j][k] >= l[j + 1][k] && l[j + 1][k] > m)
t -= f[k][l[j + 1][k]];
cmax(m, r[j][k]);
cmin(l[j][k], l[j + 1][k]);
cmax(r[j][k], r[j + 1][k]);
}
f[i][j] = t;
} else {
l[j][i] = r[j][i] = j;
f[i][j] = f[i + 1][j];
}
} else {
if (a[i][j + 1]) {
memcpy(l[j] + i, l[j + 1] + i, (n - i + 1) << 1);
memcpy(r[j] + i, r[j + 1] + i, (n - i + 1) << 1);
l[j][i] = j;
f[i][j] = f[i][j + 1];
} else
l[j][i] = r[j][i] = j;
}
ans += a[i][j] * f[i][j];
f[i][j] += a[i][j];
} else {
memset(l[j] + i, 0x3f, (n - i + 1) << 1);
memset(r[j] + i, 0, (n - i + 1) << 1);
}
// printf("(%d,%d) f=%d\n",i,j,f[i][j]);
// rep(k,i,n)printf("(%d,[%d,%d])\n",k,l[j][k],r[j][k]);
}
printf("%lld", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
namespace io {
const int l = 1 << 20;
char buf[l], *s, *t, c;
inline void gc() {
if (s == t) {
t = (s = buf) + fread(buf, 1, l, stdin);
c = s == t ? EOF : *s++;
} else
c = *s++;
}
template <class IT> inline void gi(IT &x) {
x = 0;
gc();
while (c < '0' || c > '9')
gc();
while ('0' <= c && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ 48);
gc();
}
}
char buf0[20];
int a;
template <class IT> inline void pi(IT x) {
if (x < 0) {
putchar('-');
x = -x;
}
do
buf0[++a] = x % 10 + 48;
while (x /= 10);
while (a)
putchar(buf0[a--]);
putchar('\n');
}
}; // namespace io
using io::gi;
using io::pi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pque priority_queue
#define rep(i, l, r) for (i = (l); i <= (r); ++i)
#define per(i, l, r) for (i = (l); i >= (r); --i)
#define REP(i, l, r) for (i = (l); i < (r); ++i)
#define PER(i, l, r) for (i = (l); i > (r); --i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
template <class IT> inline void cmax(IT &a, IT b) {
if (a < b)
a = b;
}
template <class IT> inline void cmin(IT &a, IT b) {
if (b < a)
a = b;
}
const int N = 1505;
int a[N][N], f[N][N];
short l[N][N], r[N][N];
char c[N];
int main() {
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
int n, i, j, k, t;
short m;
ll ans = 0ll;
scanf("%d", &n);
rep(i, 1, n) {
scanf("%s", c + 1);
rep(j, 1, n) a[i][j] = ((c[j] == '#') ? 0 : (c[j] ^ 48));
}
per(i, n, 1) per(j, n, 1) {
if (a[i][j]) {
if (a[i + 1][j]) {
if (a[i][j + 1]) {
l[j][i] = j;
r[j][i] = r[j + 1][i];
t = f[i][j + 1] + f[i + 1][j];
m = 0;
rep(k, i + 1, n) {
if (r[j][k] >= l[j + 1][k] && l[j + 1][k] > m)
t -= f[k][l[j + 1][k]];
cmax(m, r[j][k]);
cmin(l[j][k], l[j + 1][k]);
cmax(r[j][k], r[j + 1][k]);
}
f[i][j] = t;
} else {
l[j][i] = r[j][i] = j;
f[i][j] = f[i + 1][j];
}
} else {
if (a[i][j + 1]) {
memcpy(l[j] + i, l[j + 1] + i, (n - i + 1) << 1);
memcpy(r[j] + i, r[j + 1] + i, (n - i + 1) << 1);
l[j][i] = j;
f[i][j] = f[i][j + 1];
} else
l[j][i] = r[j][i] = j;
}
ans += a[i][j] * f[i][j];
f[i][j] += a[i][j];
} else {
memset(l[j] + i, 0x3f, (n - i + 1) << 1);
memset(r[j] + i, 0, (n - i + 1) << 1);
}
// printf("(%d,%d) f=%d\n",i,j,f[i][j]);
// rep(k,i,n)printf("(%d,[%d,%d])\n",k,l[j][k],r[j][k]);
}
printf("%lld", ans);
return 0;
} | replace | 91 | 92 | 91 | 92 | 0 | |
p03237 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ri register int
const int N = 505;
int a[N][N], f[N][N], l[N][N], r[N][N];
char s[N];
/*
f[i][j] (i,j) 能走到的位置的权值和
l[i][j][k]/r[i][j][k] 表示 (i,j) 可以到达的第 k 行最左/右的位置 ,第一维省略
不能走到的点贡献相当于已经清零,因为 (i+1,j) (i,j+1)
共同能走到的点的递增序列里面不会出现这些位置,
且没有被计算到其左上的点的贡献中去
*/
int main() {
// freopen("cell.in","r",stdin);
// freopen("cell.out","w",stdout);
ri n, i, j, k, now;
register long long ans;
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
scanf("%s", s + 1);
for (j = 1; j <= n; ++j)
a[i][j] = s[j] == '#' ? 0 : s[j] - '0';
}
ans = 0;
for (i = n; i; --i)
for (j = n; j; --j) {
if (a[i][j] == 0) {
memset(l[j] + i, 127, sizeof(int) * (n - i + 1));
memset(r[j] + i, 128, sizeof(int) * (n - i + 1));
continue;
}
if (a[i + 1][j] == 0 && a[i][j + 1] == 0)
l[j][i] = r[j][i] = j;
else if (a[i + 1][j] == 0)
memcpy(l[j] + i, l[j + 1] + i, sizeof(int) * (n - i + 1)),
memcpy(r[j] + i, r[j + 1] + i, sizeof(int) * (n - i + 1)),
l[j][i] = j, f[i][j] = f[i][j + 1];
else if (a[i][j + 1] == 0)
l[j][i] = r[j][i] = j, f[i][j] = f[i + 1][j];
else {
f[i][j] = f[i][j + 1] + f[i + 1][j];
l[j][i] = j;
r[j][i] = r[j + 1][i];
now = 0;
for (k = i + 1; k <= n; ++k) {
if (r[j][k] >= l[j + 1][k] && l[j + 1][k] > now)
// printf("sub %d %d %d %d\n",i,j,k,l[j+1][k]),
f[i][j] -= f[k][l[j + 1][k]];
now = max(now, r[j][k]);
l[j][k] = min(l[j][k], l[j + 1][k]);
r[j][k] = max(r[j][k], r[j + 1][k]);
}
}
ans += a[i][j] * f[i][j];
// printf("f %d %d %d\n",i,j,f[i][j]);
f[i][j] += a[i][j];
// printf("check (%d,%d)\n",i,j);
// for(k=i;k<=n;++k)
// printf("%d %d %d\n",k,l[j][k],r[j][k]);
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ri register int
const int N = 1505;
int a[N][N], f[N][N], l[N][N], r[N][N];
char s[N];
/*
f[i][j] (i,j) 能走到的位置的权值和
l[i][j][k]/r[i][j][k] 表示 (i,j) 可以到达的第 k 行最左/右的位置 ,第一维省略
不能走到的点贡献相当于已经清零,因为 (i+1,j) (i,j+1)
共同能走到的点的递增序列里面不会出现这些位置,
且没有被计算到其左上的点的贡献中去
*/
int main() {
// freopen("cell.in","r",stdin);
// freopen("cell.out","w",stdout);
ri n, i, j, k, now;
register long long ans;
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
scanf("%s", s + 1);
for (j = 1; j <= n; ++j)
a[i][j] = s[j] == '#' ? 0 : s[j] - '0';
}
ans = 0;
for (i = n; i; --i)
for (j = n; j; --j) {
if (a[i][j] == 0) {
memset(l[j] + i, 127, sizeof(int) * (n - i + 1));
memset(r[j] + i, 128, sizeof(int) * (n - i + 1));
continue;
}
if (a[i + 1][j] == 0 && a[i][j + 1] == 0)
l[j][i] = r[j][i] = j;
else if (a[i + 1][j] == 0)
memcpy(l[j] + i, l[j + 1] + i, sizeof(int) * (n - i + 1)),
memcpy(r[j] + i, r[j + 1] + i, sizeof(int) * (n - i + 1)),
l[j][i] = j, f[i][j] = f[i][j + 1];
else if (a[i][j + 1] == 0)
l[j][i] = r[j][i] = j, f[i][j] = f[i + 1][j];
else {
f[i][j] = f[i][j + 1] + f[i + 1][j];
l[j][i] = j;
r[j][i] = r[j + 1][i];
now = 0;
for (k = i + 1; k <= n; ++k) {
if (r[j][k] >= l[j + 1][k] && l[j + 1][k] > now)
// printf("sub %d %d %d %d\n",i,j,k,l[j+1][k]),
f[i][j] -= f[k][l[j + 1][k]];
now = max(now, r[j][k]);
l[j][k] = min(l[j][k], l[j + 1][k]);
r[j][k] = max(r[j][k], r[j + 1][k]);
}
}
ans += a[i][j] * f[i][j];
// printf("f %d %d %d\n",i,j,f[i][j]);
f[i][j] += a[i][j];
// printf("check (%d,%d)\n",i,j);
// for(k=i;k<=n;++k)
// printf("%d %d %d\n",k,l[j][k],r[j][k]);
}
printf("%lld\n", ans);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p03237 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
int N;
string S[2020];
short L[1500][1500], R[1500][1500];
int dp[1500][1500];
void solve() {
int i, j, k, l, r, x, y, x2, y2;
string s;
cin >> N;
FOR(y, N) {
cin >> S[y];
FORR(c, S[y]) {
if (c != '#')
c -= '0';
else
c = 0;
}
}
ll ret = 0;
for (y = N - 1; y >= 0; y--) {
L[y][N] = N;
R[y][N] = -1;
for (x = N - 1; x >= 0; x--) {
int down = (y < N - 1) && (S[y + 1][x] > 0);
int right = (x < N - 1) && (S[y][x + 1] > 0);
if (S[y][x] == 0) {
for (y2 = y; y2 < N; y2++) {
L[y][x] = N;
R[y][x] = -1;
}
} else {
dp[y][x] = dp[y + 1][x] + dp[y][x + 1];
L[y][x] = x;
if (down && right) {
R[y][x] = R[y][x + 1];
int r = 0;
for (y2 = y + 1; y2 < N; y2++) {
if (L[y2][x + 1] <= R[y2][x] && r < L[y2][x + 1]) {
dp[y][x] -= dp[y2][L[y2][x + 1]];
}
r = R[y2][x];
R[y2][x] = max(R[y2][x], R[y2][x + 1]);
L[y2][x] = min(L[y2][x], L[y2][x + 1]);
}
} else if (down) {
R[y][x] = x;
} else if (right) {
R[y][x] = R[y][x + 1];
for (y2 = y + 1; y2 < N; y2++) {
L[y2][x] = L[y2][x + 1];
R[y2][x] = R[y2][x + 1];
}
} else {
R[y][x] = x;
for (y2 = y + 1; y2 < N; y2++) {
L[y2][x] = N;
R[y2][x] = 0;
}
}
ret += S[y][x] * dp[y][x];
dp[y][x] += S[y][x];
}
}
}
cout << ret << endl;
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
int N;
string S[2020];
short L[1504][1504], R[1504][1504];
int dp[1504][1504];
void solve() {
int i, j, k, l, r, x, y, x2, y2;
string s;
cin >> N;
FOR(y, N) {
cin >> S[y];
FORR(c, S[y]) {
if (c != '#')
c -= '0';
else
c = 0;
}
}
ll ret = 0;
for (y = N - 1; y >= 0; y--) {
L[y][N] = N;
R[y][N] = -1;
for (x = N - 1; x >= 0; x--) {
int down = (y < N - 1) && (S[y + 1][x] > 0);
int right = (x < N - 1) && (S[y][x + 1] > 0);
if (S[y][x] == 0) {
for (y2 = y; y2 < N; y2++) {
L[y][x] = N;
R[y][x] = -1;
}
} else {
dp[y][x] = dp[y + 1][x] + dp[y][x + 1];
L[y][x] = x;
if (down && right) {
R[y][x] = R[y][x + 1];
int r = 0;
for (y2 = y + 1; y2 < N; y2++) {
if (L[y2][x + 1] <= R[y2][x] && r < L[y2][x + 1]) {
dp[y][x] -= dp[y2][L[y2][x + 1]];
}
r = R[y2][x];
R[y2][x] = max(R[y2][x], R[y2][x + 1]);
L[y2][x] = min(L[y2][x], L[y2][x + 1]);
}
} else if (down) {
R[y][x] = x;
} else if (right) {
R[y][x] = R[y][x + 1];
for (y2 = y + 1; y2 < N; y2++) {
L[y2][x] = L[y2][x + 1];
R[y2][x] = R[y2][x + 1];
}
} else {
R[y][x] = x;
for (y2 = y + 1; y2 < N; y2++) {
L[y2][x] = N;
R[y2][x] = 0;
}
}
ret += S[y][x] * dp[y][x];
dp[y][x] += S[y][x];
}
}
}
cout << ret << endl;
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
| replace | 16 | 18 | 16 | 18 | 0 | |
p03237 | C++ | Runtime Error | #pragma GCC diagnostic ignored "-Wunused-result"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 502;
// const ll INF = (ll)1e18 + 41;
const int INF = (int)1e9 + 41;
const ll MD = (ll)1e9 + 7;
bool D = false;
int sum[N][N], a[N][N];
int max_depth[N][N];
short int r[2][N][N];
short int l[2][N][N];
void solve() {
int n, m;
cin >> n;
m = n;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
a[i][j] = 0;
max_depth[i][j] = i;
sum[i][j] = 0;
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j <= m; j++) {
for (int h = 0; h <= m; h++) {
r[i][j][h] = (short int)-1;
l[i][j][h] = (short int)N;
}
}
}
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) {
if (s[j] == '#')
a[i][j] = 0;
else
a[i][j] = s[j] - '0';
}
}
ll ans = 0;
for (int i = n - 1; i >= 0; i--) {
int my = i % 2;
int nx = (i + 1) % 2;
for (int j = 0; j <= m; j++) {
for (int h = i; h <= n; h++) {
l[my][j][h] = (short int)N;
r[my][j][h] = (short int)-1;
}
}
for (int j = m - 1; j >= 0; j--) {
if (a[i][j] == 0) {
max_depth[i][j] = -1;
continue;
}
short int *left = r[nx][j];
short int *_left = l[nx][j];
short int *rait = l[my][j + 1];
short int *_rait = r[my][j + 1];
short int *meL = l[my][j];
short int *meR = r[my][j];
meL[i] = (short int)j;
meR[i] = max(meL[i], _rait[i]);
for (int h = i + 1; h < n; h++) {
meL[h] = min(_left[h], rait[h]);
meR[h] = max(left[h], _rait[h]);
}
max_depth[i][j] = max(i, max(max_depth[i + 1][j], max_depth[i][j + 1]));
int cur_sum = sum[i][j + 1] + sum[i + 1][j];
int h = i;
// cout << i << " " << j << endl;
if (i == 1 && j == 0) {
j = i * j;
}
while (h < n) {
while (h < n && left[h] < rait[h])
h++;
if (h >= n)
continue;
cur_sum -= sum[h][rait[h]];
h = max_depth[h][rait[h]] + 2;
}
sum[i][j] = cur_sum + a[i][j];
ans += a[i][j] * cur_sum;
}
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tst = 1;
// scanf("%d", &tst);
// cin >> tst;
#ifdef MADE_BY_SERT
// freopen("a.in", "r", stdin);
D = true;
tst = 4;
while (tst--) {
solve();
}
#else
while (tst--)
solve();
#endif
}
| #pragma GCC diagnostic ignored "-Wunused-result"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1502;
// const ll INF = (ll)1e18 + 41;
const int INF = (int)1e9 + 41;
const ll MD = (ll)1e9 + 7;
bool D = false;
int sum[N][N], a[N][N];
int max_depth[N][N];
short int r[2][N][N];
short int l[2][N][N];
void solve() {
int n, m;
cin >> n;
m = n;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
a[i][j] = 0;
max_depth[i][j] = i;
sum[i][j] = 0;
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j <= m; j++) {
for (int h = 0; h <= m; h++) {
r[i][j][h] = (short int)-1;
l[i][j][h] = (short int)N;
}
}
}
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) {
if (s[j] == '#')
a[i][j] = 0;
else
a[i][j] = s[j] - '0';
}
}
ll ans = 0;
for (int i = n - 1; i >= 0; i--) {
int my = i % 2;
int nx = (i + 1) % 2;
for (int j = 0; j <= m; j++) {
for (int h = i; h <= n; h++) {
l[my][j][h] = (short int)N;
r[my][j][h] = (short int)-1;
}
}
for (int j = m - 1; j >= 0; j--) {
if (a[i][j] == 0) {
max_depth[i][j] = -1;
continue;
}
short int *left = r[nx][j];
short int *_left = l[nx][j];
short int *rait = l[my][j + 1];
short int *_rait = r[my][j + 1];
short int *meL = l[my][j];
short int *meR = r[my][j];
meL[i] = (short int)j;
meR[i] = max(meL[i], _rait[i]);
for (int h = i + 1; h < n; h++) {
meL[h] = min(_left[h], rait[h]);
meR[h] = max(left[h], _rait[h]);
}
max_depth[i][j] = max(i, max(max_depth[i + 1][j], max_depth[i][j + 1]));
int cur_sum = sum[i][j + 1] + sum[i + 1][j];
int h = i;
// cout << i << " " << j << endl;
if (i == 1 && j == 0) {
j = i * j;
}
while (h < n) {
while (h < n && left[h] < rait[h])
h++;
if (h >= n)
continue;
cur_sum -= sum[h][rait[h]];
h = max_depth[h][rait[h]] + 2;
}
sum[i][j] = cur_sum + a[i][j];
ans += a[i][j] * cur_sum;
}
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tst = 1;
// scanf("%d", &tst);
// cin >> tst;
#ifdef MADE_BY_SERT
// freopen("a.in", "r", stdin);
D = true;
tst = 4;
while (tst--) {
solve();
}
#else
while (tst--)
solve();
#endif
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03238 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
// 歳入力
int N;
cin >> N;
// 条件分岐
if (N == 2) {
// 2歳
int A = 0, B = 0;
cin >> A;
cin >> B;
cout << A + B << endl;
} else if (N == 1) {
// 1歳
cout << "Hello World" << endl;
return 0;
} else {
// 一応その他
return 0;
}
return -1;
} | #include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
// 歳入力
int N;
cin >> N;
// 条件分岐
if (N == 2) {
// 2歳
int A = 0, B = 0;
cin >> A;
cin >> B;
cout << A + B << endl;
return 0;
} else if (N == 1) {
// 1歳
cout << "Hello World" << endl;
return 0;
} else {
// 一応その他
return 0;
}
return -1;
} | insert | 19 | 19 | 19 | 20 | 0 | |
p03238 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b) // 比較は昇順
#define toInt(x) (x - '0')
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;
int main() {
int n, a, b;
cin >> n;
if (n % 0) {
cout << "Hello World" << endl;
} else {
cin >> a >> b;
cout << a + b << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b) // 比較は昇順
#define toInt(x) (x - '0')
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define MM multimap
#define PB push_back
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;
int main() {
int n, a, b;
cin >> n;
if (n % 2) {
cout << "Hello World" << endl;
} else {
cin >> a >> b;
cout << a + b << endl;
}
return 0;
} | replace | 31 | 32 | 31 | 32 | -8 | |
p03238 | Python | Runtime Error | def solve(string):
flag, *ab = map(int, string.split())
return str(sum(ab)) if flag - 1 else "Hello World"
if __name__ == "__main__":
flag = int(input())
if flag - 1:
flag = "{}\n".format(flag) + "\n".join([input(), input()])
print(solve(flag))
| def solve(string):
flag, *ab = map(int, string.split())
return str(sum(ab)) if flag - 1 else "Hello World"
if __name__ == "__main__":
flag = int(input())
if flag - 1:
flag = "{}\n".format(flag) + "\n".join([input(), input()])
print(solve(str(flag)))
| replace | 9 | 10 | 9 | 10 | AttributeError: 'int' object has no attribute 'split' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03238/Python/s553677873.py", line 10, in <module>
print(solve(flag))
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03238/Python/s553677873.py", line 2, in solve
flag, *ab = map(int, string.split())
AttributeError: 'int' object has no attribute 'split'
|
p03238 | Python | Runtime Error | def solve():
age = int(input())
if age == 1:
return "Hello World"
a, b = map(int, input().split())
return a + b
if __name__ == "__main__":
print(solve())
| def solve():
age = int(input())
if age == 1:
return "Hello World"
a, b = list(int(input()) for _ in range(2))
return a + b
if __name__ == "__main__":
print(solve())
| replace | 4 | 5 | 4 | 5 | 0 | |
p03238 | Python | Runtime Error | def programming_education(N: int) -> str:
if N == 1:
return "Hello World"
A, B = map(int, input().split())
return str(A + B)
if __name__ == "__main__":
N = int(input())
ans = programming_education(N)
print(ans)
| def programming_education(N: int) -> str:
if N == 1:
return "Hello World"
A = int(input())
B = int(input())
return str(A + B)
if __name__ == "__main__":
N = int(input())
ans = programming_education(N)
print(ans)
| replace | 4 | 5 | 4 | 6 | 0 | |
p03238 | Python | Runtime Error | dat0 = input()
if dat0 == 1:
print("Hello World")
else:
dat1 = input()
dat2 = input()
ans = int(dat1) + int(dat2)
print(ans)
| dat0 = input()
if dat0 == "1":
print("Hello World")
else:
dat1 = input()
dat2 = input()
ans = int(dat1) + int(dat2)
print(ans)
| replace | 1 | 2 | 1 | 2 | EOFError: EOF when reading a line | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03238/Python/s913510472.py", line 5, in <module>
dat1 = input()
EOFError: EOF when reading a line
|
p03238 | Python | Runtime Error | N = int(input())
if N == 1:
print("Hello World")
else:
a, b = map(int, input().split())
print(a + b)
| N = int(input())
if N == 1:
print("Hello World")
else:
a = int(input())
b = int(input())
print(a + b)
| replace | 4 | 5 | 4 | 6 | 0 | |
p03238 | Python | Runtime Error | import sys
N = int(sys.stdin.readline())
if N == 1:
print("Hello World")
sys.exit()
if N == 2:
ans = 0
for value in sys.stdin.readlines():
ans += value
print(ans)
| import sys
N = int(sys.stdin.readline())
if N == 1:
print("Hello World")
sys.exit()
if N == 2:
ans = 0
for value in sys.stdin.readlines():
ans += int(value)
print(ans)
| replace | 11 | 12 | 11 | 12 | 0 | |
p03238 | C++ | Runtime Error | // Devarshi
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (i = 0; i < n; i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it, x) for (auto it : x)
#define PI 3.14159265
#define sync \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int maxn = 1000001;
int main() {
sync
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
if (n == 1) {
cout << "Hello World";
} else {
int a, b;
cin >> a >> b;
cout << a + b;
}
return 0;
}
| // Devarshi
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (i = 0; i < n; i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it, x) for (auto it : x)
#define PI 3.14159265
#define sync \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int maxn = 1000001;
int main() {
sync
/*a
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
*/
int n;
cin >> n;
if (n == 1) {
cout << "Hello World";
} else {
int a, b;
cin >> a >> b;
cout << a + b;
}
return 0;
}
| replace | 43 | 52 | 43 | 52 | 0 | |
p03238 | Python | Runtime Error | N = int(input())
if N == 1:
print("Hello World")
elif N == 2:
A, B = map(int, input().split())
print(A + B)
| N = int(input())
if N == 1:
print("Hello World")
elif N == 2:
A = int(input())
B = int(input())
print(A + B)
| replace | 5 | 7 | 5 | 7 | 0 | |
p03238 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define int long long int
int32_t main() {
fastIO;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, i;
cin >> n;
if (n == 1)
cout << "Hello World";
else {
int a, b, c;
cin >> a >> b;
c = a + b;
cout << c;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define int long long int
int32_t main() {
fastIO;
int n, i;
cin >> n;
if (n == 1)
cout << "Hello World";
else {
int a, b, c;
cin >> a >> b;
c = a + b;
cout << c;
}
return 0;
} | delete | 13 | 17 | 13 | 13 | 0 | |
p03238 | Python | Runtime Error | N = int(input())
if N == 1:
print("Hello World")
else:
A, B = map(int, input().split())
print(A + B)
| N = int(input())
if N == 1:
print("Hello World")
else:
A = int(input())
B = int(input())
print(A + B)
| replace | 4 | 5 | 4 | 6 | 0 | |
p03238 | Python | Runtime Error | N = int(input())
if N == 1:
print("Hello World")
else:
A, B = map(int, input().split())
print(A + B)
| N = int(input())
if N == 1:
print("Hello World")
else:
A = int(input())
B = int(input())
print(A + B)
| replace | 5 | 6 | 5 | 7 | 0 | |
p03239 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = int(1e9) + 7;
using P = pair<ll, ll>;
using ld = long double;
int main() {
ll N, T;
cin >> N >> T;
vector<P> p;
for (int i = 0; i < N; ++i) {
ll t, c;
cin >> c >> t;
if (t <= T)
p.push_back({c, t});
}
if (p.empty())
puts("TLE");
sort(all(p));
cout << p[0].first << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
using ll = long long;
const int INF = 1 << 30;
const ll INFll = 1LL << 62;
const int mod = int(1e9) + 7;
using P = pair<ll, ll>;
using ld = long double;
int main() {
ll N, T;
cin >> N >> T;
vector<P> p;
for (int i = 0; i < N; ++i) {
ll t, c;
cin >> c >> t;
if (t <= T)
p.push_back({c, t});
}
if (p.empty())
puts("TLE");
else {
sort(all(p));
cout << p[0].first << endl;
}
return 0;
} | replace | 23 | 25 | 23 | 27 | 0 | |
p03239 | Python | Runtime Error | import sys
N, T = map(int, sys.stdin.readline().strip().split()) # N個の帰宅経路, T時間以内に
cost = 1001
for line in sys.stdin.readlines():
c, t = line.strip().split()
if T >= t:
cost = min(cost, c)
if cost == 1001:
print("TLE")
else:
print(cost)
| import sys
N, T = map(int, sys.stdin.readline().strip().split()) # N個の帰宅経路, T時間以内に
cost = 1001
for line in sys.stdin.readlines():
c, t = map(int, line.strip().split())
if T >= t:
cost = min(cost, c)
if cost == 1001:
print("TLE")
else:
print(cost)
| replace | 6 | 7 | 6 | 7 | TypeError: '>=' not supported between instances of 'int' and 'str' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03239/Python/s756451792.py", line 7, in <module>
if T >= t:
TypeError: '>=' not supported between instances of 'int' and 'str'
|
p03239 | Python | Runtime Error | N, T = map(int, input().split())
c = set()
for i in range(0, N):
ci, ti = map(int, input().split())
if ti > T:
continue
c.add(ci)
print(min(c))
| N, T = map(int, input().split())
c = set()
for i in range(0, N):
ci, ti = map(int, input().split())
if ti > T:
continue
c.add(ci)
if c:
print(min(c))
else:
print("TLE")
| replace | 9 | 10 | 9 | 13 | 0 | |
p03239 | Python | Runtime Error | import sys
input = sys.stdin.readline
def main():
n, t = map(int, input().split())
routes = filter(
lambda x: x[1] <= t, [list(map(int, input().split())) for _ in range(n)]
)
if routes:
print(min(routes)[0])
else:
print("TLE")
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
n, t = map(int, input().split())
routes = list(
filter(lambda x: x[1] <= t, [list(map(int, input().split())) for _ in range(n)])
)
if routes:
print(min(routes)[0])
else:
print("TLE")
if __name__ == "__main__":
main()
| replace | 7 | 9 | 7 | 9 | 0 | |
p03239 | Python | Runtime Error | N, T = map(int, input().split())
a = 9999
for _ in N:
c, t = map(int, input().split())
if t <= T:
a = min(a, c)
if a == 9999:
print("TLE")
else:
print(a)
| N, T = map(int, input().split())
a = 9999
for _ in range(N):
c, t = map(int, input().split())
if t <= T:
a = min(a, c)
if a == 9999:
print("TLE")
else:
print(a)
| replace | 2 | 3 | 2 | 3 | TypeError: 'int' object is not iterable | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03239/Python/s125957477.py", line 3, in <module>
for _ in N:
TypeError: 'int' object is not iterable
|
p03239 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n >> t;
vector<pair<int, int>> vp;
for (int i = 0; i < n; ++i) {
int ci, ti;
cin >> ci >> ti;
if (ti > t)
continue;
vp.push_back(make_pair(ci, ti));
}
sort(vp.begin(), vp.end());
cout << vp[0].first << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n >> t;
vector<pair<int, int>> vp;
for (int i = 0; i < n; ++i) {
int ci, ti;
cin >> ci >> ti;
if (ti > t)
continue;
vp.push_back(make_pair(ci, ti));
}
sort(vp.begin(), vp.end());
if (vp.empty())
cout << "TLE" << endl;
else
cout << vp[0].first << endl;
} | replace | 19 | 20 | 19 | 23 | 0 | |
p03239 | Python | Runtime Error | N, T = map(int, input().split())
r = [tuple(map(int, input().split())) for _ in range(N)]
f = [(c, t) for c, t in r if t <= T]
print(min(f, key=lambda x: x[0])[0])
| N, T = map(int, input().split())
r = [tuple(map(int, input().split())) for _ in range(N)]
f = [(c, t) for c, t in r if t <= T]
if len(f) == 0:
print("TLE")
else:
print(min(f, key=lambda x: x[0])[0])
| replace | 3 | 4 | 3 | 7 | 0 | |
p03239 | Python | Runtime Error | def solve(string):
n, t, *ct = map(int, string.split())
c = [_c for _c, _t in zip(ct[::2], ct[1::2]) if _t <= t]
return str(min(c)) if len(c) else "TLE"
if __name__ == "__main__":
n, t = map(int, input().split())
print(solve("{} {}\n".format(n, t) + "\n".join([input() for _ in n])))
| def solve(string):
n, t, *ct = map(int, string.split())
c = [_c for _c, _t in zip(ct[::2], ct[1::2]) if _t <= t]
return str(min(c)) if len(c) else "TLE"
if __name__ == "__main__":
n, t = map(int, input().split())
print(solve("{} {}\n".format(n, t) + "\n".join([input() for _ in range(n)])))
| replace | 8 | 9 | 8 | 9 | TypeError: 'int' object is not iterable | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03239/Python/s779800450.py", line 9, in <module>
print(solve("{} {}\n".format(n, t) + "\n".join([input() for _ in n])))
TypeError: 'int' object is not iterable
|
p03239 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
bool compare_pair(pair<int, int> a, pair<int, int> b) {
if (a.first == b.first) {
return a.first > b.first;
} else {
return a.second < b.second;
}
}
int main() {
int n, t;
cin >> n >> t;
vector<pair<int, int>> c(n);
rep(i, n) cin >> c[i].first >> c[i].second;
sort(ALL(c), compare_pair);
int ans = 10000;
int no = 0;
while (c[no].second <= t)
ans = min(ans, c[no++].first);
if (ans == 10000)
cout << "TLE";
else
cout << ans;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
bool compare_pair(pair<int, int> a, pair<int, int> b) {
if (a.first == b.first) {
return a.first > b.first;
} else {
return a.second < b.second;
}
}
int main() {
int n, t;
cin >> n >> t;
vector<pair<int, int>> c(n);
rep(i, n) cin >> c[i].first >> c[i].second;
sort(ALL(c), compare_pair);
int ans = 10000;
int no = 0;
while (c[no].second <= t && no < n)
ans = min(ans, c[no++].first);
if (ans == 10000)
cout << "TLE";
else
cout << ans;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p03239 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
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;
}
const ll MOD = 1000000007;
const int INF = 1 << 30;
// const ll INF = (ll)1e18 + 1;
int main() {
int N, T;
cin >> N >> T;
vector<int> cost;
rep(i, N) {
int c, t;
cin >> c >> t;
if (t <= T)
cost.push_back(c);
}
sort(cost.begin(), cost.end());
cout << cost[0] << endl;
}
| #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
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;
}
const ll MOD = 1000000007;
const int INF = 1 << 30;
// const ll INF = (ll)1e18 + 1;
int main() {
int N, T;
cin >> N >> T;
vector<int> cost;
rep(i, N) {
int c, t;
cin >> c >> t;
if (t <= T)
cost.push_back(c);
}
if (cost.empty()) {
cout << "TLE" << endl;
return 0;
}
sort(cost.begin(), cost.end());
cout << cost[0] << endl;
}
| insert | 46 | 46 | 46 | 50 | 0 | |
p03239 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, T;
cin >> N >> T;
int c[T], t[N];
for (int i = 0; i < N; ++i) {
cin >> c[i] >> t[i];
}
int min = 1001;
for (int i = 0; i < N; ++i) {
if (t[i] <= T) {
if (c[i] <= min) {
min = c[i];
}
}
}
if (min == 1001) {
cout << "TLE" << endl;
return 0;
}
cout << min << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N, T;
cin >> N >> T;
int c[N], t[N];
for (int i = 0; i < N; ++i) {
cin >> c[i] >> t[i];
}
int min = 1001;
for (int i = 0; i < N; ++i) {
if (t[i] <= T) {
if (c[i] <= min) {
min = c[i];
}
}
}
if (min == 1001) {
cout << "TLE" << endl;
return 0;
}
cout << min << endl;
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 |
Subsets and Splits