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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define MAXN 100001
using namespace std;
ll spf[MAXN];
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
void get(map<ll, ll> &ma, ll a[], ll n) {
// ll f=0;
for (ll i = 0; i < n; i++) {
while (a[i] != 1) {
ma[spf[a[i]]]++;
ll temp = spf[a[i]];
// cout<<temp<<endl;
while (spf[a[i]] == temp) {
a[i] = a[i] / spf[a[i]];
}
}
}
ll gcd = 1, f = 0;
map<ll, ll>::iterator it;
for (it = ma.begin(); it != ma.end(); it++) {
ll d = (it->second) / n;
// cout<<it->first<<" "<<it->second<<" "<<d<<endl;
if (d != 0)
gcd = gcd * (it->first);
if (it->second != 1) {
f = 1;
}
}
if (f == 0) {
cout << "pairwise coprime" << endl;
} else if (gcd == 1) {
cout << "setwise coprime" << endl;
} else {
cout << "not coprime" << endl;
}
}
int main() {
sieve();
ll n;
cin >> n;
ll a[n];
map<ll, ll> ma;
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
get(ma, a, n);
} | #include <bits/stdc++.h>
#define ll long long int
#define MAXN 1000001
using namespace std;
ll spf[MAXN];
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
void get(map<ll, ll> &ma, ll a[], ll n) {
// ll f=0;
for (ll i = 0; i < n; i++) {
while (a[i] != 1) {
ma[spf[a[i]]]++;
ll temp = spf[a[i]];
// cout<<temp<<endl;
while (spf[a[i]] == temp) {
a[i] = a[i] / spf[a[i]];
}
}
}
ll gcd = 1, f = 0;
map<ll, ll>::iterator it;
for (it = ma.begin(); it != ma.end(); it++) {
ll d = (it->second) / n;
// cout<<it->first<<" "<<it->second<<" "<<d<<endl;
if (d != 0)
gcd = gcd * (it->first);
if (it->second != 1) {
f = 1;
}
}
if (f == 0) {
cout << "pairwise coprime" << endl;
} else if (gcd == 1) {
cout << "setwise coprime" << endl;
} else {
cout << "not coprime" << endl;
}
}
int main() {
sieve();
ll n;
cin >> n;
ll a[n];
map<ll, ll> ma;
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
get(ma, a, n);
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02574 | C++ | Runtime Error | /* Simplicity and Goodness */
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args> void my_dbg(Arg A, Args... B) {
cout << ' ' << A;
my_dbg(B...);
}
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int maxN = 2e5 + 2;
vi find_prime(int val) {
vi ret;
for (int i = 2; i * i <= val; i++) {
if (val % i == 0) {
ret.pb(i);
while (val % i == 0)
val /= i;
}
}
if (val > 1)
ret.pb(val);
return ret;
}
void solve() {
int n;
scn(n);
vi a(n), fa(maxN, 0);
bool pairwise = 1;
rep(i, 0, n) {
scn(a[i]);
vi here = find_prime(a[i]);
for (int it : here) {
if (fa[it] != 0)
pairwise = 0;
fa[it] = 1;
}
}
if (pairwise) {
puts("pairwise coprime");
exit(0);
}
int g = a[0];
rep(i, 1, n) g = __gcd(g, a[i]);
if (g == 1) {
puts("setwise coprime");
exit(0);
}
puts("not coprime");
}
int main() {
int t = 1;
// scn(t);
while (t--) {
solve();
}
return 0;
}
| /* Simplicity and Goodness */
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args> void my_dbg(Arg A, Args... B) {
cout << ' ' << A;
my_dbg(B...);
}
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int maxN = 1e6 + 2;
vi find_prime(int val) {
vi ret;
for (int i = 2; i * i <= val; i++) {
if (val % i == 0) {
ret.pb(i);
while (val % i == 0)
val /= i;
}
}
if (val > 1)
ret.pb(val);
return ret;
}
void solve() {
int n;
scn(n);
vi a(n), fa(maxN, 0);
bool pairwise = 1;
rep(i, 0, n) {
scn(a[i]);
vi here = find_prime(a[i]);
for (int it : here) {
if (fa[it] != 0)
pairwise = 0;
fa[it] = 1;
}
}
if (pairwise) {
puts("pairwise coprime");
exit(0);
}
int g = a[0];
rep(i, 1, n) g = __gcd(g, a[i]);
if (g == 1) {
puts("setwise coprime");
exit(0);
}
puts("not coprime");
}
int main() {
int t = 1;
// scn(t);
while (t--) {
solve();
}
return 0;
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
ll N;
ll A[1000010];
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
cin >> N;
for (ll i = 0; i < N; i++)
cin >> A[i];
sort(A, A + N);
bool pairwise = true;
bool isPrime[1000010];
for (ll i = 1; i <= A[N - 1]; i++)
isPrime[i] = true;
for (ll i = 0; i < N; i++) {
if (!isPrime[A[i]]) {
pairwise = false;
break;
}
vector<ll> v;
ll a = A[i];
for (ll j = 2; j <= a; j++) {
if (a % j == 0)
v.push_back(j);
while (a % j == 0)
a /= j;
}
if (a != 1)
v.push_back(a);
for (auto x : v) {
for (ll j = x; j <= A[N - 1]; j += x) {
isPrime[j] = false;
}
}
}
if (pairwise) {
cout << "pairwise coprime" << endl;
return 0;
}
ll _gcd = A[0];
for (ll i = 1; i < N; i++) {
_gcd = gcd(_gcd, A[i]);
}
if (_gcd == 1) {
cout << "setwise coprime" << endl;
return 0;
}
cout << "not coprime" << endl;
return 0;
} | #include <algorithm>
#include <cassert>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
ll N;
ll A[1000010];
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
cin >> N;
for (ll i = 0; i < N; i++)
cin >> A[i];
sort(A, A + N);
bool pairwise = true;
bool isPrime[1000010];
for (ll i = 1; i <= A[N - 1]; i++)
isPrime[i] = true;
for (ll i = 0; i < N; i++) {
if (!isPrime[A[i]]) {
pairwise = false;
break;
}
vector<ll> v;
ll a = A[i];
for (ll j = 2; j * j <= a; j++) {
if (a % j == 0)
v.push_back(j);
while (a % j == 0)
a /= j;
}
if (a != 1)
v.push_back(a);
for (auto x : v) {
for (ll j = x; j <= A[N - 1]; j += x) {
isPrime[j] = false;
}
}
}
if (pairwise) {
cout << "pairwise coprime" << endl;
return 0;
}
ll _gcd = A[0];
for (ll i = 1; i < N; i++) {
_gcd = gcd(_gcd, A[i]);
}
if (_gcd == 1) {
cout << "setwise coprime" << endl;
return 0;
}
cout << "not coprime" << endl;
return 0;
} | replace | 44 | 45 | 44 | 45 | TLE | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
#define F(i, a, b) for (ll i = a; i <= (b); ++i)
#define dF(i, a, b) for (int i = a; i >= (b); --i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-7
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int mods = 1e9 + 7;
const int maxn = 1e6 + 10;
const int N = 1e5 + 10;
const int E = 1e6 + 10;
int n;
ll a[maxn];
ll fac;
ll prime[maxn]; // 下标从1开始
bool not_prime[maxn];
int sieve(int n) { // 把2到n内所有素数筛选出来
int p = 0;
for (int i = 2; i <= n; ++i) {
if (!not_prime[i])
prime[++p] = i;
for (int j = 1; j <= p && i * prime[j] <= n; j++) {
not_prime[i * prime[j]] = true; // 把比最小素因子的素数的倍数筛除
if (i % prime[j] == 0)
break; // 已找到最小素因子
}
}
return p; // 返回素数个数
}
int cnt[maxn];
bool flg = 1;
void pri_fac(int x) {
for (int i = 1; prime[i] * prime[i] <= x; i++) {
if (x % prime[i] == 0) {
if (cnt[prime[i]]) {
flg = 0;
break;
} else
cnt[prime[i]] = 1;
while (x % prime[i] == 0)
x /= prime[i];
}
}
if (x > 1) {
if (cnt[x]) {
flg = 0;
return;
} else
cnt[x] = 1;
}
}
int main() {
int len = sieve(1000);
cin >> n;
F(i, 1, n) { cin >> a[i]; }
ll gg = a[1];
F(i, 2, n) { gg = __gcd(gg, a[i]); }
if (gg != 1) {
printf("not coprime\n");
return 0;
}
F(i, 1, n) {
pri_fac(a[i]);
if (!flg)
break;
}
if (flg) {
printf("pairwise coprime\n");
} else {
printf("setwise coprime\n");
}
} | #include <bits/stdc++.h>
#define F(i, a, b) for (ll i = a; i <= (b); ++i)
#define dF(i, a, b) for (int i = a; i >= (b); --i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-7
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int mods = 1e9 + 7;
const int maxn = 1e6 + 10;
const int N = 1e5 + 10;
const int E = 1e6 + 10;
int n;
ll a[maxn];
ll fac;
ll prime[maxn]; // 下标从1开始
bool not_prime[maxn];
int sieve(int n) { // 把2到n内所有素数筛选出来
int p = 0;
for (int i = 2; i <= n; ++i) {
if (!not_prime[i])
prime[++p] = i;
for (int j = 1; j <= p && i * prime[j] <= n; j++) {
not_prime[i * prime[j]] = true; // 把比最小素因子的素数的倍数筛除
if (i % prime[j] == 0)
break; // 已找到最小素因子
}
}
return p; // 返回素数个数
}
int cnt[maxn];
bool flg = 1;
void pri_fac(int x) {
for (int i = 1; prime[i] * prime[i] <= x; i++) {
if (x % prime[i] == 0) {
if (cnt[prime[i]]) {
flg = 0;
break;
} else
cnt[prime[i]] = 1;
while (x % prime[i] == 0)
x /= prime[i];
}
}
if (x > 1) {
if (cnt[x]) {
flg = 0;
return;
} else
cnt[x] = 1;
}
}
int main() {
int len = sieve(1000000);
cin >> n;
F(i, 1, n) { cin >> a[i]; }
ll gg = a[1];
F(i, 2, n) { gg = __gcd(gg, a[i]); }
if (gg != 1) {
printf("not coprime\n");
return 0;
}
F(i, 1, n) {
pri_fac(a[i]);
if (!flg)
break;
}
if (flg) {
printf("pairwise coprime\n");
} else {
printf("setwise coprime\n");
}
} | replace | 61 | 62 | 61 | 62 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
// map<pair<long long int,long long int>,long long int>mapa;
// pair<ll,ll>v[200005];
map<ll, ll> mp, mpp;
// priority_queue<ll>pq;
class Myfirst {
private:
string *name;
ll *age;
public:
ll gcd(ll a, ll b) {
if (b == 0)
return a;
a %= b;
return gcd(b, a);
}
ll exte_gcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll x1, y1;
ll d = exte_gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
ll powe(ll d, ll s) {
if (s == 1)
return d;
else if (s == 0)
return 1;
else {
ll u, v = d;
for (u = 1; u < s; u++)
d = d * v;
return d;
}
}
ll count_divisors(ll b) {
ll i, count = 0, n = 1;
for (i = 2; i * i <= b; i++) {
count = 0;
if (b % i == 0) {
while (b % i == 0) {
b = b / i;
count++;
}
n = n * (count + 1);
}
}
if (b > 1)
n = 2 * n;
return n;
}
ll bigmod(ll a, ll b, ll mod) {
if (b == 0)
return 1;
ll x = bigmod(a, b / 2, mod);
x = (x * x) % mod;
if (b % 2)
x = (x * a) % mod;
return x;
}
ll phi(ll n) {
double result = n;
for (ll p = 2; p * p <= n; ++p) {
if (n % p == 0) {
while (n % p == 0)
n /= p;
result *= (1.0 - (1.0 / (double)p));
}
}
if (n > 1)
result *= (1.0 - (1.0 / (double)n));
return (ll)result;
}
void solve() {
ll n, i, mx = 0, j, x;
cin >> n;
ll a[n + 5];
for (i = 1; i <= n; i++)
cin >> a[i];
for (i = 1; i <= n; i++) {
x = a[i];
for (j = 2; j * j <= x; j++) {
if (x % j == 0) {
while (x % j == 0) {
x = x / j;
}
mp[j]++;
mx = max(mp[j], mx);
}
}
if (x > 1)
mp[x]++;
mx = max(mx, mp[x]);
// cout<<mx<<endl;
}
if (mx == 1)
cout << "pairwise coprime";
else if (mx == 0)
cout << "pairwise coprime";
else if (mx < n)
cout << "setwise coprime";
else
cout << "not coprime";
}
};
int main() {
Myfirst *prg = new Myfirst();
prg->solve();
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
// map<pair<long long int,long long int>,long long int>mapa;
// pair<ll,ll>v[200005];
map<ll, ll> mp, mpp;
// priority_queue<ll>pq;
class Myfirst {
private:
string *name;
ll *age;
public:
ll gcd(ll a, ll b) {
if (b == 0)
return a;
a %= b;
return gcd(b, a);
}
ll exte_gcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll x1, y1;
ll d = exte_gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
ll powe(ll d, ll s) {
if (s == 1)
return d;
else if (s == 0)
return 1;
else {
ll u, v = d;
for (u = 1; u < s; u++)
d = d * v;
return d;
}
}
ll count_divisors(ll b) {
ll i, count = 0, n = 1;
for (i = 2; i * i <= b; i++) {
count = 0;
if (b % i == 0) {
while (b % i == 0) {
b = b / i;
count++;
}
n = n * (count + 1);
}
}
if (b > 1)
n = 2 * n;
return n;
}
ll bigmod(ll a, ll b, ll mod) {
if (b == 0)
return 1;
ll x = bigmod(a, b / 2, mod);
x = (x * x) % mod;
if (b % 2)
x = (x * a) % mod;
return x;
}
ll phi(ll n) {
double result = n;
for (ll p = 2; p * p <= n; ++p) {
if (n % p == 0) {
while (n % p == 0)
n /= p;
result *= (1.0 - (1.0 / (double)p));
}
}
if (n > 1)
result *= (1.0 - (1.0 / (double)n));
return (ll)result;
}
void solve() {
ll n, i, mx = 0, j, x;
cin >> n;
ll a[n + 5];
for (i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (i = 1; i <= n; i++) {
x = a[i];
for (j = 2; j * j <= x; j++) {
if (x % j == 0) {
while (x % j == 0) {
x = x / j;
}
mp[j]++;
mx = max(mp[j], mx);
}
}
if (x > 1)
mp[x]++;
mx = max(mx, mp[x]);
// cout<<mx<<endl;
}
if (mx == 1)
cout << "pairwise coprime";
else if (mx == 0)
cout << "pairwise coprime";
else if (mx < n)
cout << "setwise coprime";
else
cout << "not coprime";
}
};
int main() {
Myfirst *prg = new Myfirst();
prg->solve();
}
| replace | 87 | 88 | 87 | 88 | TLE | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, N) for (ll i = 0; i < N; i++)
using ll = long long;
using namespace std;
#define MOD 1000000007
typedef pair<ll, ll> Pl;
typedef vector<int> vi;
int main() {
int n;
cin >> n;
vi a(n);
rep(i, n) cin >> a[i];
int ggg = a[0];
rep(i, n - 1) ggg = __gcd(ggg, a[i + 1]);
int cnt = 0, flag = 1;
rep(i, n) {
if (a[i] % 2 == 0) {
while (a[i] % 2 == 0)
a[i] /= 2;
cnt++;
}
}
if (cnt > 1) {
flag = 0;
}
if (flag) {
for (int j = 3; j < 1000; j += 2) {
cnt = 0;
rep(i, n) {
if (a[i] % j == 0) {
if (a[i] % j == 0) {
while (a[i] % j == 0)
a[i] /= j;
cnt++;
}
}
}
if (cnt > 1) {
flag = 0;
break;
}
}
}
if (flag) {
int ch[101010] = {0};
rep(i, n) {
if (a[i] != 1) {
if (ch[a[i]]) {
flag = 0;
break;
} else {
ch[a[i]]++;
}
}
}
}
if (flag) {
puts("pairwise coprime");
} else if (ggg == 1) {
puts("setwise coprime");
} else {
puts("not coprime");
}
}
| #include <bits/stdc++.h>
#define rep(i, N) for (ll i = 0; i < N; i++)
using ll = long long;
using namespace std;
#define MOD 1000000007
typedef pair<ll, ll> Pl;
typedef vector<int> vi;
int main() {
int n;
cin >> n;
vi a(n);
rep(i, n) cin >> a[i];
int ggg = a[0];
rep(i, n - 1) ggg = __gcd(ggg, a[i + 1]);
int cnt = 0, flag = 1;
rep(i, n) {
if (a[i] % 2 == 0) {
while (a[i] % 2 == 0)
a[i] /= 2;
cnt++;
}
}
if (cnt > 1) {
flag = 0;
}
if (flag) {
for (int j = 3; j < 1000; j += 2) {
cnt = 0;
rep(i, n) {
if (a[i] % j == 0) {
if (a[i] % j == 0) {
while (a[i] % j == 0)
a[i] /= j;
cnt++;
}
}
}
if (cnt > 1) {
flag = 0;
break;
}
}
}
if (flag) {
int ch[1010101] = {0};
rep(i, n) {
if (a[i] != 1) {
if (ch[a[i]]) {
flag = 0;
break;
} else {
ch[a[i]]++;
}
}
}
}
if (flag) {
puts("pairwise coprime");
} else if (ggg == 1) {
puts("setwise coprime");
} else {
puts("not coprime");
}
}
| replace | 46 | 47 | 46 | 47 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
int a[n];
rep(i, n) { cin >> a[i]; }
sort(a, a + n);
int dp[100003]{};
bool z = false;
rep(i, n) {
int q = a[i];
for (int j = 2; j * j <= q; j++) {
if (q % j == 0) {
if (dp[j] != 0) {
z = true;
break;
} else {
dp[j] = 1;
while (q % j == 0)
q /= j;
}
}
}
if (q != 1 && dp[q] == 1) {
z = true;
break;
} else if (q != 1) {
dp[q] = 1;
}
if (z)
break;
}
// rep(i,n){
// if(a[i]==a[i+1]){
// z=true;
// break;
// }
// for(int j=1;a[i]*j<=a[n-1];j++){
// if(j==1&&dp[a[i]*j]!=0){
// z=true;
// break;
// //z=true;
// }else dp[a[i]*j]=1;
// }
// if(z)break;
// }
// //cout<<z << " ";
// rep(i,20)cout<<dp[i]<<" ";
if (z == false) {
cout << "pairwise coprime" << endl;
return 0;
}
int p = a[0];
for (int i = 1; i < n; i++) {
p = __gcd(p, a[i]);
}
if (p == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
int a[n];
rep(i, n) { cin >> a[i]; }
// sort(a,a+n);
int dp[1000003]{};
bool z = false;
rep(i, n) {
int q = a[i];
for (int j = 2; j * j <= q; j++) {
if (q % j == 0) {
if (dp[j] != 0) {
z = true;
break;
} else {
dp[j] = 1;
while (q % j == 0)
q /= j;
}
}
}
if (q != 1 && dp[q] == 1) {
z = true;
break;
} else if (q != 1) {
dp[q] = 1;
}
if (z)
break;
}
// rep(i,n){
// if(a[i]==a[i+1]){
// z=true;
// break;
// }
// for(int j=1;a[i]*j<=a[n-1];j++){
// if(j==1&&dp[a[i]*j]!=0){
// z=true;
// break;
// //z=true;
// }else dp[a[i]*j]=1;
// }
// if(z)break;
// }
// //cout<<z << " ";
// rep(i,20)cout<<dp[i]<<" ";
if (z == false) {
cout << "pairwise coprime" << endl;
return 0;
}
int p = a[0];
for (int i = 1; i < n; i++) {
p = __gcd(p, a[i]);
}
if (p == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
}
| replace | 17 | 19 | 17 | 19 | 0 | |
p02574 | Python | Runtime Error | n = int(input())
(*A,) = map(int, input().split())
m = max(A)
C = [0 for a in range(m + 1)]
for a in A:
C[a] += 1
s = max(sum(C[a::a]) for a in range(2, m + 1))
if s < 2:
print("pairwise coprime")
elif s < n:
print("setwise coprime")
else:
print("not coprime")
| n = int(input())
(*A,) = map(int, input().split())
m = max(A)
C = [0 for a in range(m + 1)]
for a in A:
C[a] += 1
s = 0
for a in range(2, m + 1):
s = max(s, sum(C[a::a]))
if s < 2:
print("pairwise coprime")
elif s < n:
print("setwise coprime")
else:
print("not coprime")
| replace | 6 | 7 | 6 | 9 | 0 | |
p02574 | Python | Runtime Error | n = int(input())
(*A,) = map(int, input().split())
m = max(A)
is_prime = [True] * (m + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, m + 1):
for j in range(i * 2, m + 1, i):
is_prime[j] = False
primes = [i for i in range(m + 1) if is_prime[i]]
Amap = {a: 0 for a in range(1, m + 1)}
for a in A:
Amap[a] += 1
# Pmap[p]はAにでてくるpの倍数の数
Pmap = {p: 0 for p in primes}
for p in primes:
for a in range(p, m + 1, p):
Pmap[p] += Amap[a]
score = max(Pmap.values())
if score == 1:
print("pairwise coprime")
elif score != n:
print("setwise coprime")
else:
print("not coprime")
| n = int(input())
(*A,) = map(int, input().split())
m = max(A)
is_prime = [True] * (m + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, m + 1):
for j in range(i * 2, m + 1, i):
is_prime[j] = False
primes = [i for i in range(m + 1) if is_prime[i]]
Amap = {a: 0 for a in range(1, m + 1)}
for a in A:
Amap[a] += 1
# Pmap[p]はAにでてくるpの倍数の数
Pmap = {p: 0 for p in primes}
for p in primes:
for a in range(p, m + 1, p):
Pmap[p] += Amap[a]
try:
score = max(Pmap.values())
except BaseException:
print("pairwise coprime")
exit()
if score == 1:
print("pairwise coprime")
elif score != n:
print("setwise coprime")
else:
print("not coprime")
| replace | 22 | 24 | 22 | 27 | 0 | |
p02574 | C++ | Runtime Error | /******
AUTHOR : RUDRANSH TRIPATHI, IIIT NAGPUR, CCID(rt24) & CFID(rsgt24)
MOTTO : Use criticism as fuel and you will never run out of energy.
AIM : TO BECOME A BETTER CODER
INTROSPECT + COURSE CORRECTIONS = CATALYST FOR SUCCESS
Every moment is an opportunity to better yourself
*******/
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int MAX = 1e5 + 5;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define int long long int
#define pb push_back
#define d(x) cout << x << "\n"
// basic mathematics
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
// modular arithmetic
int powermod(int x, int y, int p) {
int res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
// Prime numbers till n precomputation - range query
int prefix[MAX + 1];
void buildPrefix() {
bool prime[MAX + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= MAX; p++) {
if (prime[p] == true) {
for (int i = p * 2; i <= MAX; i += p)
prime[i] = false;
}
}
prefix[0] = prefix[1] = 0;
for (int p = 2; p <= MAX; p++) {
prefix[p] = prefix[p - 1];
if (prime[p])
prefix[p]++;
}
}
int query(int L, int R) { return prefix[R] - prefix[L - 1]; }
// Find all paths from a to b in an undirected graph
vector<int> g[MAX];
int visited[MAX];
// count of all the paths from 1 to n;
void dfs(int visited[MAX], int u, int v, vector<int> path) {
visited[u] = 1;
if (u == v) {
for (int i = 0; i < path.size(); i++) {
cout << path[i] << " ";
}
cout << "\n";
} else {
for (int i = 0; i < g[u].size(); i++) {
int y = g[u][i];
if (visited[y] == 0) {
visited[y] = 1;
path.pb(y);
dfs(visited, y, v, path);
path.pop_back();
}
}
}
visited[u] = 0;
}
#define N 100050
int lpf[N], mobius[N];
// Function to calculate least
// prime factor of each number
void least_prime_factor() {
for (int i = 2; i < N; i++)
// If it is a prime number
if (!lpf[i])
for (int j = i; j < N; j += i)
// For all multiples which are not
// visited yet.
if (!lpf[j])
lpf[j] = i;
}
// Function to find the value of Mobius function
// for all the numbers from 1 to n
void Mobius() {
for (int i = 1; i < N; i++) {
// If number is one
if (i == 1)
mobius[i] = 1;
else {
// If number has a squared prime factor
if (lpf[i / lpf[i]] == lpf[i])
mobius[i] = 0;
// Multiply -1 with the previous number
else
mobius[i] = -1 * mobius[i / lpf[i]];
}
}
}
// Function to find the number of pairs
// such that gcd equals to 1
int gcd_pairs(int a[], int n) {
// To store maximum number
int maxi = 0;
// To store frequency of each number
int fre[N] = {0};
// Find frequency and maximum number
for (int i = 0; i < n; i++) {
fre[a[i]]++;
maxi = max(a[i], maxi);
}
least_prime_factor();
Mobius();
// To store number of pairs with gcd equals to 1
int ans = 0;
// Traverse through the all possible elements
for (int i = 1; i <= maxi; i++) {
if (!mobius[i])
continue;
int temp = 0;
for (int j = i; j <= maxi; j += i)
temp += fre[j];
ans += temp * (temp - 1) / 2 * mobius[i];
}
// Return the number of pairs
return ans;
}
int findProductSum(int A[], int n) {
// calculating array sum (a1 + a2 ... + an)
int array_sum = 0;
for (int i = 0; i < n; i++)
array_sum = (array_sum + A[i]) % M;
// calcualting square of array sum
// (a1 + a2 + ... + an)^2
int array_sum_square = (array_sum * array_sum) % M;
// calcualting a1^2 + a2^2 + ... + an^2
int individual_square_sum = 0;
for (int i = 0; i < n; i++)
individual_square_sum += (A[i] * A[i]) % M;
// required sum is (array_sum_square -
// individual_square_sum) / 2
return ((array_sum_square - individual_square_sum % M) / 2) % M;
}
int findGCD(int arr[], int n) {
int result = arr[0];
for (int i = 1; i < n; i++) {
result = gcd(arr[i], result);
if (result == 1) {
return 1;
}
}
return result;
}
void solve() {
int n;
cin >> n;
int ar[n];
for (int i = 0; i < n; i++)
cin >> ar[i];
int yy = findGCD(ar, n);
int xx = gcd_pairs(ar, n);
if (xx == (n * (n - 1)) / 2)
cout << "pairwise coprime"
<< "\n";
else if (yy == 1)
cout << "setwise coprime"
<< "\n";
else
cout << "not coprime"
<< "\n";
}
int32_t main(void) {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
} | /******
AUTHOR : RUDRANSH TRIPATHI, IIIT NAGPUR, CCID(rt24) & CFID(rsgt24)
MOTTO : Use criticism as fuel and you will never run out of energy.
AIM : TO BECOME A BETTER CODER
INTROSPECT + COURSE CORRECTIONS = CATALYST FOR SUCCESS
Every moment is an opportunity to better yourself
*******/
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int MAX = 1e5 + 5;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define int long long int
#define pb push_back
#define d(x) cout << x << "\n"
// basic mathematics
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
// modular arithmetic
int powermod(int x, int y, int p) {
int res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
// Prime numbers till n precomputation - range query
int prefix[MAX + 1];
void buildPrefix() {
bool prime[MAX + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= MAX; p++) {
if (prime[p] == true) {
for (int i = p * 2; i <= MAX; i += p)
prime[i] = false;
}
}
prefix[0] = prefix[1] = 0;
for (int p = 2; p <= MAX; p++) {
prefix[p] = prefix[p - 1];
if (prime[p])
prefix[p]++;
}
}
int query(int L, int R) { return prefix[R] - prefix[L - 1]; }
// Find all paths from a to b in an undirected graph
vector<int> g[MAX];
int visited[MAX];
// count of all the paths from 1 to n;
void dfs(int visited[MAX], int u, int v, vector<int> path) {
visited[u] = 1;
if (u == v) {
for (int i = 0; i < path.size(); i++) {
cout << path[i] << " ";
}
cout << "\n";
} else {
for (int i = 0; i < g[u].size(); i++) {
int y = g[u][i];
if (visited[y] == 0) {
visited[y] = 1;
path.pb(y);
dfs(visited, y, v, path);
path.pop_back();
}
}
}
visited[u] = 0;
}
#define N 1000000
int lpf[N], mobius[N];
// Function to calculate least
// prime factor of each number
void least_prime_factor() {
for (int i = 2; i < N; i++)
// If it is a prime number
if (!lpf[i])
for (int j = i; j < N; j += i)
// For all multiples which are not
// visited yet.
if (!lpf[j])
lpf[j] = i;
}
// Function to find the value of Mobius function
// for all the numbers from 1 to n
void Mobius() {
for (int i = 1; i < N; i++) {
// If number is one
if (i == 1)
mobius[i] = 1;
else {
// If number has a squared prime factor
if (lpf[i / lpf[i]] == lpf[i])
mobius[i] = 0;
// Multiply -1 with the previous number
else
mobius[i] = -1 * mobius[i / lpf[i]];
}
}
}
// Function to find the number of pairs
// such that gcd equals to 1
int gcd_pairs(int a[], int n) {
// To store maximum number
int maxi = 0;
// To store frequency of each number
int fre[N] = {0};
// Find frequency and maximum number
for (int i = 0; i < n; i++) {
fre[a[i]]++;
maxi = max(a[i], maxi);
}
least_prime_factor();
Mobius();
// To store number of pairs with gcd equals to 1
int ans = 0;
// Traverse through the all possible elements
for (int i = 1; i <= maxi; i++) {
if (!mobius[i])
continue;
int temp = 0;
for (int j = i; j <= maxi; j += i)
temp += fre[j];
ans += temp * (temp - 1) / 2 * mobius[i];
}
// Return the number of pairs
return ans;
}
int findProductSum(int A[], int n) {
// calculating array sum (a1 + a2 ... + an)
int array_sum = 0;
for (int i = 0; i < n; i++)
array_sum = (array_sum + A[i]) % M;
// calcualting square of array sum
// (a1 + a2 + ... + an)^2
int array_sum_square = (array_sum * array_sum) % M;
// calcualting a1^2 + a2^2 + ... + an^2
int individual_square_sum = 0;
for (int i = 0; i < n; i++)
individual_square_sum += (A[i] * A[i]) % M;
// required sum is (array_sum_square -
// individual_square_sum) / 2
return ((array_sum_square - individual_square_sum % M) / 2) % M;
}
int findGCD(int arr[], int n) {
int result = arr[0];
for (int i = 1; i < n; i++) {
result = gcd(arr[i], result);
if (result == 1) {
return 1;
}
}
return result;
}
void solve() {
int n;
cin >> n;
int ar[n];
for (int i = 0; i < n; i++)
cin >> ar[i];
int yy = findGCD(ar, n);
int xx = gcd_pairs(ar, n);
if (xx == (n * (n - 1)) / 2)
cout << "pairwise coprime"
<< "\n";
else if (yy == 1)
cout << "setwise coprime"
<< "\n";
else
cout << "not coprime"
<< "\n";
}
int32_t main(void) {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
} | replace | 98 | 99 | 98 | 99 | -11 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define forn(i, a, n) for (int i = a; i < n; i++)
int n;
int a[1000001];
vector<int> v;
map<int, int> mp;
int isp[1000001];
void buildprime() {
isp[0] = isp[1] = 1;
forn(i, 2, 1000001) {
if (isp[i])
continue;
for (int j = i + i; j < 1000001; j += i)
isp[j] = 1;
}
forn(i, 2, 1000001) if (!isp[i]) v.push_back(i);
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
bool ispairwise() {
vector<int> w;
forn(i, 0, n) {
int x = a[i];
forn(i, 0, v.size()) {
if (v[i] * v[i] > x)
break;
if (x % v[i] == 0) {
mp[v[i]]++;
w.push_back(v[i]);
while (x % v[i] == 0) {
x /= v[i];
}
}
}
if (x != 1) {
mp[x]++;
w.push_back(x);
}
}
sort(w.begin(), w.end());
int mx = w[w.size() - 1];
forn(i, 0, v.size()) {
if (v[i] > mx)
break;
if (mp[v[i]] > 1)
return false;
}
return true;
}
bool issetwise() {
int res = a[0];
forn(i, 0, n) { res = gcd(res, a[i]); }
return res == 1;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
buildprime();
cin >> n;
forn(i, 0, n) cin >> a[i];
bool isp = ispairwise();
bool iss = issetwise();
if (isp) {
cout << "pairwise coprime" << endl;
return 0;
} else if (iss) {
cout << "setwise coprime" << endl;
return 0;
}
cout << "not coprime" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define forn(i, a, n) for (int i = a; i < n; i++)
int n;
int a[1000001];
vector<int> v;
map<int, int> mp;
int isp[1000001];
void buildprime() {
isp[0] = isp[1] = 1;
forn(i, 2, 1000001) {
if (isp[i])
continue;
for (int j = i + i; j < 1000001; j += i)
isp[j] = 1;
}
forn(i, 2, 1000001) if (!isp[i]) v.push_back(i);
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
bool ispairwise() {
vector<int> w;
forn(i, 0, n) {
int x = a[i];
forn(i, 0, v.size()) {
if (v[i] * v[i] > x)
break;
if (x % v[i] == 0) {
mp[v[i]]++;
w.push_back(v[i]);
while (x % v[i] == 0) {
x /= v[i];
}
}
}
if (x != 1 || x == i) {
mp[x]++;
w.push_back(x);
}
}
sort(w.begin(), w.end());
int mx = w[w.size() - 1];
forn(i, 0, v.size()) {
if (v[i] > mx)
break;
if (mp[v[i]] > 1)
return false;
}
return true;
}
bool issetwise() {
int res = a[0];
forn(i, 0, n) { res = gcd(res, a[i]); }
return res == 1;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
buildprime();
cin >> n;
forn(i, 0, n) cin >> a[i];
bool isp = ispairwise();
bool iss = issetwise();
if (isp) {
cout << "pairwise coprime" << endl;
return 0;
} else if (iss) {
cout << "setwise coprime" << endl;
return 0;
}
cout << "not coprime" << endl;
return 0;
} | replace | 40 | 41 | 40 | 41 | 0 | |
p02574 | C++ | Runtime Error | #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 2e5 + 100;
typedef long long ll;
// prime次数
int num[N], n;
inline void divide(int x) {
for (int i = 2; i <= x / i; i++) {
if (x % i == 0) {
num[i]++;
while (x % i == 0)
x /= i;
}
}
if (x > 1)
num[x]++;
}
int main() {
cin >> n;
int MaxNum = 0;
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
divide(x);
MaxNum = max(MaxNum, x);
}
int f1 = 0;
for (int i = 2; i <= MaxNum; i++) {
if (num[i] >= n) {
puts("not coprime");
return 0;
}
if (num[i] > 1) {
f1 = 1;
// return 0;
}
}
if (f1)
puts("setwise coprime");
else
puts("pairwise coprime");
return 0;
} | #include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 1e6 + 100;
typedef long long ll;
// prime次数
int num[N], n;
inline void divide(int x) {
for (int i = 2; i <= x / i; i++) {
if (x % i == 0) {
num[i]++;
while (x % i == 0)
x /= i;
}
}
if (x > 1)
num[x]++;
}
int main() {
cin >> n;
int MaxNum = 0;
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
divide(x);
MaxNum = max(MaxNum, x);
}
int f1 = 0;
for (int i = 2; i <= MaxNum; i++) {
if (num[i] >= n) {
puts("not coprime");
return 0;
}
if (num[i] > 1) {
f1 = 1;
// return 0;
}
}
if (f1)
puts("setwise coprime");
else
puts("pairwise coprime");
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02574 | C++ | Runtime Error |
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>
long long mod = 1e9 + 7;
class Mint {
public:
long long x;
Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
Mint(long long a) {
x = a % mod;
while (x < 0) {
x += mod;
}
};
Mint &operator+=(const Mint &a) {
x += a.x;
x %= mod;
return *this;
}
Mint &operator-=(const Mint &a) {
x += (mod - a.x);
x %= mod;
return *this;
}
Mint &operator*=(const Mint &a) {
x *= a.x;
x %= mod;
return *this;
}
// a^n mod を計算する
// Useaeg: Mint z = Mint(2).pow(n);
Mint pow(long long n) const {
if (n == 0)
return Mint(1);
Mint y = pow(n >> 1); // pow(n/2)を計算する
y *= y;
if (n % 2 == 1)
y *= *this;
return y;
}
// a^{-1} mod を計算する
Mint modinv(const Mint &a) const { return a.pow(mod - 2); }
Mint &operator/=(const Mint &a) {
x *= modinv(a).x;
x %= mod;
return *this;
}
Mint operator+(Mint &a) const {
Mint y(*this);
y += a;
return y;
}
Mint operator-(Mint &a) const {
Mint y(*this);
y -= a;
return y;
}
Mint operator*(Mint &a) const {
Mint y(*this);
y *= a;
return y;
}
Mint operator/(Mint &a) const {
Mint y(*this);
y /= a;
return y.x;
}
// nCk @mod を計算する
Mint nCk(Mint &n, const long long k) const {
Mint y = Mint(1);
Mint one = Mint(1);
for (Mint i(0); (i.x) < k; i.x++) {
y *= (n - i);
y /= (i + one);
}
return y;
}
// nPk @mod を計算する
Mint nPk(Mint &n, long long k) const {
Mint y(1);
for (Mint i(0); (i.x) < k; i.x++) {
y *= (n - i);
}
return y;
}
};
int getgcd(int a, int b) {
int max = std::max(a, b);
int min = std::min(a, b);
if (min == 0)
return max;
return getgcd(min, max % min);
}
int main() {
int N;
std::cin >> N;
std::vector<int> A(N);
for (int i = 0; i < N; i++) {
std::cin >> A[i];
}
int gcd = A[0];
for (int i = 1; i < N; i++) {
gcd = getgcd(gcd, A[i]);
// printf("gcd (i=%d)=%d\n", i, gcd);
}
std::vector<int> prime;
std::vector<bool> use(3001, false);
for (int i = 2; i * i <= 1000000; i++) {
if (!use[i]) {
prime.push_back(i);
for (int j = i * 2; j * j <= 1000000; j += i) {
use[j] = true;
}
}
}
// printf("kuso\n");
bool ng = false;
for (int p : prime) {
// printf("p=%d\n", p);
bool find = false;
for (int j = 0; j < N; j++) {
if (find && A[j] % p == 0) {
// printf("find: A[%d]=%d, p=%d\n", j, A[j], p);
ng = true;
break;
}
// while (A[j]>=1 && A[j]%p==0){
// printf("A[%d]=%d\n", j, A[j]);
while (A[j] % p == 0) {
// printf("A[%d]=%d\n", j,A[j]);
A[j] /= p;
find = true;
}
}
}
// printf("hoge\n");
std::vector<int> amari;
for (int i = 0; i < N; i++) {
if (A[i] != 1)
amari.push_back(A[i]);
}
std::sort(amari.begin(), amari.end());
for (int i = 0; i < amari.size() - 1; i++) {
if (amari[i] == amari[i + 1]) {
ng = true;
break;
}
}
// printf("gcd=%d\n", gcd);
if (!ng) {
printf("pairwise coprime\n");
} else if (gcd == 1) {
printf("setwise coprime\n");
} else {
printf("not coprime\n");
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>
long long mod = 1e9 + 7;
class Mint {
public:
long long x;
Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
Mint(long long a) {
x = a % mod;
while (x < 0) {
x += mod;
}
};
Mint &operator+=(const Mint &a) {
x += a.x;
x %= mod;
return *this;
}
Mint &operator-=(const Mint &a) {
x += (mod - a.x);
x %= mod;
return *this;
}
Mint &operator*=(const Mint &a) {
x *= a.x;
x %= mod;
return *this;
}
// a^n mod を計算する
// Useaeg: Mint z = Mint(2).pow(n);
Mint pow(long long n) const {
if (n == 0)
return Mint(1);
Mint y = pow(n >> 1); // pow(n/2)を計算する
y *= y;
if (n % 2 == 1)
y *= *this;
return y;
}
// a^{-1} mod を計算する
Mint modinv(const Mint &a) const { return a.pow(mod - 2); }
Mint &operator/=(const Mint &a) {
x *= modinv(a).x;
x %= mod;
return *this;
}
Mint operator+(Mint &a) const {
Mint y(*this);
y += a;
return y;
}
Mint operator-(Mint &a) const {
Mint y(*this);
y -= a;
return y;
}
Mint operator*(Mint &a) const {
Mint y(*this);
y *= a;
return y;
}
Mint operator/(Mint &a) const {
Mint y(*this);
y /= a;
return y.x;
}
// nCk @mod を計算する
Mint nCk(Mint &n, const long long k) const {
Mint y = Mint(1);
Mint one = Mint(1);
for (Mint i(0); (i.x) < k; i.x++) {
y *= (n - i);
y /= (i + one);
}
return y;
}
// nPk @mod を計算する
Mint nPk(Mint &n, long long k) const {
Mint y(1);
for (Mint i(0); (i.x) < k; i.x++) {
y *= (n - i);
}
return y;
}
};
int getgcd(int a, int b) {
int max = std::max(a, b);
int min = std::min(a, b);
if (min == 0)
return max;
return getgcd(min, max % min);
}
int main() {
int N;
std::cin >> N;
std::vector<int> A(N);
for (int i = 0; i < N; i++) {
std::cin >> A[i];
}
int gcd = A[0];
for (int i = 1; i < N; i++) {
gcd = getgcd(gcd, A[i]);
// printf("gcd (i=%d)=%d\n", i, gcd);
}
std::vector<int> prime;
std::vector<bool> use(3001, false);
for (int i = 2; i * i <= 1000000; i++) {
if (!use[i]) {
prime.push_back(i);
for (int j = i * 2; j * j <= 1000000; j += i) {
use[j] = true;
}
}
}
// printf("kuso\n");
bool ng = false;
for (int p : prime) {
// printf("p=%d\n", p);
bool find = false;
for (int j = 0; j < N; j++) {
if (find && A[j] % p == 0) {
// printf("find: A[%d]=%d, p=%d\n", j, A[j], p);
ng = true;
break;
}
// while (A[j]>=1 && A[j]%p==0){
// printf("A[%d]=%d\n", j, A[j]);
while (A[j] % p == 0) {
// printf("A[%d]=%d\n", j,A[j]);
A[j] /= p;
find = true;
}
}
}
// printf("hoge\n");
std::vector<int> amari;
for (int i = 0; i < N; i++) {
if (A[i] != 1)
amari.push_back(A[i]);
}
if (amari.size() >= 2) {
std::sort(amari.begin(), amari.end());
for (int i = 0; i < amari.size() - 1; i++) {
if (amari[i] == amari[i + 1]) {
ng = true;
break;
}
}
}
// printf("gcd=%d\n", gcd);
if (!ng) {
printf("pairwise coprime\n");
} else if (gcd == 1) {
printf("setwise coprime\n");
} else {
printf("not coprime\n");
}
return 0;
}
| replace | 165 | 170 | 165 | 172 | -11 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<int> vis(100001, 0);
int flag;
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
int findGCD(vector<int> arr, int n) {
int result = arr[0];
for (int i = 1; i < n; i++) {
result = gcd(arr[i], result);
if (result == 1) {
return 1;
}
}
return result;
}
void primeFactors(int n) {
if (n % 2 == 0) {
if (vis[2] == 0) {
vis[2] = 1;
} else {
flag = 1;
return;
}
}
while (n % 2 == 0) {
n = n / 2;
}
for (int i = 3; i <= sqrt(n); i = i + 2) {
if (n % i == 0) {
if (vis[i] == 0) {
vis[i] = 1;
} else {
flag = 1;
return;
}
}
while (n % i == 0) {
n = n / i;
}
}
if (n > 2) {
if (vis[n] == 0) {
vis[n] = 1;
} else {
flag = 1;
return;
}
}
}
void solve() {
int n;
cin >> n;
vector<int> v(n);
flag = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 0; i < n; i++) {
if (flag == 1) {
break;
}
primeFactors(v[i]);
}
if (flag == 0) {
cout << "pairwise coprime";
return;
}
if (findGCD(v, v.size()) == 1) {
cout << "setwise coprime";
return;
}
cout << "not coprime";
return;
}
int main() {
int t;
// cin>>t;
t = 1;
while (t--) {
solve();
cout << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
vector<int> vis(1000001, 0);
int flag;
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
int findGCD(vector<int> arr, int n) {
int result = arr[0];
for (int i = 1; i < n; i++) {
result = gcd(arr[i], result);
if (result == 1) {
return 1;
}
}
return result;
}
void primeFactors(int n) {
if (n % 2 == 0) {
if (vis[2] == 0) {
vis[2] = 1;
} else {
flag = 1;
return;
}
}
while (n % 2 == 0) {
n = n / 2;
}
for (int i = 3; i <= sqrt(n); i = i + 2) {
if (n % i == 0) {
if (vis[i] == 0) {
vis[i] = 1;
} else {
flag = 1;
return;
}
}
while (n % i == 0) {
n = n / i;
}
}
if (n > 2) {
if (vis[n] == 0) {
vis[n] = 1;
} else {
flag = 1;
return;
}
}
}
void solve() {
int n;
cin >> n;
vector<int> v(n);
flag = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 0; i < n; i++) {
if (flag == 1) {
break;
}
primeFactors(v[i]);
}
if (flag == 0) {
cout << "pairwise coprime";
return;
}
if (findGCD(v, v.size()) == 1) {
cout << "setwise coprime";
return;
}
cout << "not coprime";
return;
}
int main() {
int t;
// cin>>t;
t = 1;
while (t--) {
solve();
cout << endl;
}
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
int a[1000005];
unordered_map<int, int> mp;
int num[1000005];
int main() {
#ifdef LOCAL
freopen("in1.txt", "r", stdin);
freopen("out1.txt", "w", stdout);
#endif
int n;
cin >> n;
// bool cjs = false;
for (int i = 0; i < n; i++) {
cin >> a[i];
// if(a[i] == 1) cjs = true;
mp[a[i]] = 1;
num[a[i]]++;
}
// if(cjs) {
// puts("not coprime");
// exit(0);
// }
bool dyh = false;
for (int i = 2; i < 1000005; i++) {
bool flag = false;
for (int j = 1; i * j < 1000010; j++) {
if (mp[i * j] == 1 and num[i * j] > 1) {
dyh = true;
break;
}
if (mp[i * j] == 1 and flag) {
dyh = true;
break;
}
if (mp[i * j] == 1 and !flag)
flag = true;
}
}
if (dyh) {
int tmp = a[0];
for (int i = 1; i < n; i++) {
tmp = __gcd(tmp, a[i]);
}
if (tmp == 1) {
puts("setwise coprime");
} else
puts("not coprime");
} else {
puts("pairwise coprime");
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
int a[1000005];
unordered_map<int, int> mp;
int num[1000010];
int main() {
#ifdef LOCAL
freopen("in1.txt", "r", stdin);
freopen("out1.txt", "w", stdout);
#endif
int n;
cin >> n;
// bool cjs = false;
for (int i = 0; i < n; i++) {
cin >> a[i];
// if(a[i] == 1) cjs = true;
mp[a[i]] = 1;
num[a[i]]++;
}
// if(cjs) {
// puts("not coprime");
// exit(0);
// }
bool dyh = false;
for (int i = 2; i < 1000005; i++) {
bool flag = false;
for (int j = 1; i * j < 1000010; j++) {
if (mp[i * j] == 1 and num[i * j] > 1) {
dyh = true;
break;
}
if (mp[i * j] == 1 and flag) {
dyh = true;
break;
}
if (mp[i * j] == 1 and !flag)
flag = true;
}
}
if (dyh) {
int tmp = a[0];
for (int i = 1; i < n; i++) {
tmp = __gcd(tmp, a[i]);
}
if (tmp == 1) {
puts("setwise coprime");
} else
puts("not coprime");
} else {
puts("pairwise coprime");
}
return 0;
} | replace | 6 | 7 | 6 | 7 | TLE | |
p02574 | C++ | Runtime Error | #ifndef ONLINE_JUDGE
#define DEBUG 1
#if DEBUG
#define _GLIBCXX_DEBUG
#endif
#endif
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using tll = tuple<ll, ll, ll>;
using vtll = vector<tll>;
using vvtll = vector<vtll>;
#define all(v) (v).begin(), (v).end()
#define for1(i, n) for (ll i = 0; i < (n); i++)
#define for2(i, m, n) for (ll i = (m); i < (n); i++)
#define for3(i, m, n, d) for (ll i = (m); i < (n); i += (d))
#define rfor2(i, m, n) for (ll i = (m); i > (n); i--)
#define rfor3(i, m, n, d) for (ll i = (m); i > (n); i += (d))
#define PI 3.1415926535897932384626433832795028841971693993751L
#define INF 1111111111111111111LL
#define print(...) print_1(__VA_ARGS__)
#define in(...) in_1(__VA_ARGS__)
#if DEBUG
#define dump(...) dump_1(#__VA_ARGS__, __VA_ARGS__)
#define dumpa(...) dumpa_1(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#define dumpa(...)
#endif
template <typename Head> void dump_1(const char *str, Head &&h) {
cerr << str << ": " << h << '\n';
}
template <typename Head, typename... Tail>
void dump_1(const char *str, Head &&h, Tail &&...t) {
while (*str != ',') {
cerr << *str++;
}
cerr << ": " << h << ' ';
dump_1(str + 1, t...);
}
template <typename T>
void dumpa_1(const char *str, const T v[], const ll size) {
while (*str != ',') {
cerr << *str++;
}
cerr << ": ";
for1(i, size) {
if (i != 0) {
cerr << ' ';
}
cerr << v[i];
}
cerr << '\n';
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &v) {
os << v.first << ' ' << v.second;
return os;
}
template <typename T1, typename T2, typename T3>
ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &v) {
os << get<0>(v) << ' ' << get<1>(v) << ' ' << get<2>(v);
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) {
os << ' ';
}
os << *it;
}
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) {
os << ' ';
}
os << *it;
}
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) {
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) {
os << ' ';
}
os << *it;
}
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &v) {
os << '{';
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) {
os << ", ";
}
os << it->first << ':' << it->second;
}
os << '}';
return os;
}
ll divup(ll nume, ll deno) {
assert(nume >= 0);
assert(deno > 0);
return (nume + deno - 1) / deno;
}
void Yes(void) { cout << "Yes\n"; }
void No(void) { cout << "No\n"; }
void YES(void) { cout << "YES\n"; }
void NO(void) { cout << "NO\n"; }
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> void vin(vector<T> &v) {
ll len = v.size();
for1(i, len) { cin >> v[i]; }
}
template <typename Head> void in_1(Head &h) { cin >> h; }
template <typename Head, typename... Tail> void in_1(Head &h, Tail &...t) {
cin >> h;
in_1(t...);
}
template <typename Head> void print_1(Head &&h) { cout << h << '\n'; }
template <typename Head, typename... Tail> void print_1(Head &&h, Tail &&...t) {
cout << h << ' ';
print_1(t...);
}
//---------------------------------------------------------
const ll mod = 1000000007LL; // 10**9 + 7
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
friend istream &operator>>(istream &is, mint &v) {
is >> v.x;
return is;
}
friend ostream &operator<<(ostream &os, const mint &v) {
os << v.x;
return os;
}
};
//---------------------------------------------------------
struct mintcomb {
vector<mint> fact, ifact;
mintcomb(int n) : fact(n + 1), ifact(n + 1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i) {
fact[i] = fact[i - 1] * i;
}
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i) {
ifact[i - 1] = ifact[i] * i;
}
}
mint permutation(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[n - k];
}
mint combination(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
};
//---------------------------------------------------------
void solve() {
ll N;
in(N);
vll A(N);
vin(A);
ll all_gcd = A[0];
vll prime;
for2(i, 2, 1001) {
bool ok = true;
for (ll p : prime) {
if (i % p == 0) {
ok = false;
break;
}
}
if (ok) {
prime.push_back(i);
}
}
for2(i, 1, N) { all_gcd = __gcd(all_gcd, A[i]); }
if (all_gcd != 1) {
print("not coprime");
return;
}
vll used(1001);
for1(i, N) {
ll a = A[i];
for (ll p : prime) {
if (a % p == 0) {
if (used[p]) {
print("setwise coprime");
return;
}
used[p] = 1;
while (a % p == 0) {
a /= p;
}
}
}
if (a != 1) {
if (used[a]) {
print("setwise coprime");
return;
}
used[a] = 1;
}
}
print("pairwise coprime");
}
//---------------------------------------------------------
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(16);
cerr << fixed << setprecision(16);
solve();
}
| #ifndef ONLINE_JUDGE
#define DEBUG 1
#if DEBUG
#define _GLIBCXX_DEBUG
#endif
#endif
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using tll = tuple<ll, ll, ll>;
using vtll = vector<tll>;
using vvtll = vector<vtll>;
#define all(v) (v).begin(), (v).end()
#define for1(i, n) for (ll i = 0; i < (n); i++)
#define for2(i, m, n) for (ll i = (m); i < (n); i++)
#define for3(i, m, n, d) for (ll i = (m); i < (n); i += (d))
#define rfor2(i, m, n) for (ll i = (m); i > (n); i--)
#define rfor3(i, m, n, d) for (ll i = (m); i > (n); i += (d))
#define PI 3.1415926535897932384626433832795028841971693993751L
#define INF 1111111111111111111LL
#define print(...) print_1(__VA_ARGS__)
#define in(...) in_1(__VA_ARGS__)
#if DEBUG
#define dump(...) dump_1(#__VA_ARGS__, __VA_ARGS__)
#define dumpa(...) dumpa_1(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#define dumpa(...)
#endif
template <typename Head> void dump_1(const char *str, Head &&h) {
cerr << str << ": " << h << '\n';
}
template <typename Head, typename... Tail>
void dump_1(const char *str, Head &&h, Tail &&...t) {
while (*str != ',') {
cerr << *str++;
}
cerr << ": " << h << ' ';
dump_1(str + 1, t...);
}
template <typename T>
void dumpa_1(const char *str, const T v[], const ll size) {
while (*str != ',') {
cerr << *str++;
}
cerr << ": ";
for1(i, size) {
if (i != 0) {
cerr << ' ';
}
cerr << v[i];
}
cerr << '\n';
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &v) {
os << v.first << ' ' << v.second;
return os;
}
template <typename T1, typename T2, typename T3>
ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &v) {
os << get<0>(v) << ' ' << get<1>(v) << ' ' << get<2>(v);
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) {
os << ' ';
}
os << *it;
}
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) {
os << ' ';
}
os << *it;
}
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) {
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) {
os << ' ';
}
os << *it;
}
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &v) {
os << '{';
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) {
os << ", ";
}
os << it->first << ':' << it->second;
}
os << '}';
return os;
}
ll divup(ll nume, ll deno) {
assert(nume >= 0);
assert(deno > 0);
return (nume + deno - 1) / deno;
}
void Yes(void) { cout << "Yes\n"; }
void No(void) { cout << "No\n"; }
void YES(void) { cout << "YES\n"; }
void NO(void) { cout << "NO\n"; }
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> void vin(vector<T> &v) {
ll len = v.size();
for1(i, len) { cin >> v[i]; }
}
template <typename Head> void in_1(Head &h) { cin >> h; }
template <typename Head, typename... Tail> void in_1(Head &h, Tail &...t) {
cin >> h;
in_1(t...);
}
template <typename Head> void print_1(Head &&h) { cout << h << '\n'; }
template <typename Head, typename... Tail> void print_1(Head &&h, Tail &&...t) {
cout << h << ' ';
print_1(t...);
}
//---------------------------------------------------------
const ll mod = 1000000007LL; // 10**9 + 7
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
friend istream &operator>>(istream &is, mint &v) {
is >> v.x;
return is;
}
friend ostream &operator<<(ostream &os, const mint &v) {
os << v.x;
return os;
}
};
//---------------------------------------------------------
struct mintcomb {
vector<mint> fact, ifact;
mintcomb(int n) : fact(n + 1), ifact(n + 1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i) {
fact[i] = fact[i - 1] * i;
}
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i) {
ifact[i - 1] = ifact[i] * i;
}
}
mint permutation(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[n - k];
}
mint combination(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
};
//---------------------------------------------------------
void solve() {
ll N;
in(N);
vll A(N);
vin(A);
ll all_gcd = A[0];
vll prime;
for2(i, 2, 1001) {
bool ok = true;
for (ll p : prime) {
if (i % p == 0) {
ok = false;
break;
}
}
if (ok) {
prime.push_back(i);
}
}
for2(i, 1, N) { all_gcd = __gcd(all_gcd, A[i]); }
if (all_gcd != 1) {
print("not coprime");
return;
}
map<ll, ll> used;
for1(i, N) {
ll a = A[i];
for (ll p : prime) {
if (a % p == 0) {
if (used[p]) {
print("setwise coprime");
return;
}
used[p] = 1;
while (a % p == 0) {
a /= p;
}
}
}
if (a != 1) {
if (used[a]) {
print("setwise coprime");
return;
}
used[a] = 1;
}
}
print("pairwise coprime");
}
//---------------------------------------------------------
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(16);
cerr << fixed << setprecision(16);
solve();
}
| replace | 271 | 272 | 271 | 272 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) scanf("%d", a[i]);
vector<int> cnt(1000005);
vector<int> m(1000005);
rep(i, n) m[a[i]]++;
bool flag = true;
for (int i = 2; i <= 1000000; i++) {
int t = 0;
if (cnt[i] != 0)
continue;
for (int j = i; j <= 1000000; j += i) {
t += m[j];
cnt[j]++;
}
if (t >= 2) {
flag = false;
break;
}
}
if (flag) {
cout << "pairwise coprime" << endl;
return 0;
}
int g = a[0];
rep(i, n) g = __gcd(g, a[i]);
if (g == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) scanf("%d", &a[i]);
vector<int> cnt(1000005);
vector<int> m(1000005);
rep(i, n) m[a[i]]++;
bool flag = true;
for (int i = 2; i <= 1000000; i++) {
int t = 0;
if (cnt[i] != 0)
continue;
for (int j = i; j <= 1000000; j += i) {
t += m[j];
cnt[j]++;
}
if (t >= 2) {
flag = false;
break;
}
}
if (flag) {
cout << "pairwise coprime" << endl;
return 0;
}
int g = a[0];
rep(i, n) g = __gcd(g, a[i]);
if (g == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
}
| replace | 10 | 11 | 10 | 11 | -11 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
#define _ % MOD
#define __ %= MOD
#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))
#define swap(a, b) \
{ \
a = a + b; \
b = a - b; \
a = a - b; \
}
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = res * x;
y = y >> 1;
x = x * x;
}
return res;
} // modular exponent
const int maxn = 1e6;
ll sieve[maxn];
map<ll, ll> pfq;
int main() {
ios_base::sync_with_stdio(false); // don't use printf and scanf
cin.tie(NULL); // cout<<fixed<<setprecision
ll n;
cin >> n;
vector<ll> a(n + 1);
repA(i, 1, n) cin >> a[i];
ll gd = 0;
for (ll i = 2; i < maxn; i++) {
if (sieve[i] == 0) {
sieve[i] = i; // largest prime factor of a number
for (ll j = 2; j * i < maxn; j++) {
sieve[j * i] = i;
}
}
}
repA(i, 1, n) {
ll val = a[i];
gd = gcd(gd, val);
set<ll> st;
while (val > 1) {
if (st.count(sieve[val]) == 0)
pfq[sieve[val]]++;
st.insert(sieve[val]);
val /= sieve[val];
}
}
int flag = 1;
for (auto it : pfq) {
if (it.se > 1) {
flag = 0;
break;
}
}
if (flag) {
cout << "pairwise coprime\n";
return 0;
} else {
if (gd == 1) {
cout << "setwise coprime\n";
return 0;
} else {
cout << "not coprime\n";
return 0;
}
}
return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
#define _ % MOD
#define __ %= MOD
#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))
#define swap(a, b) \
{ \
a = a + b; \
b = a - b; \
a = a - b; \
}
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = res * x;
y = y >> 1;
x = x * x;
}
return res;
} // modular exponent
const int maxn = 1e6 + 1;
ll sieve[maxn];
map<ll, ll> pfq;
int main() {
ios_base::sync_with_stdio(false); // don't use printf and scanf
cin.tie(NULL); // cout<<fixed<<setprecision
ll n;
cin >> n;
vector<ll> a(n + 1);
repA(i, 1, n) cin >> a[i];
ll gd = 0;
for (ll i = 2; i < maxn; i++) {
if (sieve[i] == 0) {
sieve[i] = i; // largest prime factor of a number
for (ll j = 2; j * i < maxn; j++) {
sieve[j * i] = i;
}
}
}
repA(i, 1, n) {
ll val = a[i];
gd = gcd(gd, val);
set<ll> st;
while (val > 1) {
if (st.count(sieve[val]) == 0)
pfq[sieve[val]]++;
st.insert(sieve[val]);
val /= sieve[val];
}
}
int flag = 1;
for (auto it : pfq) {
if (it.se > 1) {
flag = 0;
break;
}
}
if (flag) {
cout << "pairwise coprime\n";
return 0;
} else {
if (gd == 1) {
cout << "setwise coprime\n";
return 0;
} else {
cout << "not coprime\n";
return 0;
}
}
return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!
| replace | 60 | 61 | 60 | 61 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;
void print() { cout << endl; }
template <typename Head, typename... Tail> void print(Head head, Tail... tail) {
int size = sizeof...(Tail);
cout << head;
if (size > 0) {
cout << " ";
}
print(tail...);
}
void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
cout << head;
print0(tail...);
}
vector<ll> mkprimes(ll N) {
vector<bool> isprime(N + 1);
vector<ll> primes;
for (ll i = 0; i <= N; i++) {
isprime[i] = true;
}
isprime[0] = false;
isprime[1] = false;
for (ll i = 2; i <= N; i++) {
if (isprime[i]) {
primes.push_back(i);
for (ll j = 2 * i; j <= N; j += i) { // 素数iの倍数は素数ではない
isprime[j] = false;
}
}
}
return primes;
}
set<ll> primefact(ll n, vector<ll> &primes, vector<set<ll>> &cache) {
if (cache[n].size() > 0) {
return cache[n];
}
for (ll p = 0; p < primes.size(); p++) {
ll pr = primes[p];
if (n % pr == 0) {
set<ll> s = primefact(n / pr, primes, cache);
s.insert(pr);
cache[n] = s;
return cache[n];
}
}
}
int main() {
ll N;
cin >> N;
vector<ll> A(N);
for (ll i = 0; i < N; i++) {
cin >> A[i];
}
ll pmax = 1000002;
auto primes = mkprimes(pmax);
// vector<bool> isprime(pmax+1, false);
vector<set<ll>> cache(pmax + 1);
for (auto ppr : primes) {
// isprime[ppr] = true;
cache[ppr].insert(ppr);
}
vector<vector<ll>> factors(N);
vector<ll> usedprimes(pmax + 1, 0);
for (ll i = 0; i < N; i++) {
ll n = A[i];
for (ll pf : primefact(n, primes, cache)) {
usedprimes[pf]++;
}
}
ll maxused = 0;
for (auto u : usedprimes) {
maxused = max(u, maxused);
}
if (maxused == N) {
print("not coprime");
} else if (maxused >= 2) {
print("setwise coprime");
} else {
print("pairwise coprime");
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;
void print() { cout << endl; }
template <typename Head, typename... Tail> void print(Head head, Tail... tail) {
int size = sizeof...(Tail);
cout << head;
if (size > 0) {
cout << " ";
}
print(tail...);
}
void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
cout << head;
print0(tail...);
}
vector<ll> mkprimes(ll N) {
vector<bool> isprime(N + 1);
vector<ll> primes;
for (ll i = 0; i <= N; i++) {
isprime[i] = true;
}
isprime[0] = false;
isprime[1] = false;
for (ll i = 2; i <= N; i++) {
if (isprime[i]) {
primes.push_back(i);
for (ll j = 2 * i; j <= N; j += i) { // 素数iの倍数は素数ではない
isprime[j] = false;
}
}
}
return primes;
}
set<ll> primefact(ll n, vector<ll> &primes, vector<set<ll>> &cache) {
if (n <= 1) {
set<ll> s;
return s;
}
if (cache[n].size() > 0) {
return cache[n];
}
for (ll p = 0; p < primes.size(); p++) {
ll pr = primes[p];
if (n % pr == 0) {
set<ll> s = primefact(n / pr, primes, cache);
s.insert(pr);
cache[n] = s;
return cache[n];
}
}
}
int main() {
ll N;
cin >> N;
vector<ll> A(N);
for (ll i = 0; i < N; i++) {
cin >> A[i];
}
ll pmax = 1000002;
auto primes = mkprimes(pmax);
// vector<bool> isprime(pmax+1, false);
vector<set<ll>> cache(pmax + 1);
for (auto ppr : primes) {
// isprime[ppr] = true;
cache[ppr].insert(ppr);
}
vector<vector<ll>> factors(N);
vector<ll> usedprimes(pmax + 1, 0);
for (ll i = 0; i < N; i++) {
ll n = A[i];
for (ll pf : primefact(n, primes, cache)) {
usedprimes[pf]++;
}
}
ll maxused = 0;
for (auto u : usedprimes) {
maxused = max(u, maxused);
}
if (maxused == N) {
print("not coprime");
} else if (maxused >= 2) {
print("setwise coprime");
} else {
print("pairwise coprime");
}
}
| insert | 44 | 44 | 44 | 48 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double, ll> Ps;
typedef pair<ll, bool> Pb;
const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;
priority_queue<ll> pql;
priority_queue<P> pqp;
priority_queue<P> bag;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop
ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
// ↓,→,↑,←
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
#define p(x) cout << x << endl;
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
// const ll mod = 998244353ll;
const ll mod = 1000000007ll;
ll mypow(ll a, ll b, ll mod) {
ll x = 1;
while (b) {
while (!(b & 1)) {
(a *= a) %= mod;
b >>= 1;
}
(x *= a) %= mod;
b--;
}
return x;
}
void YES(bool cond) {
if (cond) {
p("YES");
} else {
p("NO");
}
return;
}
void Yes(bool cond) {
if (cond) {
p("Yes");
} else {
p("No");
}
return;
}
void line() {
p("--------------------");
return;
}
/*
ll fact[fact_table + 5], rfact[fact_table + 5];
void c3_init() {
fact[0] = rfact[0] = 1;
for (ll i = 1; i <= fact_table; i++) {
fact[i] = (fact[i - 1] * i) % mod;
}
rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
for (ll i = fact_table; i >= 1; i--) {
rfact[i - 1] = rfact[i] * i;
rfact[i - 1] %= mod;
}
return;
}
ll c3(ll n, ll r) {
return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/
struct Timer {
int64_t start;
const int64_t CYCLES_PER_SEC = 2800000000;
Timer() { reset(); }
void reset() { start = getCycle(); }
inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
inline int64_t getCycle() {
uint32_t low, high;
__asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
return ((int64_t)low) | ((int64_t)high << 32);
}
};
bool multicase = false;
ll n, m, k, w, a, b, c, d, e, h, q, ans, sum, l;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
ll mygcd(ll a, ll b) {
if (b > a)
swap(a, b);
if (b == 0 || a == b)
return a;
return mygcd(b, a % b);
}
void solve() {
cin >> n;
vec x(n), y(n);
for (int i = 0; i < n; i++) {
cin >> x[i];
y[i] = x[i];
}
vec table(n, 0);
bool find = false;
for (int i = 0; i < n; i++) {
for (int j = 2; j * j <= x[i]; j++) {
bool divid = false;
while (x[i] % j == 0) {
x[i] /= j;
divid = true;
}
if (divid) {
if (table[j] >= 1) {
find = true;
break;
}
table[j]++;
}
}
if (x[i] != 1) {
if (table[x[i]] >= 1) {
find = true;
break;
}
table[x[i]]++;
}
}
if (!find) {
p("pairwise coprime");
return;
}
ll my = y[0];
for (int i = 1; i < n; i++) {
my = mygcd(my, y[i]);
}
if (my == 1) {
p("setwise coprime");
return;
}
p("not coprime");
return;
return;
}
int main() {
// init();
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll q, testcase = 1;
if (multicase) {
cin >> q;
} else {
q = 1;
}
while (q--) {
// pu("Case ");pu("#");pu(testcase);pu(": ");
solve();
testcase++;
}
// solve();
return 0;
}
| #include <bits/stdc++.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double, ll> Ps;
typedef pair<ll, bool> Pb;
const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;
priority_queue<ll> pql;
priority_queue<P> pqp;
priority_queue<P> bag;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop
ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
// ↓,→,↑,←
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
#define p(x) cout << x << endl;
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
// const ll mod = 998244353ll;
const ll mod = 1000000007ll;
ll mypow(ll a, ll b, ll mod) {
ll x = 1;
while (b) {
while (!(b & 1)) {
(a *= a) %= mod;
b >>= 1;
}
(x *= a) %= mod;
b--;
}
return x;
}
void YES(bool cond) {
if (cond) {
p("YES");
} else {
p("NO");
}
return;
}
void Yes(bool cond) {
if (cond) {
p("Yes");
} else {
p("No");
}
return;
}
void line() {
p("--------------------");
return;
}
/*
ll fact[fact_table + 5], rfact[fact_table + 5];
void c3_init() {
fact[0] = rfact[0] = 1;
for (ll i = 1; i <= fact_table; i++) {
fact[i] = (fact[i - 1] * i) % mod;
}
rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
for (ll i = fact_table; i >= 1; i--) {
rfact[i - 1] = rfact[i] * i;
rfact[i - 1] %= mod;
}
return;
}
ll c3(ll n, ll r) {
return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/
struct Timer {
int64_t start;
const int64_t CYCLES_PER_SEC = 2800000000;
Timer() { reset(); }
void reset() { start = getCycle(); }
inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
inline int64_t getCycle() {
uint32_t low, high;
__asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
return ((int64_t)low) | ((int64_t)high << 32);
}
};
bool multicase = false;
ll n, m, k, w, a, b, c, d, e, h, q, ans, sum, l;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
ll mygcd(ll a, ll b) {
if (b > a)
swap(a, b);
if (b == 0 || a == b)
return a;
return mygcd(b, a % b);
}
void solve() {
cin >> n;
vec x(n), y(n);
for (int i = 0; i < n; i++) {
cin >> x[i];
y[i] = x[i];
}
vec table(1000000, 0);
bool find = false;
for (int i = 0; i < n; i++) {
for (int j = 2; j * j <= x[i]; j++) {
bool divid = false;
while (x[i] % j == 0) {
x[i] /= j;
divid = true;
}
if (divid) {
if (table[j] >= 1) {
find = true;
break;
}
table[j]++;
}
}
if (x[i] != 1) {
if (table[x[i]] >= 1) {
find = true;
break;
}
table[x[i]]++;
}
}
if (!find) {
p("pairwise coprime");
return;
}
ll my = y[0];
for (int i = 1; i < n; i++) {
my = mygcd(my, y[i]);
}
if (my == 1) {
p("setwise coprime");
return;
}
p("not coprime");
return;
return;
}
int main() {
// init();
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll q, testcase = 1;
if (multicase) {
cin >> q;
} else {
q = 1;
}
while (q--) {
// pu("Case ");pu("#");pu(testcase);pu(": ");
solve();
testcase++;
}
// solve();
return 0;
}
| replace | 137 | 138 | 137 | 138 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include <iostream>
#include <map>
#include <string>
#include <vector>
using ll = long long;
ll n;
const ll MAX = 100000000;
std::vector<bool> table(MAX + 1, true);
std::vector<ll> fact;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
void initTable() {
table[0] = false;
table[1] = false;
for (ll i = 2; i * i <= MAX; i++) {
if (table[i]) {
fact.push_back(i);
for (ll j = i * i; j <= MAX; j += i) {
table[j] = false;
}
}
}
}
int main() {
initTable();
std::cin >> n;
std::vector<ll> a(n);
std::cin >> a[0];
std::map<ll, ll> mp;
ll g = a[0];
ll maxCnt = 0, maxMap = 0;
ll k = fact.size();
std::vector<ll> cnt(k, 0);
for (int j = 0; j < k; j++) {
if (a[0] % fact[j] == 0) {
a[0] /= fact[j];
cnt[j]++;
maxCnt = std::max(maxCnt, cnt[j]);
}
}
if (table[a[0]])
mp[a[0]]++;
for (int i = 1; i < n; i++) {
std::cin >> a[i];
g = gcd(g, a[i]);
for (int j = 0; j < k; j++) {
if (a[i] % fact[j] == 0) {
a[i] /= fact[j];
cnt[j]++;
maxCnt = std::max(maxCnt, cnt[j]);
}
}
if (table[a[i]]) {
mp[a[i]]++;
maxMap = std::max(maxMap, mp[a[i]]);
}
}
maxCnt = std::max(maxMap, maxCnt);
// std::cout << maxCnt << " " << g << std::endl;
if (maxCnt >= 2 && g > 1) {
std::cout << "not coprime" << std::endl;
} else if (maxCnt >= 2 && g == 1) {
std::cout << "setwise coprime" << std::endl;
} else {
std::cout << "pairwise coprime" << std::endl;
}
return 0;
}
| #include <iostream>
#include <map>
#include <string>
#include <vector>
using ll = long long;
ll n;
const ll MAX = 1000000;
std::vector<bool> table(MAX + 1, true);
std::vector<ll> fact;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
void initTable() {
table[0] = false;
table[1] = false;
for (ll i = 2; i * i <= MAX; i++) {
if (table[i]) {
fact.push_back(i);
for (ll j = i * i; j <= MAX; j += i) {
table[j] = false;
}
}
}
}
int main() {
initTable();
std::cin >> n;
std::vector<ll> a(n);
std::cin >> a[0];
std::map<ll, ll> mp;
ll g = a[0];
ll maxCnt = 0, maxMap = 0;
ll k = fact.size();
std::vector<ll> cnt(k, 0);
for (int j = 0; j < k; j++) {
if (a[0] % fact[j] == 0) {
a[0] /= fact[j];
cnt[j]++;
maxCnt = std::max(maxCnt, cnt[j]);
}
}
if (table[a[0]])
mp[a[0]]++;
for (int i = 1; i < n; i++) {
std::cin >> a[i];
g = gcd(g, a[i]);
for (int j = 0; j < k; j++) {
if (a[i] % fact[j] == 0) {
a[i] /= fact[j];
cnt[j]++;
maxCnt = std::max(maxCnt, cnt[j]);
}
}
if (table[a[i]]) {
mp[a[i]]++;
maxMap = std::max(maxMap, mp[a[i]]);
}
}
maxCnt = std::max(maxMap, maxCnt);
// std::cout << maxCnt << " " << g << std::endl;
if (maxCnt >= 2 && g > 1) {
std::cout << "not coprime" << std::endl;
} else if (maxCnt >= 2 && g == 1) {
std::cout << "setwise coprime" << std::endl;
} else {
std::cout << "pairwise coprime" << std::endl;
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | TLE | |
p02574 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define loop(n, i, a) for (ll i = a; i < n; i++)
#define loopR(n, i, a) for (ll i = n - 1; i >= a; i--)
#define all(arr, n) arr, arr + n
#define allv(v) (v).begin(), (v).end()
#define rallv(v) (v).rbegin(), (v).rend()
#define m_p make_pair
#define ll long long
#define pii pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<ll, ll>>
#define sz(x) (int)x.size()
#define pb push_back
#define endl "\n"
#define Endl "\n"
#define f first
#define s second
#define mem(dp, n) memset(dp, n, sizeof dp)
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
int KnightI[] = {2, 1, -1, -2, -2, -1, 1, 2};
int KnightJ[] = {1, 2, 2, 1, -1, -2, -2, -1};
template <typename T> void max_self(T &a, T b) { a = max(a, b); }
template <typename T> void min_self(T &a, T b) { a = min(a, b); }
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while (!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
__attribute__((unused)) int idx,
__attribute__((unused)) int LINE_NUM) {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if (idx > 0)
cerr << ", ";
else
cerr << "Line(" << LINE_NUM << ") ";
stringstream ss;
ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) \
debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN = 1e3 + 5, oo = 0x3f3f3f3f, MOD = 1e9 + 7;
const double PI = acos(-1);
void solve() {
int n;
cin >> n;
int arr[n], freq[mxN] = {}, mx = 0;
loop(n, i, 0) {
cin >> arr[i];
freq[arr[i]]++;
max_self(mx, arr[i]);
}
bool x1 = 0, x2 = 0;
for (int i = mx; i >= 1; i--) {
int j = i;
int cnt = 0;
while (j <= mx) {
cnt += freq[j];
j += i;
}
if (cnt >= 2 && i != 1) {
x1 = 1;
break;
}
}
if (!x1) {
cout << "pairwise coprime" << endl;
return;
}
int g = 0;
loop(n, i, 0) { g = __gcd(g, arr[i]); }
if (g == 1) {
cout << "setwise coprime" << endl;
return;
} else {
cout << "not coprime" << endl;
return;
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast();
solve();
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define loop(n, i, a) for (ll i = a; i < n; i++)
#define loopR(n, i, a) for (ll i = n - 1; i >= a; i--)
#define all(arr, n) arr, arr + n
#define allv(v) (v).begin(), (v).end()
#define rallv(v) (v).rbegin(), (v).rend()
#define m_p make_pair
#define ll long long
#define pii pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<ll, ll>>
#define sz(x) (int)x.size()
#define pb push_back
#define endl "\n"
#define Endl "\n"
#define f first
#define s second
#define mem(dp, n) memset(dp, n, sizeof dp)
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
int KnightI[] = {2, 1, -1, -2, -2, -1, 1, 2};
int KnightJ[] = {1, 2, 2, 1, -1, -2, -2, -1};
template <typename T> void max_self(T &a, T b) { a = max(a, b); }
template <typename T> void min_self(T &a, T b) { a = min(a, b); }
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while (!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
__attribute__((unused)) int idx,
__attribute__((unused)) int LINE_NUM) {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if (idx > 0)
cerr << ", ";
else
cerr << "Line(" << LINE_NUM << ") ";
stringstream ss;
ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) \
debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN = 1e6 + 5, oo = 0x3f3f3f3f, MOD = 1e9 + 7;
const double PI = acos(-1);
void solve() {
int n;
cin >> n;
int arr[n], freq[mxN] = {}, mx = 0;
loop(n, i, 0) {
cin >> arr[i];
freq[arr[i]]++;
max_self(mx, arr[i]);
}
bool x1 = 0, x2 = 0;
for (int i = mx; i >= 1; i--) {
int j = i;
int cnt = 0;
while (j <= mx) {
cnt += freq[j];
j += i;
}
if (cnt >= 2 && i != 1) {
x1 = 1;
break;
}
}
if (!x1) {
cout << "pairwise coprime" << endl;
return;
}
int g = 0;
loop(n, i, 0) { g = __gcd(g, arr[i]); }
if (g == 1) {
cout << "setwise coprime" << endl;
return;
} else {
cout << "not coprime" << endl;
return;
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast();
solve();
}
| replace | 78 | 79 | 78 | 79 | -11 | |
p02574 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
#define MOD 1000000007
vector<int> prime;
bool is[1000001];
int cnt[1000001];
void gen() {
for (int i = 0; i <= 1000000; i++)
is[i] = true;
is[0] = is[1] = false;
for (int i = 2; i <= 1000000; i++) {
for (int j = i + i; j <= 1000000; j += i) {
is[j] = false;
}
}
for (int i = 2; i <= 1000000; i++) {
if (is[i] == true)
prime.push_back(i);
}
}
int main() {
gen();
int a;
cin >> a;
int arr[a];
for (int i = 0; i < a; i++)
cin >> arr[i];
for (int i = 0; i < a; i++) {
int cur = arr[i];
for (int i = 0; i < prime.size(); i++) {
if (cur % prime[i] == 0) {
cur /= prime[i];
cnt[prime[i]]++;
}
while (cur % prime[i] == 0)
cur /= prime[i];
if (cur == 1) {
break;
}
}
}
int key1 = 0, key2 = 0;
for (int i = 1; i <= 1000000; i++) {
if (cnt[i] >= 2)
key1 = 1;
if (cnt[i] == a)
key2 = 1;
}
if (key1 == 0)
cout << "pairwise coprime\n";
else if (key2 == 0)
cout << "setwise coprime\n";
else
cout << "not coprime\n";
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
#define MOD 1000000007
vector<int> prime;
bool is[1000001];
int cnt[1000001];
void gen() {
for (int i = 0; i <= 1000000; i++)
is[i] = true;
is[0] = is[1] = false;
for (int i = 2; i <= 1000000; i++) {
for (int j = i + i; j <= 1000000; j += i) {
is[j] = false;
}
}
for (int i = 2; i <= 1000000; i++) {
if (is[i] == true)
prime.push_back(i);
}
}
int main() {
gen();
int a;
cin >> a;
int arr[a];
for (int i = 0; i < a; i++)
cin >> arr[i];
for (int i = 0; i < a; i++) {
int cur = arr[i];
for (int i = 0; i < prime.size(); i++) {
if (cur % prime[i] == 0) {
cur /= prime[i];
cnt[prime[i]]++;
}
while (cur % prime[i] == 0)
cur /= prime[i];
if (is[cur] == true) {
cnt[cur]++;
break;
}
if (cur == 1) {
break;
}
}
}
int key1 = 0, key2 = 0;
for (int i = 1; i <= 1000000; i++) {
if (cnt[i] >= 2)
key1 = 1;
if (cnt[i] == a)
key2 = 1;
}
if (key1 == 0)
cout << "pairwise coprime\n";
else if (key2 == 0)
cout << "setwise coprime\n";
else
cout << "not coprime\n";
} | insert | 39 | 39 | 39 | 43 | TLE | |
p02574 | C++ | Runtime Error | #include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed main() {
int n;
cin >> n;
int a[n];
rep(i, 0, n) cin >> a[i];
bool p = 1, s = 1;
set<int> st;
rep(i, 0, n) {
int q = a[i];
for (int j = 2; j * j <= q; j++) {
if (q % j == 0) {
// if (*st.find(j) == j) {
if (st.count(j) > 0) {
p = 0;
break;
}
st.insert(j);
while (q % j == 0) {
q /= j;
}
}
}
assert(q >= 1);
if (q != 1) {
assert((*st.find(q) == q) == (st.count(q) > 0));
// if (*st.find(q) == q) p = 0;
// if(st.count(q)>0)p=0;
if (st.find(q) != st.end())
p = 0;
}
st.insert(q);
if (!p)
break;
}
// for (auto p : st) cout << p << " ";
int now = a[0];
rep(i, 0, n) { now = gcd(now, a[i]); }
if (now != 1)
s = 0;
if (p) {
cout << "pairwise coprime\n";
} else if (s) {
cout << "setwise coprime\n";
} else {
cout << "not coprime\n";
}
}
| #include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed main() {
int n;
cin >> n;
int a[n];
rep(i, 0, n) cin >> a[i];
bool p = 1, s = 1;
set<int> st;
rep(i, 0, n) {
int q = a[i];
for (int j = 2; j * j <= q; j++) {
if (q % j == 0) {
// if (*st.find(j) == j) {
if (st.count(j) > 0) {
p = 0;
break;
}
st.insert(j);
while (q % j == 0) {
q /= j;
}
}
}
assert(q >= 1);
if (q != 1) {
// assert((*st.find(q)==q)==(st.count(q)>0));
// if (*st.find(q) == q) p = 0;
// if(st.count(q)>0)p=0;
if (st.find(q) != st.end())
p = 0;
}
st.insert(q);
if (!p)
break;
}
// for (auto p : st) cout << p << " ";
int now = a[0];
rep(i, 0, n) { now = gcd(now, a[i]); }
if (now != 1)
s = 0;
if (p) {
cout << "pairwise coprime\n";
} else if (s) {
cout << "setwise coprime\n";
} else {
cout << "not coprime\n";
}
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p02574 | C++ | Runtime Error | #include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed main() {
int n;
cin >> n;
int a[n];
rep(i, 0, n) cin >> a[i];
bool p = 1, s = 1;
set<int> st;
rep(i, 0, n) {
int q = a[i];
for (int j = 2; j * j <= q; j++) {
if (q % j == 0) {
assert((*st.find(j) == j) && (st.count(j) > 0));
// if (*st.find(j) == j) {
if (st.count(j) > 0) {
p = 0;
break;
}
st.insert(j);
while (q % j == 0) {
q /= j;
}
}
}
assert(q >= 1);
if (q != 1) {
// if (*st.find(q) == q) p = 0;
if (st.count(q) > 0)
p = 0;
}
st.insert(q);
if (!p)
break;
}
// for (auto p : st) cout << p << " ";
int now = a[0];
rep(i, 0, n) { now = gcd(now, a[i]); }
if (now != 1)
s = 0;
if (p) {
cout << "pairwise coprime\n";
} else if (s) {
cout << "setwise coprime\n";
} else {
cout << "not coprime\n";
}
}
| #include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
signed main() {
int n;
cin >> n;
int a[n];
rep(i, 0, n) cin >> a[i];
bool p = 1, s = 1;
set<int> st;
rep(i, 0, n) {
int q = a[i];
for (int j = 2; j * j <= q; j++) {
if (q % j == 0) {
assert((*st.find(j) == j) == (st.count(j) > 0));
// if (*st.find(j) == j) {
if (st.count(j) > 0) {
p = 0;
break;
}
st.insert(j);
while (q % j == 0) {
q /= j;
}
}
}
assert(q >= 1);
if (q != 1) {
// if (*st.find(q) == q) p = 0;
if (st.count(q) > 0)
p = 0;
}
st.insert(q);
if (!p)
break;
}
// for (auto p : st) cout << p << " ";
int now = a[0];
rep(i, 0, n) { now = gcd(now, a[i]); }
if (now != 1)
s = 0;
if (p) {
cout << "pairwise coprime\n";
} else if (s) {
cout << "setwise coprime\n";
} else {
cout << "not coprime\n";
}
}
| replace | 25 | 26 | 25 | 26 | -6 | 2d214d0d-ecd3-4f99-a290-1b0d40c9c2f9.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02574/C++/s843041518.cpp:26: int main(): Assertion `(*st.find(j)==j)&&(st.count(j)>0)' failed.
|
p02574 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
/**** Type Define ****/
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
/**** Const List ****/
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const ll NCK_MAX = 510000;
/**** General Functions ****/
ll ketawa(ll n) {
ll a = 0;
while (n != 0) {
a += n % 10;
n /= 10;
}
return a;
}
ll RepeatSquaring(ll N, ll P, ll M) { // pow->double
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = RepeatSquaring(N, P / 2, M);
return (t % M) * (t % M) % M;
}
return (N * RepeatSquaring(N, P - 1, M)) % M;
}
ll RS(ll N, ll P) { // modがだるいときにつかう
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = RS(N, P / 2);
return t * t;
}
return (N * RS(N, P - 1));
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
bool IsPrime(ll a) { // order root a
if (a == 1)
return false;
for (int i = 2; i * i <= a; i++) {
if (a % i == 0 && a != i) {
return false;
}
}
return true;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
ll q = a / b, g = extgcd(b, a - q * b, x, y);
ll z = x - q * y;
x = y;
y = z;
return g;
}
ll invmod(ll a, ll m) { // a^-1 mod m
ll x, y;
extgcd(a, m, x, y);
x %= m;
if (x < 0)
x += m;
return x;
}
ll *fac, *finv, *inv;
void nCk_init(ll mod) {
fac = new ll[NCK_MAX];
finv = new ll[NCK_MAX];
inv = new ll[NCK_MAX];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < NCK_MAX; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
ll nCk(ll n, ll k, ll mod) {
if (fac == NULL)
nCk_init(mod);
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll lmin(ll a, ll b) { return a > b ? b : a; };
ll lmax(ll a, ll b) { return a > b ? a : b; };
ll lsum(ll a, ll b) { return a + b; };
/*
void warshall_floyd(int n) {
for (int k = 0; k < n; k++){ // 経由する頂点
for (int i = 0; i < n; i++) { // 始点
for (int j = 0; j < n; j++) { // 終点
//d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
}
*/
// 汎用的な二分探索のテンプレ
/*
int binary_search(int key) {
ll ng = -1; //絶対falseの値、なければ最小値-1
ll ok = (int)a.size(); // 絶対trueの値 なければ最大値+1
// ok と ng のどちらが大きいかわからないことを考慮
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (isOK(mid, key)) ok = mid;
else ng = mid;
}
return ok;
}
*/
/**** Zip ****/
template <typename T> class Zip {
vector<T> d;
bool flag;
public:
Zip() { flag = false; }
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) { // T need to have operator < !!
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return (ll)d.size();
}
};
/**** Union Find ****/
class UnionFind {
vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
void init(ll n) {
par.resize(n, 1);
rank.resize(n, 0);
}
ll getSize(ll x) { return par[find(x)]; }
ll find(ll x) {
if (par[x] > 0)
return x;
return -(par[x] = -find(-par[x]));
}
void merge(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = -y;
} else {
par[x] += par[y];
par[y] = -x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool isSame(ll x, ll y) { return find(x) == find(y); }
};
/**** Segment Tree ****/
class SegmentTree {
public:
vector<pair<double, double>> node; // node[0]は使用しない
ll n; // データの個数(nodeの最下層には何個並んでいるか)
pair<double, double> initial_value; // 初期値
public:
void Init(ll n_, pair<double, double> initial_value_) {
n = 1;
while (n < n_)
n *= 2;
node.resize(2 * n);
for (ll i = 0; i < 2 * n; i++) {
node[i] = initial_value_;
}
initial_value = initial_value_;
}
void Update(ll k, pair<double, double> a) {
// node[k]をaにする
// それに従って先祖も変わっていく
k += n;
node[k] = a;
while (k > 1) {
k = k / 2;
node[k] = pair<double, double>(
node[k * 2].first * node[k * 2 + 1].first,
node[k * 2].second * node[k * 2 + 1].first + node[k * 2 + 1].second);
}
}
/*void Watch(){
for(ll i=0;i<2*n;i++){
cout<<node[i]<<endl;
}
}*/
double Query() { //[a,b)
return node[1].first + node[1].second;
}
};
/**** LIS(Longest Increasing Subsequence) ****/
ll lis(ll *a, ll n, ll *dp) {
// a:数列 n:要素数 dp:dpテーブル 配列
fill(dp, dp + n, INF); // INFを代入
for (ll i = 0; i < n; i++)
*lower_bound(dp, dp + n, a[i]) = a[i];
return (ll)(lower_bound(dp, dp + n, INF) - dp);
}
/*
for(ll i=0;i<n;i++){
}
*/
/**** main function ****/
ll n, m;
string s, t;
ll ans = 0;
vector<ll> a, b;
map<ll, ll> mp;
ll ok;
ll hurui[1000001]; //
ll allgcd;
ll zenbukake = 1;
int main() {
cin >> n;
for (ll i = 0; i < n; i++) {
ll aa;
cin >> aa;
if (aa != 1)
a.push_back(aa);
if (i == 0) {
allgcd = aa;
} else {
allgcd = gcd(allgcd, aa);
}
}
if (allgcd == 1) {
ok = 1;
if (a.size() >= 80000) {
cout << "setwise coprime" << endl;
return 0;
}
for (ll i = 0; i < n; i++) {
ll bunkai = a[i];
for (ll i = 2; i * i <= bunkai; i++) {
while (bunkai % i == 0) {
bunkai /= i;
if (mp[i] == 0) {
mp[i] = 1;
while (bunkai % i == 0) {
bunkai /= i;
}
} else {
ok = 0;
goto judge;
}
}
}
if (bunkai != 1) {
if (mp[bunkai] == 0) {
mp[bunkai] = 1;
} else {
ok = 0;
goto judge;
}
}
}
judge:
if (ok) {
cout << "pairwise coprime" << endl;
} else {
cout << "setwise coprime" << endl;
}
} else {
cout << "not coprime" << endl;
}
}
| #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
/**** Type Define ****/
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
/**** Const List ****/
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, -1, 0, 1};
const ll NCK_MAX = 510000;
/**** General Functions ****/
ll ketawa(ll n) {
ll a = 0;
while (n != 0) {
a += n % 10;
n /= 10;
}
return a;
}
ll RepeatSquaring(ll N, ll P, ll M) { // pow->double
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = RepeatSquaring(N, P / 2, M);
return (t % M) * (t % M) % M;
}
return (N * RepeatSquaring(N, P - 1, M)) % M;
}
ll RS(ll N, ll P) { // modがだるいときにつかう
if (P == 0)
return 1;
if (P % 2 == 0) {
ll t = RS(N, P / 2);
return t * t;
}
return (N * RS(N, P - 1));
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
bool IsPrime(ll a) { // order root a
if (a == 1)
return false;
for (int i = 2; i * i <= a; i++) {
if (a % i == 0 && a != i) {
return false;
}
}
return true;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
ll q = a / b, g = extgcd(b, a - q * b, x, y);
ll z = x - q * y;
x = y;
y = z;
return g;
}
ll invmod(ll a, ll m) { // a^-1 mod m
ll x, y;
extgcd(a, m, x, y);
x %= m;
if (x < 0)
x += m;
return x;
}
ll *fac, *finv, *inv;
void nCk_init(ll mod) {
fac = new ll[NCK_MAX];
finv = new ll[NCK_MAX];
inv = new ll[NCK_MAX];
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < NCK_MAX; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
ll nCk(ll n, ll k, ll mod) {
if (fac == NULL)
nCk_init(mod);
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll lmin(ll a, ll b) { return a > b ? b : a; };
ll lmax(ll a, ll b) { return a > b ? a : b; };
ll lsum(ll a, ll b) { return a + b; };
/*
void warshall_floyd(int n) {
for (int k = 0; k < n; k++){ // 経由する頂点
for (int i = 0; i < n; i++) { // 始点
for (int j = 0; j < n; j++) { // 終点
//d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
}
*/
// 汎用的な二分探索のテンプレ
/*
int binary_search(int key) {
ll ng = -1; //絶対falseの値、なければ最小値-1
ll ok = (int)a.size(); // 絶対trueの値 なければ最大値+1
// ok と ng のどちらが大きいかわからないことを考慮
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (isOK(mid, key)) ok = mid;
else ng = mid;
}
return ok;
}
*/
/**** Zip ****/
template <typename T> class Zip {
vector<T> d;
bool flag;
public:
Zip() { flag = false; }
void add(T x) {
d.push_back(x);
flag = true;
}
ll getNum(T x) { // T need to have operator < !!
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return lower_bound(d.begin(), d.end(), x) - d.begin();
}
ll size() {
if (flag) {
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
flag = false;
}
return (ll)d.size();
}
};
/**** Union Find ****/
class UnionFind {
vector<ll> par, rank; // par > 0: number, par < 0: -par
public:
void init(ll n) {
par.resize(n, 1);
rank.resize(n, 0);
}
ll getSize(ll x) { return par[find(x)]; }
ll find(ll x) {
if (par[x] > 0)
return x;
return -(par[x] = -find(-par[x]));
}
void merge(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y]) {
par[y] += par[x];
par[x] = -y;
} else {
par[x] += par[y];
par[y] = -x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool isSame(ll x, ll y) { return find(x) == find(y); }
};
/**** Segment Tree ****/
class SegmentTree {
public:
vector<pair<double, double>> node; // node[0]は使用しない
ll n; // データの個数(nodeの最下層には何個並んでいるか)
pair<double, double> initial_value; // 初期値
public:
void Init(ll n_, pair<double, double> initial_value_) {
n = 1;
while (n < n_)
n *= 2;
node.resize(2 * n);
for (ll i = 0; i < 2 * n; i++) {
node[i] = initial_value_;
}
initial_value = initial_value_;
}
void Update(ll k, pair<double, double> a) {
// node[k]をaにする
// それに従って先祖も変わっていく
k += n;
node[k] = a;
while (k > 1) {
k = k / 2;
node[k] = pair<double, double>(
node[k * 2].first * node[k * 2 + 1].first,
node[k * 2].second * node[k * 2 + 1].first + node[k * 2 + 1].second);
}
}
/*void Watch(){
for(ll i=0;i<2*n;i++){
cout<<node[i]<<endl;
}
}*/
double Query() { //[a,b)
return node[1].first + node[1].second;
}
};
/**** LIS(Longest Increasing Subsequence) ****/
ll lis(ll *a, ll n, ll *dp) {
// a:数列 n:要素数 dp:dpテーブル 配列
fill(dp, dp + n, INF); // INFを代入
for (ll i = 0; i < n; i++)
*lower_bound(dp, dp + n, a[i]) = a[i];
return (ll)(lower_bound(dp, dp + n, INF) - dp);
}
/*
for(ll i=0;i<n;i++){
}
*/
/**** main function ****/
ll n, m;
string s, t;
ll ans = 0;
vector<ll> a, b;
map<ll, ll> mp;
ll ok;
ll hurui[1000001]; //
ll allgcd;
ll zenbukake = 1;
int main() {
cin >> n;
for (ll i = 0; i < n; i++) {
ll aa;
cin >> aa;
if (aa != 1)
a.push_back(aa);
if (i == 0) {
allgcd = aa;
} else {
allgcd = gcd(allgcd, aa);
}
}
if (allgcd == 1) {
ok = 1;
if (a.size() >= 80000) {
cout << "setwise coprime" << endl;
return 0;
}
for (ll i = 0; i < a.size(); i++) {
ll bunkai = a[i];
for (ll i = 2; i * i <= bunkai; i++) {
while (bunkai % i == 0) {
bunkai /= i;
if (mp[i] == 0) {
mp[i] = 1;
while (bunkai % i == 0) {
bunkai /= i;
}
} else {
ok = 0;
goto judge;
}
}
}
if (bunkai != 1) {
if (mp[bunkai] == 0) {
mp[bunkai] = 1;
} else {
ok = 0;
goto judge;
}
}
}
judge:
if (ok) {
cout << "pairwise coprime" << endl;
} else {
cout << "setwise coprime" << endl;
}
} else {
cout << "not coprime" << endl;
}
}
| replace | 311 | 312 | 311 | 312 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;
const int MAX_N = 1e6;
vector<bool> isp(MAX_N + 1, true);
vector<int> primeNumbers;
void sieve() {
isp[0] = false;
isp[1] = false;
for (int i = 2; i * i <= MAX_N; i++) {
if (isp[i] == true) {
for (int j = 2; i * j <= MAX_N; j++) {
isp[i * j] = false;
}
}
}
for (int i = 2; i <= MAX_N; i++) {
if (isp[i] == true)
primeNumbers.push_back(i);
}
}
bool isPrime(int num) {
if (num == 0 || num == 1)
return false;
int n = primeNumbers.size();
for (int i = 0; primeNumbers[i] * primeNumbers[i] <= num; i++) {
if (num == primeNumbers[i])
return true;
if (num % primeNumbers[i] == 0)
return false;
}
return true;
}
int gcd(int a, int b) {
if (a < b)
return gcd(b, a);
int r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
int main() {
sieve();
int n;
cin >> n;
vector<int> A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
set<int> factorList;
bool isPairWise = true;
for (int i = 0; i < n; i++) {
if (isPrime(A[i]) == true) {
if (factorList.count(A[i]) != 0) {
isPairWise = false;
break;
} else {
factorList.insert(A[i]);
}
} else {
for (auto iter = primeNumbers.begin(); iter != primeNumbers.end();
iter++) {
if (A[i] % *iter == 0) {
if (factorList.count(*iter) == 0) {
factorList.insert(*iter);
} else {
isPairWise = false;
break;
}
}
}
}
}
int cumProduct = gcd(A[0], A[1]);
for (int i = 2; i < n; i++) {
cumProduct = gcd(cumProduct, A[i]);
}
bool isSetWise;
if (cumProduct == 1) {
isSetWise = true;
} else {
isSetWise = false;
}
if (isPairWise == true) {
cout << "pairwise coprime" << endl;
} else if (isSetWise == true) {
cout << "setwise coprime" << endl;
} else {
cout << "not coprime" << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;
const int MAX_N = 1e6;
vector<bool> isp(MAX_N + 1, true);
vector<int> primeNumbers;
void sieve() {
isp[0] = false;
isp[1] = false;
for (int i = 2; i * i <= MAX_N; i++) {
if (isp[i] == true) {
for (int j = 2; i * j <= MAX_N; j++) {
isp[i * j] = false;
}
}
}
for (int i = 2; i <= MAX_N; i++) {
if (isp[i] == true)
primeNumbers.push_back(i);
}
}
bool isPrime(int num) {
if (num == 0 || num == 1)
return false;
int n = primeNumbers.size();
for (int i = 0; primeNumbers[i] * primeNumbers[i] <= num; i++) {
if (num == primeNumbers[i])
return true;
if (num % primeNumbers[i] == 0)
return false;
}
return true;
}
int gcd(int a, int b) {
if (a < b)
return gcd(b, a);
int r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
int main() {
sieve();
int n;
cin >> n;
vector<int> A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
set<int> factorList;
bool isPairWise = true;
for (int i = 0; i < n; i++) {
if (isPrime(A[i]) == true) {
if (factorList.count(A[i]) != 0) {
isPairWise = false;
break;
} else {
factorList.insert(A[i]);
}
} else {
for (auto iter = primeNumbers.begin();
iter != primeNumbers.end() && (*iter) <= A[i]; iter++) {
if (A[i] % *iter == 0) {
if (factorList.count(*iter) == 0) {
factorList.insert(*iter);
} else {
isPairWise = false;
break;
}
}
}
}
}
int cumProduct = gcd(A[0], A[1]);
for (int i = 2; i < n; i++) {
cumProduct = gcd(cumProduct, A[i]);
}
bool isSetWise;
if (cumProduct == 1) {
isSetWise = true;
} else {
isSetWise = false;
}
if (isPairWise == true) {
cout << "pairwise coprime" << endl;
} else if (isSetWise == true) {
cout << "setwise coprime" << endl;
} else {
cout << "not coprime" << endl;
}
return 0;
}
| replace | 79 | 81 | 79 | 81 | TLE | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define all(a) a.begin(), a.end()
#define Nmax 1000005
#define INF 1000000000
#define MOD 1000000007
#define MAXN 1000000
using namespace std;
ll mod = 1e9 + 7;
ll expo(ll base, ll exponent, ll mod) {
ll ans = 1;
while (exponent != 0) {
if (exponent & 1)
ans = (1LL * ans * base) % mod;
base = (1LL * base * base) % mod;
exponent >>= 1;
}
return ans % mod;
}
ll expo2(ll base, ll exponent) {
ll ans = 1;
while (exponent != 0) {
if (exponent & 1)
ans = (1LL * ans * base);
base = (1LL * base * base);
exponent >>= 1;
}
return ans;
}
// vector<bool> prime(90000002,true);
// void Sieve()
// {
// for (int p=2; p*p<=90000001; p++)
// {
// // If prime[p] is not changed, then it is a prime
// if (prime[p] == true)
// {
// for (int i=p*p; i<=90000001; i += p)
// prime[i] = false;
// }
// }
// }
// stores smallest prime factor for every number
ll spf[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
// marking smallest prime factor for every
// number to be itself.
spf[i] = i;
// separately marking spf for every even
// number as 2
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
// checking if i is prime
if (spf[i] == i) {
// marking SPF for all numbers divisible by i
for (ll j = i * i; j < MAXN; j += i)
// marking spf[j] if it is not
// previously marked
if (spf[j] == j)
spf[j] = i;
}
}
}
vector<ll> vis(1000001, 0);
int main() {
// #ifndef ONLINE_JUDGE
// freopen ("data.in","r",stdin);
// freopen ("E.out","w",stdout);
// #endif
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// Sieve();
sieve();
int tests = 1;
// cin>>tests;
while (tests--) {
ll i, j, n;
cin >> n;
vector<ll> a(n);
rep(i, 0, n - 1) cin >> a[i];
ll g = __gcd(a[0], a[1]);
for (i = 2; i < n; i++)
g = __gcd(g, a[i]);
bool flag = true;
rep(i, 0, n - 1) {
set<ll> st;
ll tmp = a[i];
while (tmp > 1) {
st.insert(spf[tmp]);
tmp /= spf[tmp];
}
for (auto x : st) {
if (vis[x]) {
flag = false;
break;
} else
vis[x] = 1;
}
if (!flag)
break;
}
if (flag)
cout << "pairwise coprime";
else if (g == 1)
cout << "setwise coprime";
else
cout << "not coprime";
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define all(a) a.begin(), a.end()
#define Nmax 1000005
#define INF 1000000000
#define MOD 1000000007
#define MAXN 1000005
using namespace std;
ll mod = 1e9 + 7;
ll expo(ll base, ll exponent, ll mod) {
ll ans = 1;
while (exponent != 0) {
if (exponent & 1)
ans = (1LL * ans * base) % mod;
base = (1LL * base * base) % mod;
exponent >>= 1;
}
return ans % mod;
}
ll expo2(ll base, ll exponent) {
ll ans = 1;
while (exponent != 0) {
if (exponent & 1)
ans = (1LL * ans * base);
base = (1LL * base * base);
exponent >>= 1;
}
return ans;
}
// vector<bool> prime(90000002,true);
// void Sieve()
// {
// for (int p=2; p*p<=90000001; p++)
// {
// // If prime[p] is not changed, then it is a prime
// if (prime[p] == true)
// {
// for (int i=p*p; i<=90000001; i += p)
// prime[i] = false;
// }
// }
// }
// stores smallest prime factor for every number
ll spf[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
// marking smallest prime factor for every
// number to be itself.
spf[i] = i;
// separately marking spf for every even
// number as 2
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
// checking if i is prime
if (spf[i] == i) {
// marking SPF for all numbers divisible by i
for (ll j = i * i; j < MAXN; j += i)
// marking spf[j] if it is not
// previously marked
if (spf[j] == j)
spf[j] = i;
}
}
}
vector<ll> vis(1000001, 0);
int main() {
// #ifndef ONLINE_JUDGE
// freopen ("data.in","r",stdin);
// freopen ("E.out","w",stdout);
// #endif
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// Sieve();
sieve();
int tests = 1;
// cin>>tests;
while (tests--) {
ll i, j, n;
cin >> n;
vector<ll> a(n);
rep(i, 0, n - 1) cin >> a[i];
ll g = __gcd(a[0], a[1]);
for (i = 2; i < n; i++)
g = __gcd(g, a[i]);
bool flag = true;
rep(i, 0, n - 1) {
set<ll> st;
ll tmp = a[i];
while (tmp > 1) {
st.insert(spf[tmp]);
tmp /= spf[tmp];
}
for (auto x : st) {
if (vis[x]) {
flag = false;
break;
} else
vis[x] = 1;
}
if (!flag)
break;
}
if (flag)
cout << "pairwise coprime";
else if (g == 1)
cout << "setwise coprime";
else
cout << "not coprime";
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
for (int T = 0; T < t; T++) {
ll n;
cin >> n;
ll a[n], cnt[100000001] = {0};
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
bool ok = true;
for (ll i = 2; i <= 1e6; i++) {
ll ans = 0;
for (ll j = i; j <= 1e6; j += i) {
ans += cnt[j];
}
if (ans > 1) {
ok = false;
break;
}
}
if (ok == true)
cout << "pairwise coprime" << endl;
else {
ll gh = a[0];
for (int i = 1; i < n; i++)
gh = __gcd(gh, a[i]);
if (gh == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
}
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
for (int T = 0; T < t; T++) {
ll n;
cin >> n;
ll a[n], cnt[10000001] = {0};
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
bool ok = true;
for (ll i = 2; i <= 1e6; i++) {
ll ans = 0;
for (ll j = i; j <= 1e6; j += i) {
ans += cnt[j];
}
if (ans > 1) {
ok = false;
break;
}
}
if (ok == true)
cout << "pairwise coprime" << endl;
else {
ll gh = a[0];
for (int i = 1; i < n; i++)
gh = __gcd(gh, a[i]);
if (gh == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
}
}
return 0;
}
| replace | 11 | 12 | 11 | 12 | -11 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxm = 1e4 + 5;
int a[maxm], mf[maxm];
unordered_map<int, int> ump;
bool not_pairwise = false;
void init() {
mf[1] = 1;
for (int i = 2; i < maxm; i += 2) {
mf[i] = 2;
}
for (int i = 3; i < maxm; i += 2) {
if (!mf[i]) {
mf[i] = i;
for (long long j = 1ll * i * i; j < maxm; j += i) {
mf[j] = i;
}
}
}
}
void factorize(int x) {
vector<int> a;
while (x > 1) {
a.push_back(mf[x]);
x /= mf[x];
}
for (int y : a) {
if (ump[y] == 1) {
not_pairwise = true;
}
}
for (int y : a) {
ump[y] = 1;
}
}
int main() {
init();
int n;
cin >> n;
int g = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (g == -1)
g = a[i];
else
g = __gcd(g, a[i]);
factorize(a[i]);
}
if (!not_pairwise)
cout << "pairwise coprime";
else if (g == 1)
cout << "setwise coprime";
else
cout << "not coprime";
} | #include <bits/stdc++.h>
using namespace std;
const int maxm = 1e6 + 5;
int a[maxm], mf[maxm];
unordered_map<int, int> ump;
bool not_pairwise = false;
void init() {
mf[1] = 1;
for (int i = 2; i < maxm; i += 2) {
mf[i] = 2;
}
for (int i = 3; i < maxm; i += 2) {
if (!mf[i]) {
mf[i] = i;
for (long long j = 1ll * i * i; j < maxm; j += i) {
mf[j] = i;
}
}
}
}
void factorize(int x) {
vector<int> a;
while (x > 1) {
a.push_back(mf[x]);
x /= mf[x];
}
for (int y : a) {
if (ump[y] == 1) {
not_pairwise = true;
}
}
for (int y : a) {
ump[y] = 1;
}
}
int main() {
init();
int n;
cin >> n;
int g = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (g == -1)
g = a[i];
else
g = __gcd(g, a[i]);
factorize(a[i]);
}
if (!not_pairwise)
cout << "pairwise coprime";
else if (g == 1)
cout << "setwise coprime";
else
cout << "not coprime";
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
// ------------------ Debugging ------------------
#define trace(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
cout << endl; \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << "[ " << *it << " = " << a << " ] ";
err(++it, args...);
}
template <typename Tk, typename Tv>
ostream &operator<<(ostream &os, const pair<Tk, Tv> &p) {
os << "{" << p.first << ',' << p.second << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &p) {
os << "[ ";
for (T x : p)
os << x << " ";
os << "]" << endl;
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &p) {
os << "{ ";
for (T x : p)
os << x << " ";
os << "}" << endl;
return os;
}
template <typename Tk, typename Tv>
ostream &operator<<(ostream &os, const map<Tk, Tv> &p) {
os << "{ ";
for (pair<Tk, Tv> x : p)
os << x << " ";
os << "}" << endl;
return os;
}
// -----------------------------------------------
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
const int MAXN = 1e4 + 5;
int spf[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
void sieve() {
spf[1] = 1;
for (int i = 2; i < MAXN; i++)
// marking smallest prime factor for every
// number to be itself.
spf[i] = i;
// separately marking spf for every even
// number as 2
for (int i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (int i = 3; i * i < MAXN; i++) {
// checking if i is prime
if (spf[i] == i) {
// marking SPF for all numbers divisible by i
for (int j = i * i; j < MAXN; j += i)
// marking spf[j] if it is not
// previously marked
if (spf[j] == j)
spf[j] = i;
}
}
}
// A O(log n) function returning primefactorization
// by dividing by smallest prime factor at every step
set<int> getFactorization(int x) {
set<int> ret;
while (x != 1) {
ret.insert(spf[x]);
x = x / spf[x];
}
return ret;
}
signed main() {
fastIO
int t = 1;
// cin >> t;
while (t--) {
int n;
cin >> n;
sieve();
vector<int> a(n);
cin >> a[0];
int allgcd = a[0];
for (int i = 1; i < n; i++) {
cin >> a[i];
allgcd = gcd(allgcd, a[i]);
}
bool parco = true;
set<int> s;
for (int i = 0; i < n; i++) {
int val = a[i];
set<int> gett = getFactorization(val);
for (int tmp : gett) {
if (s.find(tmp) != s.end()) {
parco = false;
goto out;
}
s.insert(tmp);
}
}
out:
if (parco) {
cout << "pairwise coprime\n";
} else {
if (allgcd != 1) {
cout << "not coprime\n";
} else {
cout << "setwise coprime\n";
}
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
// ------------------ Debugging ------------------
#define trace(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
cout << endl; \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << "[ " << *it << " = " << a << " ] ";
err(++it, args...);
}
template <typename Tk, typename Tv>
ostream &operator<<(ostream &os, const pair<Tk, Tv> &p) {
os << "{" << p.first << ',' << p.second << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &p) {
os << "[ ";
for (T x : p)
os << x << " ";
os << "]" << endl;
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &p) {
os << "{ ";
for (T x : p)
os << x << " ";
os << "}" << endl;
return os;
}
template <typename Tk, typename Tv>
ostream &operator<<(ostream &os, const map<Tk, Tv> &p) {
os << "{ ";
for (pair<Tk, Tv> x : p)
os << x << " ";
os << "}" << endl;
return os;
}
// -----------------------------------------------
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
const int MAXN = 1e6 + 5;
int spf[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
void sieve() {
spf[1] = 1;
for (int i = 2; i < MAXN; i++)
// marking smallest prime factor for every
// number to be itself.
spf[i] = i;
// separately marking spf for every even
// number as 2
for (int i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (int i = 3; i * i < MAXN; i++) {
// checking if i is prime
if (spf[i] == i) {
// marking SPF for all numbers divisible by i
for (int j = i * i; j < MAXN; j += i)
// marking spf[j] if it is not
// previously marked
if (spf[j] == j)
spf[j] = i;
}
}
}
// A O(log n) function returning primefactorization
// by dividing by smallest prime factor at every step
set<int> getFactorization(int x) {
set<int> ret;
while (x != 1) {
ret.insert(spf[x]);
x = x / spf[x];
}
return ret;
}
signed main() {
fastIO
int t = 1;
// cin >> t;
while (t--) {
int n;
cin >> n;
sieve();
vector<int> a(n);
cin >> a[0];
int allgcd = a[0];
for (int i = 1; i < n; i++) {
cin >> a[i];
allgcd = gcd(allgcd, a[i]);
}
bool parco = true;
set<int> s;
for (int i = 0; i < n; i++) {
int val = a[i];
set<int> gett = getFactorization(val);
for (int tmp : gett) {
if (s.find(tmp) != s.end()) {
parco = false;
goto out;
}
s.insert(tmp);
}
}
out:
if (parco) {
cout << "pairwise coprime\n";
} else {
if (allgcd != 1) {
cout << "not coprime\n";
} else {
cout << "setwise coprime\n";
}
}
}
return 0;
} | replace | 60 | 61 | 60 | 61 | 0 | |
p02574 | C++ | Time Limit Exceeded | /////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp) \
ll inp; \
cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define FR(i, a) for (auto i : a)
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve() {
IN(n);
vl v;
map<ll, ll> m;
FOR(i, 0, n) {
IN(in);
v.pb(in);
}
FOR(i, 0, n) {
ll k = v[i];
FOR(j, 2, sqrt(k) + 1) {
if (k % j == 0)
m[j]++;
while (k % j == 0) {
k /= j;
}
}
if (k != 1)
m[k]++;
}
ll f = 0, f1 = 0;
for (auto i : m) {
if (i.second == n)
f = 1;
if (i.second > 1)
f1 = 1;
}
if (f == 1) {
cout << "not coprime";
} else if (f1 == 1) {
cout << "setwise coprime";
} else
cout << "pairwise coprime";
}
int main() {
fastio
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
ll test = 1;
// cin >> test;
while (test--) {
solve();
}
} | /////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp) \
ll inp; \
cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define FR(i, a) for (auto i : a)
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve() {
IN(n);
vl v;
map<ll, ll> m;
FOR(i, 0, n) {
IN(in);
v.pb(in);
}
FOR(i, 0, n) {
ll k = v[i];
FOR(j, 2, sqrt(k) + 1) {
if (k % j == 0)
m[j]++;
while (k % j == 0) {
k /= j;
}
}
if (k != 1)
m[k]++;
}
ll f = 0, f1 = 0;
for (auto i : m) {
if (i.second == n)
f = 1;
if (i.second > 1)
f1 = 1;
}
if (f == 1) {
cout << "not coprime";
} else if (f1 == 1) {
cout << "setwise coprime";
} else
cout << "pairwise coprime";
}
int main() {
fastio
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
ll test = 1;
// cin >> test;
while (test--) {
solve();
}
} | insert | 4 | 4 | 4 | 7 | TLE | |
p02574 | Python | Time Limit Exceeded | import collections
N = int(input())
A = [int(_) for _ in input().split()]
class Prime:
@staticmethod
def trial_division(x):
if x % 2 == 0:
return True
for p in range(3, int(x**0.5 + 1), 2):
if x % p == 0:
return False
return True
@staticmethod
def factorization(x):
ret = set()
while True:
if x % 2:
break
x //= 2
ret.add(2)
for p in range(3, int(x**0.5 + 1), 2):
while True:
if x % p:
break
x //= p
ret.add(p)
if x > 1:
ret.add(x)
return ret
@staticmethod
def miller_rabin(n):
def suspect(a, t, n):
x = pow(a, t, n)
n1 = n - 1
while t != n1 and x != 1 and x != n1:
x = pow(x, 2, n)
t <<= 1
return t & 1 or x == n1
if n == 2:
return True
if n < 2 or n % 2 == 0:
return False
d = (n - 1) >> 1
while d & 1 == 0:
d >>= 1
if n < 2**32:
check_list = (2, 7, 61)
elif n < 2**48:
check_list = (2, 3, 5, 7, 11, 13, 17, 19, 23)
else:
check_list = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37)
for i in check_list:
if i >= n:
break
if not suspect(i, d, n):
return False
return True
c = collections.defaultdict(int)
for a in A:
for p in Prime.factorization(a):
c[p] += 1
ans = "pairwise coprime"
if c:
x = max(c.values())
if x == 1:
ans = "pairwise coprime"
elif x == N:
ans = "not coprime"
else:
ans = "setwise coprime"
print(ans)
| import collections
N = int(input())
A = [int(_) for _ in input().split()]
class Prime:
@staticmethod
def trial_division(x):
if x % 2 == 0:
return True
for p in range(3, int(x**0.5 + 1), 2):
if x % p == 0:
return False
return True
@staticmethod
def factorization(n):
a = set()
while n % 2 == 0:
a.add(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.add(f)
n //= f
else:
f += 2
if n != 1:
a.add(n)
return a
@staticmethod
def miller_rabin(n):
def suspect(a, t, n):
x = pow(a, t, n)
n1 = n - 1
while t != n1 and x != 1 and x != n1:
x = pow(x, 2, n)
t <<= 1
return t & 1 or x == n1
if n == 2:
return True
if n < 2 or n % 2 == 0:
return False
d = (n - 1) >> 1
while d & 1 == 0:
d >>= 1
if n < 2**32:
check_list = (2, 7, 61)
elif n < 2**48:
check_list = (2, 3, 5, 7, 11, 13, 17, 19, 23)
else:
check_list = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37)
for i in check_list:
if i >= n:
break
if not suspect(i, d, n):
return False
return True
c = collections.defaultdict(int)
for a in A:
for p in Prime.factorization(a):
c[p] += 1
ans = "pairwise coprime"
if c:
x = max(c.values())
if x == 1:
ans = "pairwise coprime"
elif x == N:
ans = "not coprime"
else:
ans = "setwise coprime"
print(ans)
| replace | 17 | 33 | 17 | 32 | TLE | |
p02574 | Python | Runtime Error | import collections
N = int(input())
A = [int(_) for _ in input().split()]
def prime_factorize(n):
a = set()
while n % 2 == 0:
a.add(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.add(f)
n //= f
else:
f += 2
if n != 1:
a.add(n)
return a
d = collections.defaultdict(int)
for a in A:
for x in prime_factorize(a):
d[x] += 1
e = max(d.values())
if e == 1:
ans = "pairwise coprime"
elif e == N:
ans = "not coprime"
else:
ans = "setwise coprime"
print(ans)
| import collections
N = int(input())
A = [int(_) for _ in input().split()]
def prime_factorize(n):
a = set()
while n % 2 == 0:
a.add(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.add(f)
n //= f
else:
f += 2
if n != 1:
a.add(n)
return a
d = collections.defaultdict(int)
for a in A:
for x in prime_factorize(a):
d[x] += 1
if len(d):
e = max(d.values())
if len(d) == 0 or e == 1:
ans = "pairwise coprime"
elif e == N:
ans = "not coprime"
else:
ans = "setwise coprime"
print(ans)
| replace | 27 | 29 | 27 | 30 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
const ll INF = (1LL << 60);
vector<int> Eratosthenes(const int N) {
vector<bool> is_prime(N + 1);
for (int i = 0; i <= N; i++) {
is_prime[i] = true;
}
vector<int> P;
for (int i = 2; i <= N; i++) {
if (is_prime[i]) {
for (int j = 2 * i; j <= N; j += i) {
is_prime[j] = false;
}
P.emplace_back(i);
}
}
return P;
}
ll gcd(ll x, ll y) {
if (x < y)
swap(x, y);
// xの方が常に大きい
ll r;
while (y > 0) {
r = x % y;
x = y;
y = r;
}
return x;
}
int main() {
int N;
cin >> N;
vector<ll> A(N);
ll ma = -1;
map<int, int> mp;
rep(i, N) {
cin >> A[i];
mp[A[i]]++;
ma = max(ma, A[i]);
}
ll SA = A[0];
rep(i, N - 1) { SA = gcd(SA, A[i + 1]); }
bool is_P = true, is_S = false;
if (SA == 1)
is_S = true;
vector<int> prime = Eratosthenes(ma);
for (int i = 0; i <= prime.size(); i++) {
int p = prime[i];
int x = p;
if (p == 0)
continue;
int tmp = 0, cnt = 1;
while (x <= ma) {
// cout << x << " " << tmp << endl;
cnt++;
tmp += mp[x];
x = p * cnt;
}
if (tmp >= 2) {
is_P = false;
break;
}
}
if (is_P)
cout << "pairwise coprime" << endl;
else if (is_S)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
const ll INF = (1LL << 60);
vector<int> Eratosthenes(const int N) {
vector<bool> is_prime(N + 1);
for (int i = 0; i <= N; i++) {
is_prime[i] = true;
}
vector<int> P;
for (int i = 2; i <= N; i++) {
if (is_prime[i]) {
for (int j = 2 * i; j <= N; j += i) {
is_prime[j] = false;
}
P.emplace_back(i);
}
}
return P;
}
ll gcd(ll x, ll y) {
if (x < y)
swap(x, y);
// xの方が常に大きい
ll r;
while (y > 0) {
r = x % y;
x = y;
y = r;
}
return x;
}
int main() {
int N;
cin >> N;
vector<ll> A(N);
ll ma = -1;
map<int, int> mp;
rep(i, N) {
cin >> A[i];
mp[A[i]]++;
ma = max(ma, A[i]);
}
ll SA = A[0];
rep(i, N - 1) { SA = gcd(SA, A[i + 1]); }
bool is_P = true, is_S = false;
if (SA == 1)
is_S = true;
if (ma == 1) {
cout << "pairwise coprime" << endl;
return 0;
}
vector<int> prime = Eratosthenes(ma);
for (int i = 0; i <= prime.size(); i++) {
int p = prime[i];
int x = p;
if (p == 0)
continue;
int tmp = 0, cnt = 1;
while (x <= ma) {
// cout << x << " " << tmp << endl;
cnt++;
tmp += mp[x];
x = p * cnt;
}
if (tmp >= 2) {
is_P = false;
break;
}
}
if (is_P)
cout << "pairwise coprime" << endl;
else if (is_S)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
} | insert | 55 | 55 | 55 | 59 | 0 | |
p02574 | Python | Runtime Error | N = int(input())
A = [int(s) for s in input().split()]
PRIME_LENGTH = 10**6
prime_list = [[] for _ in range(PRIME_LENGTH)]
for i in range(2, PRIME_LENGTH):
if not prime_list[i]:
idx = i
while idx < PRIME_LENGTH:
prime_list[idx].append(i)
idx += i
vote = [0] * (PRIME_LENGTH)
for a in A:
for v in prime_list[a]:
vote[v] += 1
if max(vote) == len(A):
print("not coprime")
elif sum(map(lambda x: x > 1, vote)) > 0:
print("setwise coprime")
else:
print("pairwise coprime")
| N = int(input())
A = [int(s) for s in input().split()]
PRIME_LENGTH = 10**6 + 1
prime_list = [[] for _ in range(PRIME_LENGTH)]
for i in range(2, PRIME_LENGTH):
if not prime_list[i]:
idx = i
while idx < PRIME_LENGTH:
prime_list[idx].append(i)
idx += i
vote = [0] * (PRIME_LENGTH)
for a in A:
for v in prime_list[a]:
vote[v] += 1
if max(vote) == len(A):
print("not coprime")
elif sum(map(lambda x: x > 1, vote)) > 0:
print("setwise coprime")
else:
print("pairwise coprime")
| replace | 3 | 4 | 3 | 4 | 1 | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02574/Python/s630548682.py", line 13, in <module>
idx += i
MemoryError
|
p02574 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pp pair<pair<ll, ll>, pair<ll, ll>>
#define pll pair<ll, ll>
#define ppll pair<ll, pll>
#define pdd pair<double, double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll, vector<ll>, greater<ll>>
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define ERASE(v) \
sort(v.begin(), v.end()); \
v.erase(unique(v.begin(), v.end()), v.end())
#define int ll
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
// #define ll int
#define PN 1
using namespace std;
const ll MAXR = 1000000;
const ll INF = 1 << 29;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const int MAX_V = 500;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
map<ll, ll> res;
bool ok1 = true, ok2 = true;
void prime_factor(ll n) {
map<ll, ll> res2;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
res2[i]++;
n /= i;
}
}
if (n != 1)
res2[n]++;
for (auto i : res2) {
if (res[i.fi] > 0) {
ok1 = false;
}
res[i.fi] += i.sc;
}
return;
}
void solve() {
ll n;
ll a[1000010];
cin >> n;
rep(i, n) cin >> a[i];
repr(i, n) {
prime_factor(a[i]);
// cout<<i<<endl;
if (ok1 == false)
break;
}
if (ok1 == true) {
cout << "pairwise coprime" << endl;
return;
}
for (auto i : res) {
// cout<<i.fi<<" "<<i.sc<<endl;
// if(i.sc < n) continue;
ll cnt = 0;
rep(j, n) {
if (a[j] % i.fi == 0)
cnt++;
}
if (cnt == n)
ok2 = false;
if (ok2 == false)
break;
}
if (ok2) {
cout << "setwise coprime" << endl;
return;
}
cout << "not coprime" << endl;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
ll t = 1;
rep(i, t) { solve(); }
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pp pair<pair<ll, ll>, pair<ll, ll>>
#define pll pair<ll, ll>
#define ppll pair<ll, pll>
#define pdd pair<double, double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll, vector<ll>, greater<ll>>
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define ERASE(v) \
sort(v.begin(), v.end()); \
v.erase(unique(v.begin(), v.end()), v.end())
#define int ll
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
// #define ll int
#define PN 1
using namespace std;
const ll MAXR = 1000000;
const ll INF = 1 << 29;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const int MAX_V = 500;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
map<ll, ll> res;
bool ok1 = true, ok2 = true;
void prime_factor(ll n) {
map<ll, ll> res2;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
res2[i]++;
n /= i;
}
}
if (n != 1)
res2[n]++;
for (auto i : res2) {
if (res[i.fi] > 0) {
ok1 = false;
}
res[i.fi] += i.sc;
}
return;
}
void solve() {
ll n;
ll a[1000010];
cin >> n;
rep(i, n) cin >> a[i];
repr(i, n) {
prime_factor(a[i]);
// cout<<i<<endl;
if (ok1 == false)
break;
}
if (ok1 == true) {
cout << "pairwise coprime" << endl;
return;
}
for (auto i : res) {
// cout<<i.fi<<" "<<i.sc<<endl;
// if(i.sc < n) continue;
ll cnt = 0;
rep(j, n) {
if (a[j] % i.fi == 0)
cnt++;
else
break;
}
if (cnt == n)
ok2 = false;
if (ok2 == false)
break;
}
if (ok2) {
cout << "setwise coprime" << endl;
return;
}
cout << "not coprime" << endl;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
ll t = 1;
rep(i, t) { solve(); }
return 0;
} | insert | 107 | 107 | 107 | 109 | TLE | |
p02574 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <set>
// 素因数分解
// pair<ll,ll>型
// auto pf=prime_factorize(ll N);で呼ぶ
// for(auto p:pf){}で探す
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
const int K = 100005;
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<int> c(K);
rep(i, n) {
cin >> a[i];
c[a[i]]++;
}
bool ok = true;
for (int i = 2; i < K; ++i) {
int cnt = 0;
for (int j = i; j < K; j += i) {
cnt += c[j];
}
if (cnt >= 2)
ok = false;
}
if (ok) {
cout << "pairwise coprime";
return 0;
}
int k = a[0];
rep(i, n) { k = gcd(a[i], k); }
if (k == 1)
cout << "setwise coprime";
else
cout << "not coprime";
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <set>
// 素因数分解
// pair<ll,ll>型
// auto pf=prime_factorize(ll N);で呼ぶ
// for(auto p:pf){}で探す
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
const int K = 1000005;
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<int> c(K);
rep(i, n) {
cin >> a[i];
c[a[i]]++;
}
bool ok = true;
for (int i = 2; i < K; ++i) {
int cnt = 0;
for (int j = i; j < K; j += i) {
cnt += c[j];
}
if (cnt >= 2)
ok = false;
}
if (ok) {
cout << "pairwise coprime";
return 0;
}
int k = a[0];
rep(i, n) { k = gcd(a[i], k); }
if (k == 1)
cout << "setwise coprime";
else
cout << "not coprime";
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
std::vector<bool> IsPrime;
void sieve(size_t max) {
if (max + 1 > IsPrime.size()) { // resizeで要素数が減らないように
IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
}
IsPrime[0] = false; // 0は素数ではない
IsPrime[1] = false; // 1は素数ではない
for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる
if (IsPrime[i]) // iが素数ならば
for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
IsPrime[i * j] = false; // 素数ではない
}
map<int, int> factorization(int x) {
map<int, int> pn;
for (int i = 2; i * i <= x; i++) {
while (x % i == 0) {
x /= i;
pn[i]++;
}
}
if (x != 1)
pn[x]++;
return pn;
}
void Main() {
int n;
cin >> n;
int M = 1000000;
sieve(M);
// vector<long> sosu;
// for (int i = 2; i <= M; i++)
// {
// if(IsPrime[i]) sosu.push_back(i);
// }
// vector<int> sum(sosu.size());
vector<int> sum(n + 1);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
map<int, int> fac = factorization(a);
// for (int j = 0; j < sosu.size(); j++)
// {
// if(a % sosu[j] == 0) sum[j]++;
// }
for (auto j : fac) {
sum[j.first]++;
}
}
int maxsum = 0;
for (int i = 0; i < sum.size(); i++) {
maxsum = max(maxsum, sum[i]);
}
if (maxsum <= 1)
cout << "pairwise coprime" << endl;
else if (maxsum <= n - 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
}
int main(int argc, char **argv) {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
Main();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
std::vector<bool> IsPrime;
void sieve(size_t max) {
if (max + 1 > IsPrime.size()) { // resizeで要素数が減らないように
IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
}
IsPrime[0] = false; // 0は素数ではない
IsPrime[1] = false; // 1は素数ではない
for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる
if (IsPrime[i]) // iが素数ならば
for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
IsPrime[i * j] = false; // 素数ではない
}
map<int, int> factorization(int x) {
map<int, int> pn;
for (int i = 2; i * i <= x; i++) {
while (x % i == 0) {
x /= i;
pn[i]++;
}
}
if (x != 1)
pn[x]++;
return pn;
}
void Main() {
int n;
cin >> n;
int M = 1000000;
sieve(M);
// vector<long> sosu;
// for (int i = 2; i <= M; i++)
// {
// if(IsPrime[i]) sosu.push_back(i);
// }
// vector<int> sum(sosu.size());
vector<int> sum(M + 1);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
map<int, int> fac = factorization(a);
// for (int j = 0; j < sosu.size(); j++)
// {
// if(a % sosu[j] == 0) sum[j]++;
// }
for (auto j : fac) {
sum[j.first]++;
}
}
int maxsum = 0;
for (int i = 0; i < sum.size(); i++) {
maxsum = max(maxsum, sum[i]);
}
if (maxsum <= 1)
cout << "pairwise coprime" << endl;
else if (maxsum <= n - 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
}
int main(int argc, char **argv) {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
Main();
return 0;
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for (int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y) \
cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG \
int x12345; \
cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
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;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
std::vector<int> sieve(int n) {
std::vector<int> res(n);
std::iota(res.begin(), res.end(), 0);
for (int i = 2; i * i < n; ++i) {
if (res[i] < i)
continue;
for (int j = i * i; j < n; j += i)
if (res[j] == j)
res[j] = i;
}
return res;
}
std::vector<int> factor(int n, const std::vector<int> &min_factor) {
// min_factor は sieve() で得られたものとする
std::vector<int> res;
while (n > 1) {
res.push_back(min_factor[n]);
n /= min_factor[n];
// 割った後の値についても素因数を知っているので順次求まる
}
return res;
}
int main() {
int N;
cin >> N;
vector<int> exists(1000002, -1);
set<ll> setwisec;
bool pairwise = true;
bool setwise = false;
vector<int> sieves = sieve(1000000);
vector<ll> A(N);
REP(i, N) { cin >> A[i]; }
REP(i, N) {
// for (auto x : setwisec){
// DB2(i,x);
// }
for (auto x : setwisec) {
if (A[i] % x != 0)
setwisec.erase(x);
}
vector<int> D = factor(A[i], sieves);
REP(j, D.size()) {
ll NowDiv = D[j];
if (NowDiv == 1)
continue;
// DB2(j, NowDiv);
if (i == 0) {
setwisec.insert(NowDiv);
}
if ((exists[NowDiv] != i) and (exists[NowDiv] != -1))
pairwise = false;
exists[NowDiv] = i;
}
}
if (setwisec.empty())
setwise = true;
if (pairwise) {
puts("pairwise coprime");
} else if (setwise) {
puts("setwise coprime");
} else {
puts("not coprime");
}
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPr(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for (int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for (int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y) \
cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG \
int x12345; \
cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
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;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
std::vector<int> sieve(int n) {
std::vector<int> res(n);
std::iota(res.begin(), res.end(), 0);
for (int i = 2; i * i < n; ++i) {
if (res[i] < i)
continue;
for (int j = i * i; j < n; j += i)
if (res[j] == j)
res[j] = i;
}
return res;
}
std::vector<int> factor(int n, const std::vector<int> &min_factor) {
// min_factor は sieve() で得られたものとする
std::vector<int> res;
while (n > 1) {
res.push_back(min_factor[n]);
n /= min_factor[n];
// 割った後の値についても素因数を知っているので順次求まる
}
return res;
}
int main() {
int N;
cin >> N;
vector<int> exists(1000002, -1);
set<ll> setwisec;
bool pairwise = true;
bool setwise = false;
vector<int> sieves = sieve(1000001);
vector<ll> A(N);
REP(i, N) { cin >> A[i]; }
REP(i, N) {
// for (auto x : setwisec){
// DB2(i,x);
// }
for (auto x : setwisec) {
if (A[i] % x != 0)
setwisec.erase(x);
}
vector<int> D = factor(A[i], sieves);
REP(j, D.size()) {
ll NowDiv = D[j];
if (NowDiv == 1)
continue;
// DB2(j, NowDiv);
if (i == 0) {
setwisec.insert(NowDiv);
}
if ((exists[NowDiv] != i) and (exists[NowDiv] != -1))
pairwise = false;
exists[NowDiv] = i;
}
}
if (setwisec.empty())
setwise = true;
if (pairwise) {
puts("pairwise coprime");
} else if (setwise) {
puts("setwise coprime");
} else {
puts("not coprime");
}
} | replace | 78 | 79 | 78 | 79 | -11 | |
p02574 | Python | Runtime Error | from math import gcd
N = int(input())
A = list(map(int, input().split()))
# setwise validation
tmp = 0
for a in A:
tmp = gcd(tmp, a)
isSetwise = tmp == 1
# pairwise validation
M = 10**6
A = set(A)
isPairwise = True
for i in range(2, M):
cnt = 0
ni = 0
while (ni := ni + i) <= M:
cnt += ni in A
isPairwise &= cnt <= 1
# check
if isPairwise:
ans = "pairwise coprime"
elif isSetwise:
ans = "setwise coprime"
else:
ans = "not coprime"
print(ans)
| from math import gcd
N = int(input())
A = list(map(int, input().split()))
# setwise validation
tmp = 0
for a in A:
tmp = gcd(tmp, a)
isSetwise = tmp == 1
# pairwise validation
M = 10**6
sieve = [0] * (M + 1)
for a in A:
sieve[a] += 1
cnt = 0
for i in range(2, M + 1):
cnt = max(cnt, sum(sieve[j] for j in range(i, M + 1, i)))
isPairwise = cnt <= 1
# check
if isPairwise:
ans = "pairwise coprime"
elif isSetwise:
ans = "setwise coprime"
else:
ans = "not coprime"
print(ans)
| replace | 15 | 23 | 15 | 23 | TLE | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()
#define endl "\n"
int_fast64_t gcd(int_fast64_t a, int_fast64_t b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
sort(rng(A));
vector<int> a(1000001);
vector<bool> isprime(1000001, true);
isprime[0] = isprime[1] = false;
for (int i = 0; i <= 1000000; i++) {
if (isprime[i])
for (int j = i + i; j <= 1000000; j += i) {
isprime[j] = false;
a[j] = i;
}
}
vector<vector<pii>> div(1000001);
for (int i = 0; i <= 1000000; i++) {
int n = i;
map<int, int> ans;
while (a[n] != 0) {
ans[a[n]]++;
n = n / a[n];
}
if (n != 0 && n != 1)
ans[n]++;
for (auto it : ans)
div[i].push_back({it.first, it.second});
}
vector<int> prime;
for (int i = 0; i <= 1000000; i++)
if (isprime[i])
prime.push_back(i);
bool pairwise = true;
vector<int> x(100001, 0);
for (auto it : div[A[0]])
x[it.first] = max(x[it.first], it.second);
for (int i = 0; i < N - 1; i++) {
for (auto it : div[A[i + 1]])
if (min(x[it.first], it.second) != 0)
pairwise = false;
for (auto it : div[A[i + 1]])
x[it.first] = max(x[it.first], it.second);
}
int GCD = A[0];
for (int i = 0; i < N - 1; i++)
GCD = gcd(GCD, A[i + 1]);
bool setwise = (GCD == 1);
if (pairwise)
cout << "pairwise coprime" << endl;
else if (setwise)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()
#define endl "\n"
int_fast64_t gcd(int_fast64_t a, int_fast64_t b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
sort(rng(A));
vector<int> a(1000001);
vector<bool> isprime(1000001, true);
isprime[0] = isprime[1] = false;
for (int i = 0; i <= 1000000; i++) {
if (isprime[i])
for (int j = i + i; j <= 1000000; j += i) {
isprime[j] = false;
a[j] = i;
}
}
vector<vector<pii>> div(1000001);
for (int i = 0; i <= 1000000; i++) {
int n = i;
map<int, int> ans;
while (a[n] != 0) {
ans[a[n]]++;
n = n / a[n];
}
if (n != 0 && n != 1)
ans[n]++;
for (auto it : ans)
div[i].push_back({it.first, it.second});
}
vector<int> prime;
for (int i = 0; i <= 1000000; i++)
if (isprime[i])
prime.push_back(i);
bool pairwise = true;
vector<int> x(1000001, 0);
for (auto it : div[A[0]])
x[it.first] = max(x[it.first], it.second);
for (int i = 0; i < N - 1; i++) {
for (auto it : div[A[i + 1]])
if (min(x[it.first], it.second) != 0)
pairwise = false;
for (auto it : div[A[i + 1]])
x[it.first] = max(x[it.first], it.second);
}
int GCD = A[0];
for (int i = 0; i < N - 1; i++)
GCD = gcd(GCD, A[i + 1]);
bool setwise = (GCD == 1);
if (pairwise)
cout << "pairwise coprime" << endl;
else if (setwise)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
return 0;
}
| replace | 61 | 62 | 61 | 62 | TLE | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define Rep(i, a, b) for (ll i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = b - 1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 100000000000000;
#define pp pair<ll, pair<ll, ll>>
// #define fi first
// #define se second
void printv(Vl v) {
for (int i = 0; i < v.size(); i++)
cout << v[i] << " \n"[i == v.size() - 1];
}
/*--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------*/
// O(log (N)) の素因数分解
// エラストテネスの篩を使った素因数分解
// 前処理 O(N loglog(N))
class smart_sieve {
ll L, R, M;
vector<int> small; // 小さい篩
vector<vector<ll>> large; // 大きい篩
vector<ll> aux; // aux[i] := large[i] の素因数の積
public:
smart_sieve(ll L, ll R) : L(L), R(R), M(sqrt(R) + 1) {
small.resize(M);
iota(small.begin(), small.end(), 0);
large.resize(R - L);
aux.assign(R - L, 1);
for (ll i = 2; i * i < R; ++i) {
if (small[i] < i)
continue;
small[i] = i;
for (ll j = i * i; j < M; j += i)
if (small[j] == j)
small[j] = i;
for (ll j = (L + i - 1) / i * i; j < R; j += i) {
ll k = j;
do {
if (aux[j - L] * aux[j - L] > R)
break;
large[j - L].push_back(i);
aux[j - L] *= i;
k /= i;
} while (k % i == 0);
}
}
}
vector<ll> factor(ll n) {
assert(L <= n && n < R);
vector<ll> res = large[n - L];
n /= aux[n - L];
if (n >= M) {
res.push_back(n);
return res;
}
while (n > 1) {
res.push_back(small[n]);
n /= small[n];
}
return res;
}
};
ll b[1000005];
int main() {
smart_sieve ss(1, 1000000); // 前処理
ll n;
cin >> n;
Vl a(n);
rep(i, 0, n) cin >> a[i];
rep(i, 0, n) {
Vl fac = ss.factor(a[i]);
set<ll> factor;
for (auto it : fac)
factor.insert(it);
for (auto it : factor)
b[it]++;
}
int f = 0;
Rep(i, 1, 1000000) {
if (b[i] >= 2)
f = 1;
if (b[i] == n) {
co("not coprime");
return 0;
}
}
if (f == 0)
co("pairwise coprime");
if (f == 1)
co("setwise coprime");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define Rep(i, a, b) for (ll i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = b - 1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 100000000000000;
#define pp pair<ll, pair<ll, ll>>
// #define fi first
// #define se second
void printv(Vl v) {
for (int i = 0; i < v.size(); i++)
cout << v[i] << " \n"[i == v.size() - 1];
}
/*--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------*/
// O(log (N)) の素因数分解
// エラストテネスの篩を使った素因数分解
// 前処理 O(N loglog(N))
class smart_sieve {
ll L, R, M;
vector<int> small; // 小さい篩
vector<vector<ll>> large; // 大きい篩
vector<ll> aux; // aux[i] := large[i] の素因数の積
public:
smart_sieve(ll L, ll R) : L(L), R(R), M(sqrt(R) + 1) {
small.resize(M);
iota(small.begin(), small.end(), 0);
large.resize(R - L);
aux.assign(R - L, 1);
for (ll i = 2; i * i < R; ++i) {
if (small[i] < i)
continue;
small[i] = i;
for (ll j = i * i; j < M; j += i)
if (small[j] == j)
small[j] = i;
for (ll j = (L + i - 1) / i * i; j < R; j += i) {
ll k = j;
do {
if (aux[j - L] * aux[j - L] > R)
break;
large[j - L].push_back(i);
aux[j - L] *= i;
k /= i;
} while (k % i == 0);
}
}
}
vector<ll> factor(ll n) {
assert(L <= n && n < R);
vector<ll> res = large[n - L];
n /= aux[n - L];
if (n >= M) {
res.push_back(n);
return res;
}
while (n > 1) {
res.push_back(small[n]);
n /= small[n];
}
return res;
}
};
ll b[1000005];
int main() {
smart_sieve ss(1, 1000001); // 前処理
ll n;
cin >> n;
Vl a(n);
rep(i, 0, n) cin >> a[i];
rep(i, 0, n) {
Vl fac = ss.factor(a[i]);
set<ll> factor;
for (auto it : fac)
factor.insert(it);
for (auto it : factor)
b[it]++;
}
int f = 0;
Rep(i, 1, 1000000) {
if (b[i] >= 2)
f = 1;
if (b[i] == n) {
co("not coprime");
return 0;
}
}
if (f == 0)
co("pairwise coprime");
if (f == 1)
co("setwise coprime");
return 0;
}
| replace | 94 | 95 | 94 | 95 | 0 | |
p02574 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;
#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(), (x).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector<pair<ll, ll>> prime_fact(ll x) {
ll i = 2;
vector<pair<ll, ll>> ans;
while (i * i <= x) {
ll tmp = 0;
while (x % i == 0) {
tmp++;
x /= i;
}
if (tmp != 0) {
ans.push_back(make_pair(i, tmp));
}
i++;
}
if (x != 1)
ans.push_back(make_pair(x, 1));
return ans;
}
ll gcd(ll x, ll y) {
while (y > 0) {
ll tmp = y;
y = x % y;
x = tmp;
}
return x;
}
int main() {
ll N;
cin >> N;
v A(N);
rep(i, 0, N) cin >> A[i];
v used(100001, 0);
bool p_ans = true;
rep(i, 0, N) {
vector<pair<ll, ll>> now;
now = prime_fact(A[i]);
rep(j, 0, now.size()) {
if (used[now[j].first] >= 1)
p_ans = false;
else
used[now[j].first]++;
// cout<<now[j].first<<endl;
}
if (p_ans == false)
break;
}
ll now = A[0];
rep(i, 1, N) { now = gcd(now, A[i]); }
ll s_ans = false;
if (now == 1)
s_ans = true;
if (p_ans)
cout << "pairwise coprime";
else if (s_ans)
cout << "setwise coprime";
else
cout << "not coprime";
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;
#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i, k, N) for (int i = k; i < N; i++)
#define MP make_pair
#define MT make_tuple // tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(), (x).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector<pair<ll, ll>> prime_fact(ll x) {
ll i = 2;
vector<pair<ll, ll>> ans;
while (i * i <= x) {
ll tmp = 0;
while (x % i == 0) {
tmp++;
x /= i;
}
if (tmp != 0) {
ans.push_back(make_pair(i, tmp));
}
i++;
}
if (x != 1)
ans.push_back(make_pair(x, 1));
return ans;
}
ll gcd(ll x, ll y) {
while (y > 0) {
ll tmp = y;
y = x % y;
x = tmp;
}
return x;
}
int main() {
ll N;
cin >> N;
v A(N);
rep(i, 0, N) cin >> A[i];
v used(1000001, 0);
bool p_ans = true;
rep(i, 0, N) {
vector<pair<ll, ll>> now;
now = prime_fact(A[i]);
rep(j, 0, now.size()) {
if (used[now[j].first] >= 1)
p_ans = false;
else
used[now[j].first]++;
// cout<<now[j].first<<endl;
}
if (p_ans == false)
break;
}
ll now = A[0];
rep(i, 1, N) { now = gcd(now, A[i]); }
ll s_ans = false;
if (now == 1)
s_ans = true;
if (p_ans)
cout << "pairwise coprime";
else if (s_ans)
cout << "setwise coprime";
else
cout << "not coprime";
return 0;
} | replace | 64 | 65 | 64 | 65 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>
int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main() {
int n, x, flag, flag2 = 1;
cin >> n;
vector<int> a(n);
set<int> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n && flag2 == 1; i++) {
x = a[i];
for (int j = 2; j <= 1000; j++) {
flag = 0;
while (x % j == 0) {
x /= j;
flag = 1;
}
if (flag && s.find(j) == s.end()) {
s.insert(j);
} else if (flag) {
flag2 = 0;
break;
}
}
if (x != 1 && s.find(x) == s.end()) {
s.insert(x);
} else if (x != 1) {
flag2 = 0;
break;
}
}
if (flag2 == 1) {
cout << "pairwise coprime" << endl;
return 0;
}
int g = a[0];
for (int i = 0; i < n; i++) {
g = gcd(g, a[i]);
}
cout << (g == 1 ? "setwise coprime" : "not coprime") << endl;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>
int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main() {
int n, x, flag, flag2 = 1;
cin >> n;
vector<int> a(n);
set<int> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n && flag2 == 1; i++) {
x = a[i];
for (int j = 2; j <= 1000 && x != 1; j++) {
flag = 0;
while (x % j == 0) {
x /= j;
flag = 1;
}
if (flag && s.find(j) == s.end()) {
s.insert(j);
} else if (flag) {
flag2 = 0;
break;
}
}
if (x != 1 && s.find(x) == s.end()) {
s.insert(x);
} else if (x != 1) {
flag2 = 0;
break;
}
}
if (flag2 == 1) {
cout << "pairwise coprime" << endl;
return 0;
}
int g = a[0];
for (int i = 0; i < n; i++) {
g = gcd(g, a[i]);
}
cout << (g == 1 ? "setwise coprime" : "not coprime") << endl;
} | replace | 33 | 34 | 33 | 34 | TLE | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define MAXN 100001
// stores smallest prime factor for every number
int spf[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
void sieve() {
spf[1] = 1;
for (int i = 2; i < MAXN; i++)
// marking smallest prime factor for every
// number to be itself.
spf[i] = i;
// separately marking spf for every even
// number as 2
for (int i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (int i = 3; i * i < MAXN; i++) {
// checking if i is prime
if (spf[i] == i) {
// marking SPF for all numbers divisible by i
for (int j = i * i; j < MAXN; j += i)
// marking spf[j] if it is not
// previously marked
if (spf[j] == j)
spf[j] = i;
}
}
}
// A O(log n) function returning primefactorization
// by dividing by smallest prime factor at every step
vector<int> getFactorization(int x) {
vector<int> ret;
while (x != 1) {
ret.push_back(spf[x]);
x = x / spf[x];
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int arr[n];
sieve();
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
set<int> s;
ll fg = 0;
for (int i = 0; i < n; i++) {
set<int> st;
vector<int> p = getFactorization(arr[i]);
for (int j = 0; j < p.size(); j++) {
if (st.find(p[j]) == st.end() && s.find(p[j]) != s.end()) {
fg = 1;
break;
} else {
st.insert(p[j]);
s.insert(p[j]);
}
}
if (fg == 1)
break;
}
if (fg == 0) {
cout << "pairwise coprime";
} else {
int gcd = arr[0];
for (int i = 1; i < n; i++) {
gcd = __gcd(arr[i], gcd);
}
if (gcd == 1) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define MAXN 10000001
// stores smallest prime factor for every number
int spf[MAXN];
// Calculating SPF (Smallest Prime Factor) for every
// number till MAXN.
// Time Complexity : O(nloglogn)
void sieve() {
spf[1] = 1;
for (int i = 2; i < MAXN; i++)
// marking smallest prime factor for every
// number to be itself.
spf[i] = i;
// separately marking spf for every even
// number as 2
for (int i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (int i = 3; i * i < MAXN; i++) {
// checking if i is prime
if (spf[i] == i) {
// marking SPF for all numbers divisible by i
for (int j = i * i; j < MAXN; j += i)
// marking spf[j] if it is not
// previously marked
if (spf[j] == j)
spf[j] = i;
}
}
}
// A O(log n) function returning primefactorization
// by dividing by smallest prime factor at every step
vector<int> getFactorization(int x) {
vector<int> ret;
while (x != 1) {
ret.push_back(spf[x]);
x = x / spf[x];
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int arr[n];
sieve();
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
set<int> s;
ll fg = 0;
for (int i = 0; i < n; i++) {
set<int> st;
vector<int> p = getFactorization(arr[i]);
for (int j = 0; j < p.size(); j++) {
if (st.find(p[j]) == st.end() && s.find(p[j]) != s.end()) {
fg = 1;
break;
} else {
st.insert(p[j]);
s.insert(p[j]);
}
}
if (fg == 1)
break;
}
if (fg == 0) {
cout << "pairwise coprime";
} else {
int gcd = arr[0];
for (int i = 1; i < n; i++) {
gcd = __gcd(arr[i], gcd);
}
if (gcd == 1) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
}
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02574 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
#define ma 1000005
ll gcd(ll, ll);
int main() {
ll n;
ll x;
ll gc = 0;
bool pc = true;
cin >> n;
vector<ll> a(n);
vector<ll> c(ma);
rep(i, n) {
cin >> a[i];
c[a[i]]++;
}
for (ll i = 2; i < ma; i++) {
int count = 0;
for (ll j = i; j < ma; j += i) {
count += c[j];
}
if (count > 1) {
pc = false;
}
}
if (pc) {
cout << "pairwise coprime" << endl;
return 0;
}
rep(i, n) gc = gcd(gc, a[i]);
if (gc == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
return 0;
}
ll gcd(ll a, ll b) {
if (a % b == 0)
return b;
else
gcd(b, a % b);
}
| #include "bits/stdc++.h"
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
#define ma 1000005
ll gcd(ll, ll);
int main() {
ll n;
ll x;
ll gc = 0;
bool pc = true;
cin >> n;
vector<ll> a(n);
vector<ll> c(ma);
rep(i, n) {
cin >> a[i];
c[a[i]]++;
}
for (ll i = 2; i < ma; i++) {
int count = 0;
for (ll j = i; j < ma; j += i) {
count += c[j];
}
if (count > 1) {
pc = false;
}
}
if (pc) {
cout << "pairwise coprime" << endl;
return 0;
}
rep(i, n) gc = gcd(gc, a[i]);
if (gc == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
return 0;
}
ll gcd(ll a, ll b) {
if (a % b == 0)
return b;
else
return gcd(b, a % b);
} | replace | 48 | 49 | 48 | 49 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6;
bool is_prime[N + 5];
int d[N + 5]; // d[i]=iの最小の素因数
int mp[N + 5];
int main() {
for (int i = 0; i < N; i++)
is_prime[i] = true; // エラトステネス
for (int i = 2; i < N; i++) {
if (is_prime[i])
d[i] = i;
for (int j = i + i; j < N; j += i) {
is_prime[j] = false;
if (is_prime[i] && d[j] == 0)
d[j] = i;
}
}
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> p;
for (int i = 0; i < n; i++) {
while (a[i] > 1) {
int m = d[a[i]];
a[i] /= m;
if (a[i] % m != 0)
p.push_back(m);
}
}
for (auto x : p)
mp[x]++;
int ans = 0;
for (int i = 1; i < N + 5; i++) {
if (mp[i] >= 2 && mp[i] <= n - 1)
ans = 1;
if (mp[i] == n) {
ans = 2;
break;
}
}
if (ans == 0)
cout << "pairwise coprime" << endl;
if (ans == 1)
cout << "setwise coprime" << endl;
if (ans == 2)
cout << "not coprime" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1000005;
bool is_prime[N + 5];
int d[N + 5]; // d[i]=iの最小の素因数
int mp[N + 5];
int main() {
for (int i = 0; i < N; i++)
is_prime[i] = true; // エラトステネス
for (int i = 2; i < N; i++) {
if (is_prime[i])
d[i] = i;
for (int j = i + i; j < N; j += i) {
is_prime[j] = false;
if (is_prime[i] && d[j] == 0)
d[j] = i;
}
}
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> p;
for (int i = 0; i < n; i++) {
while (a[i] > 1) {
int m = d[a[i]];
a[i] /= m;
if (a[i] % m != 0)
p.push_back(m);
}
}
for (auto x : p)
mp[x]++;
int ans = 0;
for (int i = 1; i < N + 5; i++) {
if (mp[i] >= 2 && mp[i] <= n - 1)
ans = 1;
if (mp[i] == n) {
ans = 2;
break;
}
}
if (ans == 0)
cout << "pairwise coprime" << endl;
if (ans == 1)
cout << "setwise coprime" << endl;
if (ans == 2)
cout << "not coprime" << endl;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;
// chmin, chmax関数
template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
if (comp(xmax, x)) {
xmax = x;
return true;
}
return false;
}
template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
if (comp(x, xmin)) {
xmin = x;
return true;
}
return false;
}
// Yes-Noを出力する問題で楽をする
void Ans(bool f) {
if (f)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
// エラトステネスのふるい
// min_prime[x] = x の最小の素因数
// x が素数なら 1、x = 0,1 なら 0
const ll N = 1000010;
vector<ll> min_prime(N, 1);
void sieve() {
min_prime[0] = 0;
min_prime[1] = 0;
for (int i = 2; i * i <= N; i++) {
if (min_prime[i] == 1) {
for (int j = 2; i * j <= N; j++) {
if (min_prime[i * j] == 1)
min_prime[i * j] = i;
}
}
}
}
//---------------------------
int main() {
sieve();
ll n;
cin >> n;
VL a(n);
rep(i, n) cin >> a[i];
vector<set<ll>> S(n);
rep(i, n) {
ll cur = a[i];
bool flag = true;
while (flag) {
ll x = min_prime[cur];
if (x == 1) {
S[i].insert(cur);
flag = false;
} else {
S[i].insert(x);
cur /= x;
}
}
}
VL prime_factor_count(N, 0);
rep(i, n) {
for (auto x : S[i]) {
prime_factor_count[x]++;
}
}
bool not_coprime = false;
bool not_pairwise = false;
rep(i, N) {
if (prime_factor_count[i] == n)
not_coprime = true;
if (prime_factor_count[i] > 1)
not_pairwise = true;
}
if (not_pairwise) {
if (not_coprime) {
cout << "not coprime" << endl;
} else {
cout << "setwise coprime" << endl;
}
} else {
cout << "pairwise coprime" << endl;
}
// rep2(i,1,30){
// if(min_prime[i] == 1) cout << i << " " << prime_factor_count[i] <<
// endl;
// }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;
// chmin, chmax関数
template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
if (comp(xmax, x)) {
xmax = x;
return true;
}
return false;
}
template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
if (comp(x, xmin)) {
xmin = x;
return true;
}
return false;
}
// Yes-Noを出力する問題で楽をする
void Ans(bool f) {
if (f)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
// エラトステネスのふるい
// min_prime[x] = x の最小の素因数
// x が素数なら 1、x = 0,1 なら 0
const ll N = 1000010;
vector<ll> min_prime(N, 1);
void sieve() {
min_prime[0] = 0;
min_prime[1] = 0;
for (int i = 2; i * i <= N; i++) {
if (min_prime[i] == 1) {
for (int j = 2; i * j <= N; j++) {
if (min_prime[i * j] == 1)
min_prime[i * j] = i;
}
}
}
}
//---------------------------
int main() {
sieve();
ll n;
cin >> n;
VL a(n);
rep(i, n) cin >> a[i];
vector<set<ll>> S(n);
rep(i, n) {
ll cur = a[i];
bool flag = true;
if (cur == 1)
continue;
while (flag) {
ll x = min_prime[cur];
if (x == 1) {
S[i].insert(cur);
flag = false;
} else {
S[i].insert(x);
cur /= x;
}
}
}
VL prime_factor_count(N, 0);
rep(i, n) {
for (auto x : S[i]) {
prime_factor_count[x]++;
}
}
bool not_coprime = false;
bool not_pairwise = false;
rep(i, N) {
if (prime_factor_count[i] == n)
not_coprime = true;
if (prime_factor_count[i] > 1)
not_pairwise = true;
}
if (not_pairwise) {
if (not_coprime) {
cout << "not coprime" << endl;
} else {
cout << "setwise coprime" << endl;
}
} else {
cout << "pairwise coprime" << endl;
}
// rep2(i,1,30){
// if(min_prime[i] == 1) cout << i << " " << prime_factor_count[i] <<
// endl;
// }
return 0;
} | insert | 69 | 69 | 69 | 72 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
void fastio() {
cin.tie(nullptr);
cin.sync_with_stdio(false);
}
using LL = long long;
using LD = long double;
const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;
int main() {
fastio();
LL n;
cin >> n;
vector<LL> a(n);
for (auto &e : a) {
cin >> e;
}
LL net_gcd = a[0];
for (LL i = 1; i < n; ++i) {
net_gcd = __gcd(net_gcd, a[i]);
}
if (net_gcd != 1) {
cout << "not coprime\n";
return 0;
}
vector<LL> primes(N, 0);
for (LL i = 0; i < n; ++i) {
LL x = a[i];
for (LL j = 2; j * j <= a[i]; ++j) {
if (x % j == 0) {
while (x % j == 0)
x /= j;
primes[j]++;
}
}
if (x > 1) {
primes[x]++;
}
}
for (auto e : primes) {
if (e > 1) {
cout << "setwise coprime\n";
return 0;
}
}
cout << "pairwise coprime\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
void fastio() {
cin.tie(nullptr);
cin.sync_with_stdio(false);
}
using LL = long long;
using LD = long double;
const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;
int main() {
fastio();
LL n;
cin >> n;
vector<LL> a(n);
for (auto &e : a) {
cin >> e;
}
LL net_gcd = a[0];
for (LL i = 1; i < n; ++i) {
net_gcd = __gcd(net_gcd, a[i]);
}
if (net_gcd != 1) {
cout << "not coprime\n";
return 0;
}
vector<LL> primes(N, 0);
for (LL i = 0; i < n; ++i) {
LL x = a[i];
for (LL j = 2; j * j <= x; ++j) {
if (x % j == 0) {
while (x % j == 0)
x /= j;
primes[j]++;
}
}
if (x > 1) {
primes[x]++;
}
}
for (auto e : primes) {
if (e > 1) {
cout << "setwise coprime\n";
return 0;
}
}
cout << "pairwise coprime\n";
return 0;
} | replace | 41 | 42 | 41 | 42 | TLE | |
p02574 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define ll long long
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define gmid ((l + r) >> 1)
using namespace std;
const int maxn = 10050;
const int maxm = 1000050;
ll p[maxm], a[maxm], s[maxm], cnt = 0;
bool vis[maxm];
void init() {
for (int i = 2; i < maxn; ++i) {
if (!vis[i])
p[cnt++] = i;
for (int j = 0; j < cnt && p[j] * i < maxn; ++j) {
vis[p[j] * i] = 1;
if (i % p[j] == 0)
break;
}
}
}
int main() {
init();
int n, mx = 0;
cin >> n;
memset(s, 0, sizeof(s));
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
if (x > mx)
mx = x;
for (int j = 0; j < cnt; ++j)
if (x % p[j] == 0) {
s[p[j]]++;
while (x % p[j] == 0) {
x /= p[j];
}
}
if (x > 1)
s[x]++;
}
int f1 = 1, f2 = 1;
for (int i = 1; i < mx; ++i) {
if (s[i] > 1)
f1 = 0;
if (s[i] == n)
f2 = 0;
}
if (f1) {
cout << "pairwise coprime" << endl;
} else {
if (f2) {
cout << "setwise coprime" << endl;
} else
cout << "not coprime" << endl;
}
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define ll long long
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define gmid ((l + r) >> 1)
using namespace std;
const int maxn = 1020;
const int maxm = 1000050;
ll p[maxm], a[maxm], s[maxm], cnt = 0;
bool vis[maxm];
void init() {
for (int i = 2; i < maxn; ++i) {
if (!vis[i])
p[cnt++] = i;
for (int j = 0; j < cnt && p[j] * i < maxn; ++j) {
vis[p[j] * i] = 1;
if (i % p[j] == 0)
break;
}
}
}
int main() {
init();
int n, mx = 0;
cin >> n;
memset(s, 0, sizeof(s));
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
if (x > mx)
mx = x;
for (int j = 0; j < cnt; ++j)
if (x % p[j] == 0) {
s[p[j]]++;
while (x % p[j] == 0) {
x /= p[j];
}
}
if (x > 1)
s[x]++;
}
int f1 = 1, f2 = 1;
for (int i = 1; i < mx; ++i) {
if (s[i] > 1)
f1 = 0;
if (s[i] == n)
f2 = 0;
}
if (f1) {
cout << "pairwise coprime" << endl;
} else {
if (f2) {
cout << "setwise coprime" << endl;
} else
cout << "not coprime" << endl;
}
}
| replace | 11 | 12 | 11 | 12 | TLE | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
int main() {
int N, ans, i;
cin >> N;
int A[N];
REP(i, N) cin >> A[i];
ans = A[0];
REP(i, N - 1) ans = __gcd(ans, A[i + 1]);
if (ans == 1) {
int x = 1;
vector<int> X;
REP(i, N) {
int j = 1;
while (A[i] != 1) {
j++;
if (j * j > A[i]) {
X.push_back(A[i]);
break;
}
if (A[i] % j == 0) {
X.push_back(j);
while (A[i] % j == 0)
A[i] /= j;
}
}
if (X.size() > 78498)
break;
}
sort(ALL(X));
REP(i, X.size() - 1) if (X.at(i) == X.at(i + 1)) x = 0;
if (x == 1)
cout << "pairwise coprime" << endl;
else
cout << "setwise coprime" << endl;
} else
cout << "not coprime" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
int main() {
int N, ans, i;
cin >> N;
int A[N];
REP(i, N) cin >> A[i];
ans = A[0];
REP(i, N - 1) ans = __gcd(ans, A[i + 1]);
if (ans == 1) {
int x = 1;
vector<int> X;
REP(i, N) {
int j = 1;
while (A[i] != 1) {
j++;
if (j * j > A[i]) {
X.push_back(A[i]);
break;
}
if (A[i] % j == 0) {
X.push_back(j);
while (A[i] % j == 0)
A[i] /= j;
}
}
if (X.size() > 78498)
break;
}
if (X.size())
sort(ALL(X));
if (X.size() > 1)
REP(i, X.size() - 1) if (X.at(i) == X.at(i + 1)) x = 0;
if (x == 1)
cout << "pairwise coprime" << endl;
else
cout << "setwise coprime" << endl;
} else
cout << "not coprime" << endl;
return 0;
} | replace | 36 | 38 | 36 | 40 | 0 | |
p02574 | C++ | Runtime Error | #ifdef __APPLE__
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <ctgmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i, a, n) for (i = a; i < n; i++)
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define RFOR(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc = 1; tc <= t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int>> vpi;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll modInverse(ll a) {
ll p = mod - 2;
return powmod(a, p);
}
// head
int MAXN = 100;
vi gpd(MAXN);
void sieve() {
for (int i = 2; i < sz(gpd); i++) {
if (!gpd[i]) {
for (int j = i; j < sz(gpd); j += i) {
gpd[j] = i;
}
}
}
}
void fac(int x, vi &freq) {
while (x > 1) {
freq[gpd[x]]++;
x /= gpd[x];
}
}
bool check(int x, vi &freq) {
while (x > 1) {
int cnt = 0;
int gp = gpd[x];
while (x > 1 and x % gp == 0) {
cnt++;
x /= gp;
}
if (freq[gp] > cnt) {
return true;
}
}
return false;
}
void solve() {
int n;
cin >> n;
sieve();
vi a(n);
for (auto &x : a)
cin >> x;
int gc = a[0];
for (int i = 1; i < n; i++) {
gc = gcd(gc, a[i]);
}
vi freq(MAXN);
for (auto x : a) {
fac(x, freq);
}
bool pair = true;
for (auto x : a) {
if (check(x, freq)) {
pair = false;
break;
}
}
if (pair) {
cout << "pairwise coprime"
<< "\n";
} else if (gc == 1) {
cout << "setwise coprime"
<< "\n";
} else {
cout << "not coprime"
<< "\n";
}
}
int main() {
#ifdef LOCAL
auto t1 = std::chrono::high_resolution_clock::now();
#endif
io;
solve();
#ifdef LOCAL
auto t2 = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
std::cout << "Time Taken: " << duration << "\n";
#endif
}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases
// multiset erase is does not do what it is supposed to
| #ifdef __APPLE__
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <ctgmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i, a, n) for (i = a; i < n; i++)
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define RFOR(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc = 1; tc <= t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int>> vpi;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll modInverse(ll a) {
ll p = mod - 2;
return powmod(a, p);
}
// head
int MAXN = 1000008;
vi gpd(MAXN);
void sieve() {
for (int i = 2; i < sz(gpd); i++) {
if (!gpd[i]) {
for (int j = i; j < sz(gpd); j += i) {
gpd[j] = i;
}
}
}
}
void fac(int x, vi &freq) {
while (x > 1) {
freq[gpd[x]]++;
x /= gpd[x];
}
}
bool check(int x, vi &freq) {
while (x > 1) {
int cnt = 0;
int gp = gpd[x];
while (x > 1 and x % gp == 0) {
cnt++;
x /= gp;
}
if (freq[gp] > cnt) {
return true;
}
}
return false;
}
void solve() {
int n;
cin >> n;
sieve();
vi a(n);
for (auto &x : a)
cin >> x;
int gc = a[0];
for (int i = 1; i < n; i++) {
gc = gcd(gc, a[i]);
}
vi freq(MAXN);
for (auto x : a) {
fac(x, freq);
}
bool pair = true;
for (auto x : a) {
if (check(x, freq)) {
pair = false;
break;
}
}
if (pair) {
cout << "pairwise coprime"
<< "\n";
} else if (gc == 1) {
cout << "setwise coprime"
<< "\n";
} else {
cout << "not coprime"
<< "\n";
}
}
int main() {
#ifdef LOCAL
auto t1 = std::chrono::high_resolution_clock::now();
#endif
io;
solve();
#ifdef LOCAL
auto t2 = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
std::cout << "Time Taken: " << duration << "\n";
#endif
}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases
// multiset erase is does not do what it is supposed to | replace | 61 | 62 | 61 | 62 | 0 | |
p02574 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
const ll MOD = 9998903;
ll GCD(ll a, ll b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
void solve() {
ll i, j, count;
ll N;
cin >> N;
vector<ll> A(N, 0);
vector<ll> exist(100100, 0);
ll gcd = 0;
for (i = 0; i < N; i++) {
cin >> A[i];
gcd = GCD(gcd, A[i]);
exist[A[i]]++;
}
for (i = 2; i <= 1000000; i++) {
count = 0;
for (j = i; j <= 1000000; j += i)
count += exist[j];
if (count >= 2)
break; // 被りがあったら
}
if (i == 1000001) { // 被りがなければiは1000001となる
cout << "pairwise coprime" << endl;
return;
}
if (gcd == 1) {
cout << "setwise coprime" << endl;
} else {
cout << "not coprime" << endl;
}
}
int main() {
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vvll = vector<vector<ll>>;
using vll = vector<ll>;
const ll MOD = 9998903;
ll GCD(ll a, ll b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
void solve() {
ll i, j, count;
ll N;
cin >> N;
vector<ll> A(N, 0);
vector<ll> exist(1001000, 0);
ll gcd = 0;
for (i = 0; i < N; i++) {
cin >> A[i];
gcd = GCD(gcd, A[i]);
exist[A[i]]++;
}
for (i = 2; i <= 1000000; i++) {
count = 0;
for (j = i; j <= 1000000; j += i)
count += exist[j];
if (count >= 2)
break; // 被りがあったら
}
if (i == 1000001) { // 被りがなければiは1000001となる
cout << "pairwise coprime" << endl;
return;
}
if (gcd == 1) {
cout << "setwise coprime" << endl;
} else {
cout << "not coprime" << endl;
}
}
int main() {
solve();
return 0;
} | replace | 21 | 22 | 21 | 22 | -11 | |
p02574 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v) \
cerr << #v ":[ "; \
for (auto macro_vi : v) { \
cerr << macro_vi << " "; \
} \
cerr << "]" << endl;
#define ddump(v) \
cerr << #v ":" << endl; \
for (auto macro_row : v) { \
cerr << "["; \
for (auto macro__vi : macro_row) { \
cerr << macro__vi << " "; \
} \
cerr << "]" << endl; \
}
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const double EPS = 1e-10;
int main() {
lint N;
cin >> N;
vector<lint> A(N);
rep(i, N) cin >> A[i];
const lint M = 1001000;
// const lint M = 20;
vector<vector<lint>> primes(M + 1, vector<lint>(0));
for (int p = 2; p <= M; p++) {
if (primes[p].size() != 0)
continue;
for (int pk = p; pk <= M; pk += p) {
primes[pk].push_back(p);
}
}
vector<lint> min_factor(M, 1);
for (int p = 2; p <= M; p++) {
if (min_factor[p] != 1)
continue;
for (int pk = p; pk <= M; pk += p) {
if (min_factor[pk] == 1)
min_factor[pk] = p;
}
}
dump(min_factor);
lint G = 0;
rep(i, N) G = __gcd(G, A[i]);
if (G != 1) {
cout << "not coprime" << endl;
return 0;
}
set<lint> used;
for (int i = 0; i < N; i++) {
// for (auto p : primes[A[i]]) {
// if (used.count(p) == 1) {
// cout << "setwise coprime" << endl;
// return 0;
// } else {
// used.insert(p);
// }
// }
set<lint> primess{};
int a = A[i];
while (a != 1) {
primess.insert(min_factor[a]);
a /= min_factor[a];
}
for (auto p : primess) {
if (used.count(p) == 1) {
cout << "setwise coprime" << endl;
return 0;
} else {
used.insert(p);
}
}
}
cout << "pairwise coprime" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v) \
cerr << #v ":[ "; \
for (auto macro_vi : v) { \
cerr << macro_vi << " "; \
} \
cerr << "]" << endl;
#define ddump(v) \
cerr << #v ":" << endl; \
for (auto macro_row : v) { \
cerr << "["; \
for (auto macro__vi : macro_row) { \
cerr << macro__vi << " "; \
} \
cerr << "]" << endl; \
}
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const double EPS = 1e-10;
int main() {
lint N;
cin >> N;
vector<lint> A(N);
rep(i, N) cin >> A[i];
const lint M = 1001000;
// const lint M = 20;
vector<vector<lint>> primes(M + 1, vector<lint>(0));
for (int p = 2; p <= M; p++) {
if (primes[p].size() != 0)
continue;
for (int pk = p; pk <= M; pk += p) {
primes[pk].push_back(p);
}
}
vector<lint> min_factor(M, 1);
for (int p = 2; p <= M; p++) {
if (min_factor[p] != 1)
continue;
for (int pk = p; pk <= M; pk += p) {
if (min_factor[pk] == 1)
min_factor[pk] = p;
}
}
// dump(min_factor);
lint G = 0;
rep(i, N) G = __gcd(G, A[i]);
if (G != 1) {
cout << "not coprime" << endl;
return 0;
}
set<lint> used;
for (int i = 0; i < N; i++) {
// for (auto p : primes[A[i]]) {
// if (used.count(p) == 1) {
// cout << "setwise coprime" << endl;
// return 0;
// } else {
// used.insert(p);
// }
// }
set<lint> primess{};
int a = A[i];
while (a != 1) {
primess.insert(min_factor[a]);
a /= min_factor[a];
}
for (auto p : primess) {
if (used.count(p) == 1) {
cout << "setwise coprime" << endl;
return 0;
} else {
used.insert(p);
}
}
}
cout << "pairwise coprime" << endl;
return 0;
} | replace | 53 | 54 | 53 | 54 | TLE | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp, t, n, j, a[200600], ans, g, C[200010];
bool cond;
char c;
string s;
void solve(ll x) {
if (cond)
return;
for (j = 1; j * j <= x; j++) {
if (x % j == 0) {
ll a = j;
ll b = x / j;
if (a == b) {
a = j;
b = 1;
}
if (a != 1) {
if (C[a]) {
cond = true;
// cout << "Here 1 " << a <<endl;
return;
}
C[a]++;
// cout << "a = "<< a << endl;
}
if (b != 1) {
if (C[b]) {
cond = true;
// cout << "Here 2" <<" "<< b <<" "<<x <<" "<<C[b]<<endl;
return;
}
C[b]++;
// cout << "b = " << b << endl;
}
}
}
}
int main() {
// I am Monim, a tiny creature of Allah
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin >> n;
for (i = 0; i < n; i++)
cin >> a[i];
g = a[0];
solve(a[0]);
for (i = 1; i < n; i++) {
solve(a[i]);
g = __gcd(g, a[i]);
}
if (!cond)
cout << "pairwise coprime";
else if (g == 1)
cout << "setwise coprime";
else
cout << "not coprime";
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp, t, n, j, a[2000010], ans, g, C[2000010];
bool cond;
char c;
string s;
void solve(ll x) {
if (cond)
return;
for (j = 1; j * j <= x; j++) {
if (x % j == 0) {
ll a = j;
ll b = x / j;
if (a == b) {
a = j;
b = 1;
}
if (a != 1) {
if (C[a]) {
cond = true;
// cout << "Here 1 " << a <<endl;
return;
}
C[a]++;
// cout << "a = "<< a << endl;
}
if (b != 1) {
if (C[b]) {
cond = true;
// cout << "Here 2" <<" "<< b <<" "<<x <<" "<<C[b]<<endl;
return;
}
C[b]++;
// cout << "b = " << b << endl;
}
}
}
}
int main() {
// I am Monim, a tiny creature of Allah
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
cin >> n;
for (i = 0; i < n; i++)
cin >> a[i];
g = a[0];
solve(a[0]);
for (i = 1; i < n; i++) {
solve(a[i]);
g = __gcd(g, a[i]);
}
if (!cond)
cout << "pairwise coprime";
else if (g == 1)
cout << "setwise coprime";
else
cout << "not coprime";
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
using P = pair<long long, long long>;
#define rep(i, n) for (long long i = 0; i < (long long)n; i++)
#define req(i, n) for (long long i = n - 1; i >= 0; i--)
#define range(i, a, b) for (long long i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y, x) (y >= 0 && y < h && x >= 0 && x < w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int, int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout << #x << "=" << x << endl;
#define SUM(x) accumulate(x.begin(), x.end(), 0)
#define MAX(x) *max_element(x.begin(), x.end())
#define MIN(x) *min_element(x.begin(), x.end())
#define couty cout << "Yes" << endl
#define coutn cout << "No" << endl
#define coutY cout << "YES" << endl
#define coutN cout << "NO" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
#define YN(x) cout << (x ? "YES" : "NO") << endl
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const long long dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const long long dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long long INF = 1e15;
const long long MOD = 1e9 + 7;
const int MAX = 1e6 + 1;
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
int n;
cin >> n;
vi a(n);
rep(i, n) cin >> a[i];
vi dp(MAX, -1);
dp[1] = 1;
for (int i = 2; i * i <= MAX; i++) {
if (dp[i] != -1)
continue;
for (int j = i; j <= MAX; j += i) {
dp[j] = i;
}
}
vi sum(MAX, 0);
bool pc = true;
rep(i, n) {
int t = a[i];
while (t > 1) {
int div = dp[t];
while (t % div == 0)
t /= div;
sum[div]++;
if (sum[div] > 1) {
pc = false;
break;
}
}
if (pc == false)
break;
}
int sc = a[0];
for (int i = 1; i < n; i++)
sc = gcd(sc, a[i]);
if (pc)
cout << "pairwise coprime" << endl;
else if (sc == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
using P = pair<long long, long long>;
#define rep(i, n) for (long long i = 0; i < (long long)n; i++)
#define req(i, n) for (long long i = n - 1; i >= 0; i--)
#define range(i, a, b) for (long long i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y, x) (y >= 0 && y < h && x >= 0 && x < w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int, int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout << #x << "=" << x << endl;
#define SUM(x) accumulate(x.begin(), x.end(), 0)
#define MAX(x) *max_element(x.begin(), x.end())
#define MIN(x) *min_element(x.begin(), x.end())
#define couty cout << "Yes" << endl
#define coutn cout << "No" << endl
#define coutY cout << "YES" << endl
#define coutN cout << "NO" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
#define YN(x) cout << (x ? "YES" : "NO") << endl
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const long long dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const long long dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long long INF = 1e15;
const long long MOD = 1e9 + 7;
const int MAX = 1e6 + 1;
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
int n;
cin >> n;
vi a(n);
rep(i, n) cin >> a[i];
vi dp(MAX, -1);
dp[1] = 1;
for (int i = 2; i < MAX; i++) {
if (dp[i] != -1)
continue;
for (int j = i; j <= MAX; j += i) {
dp[j] = i;
}
}
vi sum(MAX, 0);
bool pc = true;
rep(i, n) {
int t = a[i];
while (t > 1) {
int div = dp[t];
while (t % div == 0)
t /= div;
sum[div]++;
if (sum[div] > 1) {
pc = false;
break;
}
}
if (pc == false)
break;
}
int sc = a[0];
for (int i = 1; i < n; i++)
sc = gcd(sc, a[i]);
if (pc)
cout << "pairwise coprime" << endl;
else if (sc == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
} | replace | 73 | 74 | 73 | 74 | TLE | |
p02574 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
typedef tuple<int, int, int> ituple;
// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (1000000 + 2)
bool isUsed[MAX_N];
/**
* 素因数分解クラス
*/
class PrimeFactorizer {
public:
PrimeFactorizer(VI ps) {
primes = ps;
maxNum = (ll)primes[primes.size() - 1] * primes[primes.size() - 1];
}
vector<lpair> factorize(ll n) {
assert(n <= maxNum);
vector<lpair> result;
ll threshold = (ll)sqrt(n) + 1;
for (int i = 0; i < primes.size(); i++) {
if (n < primes[i] || threshold < primes[i]) {
break;
}
ll div = 0;
while (n % primes[i] == 0) {
div++;
n /= primes[i];
}
if (div) {
result.push_back(lpair(primes[i], div));
}
}
if (n > 1) {
result.push_back(lpair(n, 1));
}
return result;
}
protected:
VI primes;
ll maxNum;
};
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
void exec() {
int org_data[] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107,
109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263,
269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,
439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521,
523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613,
617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887,
907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};
VI primes(org_data, org_data + 129);
PrimeFactorizer pf = PrimeFactorizer(primes);
int n, a[MAX_N];
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
bool isPairWise = true;
// pairwiseか
for (int i = 0; i < n; i++) {
vector<lpair> factors = pf.factorize(a[i]);
for (int j = 0; j < (int)factors.size(); j++) {
ll e = factors[j].first;
// printf("element %d's %d factor = %lld\n", i, j, e);
if (isUsed[e]) {
isPairWise = false;
break;
}
isUsed[e] = true;
}
if (!isPairWise) {
break;
}
}
if (isPairWise) {
cout << "pairwise coprime" << endl;
return;
}
ll tmp = a[0];
// setwiseか
for (int i = 1; i < n; i++) {
tmp = gcd(tmp, a[i]);
}
if (tmp == 1) {
cout << "setwise coprime" << endl;
return;
}
cout << "not coprime" << endl;
}
void solve() {
int t = 1;
// scanf("%d", &t);
for (int i = 0; i < t; i++) {
exec();
}
}
int main() {
solve();
return 0;
}
| #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
typedef tuple<int, int, int> ituple;
// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (1000000 + 2)
bool isUsed[MAX_N];
/**
* 素因数分解クラス
*/
class PrimeFactorizer {
public:
PrimeFactorizer(VI ps) {
primes = ps;
maxNum = (ll)primes[primes.size() - 1] * primes[primes.size() - 1];
}
vector<lpair> factorize(ll n) {
assert(n <= maxNum);
vector<lpair> result;
ll threshold = (ll)sqrt(n) + 1;
for (int i = 0; i < primes.size(); i++) {
if (n < primes[i] || threshold < primes[i]) {
break;
}
ll div = 0;
while (n % primes[i] == 0) {
div++;
n /= primes[i];
}
if (div) {
result.push_back(lpair(primes[i], div));
}
}
if (n > 1) {
result.push_back(lpair(n, 1));
}
return result;
}
protected:
VI primes;
ll maxNum;
};
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
void exec() {
int org_data[] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197,
199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379,
383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571,
577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761,
769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977,
983, 991, 997, 1009};
VI primes(org_data, org_data + 169);
PrimeFactorizer pf = PrimeFactorizer(primes);
int n, a[MAX_N];
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
bool isPairWise = true;
// pairwiseか
for (int i = 0; i < n; i++) {
vector<lpair> factors = pf.factorize(a[i]);
for (int j = 0; j < (int)factors.size(); j++) {
ll e = factors[j].first;
// printf("element %d's %d factor = %lld\n", i, j, e);
if (isUsed[e]) {
isPairWise = false;
break;
}
isUsed[e] = true;
}
if (!isPairWise) {
break;
}
}
if (isPairWise) {
cout << "pairwise coprime" << endl;
return;
}
ll tmp = a[0];
// setwiseか
for (int i = 1; i < n; i++) {
tmp = gcd(tmp, a[i]);
}
if (tmp == 1) {
cout << "setwise coprime" << endl;
return;
}
cout << "not coprime" << endl;
}
void solve() {
int t = 1;
// scanf("%d", &t);
for (int i = 0; i < t; i++) {
exec();
}
}
int main() {
solve();
return 0;
}
| replace | 75 | 88 | 75 | 88 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<int> sieve(int n) {
std::vector<int> res(n);
std::iota(res.begin(), res.end(), 0);
for (int i = 2; i * i < n; ++i) {
if (res[i] < i)
continue;
for (int j = i * i; j < n; j += i)
if (res[j] == j)
res[j] = i;
}
return res;
}
void factorize(long long n, vector<int> &prime_cnt, vector<int> &min_factor) {
int p;
while (n > 1) {
p = min_factor[n];
n /= p;
if (min_factor[n] != p) {
prime_cnt[p]++;
}
}
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<int> prime_cnt;
vector<int> prime_list = sieve(1e6);
prime_cnt.assign(1e6, 0);
for (int i = 0; i < N; i++) {
if (A[i] != 1) {
factorize(A[i], prime_cnt, prime_list);
}
}
bool pw_cp = true;
bool st_cp = true;
for (auto val : prime_cnt) {
if (val == 0)
continue;
if (val != 1) {
pw_cp = false;
}
if (val == N) {
st_cp = false;
}
}
if (pw_cp) {
cout << "pairwise coprime" << endl;
} else if (st_cp) {
cout << "setwise coprime" << endl;
} else {
cout << "not coprime" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<int> sieve(int n) {
std::vector<int> res(n);
std::iota(res.begin(), res.end(), 0);
for (int i = 2; i * i < n; ++i) {
if (res[i] < i)
continue;
for (int j = i * i; j < n; j += i)
if (res[j] == j)
res[j] = i;
}
return res;
}
void factorize(long long n, vector<int> &prime_cnt, vector<int> &min_factor) {
int p;
while (n > 1) {
p = min_factor[n];
n /= p;
if (min_factor[n] != p) {
prime_cnt[p]++;
}
}
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<int> prime_cnt;
vector<int> prime_list = sieve(1e6 + 1);
prime_cnt.assign(1e6, 0);
for (int i = 0; i < N; i++) {
if (A[i] != 1) {
factorize(A[i], prime_cnt, prime_list);
}
}
bool pw_cp = true;
bool st_cp = true;
for (auto val : prime_cnt) {
if (val == 0)
continue;
if (val != 1) {
pw_cp = false;
}
if (val == N) {
st_cp = false;
}
}
if (pw_cp) {
cout << "pairwise coprime" << endl;
} else if (st_cp) {
cout << "setwise coprime" << endl;
} else {
cout << "not coprime" << endl;
}
return 0;
} | replace | 39 | 40 | 39 | 40 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define NDEBUG
#include <bitset>
#include <cassert>
using namespace std;
#define prv(a) \
for (auto x : a) { \
cout << x << " "; \
} \
cout << '\n';
#define prvp(a) \
for (auto x : a) { \
cout << x.first << " " << x.second << '\n'; \
} \
cout << '\n';
#define ll long long
#define ld long double
#define INF pow(10, 10)
#define all(v) v.begin(), v.end()
#define bg begin()
#define ed end()
#define tr(it, v) for (auto it = v.bg; it != v.ed; it++)
#define f(a, b) for (ll i = a; i < b; i++)
#define fj(a, b) for (ll j = a; j < b; j++)
#define fb(b, a) for (ll i = b; i > a; i--)
#define dout(x) cout << x << '\n';
#define dout2(x, y) cout << x << " " << y << '\n';
#define dout3(x, y, z) cout << x << " " << y << " " << z << '\n';
#define pr1(x) cout << (x) << " ";
#define pr(x) cout << #x << " " << (x) << endl;
#define pr2(x, y) cout << #x << " " << (x) << " " << #y << " " << (y) << endl;
#define pr3(x, y, z) \
cout << #x << " " << (x) << " " << #y << " " << (y) << " " << #z << " " \
<< (z) << endl;
#define pp(x) cout << x.first << " " << x.second << endl;
ll min(ll a, ll b) {
if (a < b)
return a;
else
return b;
}
ll max(ll a, ll b) {
if (a < b)
return b;
else
return a;
}
ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }
ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }
ll NC = 100;
ll N = 1e9 + 7;
const ll S = 1e5 + 7;
ll mod(ll n);
ll gcd(ll a, ll b);
ll modM(ll n, ll m);
ll modA(ll n, ll m);
ll modS(ll n, ll m);
ll power(ll a, ll b);
void ipgraph(ll n, ll m);
//==============================================================================================
vector<vector<ll>> v;
vector<bool> vis;
vector<bool> pri; // is_prime
vector<ll> prime;
void printprime(ll n) {
pri.resize(n + 1, 1);
pri[0] = 0, pri[1] = 0;
for (ll i = 2; i * i <= n; i++) {
if (pri[i])
for (ll j = i * i; j <= n; j += i)
pri[j] = 0;
}
f(0, n + 1) if (pri[i]) prime.push_back(i);
}
void solve() {
ll n;
cin >> n;
vector<ll> a(n);
f(0, n) cin >> a[i];
// prv(prime)
string p = "pairwise coprime";
string s = "setwise coprime";
string none = "not coprime";
ll hcf = gcd(a[0], a[1]);
f(2, n) { hcf = gcd(hcf, a[i]); }
if (hcf > 1) {
cout << none;
return;
}
printprime(500002);
// prv(prime)
unordered_map<ll, ll> mp;
f(0, n) {
if (pri[a[i]]) {
if (mp[a[i]] > 0) {
cout << s;
return;
} else
mp[a[i]]++;
continue;
}
fj(0, prime.size()) {
if (prime[j] > a[i])
break;
if (a[i] % prime[j] == 0) {
if (mp[prime[j]] > 0) {
cout << s;
return;
} else
mp[prime[j]]++;
while (a[i] % prime[j] == 0)
a[i] /= prime[j];
}
}
}
cout << p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("/Users/aturgupta/Desktop/CP/input.txt", "r", stdin);
freopen("/Users/aturgupta/Desktop/CP/output.txt", "w", stdout);
#endif
ll t;
// cin >> t;
t = 1;
while (t--)
solve();
cerr << endl
<< "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
<< "ms\n";
return 0;
}
void ipgraph(ll n, ll m) {
v.assign(n, {});
vis.assign(n, 0);
ll x, y;
f(0, m) {
cin >> x >> y;
x--, y--;
v[y].push_back(x);
v[x].push_back(y);
}
}
ll gcd(ll a, ll b) {
if (b > a)
return gcd(b, a);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll power(ll a, ll b) {
if (b == 0)
return 1;
ll c = power(a, b / 2);
if (b % 2 == 0)
return modM(c, c);
else
return modM(modM(c, c), a);
}
ll mod(ll n) { return (n % N + N) % N; }
ll modM(ll n, ll m) { return ((n % N * m % N) + N) % N; }
ll modA(ll n, ll m) { return ((n % N + m % N) + N) % N; }
ll modS(ll n, ll m) { return ((n % N - m % N) + N) % N; }
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define NDEBUG
#include <bitset>
#include <cassert>
using namespace std;
#define prv(a) \
for (auto x : a) { \
cout << x << " "; \
} \
cout << '\n';
#define prvp(a) \
for (auto x : a) { \
cout << x.first << " " << x.second << '\n'; \
} \
cout << '\n';
#define ll long long
#define ld long double
#define INF pow(10, 10)
#define all(v) v.begin(), v.end()
#define bg begin()
#define ed end()
#define tr(it, v) for (auto it = v.bg; it != v.ed; it++)
#define f(a, b) for (ll i = a; i < b; i++)
#define fj(a, b) for (ll j = a; j < b; j++)
#define fb(b, a) for (ll i = b; i > a; i--)
#define dout(x) cout << x << '\n';
#define dout2(x, y) cout << x << " " << y << '\n';
#define dout3(x, y, z) cout << x << " " << y << " " << z << '\n';
#define pr1(x) cout << (x) << " ";
#define pr(x) cout << #x << " " << (x) << endl;
#define pr2(x, y) cout << #x << " " << (x) << " " << #y << " " << (y) << endl;
#define pr3(x, y, z) \
cout << #x << " " << (x) << " " << #y << " " << (y) << " " << #z << " " \
<< (z) << endl;
#define pp(x) cout << x.first << " " << x.second << endl;
ll min(ll a, ll b) {
if (a < b)
return a;
else
return b;
}
ll max(ll a, ll b) {
if (a < b)
return b;
else
return a;
}
ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }
ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }
ll NC = 100;
ll N = 1e9 + 7;
const ll S = 1e5 + 7;
ll mod(ll n);
ll gcd(ll a, ll b);
ll modM(ll n, ll m);
ll modA(ll n, ll m);
ll modS(ll n, ll m);
ll power(ll a, ll b);
void ipgraph(ll n, ll m);
//==============================================================================================
vector<vector<ll>> v;
vector<bool> vis;
vector<bool> pri; // is_prime
vector<ll> prime;
void printprime(ll n) {
pri.resize(n + 1, 1);
pri[0] = 0, pri[1] = 0;
for (ll i = 2; i * i <= n; i++) {
if (pri[i])
for (ll j = i * i; j <= n; j += i)
pri[j] = 0;
}
f(0, n + 1) if (pri[i]) prime.push_back(i);
}
void solve() {
ll n;
cin >> n;
vector<ll> a(n);
f(0, n) cin >> a[i];
// prv(prime)
string p = "pairwise coprime";
string s = "setwise coprime";
string none = "not coprime";
ll hcf = gcd(a[0], a[1]);
f(2, n) { hcf = gcd(hcf, a[i]); }
if (hcf > 1) {
cout << none;
return;
}
printprime(1000001);
// prv(prime)
unordered_map<ll, ll> mp;
f(0, n) {
if (pri[a[i]]) {
if (mp[a[i]] > 0) {
cout << s;
return;
} else
mp[a[i]]++;
continue;
}
fj(0, prime.size()) {
if (prime[j] > a[i])
break;
if (a[i] % prime[j] == 0) {
if (mp[prime[j]] > 0) {
cout << s;
return;
} else
mp[prime[j]]++;
while (a[i] % prime[j] == 0)
a[i] /= prime[j];
}
}
}
cout << p;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("/Users/aturgupta/Desktop/CP/input.txt", "r", stdin);
freopen("/Users/aturgupta/Desktop/CP/output.txt", "w", stdout);
#endif
ll t;
// cin >> t;
t = 1;
while (t--)
solve();
cerr << endl
<< "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
<< "ms\n";
return 0;
}
void ipgraph(ll n, ll m) {
v.assign(n, {});
vis.assign(n, 0);
ll x, y;
f(0, m) {
cin >> x >> y;
x--, y--;
v[y].push_back(x);
v[x].push_back(y);
}
}
ll gcd(ll a, ll b) {
if (b > a)
return gcd(b, a);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll power(ll a, ll b) {
if (b == 0)
return 1;
ll c = power(a, b / 2);
if (b % 2 == 0)
return modM(c, c);
else
return modM(modM(c, c), a);
}
ll mod(ll n) { return (n % N + N) % N; }
ll modM(ll n, ll m) { return ((n % N * m % N) + N) % N; }
ll modA(ll n, ll m) { return ((n % N + m % N) + N) % N; }
ll modS(ll n, ll m) { return ((n % N - m % N) + N) % N; }
| replace | 107 | 108 | 107 | 108 | TLE | |
p02574 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;
const ll inf = 1000000000000000000;
ll n, a[1000005], x;
set<ll> myset;
bool f = true;
bool is_prime(ll x) {
if (x <= 1)
return false;
for (ll i = 2; i <= (ll)sqrt(x); ++i)
if (x % i == 0)
return false;
return true;
}
void factorize(ll x) {
ll tec = 1;
if (is_prime(x)) {
if (myset.find(x) != myset.end())
f = false;
myset.insert(x);
return;
}
bool flag;
while (x > 1) {
++tec;
flag = false;
while (x % tec == 0) {
flag = true;
x /= tec;
}
if (flag) {
if (myset.find(tec) != myset.end())
f = false;
myset.insert(tec);
if (is_prime(x)) {
if (myset.find(x) != myset.end())
f = false;
myset.insert(x);
return;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (ll i = 1; i <= n; ++i)
cin >> a[i];
x = a[1];
for (ll i = 2; i <= n; ++i) {
x = __gcd(a[i], x);
}
for (ll i = 1; i <= n; ++i)
factorize(a[i]);
if (f) {
cout << "pairwise coprime";
return 0;
}
if (!f && x == 1) {
cout << "setwise coprime";
return 0;
}
cout << "not coprime";
return 0;
}
| #include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;
const ll inf = 1000000000000000000;
ll n, a[1000005], x;
set<ll> myset;
bool f = true;
bool is_prime(ll x) {
if (x <= 1)
return false;
for (ll i = 2; i <= (ll)sqrt(x); ++i)
if (x % i == 0)
return false;
return true;
}
void factorize(ll x) {
if (!f)
return;
ll tec = 1;
if (is_prime(x)) {
if (myset.find(x) != myset.end())
f = false;
myset.insert(x);
return;
}
bool flag;
while (x > 1) {
++tec;
flag = false;
while (x % tec == 0) {
flag = true;
x /= tec;
}
if (flag) {
if (myset.find(tec) != myset.end())
f = false;
myset.insert(tec);
if (is_prime(x)) {
if (myset.find(x) != myset.end())
f = false;
myset.insert(x);
return;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (ll i = 1; i <= n; ++i)
cin >> a[i];
x = a[1];
for (ll i = 2; i <= n; ++i) {
x = __gcd(a[i], x);
}
for (ll i = 1; i <= n; ++i)
factorize(a[i]);
if (f) {
cout << "pairwise coprime";
return 0;
}
if (!f && x == 1) {
cout << "setwise coprime";
return 0;
}
cout << "not coprime";
return 0;
}
| insert | 19 | 19 | 19 | 21 | TLE | |
p02574 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecd vector<double>
#define vecst vector<string>
#define vecb vector<bool>
#define vec2(var, n, m) vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m) vector<vector<ll>> var(n, vector<ll>(m, 0))
#define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define REP(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define arr(var, n) \
vec var(n); \
rep(i, n) { cin >> var[i]; }
#define arrll(var, n) \
vecll var(n); \
rep(i, n) { cin >> var[i]; }
#define arrst(var, n) \
vecst var(n); \
rep(i, n) { cin >> var[i]; }
#define all(var) (var).begin(), (var).end()
#define sortall(var) sort(all(var))
#define uniqueall(v) v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var) accumulate(all(var), 0)
#define f_sumll(var) accumulate(all(var), 0LL)
#define chmin(v1, v2) v1 = min(v1, v2)
#define chmax(v1, v2) v1 = max(v1, v2)
#define pb(var) push_back(var)
#define prt(var) cout << (var) << "\n"
#define prtd(n, var) cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var) cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2) cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v) \
rep(i, v.size()) { cout << v[i] << (i != v.size() - 1 ? " " : "\n"); }
void prtok(bool ok) { prt(ok ? "Yes" : "No"); }
//----------------------------------------------------------------
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
map<ll, ll> prime_factorize(ll n) {
map<ll, ll> mp;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
mp[i]++;
n /= i;
}
}
if (n != 1)
mp[n] = 1;
return mp;
}
int main(void) {
int n;
cin >> n;
arr(a, n);
int tmp = a[0];
rep(i, n) { tmp = gcd(tmp, a[i]); }
if (tmp != 1) {
prt("not coprime");
return 0;
}
map<ll, int> chk;
rep(i, n) {
map<ll, ll> plist = prime_factorize(a[i]);
for (auto k : plist) {
chk[k.first]++;
}
}
for (auto k : chk) {
if (k.second > 1) {
prt("setwise coprime");
return 0;
}
}
prt("pairwise coprime");
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecd vector<double>
#define vecst vector<string>
#define vecb vector<bool>
#define vec2(var, n, m) vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m) vector<vector<ll>> var(n, vector<ll>(m, 0))
#define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define REP(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define arr(var, n) \
vec var(n); \
rep(i, n) { cin >> var[i]; }
#define arrll(var, n) \
vecll var(n); \
rep(i, n) { cin >> var[i]; }
#define arrst(var, n) \
vecst var(n); \
rep(i, n) { cin >> var[i]; }
#define all(var) (var).begin(), (var).end()
#define sortall(var) sort(all(var))
#define uniqueall(v) v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var) accumulate(all(var), 0)
#define f_sumll(var) accumulate(all(var), 0LL)
#define chmin(v1, v2) v1 = min(v1, v2)
#define chmax(v1, v2) v1 = max(v1, v2)
#define pb(var) push_back(var)
#define prt(var) cout << (var) << "\n"
#define prtd(n, var) cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var) cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2) cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v) \
rep(i, v.size()) { cout << v[i] << (i != v.size() - 1 ? " " : "\n"); }
void prtok(bool ok) { prt(ok ? "Yes" : "No"); }
//----------------------------------------------------------------
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
map<ll, ll> prime_factorize(ll n) {
map<ll, ll> mp;
while (n % 2 == 0) {
mp[2]++;
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
mp[i]++;
n /= i;
}
}
if (n != 1)
mp[n] = 1;
return mp;
}
int main(void) {
int n;
cin >> n;
arr(a, n);
int tmp = a[0];
rep(i, n) { tmp = gcd(tmp, a[i]); }
if (tmp != 1) {
prt("not coprime");
return 0;
}
map<ll, int> chk;
rep(i, n) {
map<ll, ll> plist = prime_factorize(a[i]);
for (auto k : plist) {
chk[k.first]++;
}
}
for (auto k : chk) {
if (k.second > 1) {
prt("setwise coprime");
return 0;
}
}
prt("pairwise coprime");
}
| replace | 46 | 47 | 46 | 51 | TLE | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long llint;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const int base = 31337;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;
int n;
int a[maxn];
int bio[maxm + 20];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", a + i);
for (int i = 0; i < n; i++)
bio[a[i]]++;
bool flag = true;
for (int i = 2; i < maxm; i++) {
int cnt = 0;
for (int j = i; j < maxm; j += i)
cnt += bio[j];
if (cnt > 1) {
flag = false;
break;
}
}
if (flag) {
printf("pairwise coprime");
return 0;
}
flag = true;
for (int i = 2; i < maxm; i++) {
int cnt = 0;
for (int j = i; j < maxm; j += i)
cnt += bio[j];
if (cnt == n) {
flag = false;
break;
}
}
if (flag) {
printf("setwise coprime");
} else
printf("not coprime");
return 0;
} | #include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long llint;
const int maxn = 1e6 + 10;
const int maxm = 1e6 + 10;
const int base = 31337;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;
int n;
int a[maxn];
int bio[maxm + 20];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", a + i);
for (int i = 0; i < n; i++)
bio[a[i]]++;
bool flag = true;
for (int i = 2; i < maxm; i++) {
int cnt = 0;
for (int j = i; j < maxm; j += i)
cnt += bio[j];
if (cnt > 1) {
flag = false;
break;
}
}
if (flag) {
printf("pairwise coprime");
return 0;
}
flag = true;
for (int i = 2; i < maxm; i++) {
int cnt = 0;
for (int j = i; j < maxm; j += i)
cnt += bio[j];
if (cnt == n) {
flag = false;
break;
}
}
if (flag) {
printf("setwise coprime");
} else
printf("not coprime");
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 1e6 + 5;
unordered_map<int, int> prcnt;
int lp[N], n, vvod, pair_copr, set_copr;
vector<int> pr, lispr, mas;
void fact(int chis) {
if (chis <= 1) {
return;
}
lispr.push_back(lp[chis]);
fact(chis / lp[chis]);
}
int main() {
ios_base::sync_with_stdio(0);
// freopen( "input.txt", "r", stdin );
for (int i = 2; i <= N; i++) {
if (lp[i] == 0) {
lp[i] = i;
pr.push_back(i);
}
for (int j = 0; j < int(pr.size()) && pr[j] <= lp[i] && i * pr[j] <= N;
j++) {
lp[i * pr[j]] = pr[j];
}
}
cin >> n;
for (int i = 0; i < n; i++) {
cin >> vvod;
mas.push_back(vvod);
}
for (auto i : mas) {
lispr = {};
fact(i);
prcnt[lispr[0]]++;
for (int j = 0; j < int(lispr.size()) - 1; j++) {
if (lispr[j + 1] != lispr[j]) {
prcnt[lispr[j + 1]]++;
}
}
}
for (auto i : prcnt) {
if (i.s > 1) {
pair_copr = 1;
}
if (i.s == n) {
set_copr = 1;
}
}
if (!pair_copr) {
cout << "pairwise coprime";
} else {
if (!set_copr) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
}
return 0;
}
| #include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 1e6 + 5;
unordered_map<int, int> prcnt;
int lp[N], n, vvod, pair_copr, set_copr;
vector<int> pr, lispr, mas;
void fact(int chis) {
if (chis <= 1) {
return;
}
lispr.push_back(lp[chis]);
fact(chis / lp[chis]);
}
int main() {
ios_base::sync_with_stdio(0);
// freopen( "input.txt", "r", stdin );
for (int i = 2; i <= N; i++) {
if (lp[i] == 0) {
lp[i] = i;
pr.push_back(i);
}
for (int j = 0; j < int(pr.size()) && pr[j] <= lp[i] && i * pr[j] <= N;
j++) {
lp[i * pr[j]] = pr[j];
}
}
cin >> n;
for (int i = 0; i < n; i++) {
cin >> vvod;
mas.push_back(vvod);
}
for (auto i : mas) {
lispr = {};
fact(i);
if (lispr.size()) {
prcnt[lispr[0]]++;
for (int j = 0; j < int(lispr.size()) - 1; j++) {
if (lispr[j + 1] != lispr[j]) {
prcnt[lispr[j + 1]]++;
}
}
}
}
for (auto i : prcnt) {
if (i.s > 1) {
pair_copr = 1;
}
if (i.s == n) {
set_copr = 1;
}
}
if (!pair_copr) {
cout << "pairwise coprime";
} else {
if (!set_copr) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
}
return 0;
}
| replace | 48 | 52 | 48 | 54 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for (ll i = (k); i < (n); i++)
#define FORe(i, k, n) for (ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for (ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for (ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
const int INF = 1001001001;
struct Sieve {
ll n;
vector<ll> f, primes;
Sieve(ll n = 1) : n(n), f(n + 1, 0) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; i++) {
if (f[i])
continue;
primes.emplace_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i)
if (!f[j])
f[j] = i;
}
}
bool isPrime(const ll x) { return f[x] == x; }
vector<ll> factorList(ll x) {
vector<ll> res;
while (x != 1) {
res.emplace_back(f[x]);
x /= f[x];
}
return res;
}
vector<pair<ll, ll>> factor(const ll x) {
vector<ll> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<pair<ll, ll>> res(1, pair<ll, ll>(fl[0], 0));
for (ll p : fl) {
if (res.back().first == p)
res.back().second++;
else
res.emplace_back(pair<ll, ll>(p, 1));
}
return res;
}
};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main(void) {
ll n;
cin >> n;
vector<ll> a(n);
REP(i, n) cin >> a[i];
Sieve s(100000);
map<ll, ll> mp;
REP(i, n) {
auto f = s.factor(a[i]);
for (auto p : f) {
mp[p.first]++;
}
}
bool pc = true;
for (auto p : mp) {
if (p.second > 1)
pc = false;
}
if (pc) {
cout << "pairwise coprime" << endl;
return 0;
}
ll g = gcd(a[0], a[1]);
REP(i, n - 2) g = gcd(g, a[i + 2]);
if (g == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
return 0;
} | #include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for (ll i = (k); i < (n); i++)
#define FORe(i, k, n) for (ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for (ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for (ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
const int INF = 1001001001;
struct Sieve {
ll n;
vector<ll> f, primes;
Sieve(ll n = 1) : n(n), f(n + 1, 0) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; i++) {
if (f[i])
continue;
primes.emplace_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i)
if (!f[j])
f[j] = i;
}
}
bool isPrime(const ll x) { return f[x] == x; }
vector<ll> factorList(ll x) {
vector<ll> res;
while (x != 1) {
res.emplace_back(f[x]);
x /= f[x];
}
return res;
}
vector<pair<ll, ll>> factor(const ll x) {
vector<ll> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<pair<ll, ll>> res(1, pair<ll, ll>(fl[0], 0));
for (ll p : fl) {
if (res.back().first == p)
res.back().second++;
else
res.emplace_back(pair<ll, ll>(p, 1));
}
return res;
}
};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main(void) {
ll n;
cin >> n;
vector<ll> a(n);
REP(i, n) cin >> a[i];
Sieve s(1000000);
map<ll, ll> mp;
REP(i, n) {
auto f = s.factor(a[i]);
for (auto p : f) {
mp[p.first]++;
}
}
bool pc = true;
for (auto p : mp) {
if (p.second > 1)
pc = false;
}
if (pc) {
cout << "pairwise coprime" << endl;
return 0;
}
ll g = gcd(a[0], a[1]);
REP(i, n - 2) g = gcd(g, a[i + 2]);
if (g == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
return 0;
} | replace | 63 | 64 | 63 | 64 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main() {
fast();
int n;
cin >> n;
int a[n];
map<int, int> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int allgcd = a[0];
for (int i = 1; i < n; i++) {
allgcd = __gcd(a[i], allgcd);
}
const int N = 1000001;
vector<char> is_prime(N + 1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= N; i++) {
if (is_prime[i] && (long long)i * i <= N) {
for (int j = i * i; j <= N; j += i)
is_prime[j] = false;
}
}
vector<int> c;
for (int i = 0; i <= N; i++) {
if (is_prime[i]) {
c.emplace_back(i);
}
}
// cout<<(int)is_prime[6]<<"\n";
for (int i = 0; i < n; i++) {
int l = a[i];
if (is_prime[l]) {
m[l]++;
// cout<<l<<"\n";
} else {
for (int j = 0; j < (int)c.size(); j++) {
if (is_prime[l]) {
m[l]++;
break;
}
if (l % c[j] == 0) {
m[c[j]]++;
while (l % c[j] == 0) {
l = l / c[j];
}
}
}
}
}
int g = 1;
for (auto i : m) {
if (i.second == 1) {
g = 1;
// cout<<i.first<<"\n";
} else {
g = 0;
break;
}
}
if (g) {
cout << "pairwise coprime"
<< "\n";
return 0;
}
if (allgcd == 1) {
cout << "setwise coprime"
<< "\n";
return 0;
}
cout << "not coprime"
<< "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main() {
fast();
int n;
cin >> n;
int a[n];
map<int, int> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int allgcd = a[0];
for (int i = 1; i < n; i++) {
allgcd = __gcd(a[i], allgcd);
}
const int N = 1000001;
vector<char> is_prime(N + 1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= N; i++) {
if (is_prime[i] && (long long)i * i <= N) {
for (int j = i * i; j <= N; j += i)
is_prime[j] = false;
}
}
vector<int> c;
for (int i = 0; i <= N; i++) {
if (is_prime[i]) {
c.emplace_back(i);
}
}
// cout<<(int)is_prime[6]<<"\n";
for (int i = 0; i < n; i++) {
int l = a[i];
if (is_prime[l]) {
m[l]++;
// cout<<l<<"\n";
} else {
for (int j = 0; j < (int)c.size(); j++) {
if (is_prime[l]) {
m[l]++;
break;
}
if (l % c[j] == 0) {
m[c[j]]++;
while (l % c[j] == 0) {
l = l / c[j];
}
}
if (l < c[j]) {
break;
}
}
}
}
int g = 1;
for (auto i : m) {
if (i.second == 1) {
g = 1;
// cout<<i.first<<"\n";
} else {
g = 0;
break;
}
}
if (g) {
cout << "pairwise coprime"
<< "\n";
return 0;
}
if (allgcd == 1) {
cout << "setwise coprime"
<< "\n";
return 0;
}
cout << "not coprime"
<< "\n";
return 0;
}
| insert | 58 | 58 | 58 | 61 | TLE | |
p02574 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define IN(a, b) (a.find(b) != a.end())
#define p(a, b) make_pair(a, b)
#define readVec(a) \
for (int64_t __i = 0; __i < (int64_t)a.size(); __i++) { \
cin >> a[__i]; \
}
// jimjam
template <typename T> void pMin(T &a, T b) {
if (b < a) {
a = b;
}
}
template <typename T> void pMax(T &a, T b) {
if (b > a) {
a = b;
}
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &c);
template <typename A, typename B>
std::ostream &operator<<(std::ostream &os, const std::pair<A, B> &c) {
std::cout << "(" << c.first << ", " << c.second << ")";
return os;
}
using namespace std;
int64_t numFactors[1000005];
bool flag = false;
void sieve(int64_t k) {
for (int64_t i = 1; i * i <= k; i++) {
assert(i < k);
if (k % i == 0) {
int64_t a = i;
int64_t b = k / i;
assert(max(a, b) < 1000005);
if (numFactors[a] && a != 1) {
flag = true;
return;
}
numFactors[a]++;
if (a != b) {
if (numFactors[b]) {
flag = true;
return;
}
numFactors[b]++;
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int64_t n;
cin >> n;
vector<int64_t> a(n);
readVec(a);
for (int64_t i : a) {
sieve(i);
}
int64_t curr = a[0];
for (int64_t i = 1; i < n; i++) {
curr = __gcd(curr, a[i]);
}
if (!flag) {
cout << "pairwise coprime" << endl;
} else if (curr == 1) {
cout << "setwise coprime" << endl;
} else {
cout << "not coprime" << endl;
}
return 0;
}
| #include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define IN(a, b) (a.find(b) != a.end())
#define p(a, b) make_pair(a, b)
#define readVec(a) \
for (int64_t __i = 0; __i < (int64_t)a.size(); __i++) { \
cin >> a[__i]; \
}
// jimjam
template <typename T> void pMin(T &a, T b) {
if (b < a) {
a = b;
}
}
template <typename T> void pMax(T &a, T b) {
if (b > a) {
a = b;
}
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &c);
template <typename A, typename B>
std::ostream &operator<<(std::ostream &os, const std::pair<A, B> &c) {
std::cout << "(" << c.first << ", " << c.second << ")";
return os;
}
using namespace std;
int64_t numFactors[1000005];
bool flag = false;
void sieve(int64_t k) {
for (int64_t i = 1; i * i <= k; i++) {
// assert(i<k);
if (k % i == 0) {
int64_t a = i;
int64_t b = k / i;
assert(max(a, b) < 1000005);
if (numFactors[a] && a != 1) {
flag = true;
return;
}
numFactors[a]++;
if (a != b) {
if (numFactors[b]) {
flag = true;
return;
}
numFactors[b]++;
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int64_t n;
cin >> n;
vector<int64_t> a(n);
readVec(a);
for (int64_t i : a) {
sieve(i);
}
int64_t curr = a[0];
for (int64_t i = 1; i < n; i++) {
curr = __gcd(curr, a[i]);
}
if (!flag) {
cout << "pairwise coprime" << endl;
} else if (curr == 1) {
cout << "setwise coprime" << endl;
} else {
cout << "not coprime" << endl;
}
return 0;
}
| replace | 45 | 46 | 45 | 46 | 0 | |
p02574 | Python | Time Limit Exceeded | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10**9 + 1 # sys.maxsize # float("inf")
MOD = 10**9 + 7
def debug(*x):
print(*x, file=sys.stderr)
def precompute():
maxAS = 1000000
eratree = [0] * (maxAS + 10)
for p in range(2, maxAS + 1):
if eratree[p]:
continue
# p is prime
eratree[p] = p
x = p * p
while x <= maxAS:
if not eratree[x]:
eratree[x] = p
x += p
import pickle
pickle.dump(eratree, open("eratree.pickle", "wb"))
def solve(N, AS):
import pickle
eratree = pickle.load(open("eratree.pickle", "rb"))
num_division = 0
from collections import defaultdict
count = defaultdict(int)
for a in AS:
factors = []
while a > 1:
d = eratree[a]
factors.append(d)
a //= d
num_division += 1
# debug(": ", factors)
for f in set(factors):
count[f] += 1
# debug(": num_division", num_division)
if any(x == N for x in count.values()):
return "not coprime"
if any(x >= 2 for x in count.values()):
return "setwise coprime"
return "pairwise coprime"
def main():
# parse input
N = int(input())
AS = list(map(int, input().split()))
print(solve(N, AS))
# tests
T1 = """
3
3 4 5
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
pairwise coprime
"""
T2 = """
3
6 10 15
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
setwise coprime
"""
T3 = """
3
6 10 16
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
not coprime
"""
T4 = """
3
100000 100001 100003
"""
TEST_T4 = """
>>> as_input(T4)
>>> main()
pairwise coprime
"""
def _test():
import doctest
doctest.testmod()
g = globals()
for k in sorted(g):
if k.startswith("TEST_"):
doctest.run_docstring_examples(g[k], g, name=k)
def as_input(s):
"use in test, use given string as input file"
import io
f = io.StringIO(s.strip())
g = globals()
g["input"] = lambda: bytes(f.readline(), "ascii")
g["read"] = lambda: bytes(f.read(), "ascii")
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
if sys.argv[-1] == "ONLINE_JUDGE":
precompute()
else:
main()
| #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10**9 + 1 # sys.maxsize # float("inf")
MOD = 10**9 + 7
def debug(*x):
print(*x, file=sys.stderr)
def precompute():
maxAS = 1000000
eratree = [0] * (maxAS + 10)
for p in range(2, maxAS + 1):
if eratree[p]:
continue
# p is prime
eratree[p] = p
x = p * p
while x <= maxAS:
if not eratree[x]:
eratree[x] = p
x += p
import pickle
pickle.dump(eratree, open("eratree.pickle", "wb"))
def solve(N, AS):
import pickle
eratree = pickle.load(open("eratree.pickle", "rb"))
num_division = 0
from collections import defaultdict
count = defaultdict(int)
for a in AS:
factors = []
while a > 1:
d = eratree[a]
factors.append(d)
a //= d
num_division += 1
# debug(": ", factors)
for f in set(factors):
count[f] += 1
# debug(": num_division", num_division)
if any(x == N for x in count.values()):
return "not coprime"
if any(x >= 2 for x in count.values()):
return "setwise coprime"
return "pairwise coprime"
def main():
# parse input
N = int(input())
AS = list(map(int, input().split()))
print(solve(N, AS))
# tests
T1 = """
3
3 4 5
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
pairwise coprime
"""
T2 = """
3
6 10 15
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
setwise coprime
"""
T3 = """
3
6 10 16
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
not coprime
"""
T4 = """
3
100000 100001 100003
"""
TEST_T4 = """
>>> as_input(T4)
>>> main()
pairwise coprime
"""
def _test():
import doctest
doctest.testmod()
g = globals()
for k in sorted(g):
if k.startswith("TEST_"):
doctest.run_docstring_examples(g[k], g, name=k)
def as_input(s):
"use in test, use given string as input file"
import io
f = io.StringIO(s.strip())
g = globals()
g["input"] = lambda: bytes(f.readline(), "ascii")
g["read"] = lambda: bytes(f.read(), "ascii")
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
if sys.argv[-1] == "ONLINE_JUDGE":
precompute()
elif sys.argv[-1] != "DONTCALL":
import subprocess
subprocess.call(
"pypy3 Main.py DONTCALL", shell=True, stdin=sys.stdin, stdout=sys.stdout
)
else:
main()
| insert | 138 | 138 | 138 | 144 | TLE | |
p02574 | C++ | Time Limit Exceeded | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "{";
for (int i = 0; i < (int)v.size(); i++)
o << (i > 0 ? ", " : "") << v[i];
o << "}";
return o;
}
map<lint, int> p_factorization(lint n) {
map<lint, int> soinsu;
for (int i = 2; i <= sqrt(n); i++) {
while (n % i == 0) {
n /= i;
soinsu[i]++;
}
}
if (n != 1)
soinsu[n]++;
return soinsu;
}
// AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main() {
bool pairwise = true;
vector<int> vec(1000000);
int n, x, tmp;
cin >> n;
cin >> tmp;
map<lint, int> dic = p_factorization(tmp);
for (auto p : dic) {
vec[p.first] = 1;
}
for (int i = 1; i < n; i++) {
cin >> x;
tmp = __gcd(tmp, x);
map<lint, int> dic = p_factorization(x);
if (!pairwise)
continue;
for (auto p : dic) {
if (vec[p.first] == 1) {
pairwise = false;
}
vec[p.first] = 1;
}
}
if (pairwise)
cout << "pairwise coprime" << endl;
else if (tmp == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
}
| // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "{";
for (int i = 0; i < (int)v.size(); i++)
o << (i > 0 ? ", " : "") << v[i];
o << "}";
return o;
}
map<lint, int> p_factorization(lint n) {
map<lint, int> soinsu;
for (int i = 2; i <= sqrt(n); i++) {
while (n % i == 0) {
n /= i;
soinsu[i]++;
}
}
if (n != 1)
soinsu[n]++;
return soinsu;
}
// AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
bool pairwise = true;
vector<int> vec(1000000);
int n, x, tmp;
cin >> n;
cin >> tmp;
map<lint, int> dic = p_factorization(tmp);
for (auto p : dic) {
vec[p.first] = 1;
}
for (int i = 1; i < n; i++) {
cin >> x;
tmp = __gcd(tmp, x);
map<lint, int> dic = p_factorization(x);
if (!pairwise)
continue;
for (auto p : dic) {
if (vec[p.first] == 1) {
pairwise = false;
}
vec[p.first] = 1;
}
}
if (pairwise)
cout << "pairwise coprime" << endl;
else if (tmp == 1)
cout << "setwise coprime" << endl;
else
cout << "not coprime" << endl;
}
| insert | 32 | 32 | 32 | 34 | TLE | |
p02574 | Python | Runtime Error | from math import gcd
def eratosthenes(n):
prime = []
data = [i for i in range(n - 1)]
while True:
p = data[0]
if n <= p**2:
return prime + data
prime.append(p)
data = [e for e in data if e % p != 0]
return data
def factorize(N): # 素因数分解
prime = set()
for p in prime_list:
if p * p > N:
break
while N % p == 0:
N //= p
prime.add(p)
if N > 1:
prime.add(N)
return prime
n = int(input())
a = list(map(int, input().split()))
ans = 0
for ai in a:
ans = gcd(ans, ai)
if ans != 1:
print("not coprime")
exit()
prime_list = eratosthenes(10**6)
num = set()
for ai in a:
prime = factorize(ai)
if len(prime & num) > 0:
print("setwise coprime")
break
num |= prime
else:
print("pairwise coprime")
| from math import gcd
def eratosthenes(n):
prime = []
data = [i for i in range(2, n + 1)]
while True:
p = data[0]
if n <= p**2:
return prime + data
prime.append(p)
data = [e for e in data if e % p != 0]
return data
def factorize(N): # 素因数分解
prime = set()
for p in prime_list:
if p * p > N:
break
while N % p == 0:
N //= p
prime.add(p)
if N > 1:
prime.add(N)
return prime
n = int(input())
a = list(map(int, input().split()))
ans = 0
for ai in a:
ans = gcd(ans, ai)
if ans != 1:
print("not coprime")
exit()
prime_list = eratosthenes(10**6)
num = set()
for ai in a:
prime = factorize(ai)
if len(prime & num) > 0:
print("setwise coprime")
break
num |= prime
else:
print("pairwise coprime")
| replace | 5 | 6 | 5 | 6 | ZeroDivisionError: integer division or modulo by zero | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02574/Python/s445965325.py", line 39, in <module>
prime_list = eratosthenes(10 ** 6)
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02574/Python/s445965325.py", line 12, in eratosthenes
data = [e for e in data if e % p != 0]
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02574/Python/s445965325.py", line 12, in <listcomp>
data = [e for e in data if e % p != 0]
ZeroDivisionError: integer division or modulo by zero
|
p02574 | Python | Runtime Error | import math
from functools import reduce
n = int(input())
a_list = list(map(int, input().split()))
max = a_list[-1] + 1
memo = [0] * max
for a in a_list:
memo[a] += 1
for i in range(2, max):
if sum(memo[i::i]) > 1:
if reduce(math.gcd, a_list) == 1:
print("setwise coprime")
exit()
else:
print("not coprime")
exit()
print("pairwise coprime")
| import math
from functools import reduce
n = int(input())
a_list = list(map(int, input().split()))
max = 10**6 + 1
memo = [0] * max
for a in a_list:
memo[a] += 1
for i in range(2, max):
if sum(memo[i::i]) > 1:
if reduce(math.gcd, a_list) == 1:
print("setwise coprime")
exit()
else:
print("not coprime")
exit()
print("pairwise coprime")
| replace | 5 | 6 | 5 | 6 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int int64_t
#define ld long double
const int MOD = 1e9 + 7;
const int N = 1e6 + 5;
vector<int> primes;
bool isPrime[N];
int cnt[N];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int arr[n];
int gcd = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
gcd = __gcd(gcd, arr[i]);
}
for (int i = 2; i < N; i++) {
if (!isPrime[i]) {
primes.pb(i);
for (int j = i * i; j < N; j += i)
isPrime[j] = 1;
}
}
bool f = 1;
for (int i = 0; i < n; i++) {
for (int k : primes) {
if (k > arr[i] * arr[i])
break;
if (isPrime[k])
break;
if (arr[i] % k == 0) {
cnt[k]++;
if (cnt[k] > 1) {
if (gcd == 1) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
return 0;
}
while (arr[i] % k == 0)
arr[i] /= k;
}
}
if (arr[i] > 1) {
cnt[arr[i]]++;
if (cnt[arr[i]] > 1) {
if (gcd == 1) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
return 0;
}
}
}
for (int i = 2; i < N; i++) {
if (cnt[i] > 1) {
f = 0;
break;
}
}
if (gcd != 1) {
cout << "not coprime";
return 0;
}
if (f) {
cout << "pairwise coprime";
} else if (gcd == 1) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int int64_t
#define ld long double
const int MOD = 1e9 + 7;
const int N = 1e6 + 5;
vector<int> primes;
bool isPrime[N];
int cnt[N];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int arr[n];
int gcd = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
gcd = __gcd(gcd, arr[i]);
}
for (int i = 2; i < N; i++) {
if (!isPrime[i]) {
primes.pb(i);
for (int j = i * i; j < N; j += i)
isPrime[j] = 1;
}
}
bool f = 1;
for (int i = 0; i < n; i++) {
for (int k : primes) {
if (k * k > arr[i])
break;
if (isPrime[k])
break;
if (arr[i] % k == 0) {
cnt[k]++;
if (cnt[k] > 1) {
if (gcd == 1) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
return 0;
}
while (arr[i] % k == 0)
arr[i] /= k;
}
}
if (arr[i] > 1) {
cnt[arr[i]]++;
if (cnt[arr[i]] > 1) {
if (gcd == 1) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
return 0;
}
}
}
for (int i = 2; i < N; i++) {
if (cnt[i] > 1) {
f = 0;
break;
}
}
if (gcd != 1) {
cout << "not coprime";
return 0;
}
if (f) {
cout << "pairwise coprime";
} else if (gcd == 1) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
return 0;
} | replace | 39 | 40 | 39 | 40 | TLE | |
p02574 | Python | Runtime Error | import math
from functools import reduce
n = int(input())
a_list = list(map(int, input().split()))
max = a_list[n - 1] + 100
memo = [0] * max
for a in a_list:
memo[a] += 1
for i in range(2, max):
if sum(memo[i::i]) > 1:
if reduce(math.gcd, a_list) == 1:
print("setwise coprime")
exit()
else:
print("not coprime")
exit()
print("pairwise coprime")
| import math
from functools import reduce
n = int(input())
a_list = list(map(int, input().split()))
max = 10**6 + 1
memo = [0] * max
for a in a_list:
memo[a] += 1
for i in range(2, max):
if sum(memo[i::i]) > 1:
if reduce(math.gcd, a_list) == 1:
print("setwise coprime")
exit()
else:
print("not coprime")
exit()
print("pairwise coprime")
| replace | 5 | 6 | 5 | 6 | 0 | |
p02574 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int MAX = 1e6;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
struct edge {
int to, cost;
}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問の有無
int gcd(int a, int b) { // aとbの最大公約数(ユークリッドの互除法)
if (b == 0)
return a;
return gcd(b, a % b);
}
bool is_prime[MAX + 1];
int d[MAX + 1];
void erat() { // エラトステネスのふるい
// memset(is_prime, true, sizeof(is_prime));
rep(i, MAX + 1) d[i] = i;
for (int i = 2; i <= MAX; i++) {
// if (is_prime[i]) {
if (d[i] == i) {
for (int j = i + i; j <= MAX; j += i) {
// is_prime[j] = false;
d[j] = i;
}
}
}
}
void prime_fact(int x, set<int> &fact) { // 素因数分解
if (x < 2)
return;
while (/*not is_prime[x] && */ x % d[x] == 0) {
fact.insert(d[x]);
x /= d[x];
}
// if (x != 1) {
// fact.insert(x);
// }
}
int n;
int a[MAX];
set<int> s;
bool flag = true;
int main() {
// input
erat();
cin >> n;
rep(i, n) { cin >> a[i]; }
// solve
rep(i, n) {
if (a[i] == 1)
continue;
if (flag) {
set<int> fact;
prime_fact(a[i], fact);
for (int x : fact) {
if (not s.count(x)) {
s.insert(x);
} else {
flag = false;
break;
}
}
}
if (i > 0)
a[i] = gcd(a[i], a[i - 1]);
}
// output
if (flag)
cout << "pairwise coprime"
<< "\n";
else if (a[n - 1] == 1)
cout << "setwise coprime"
<< "\n";
else
cout << "not coprime"
<< "\n";
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int MAX = 1e6;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
struct edge {
int to, cost;
}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問の有無
int gcd(int a, int b) { // aとbの最大公約数(ユークリッドの互除法)
if (b == 0)
return a;
return gcd(b, a % b);
}
bool is_prime[MAX + 1];
int d[MAX + 1];
void erat() { // エラトステネスのふるい
// memset(is_prime, true, sizeof(is_prime));
rep(i, MAX + 1) d[i] = i;
for (int i = 2; i <= MAX; i++) {
// if (is_prime[i]) {
if (d[i] == i) {
for (int j = i + i; j <= MAX; j += i) {
// is_prime[j] = false;
d[j] = i;
}
}
}
}
void prime_fact(int x, set<int> &fact) { // 素因数分解
if (x < 2)
return;
while (/*not is_prime[x] && */ x > 1 && x % d[x] == 0) {
fact.insert(d[x]);
x /= d[x];
}
// if (x != 1) {
// fact.insert(x);
// }
}
int n;
int a[MAX];
set<int> s;
bool flag = true;
int main() {
// input
erat();
cin >> n;
rep(i, n) { cin >> a[i]; }
// solve
rep(i, n) {
if (a[i] == 1)
continue;
if (flag) {
set<int> fact;
prime_fact(a[i], fact);
for (int x : fact) {
if (not s.count(x)) {
s.insert(x);
} else {
flag = false;
break;
}
}
}
if (i > 0)
a[i] = gcd(a[i], a[i - 1]);
}
// output
if (flag)
cout << "pairwise coprime"
<< "\n";
else if (a[n - 1] == 1)
cout << "setwise coprime"
<< "\n";
else
cout << "not coprime"
<< "\n";
}
| replace | 49 | 50 | 49 | 50 | TLE | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pii pair<int, int>
#define F first
#define S second
#define ll long long
#define io \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 200005;
const int mod = 1e9 + 7;
int main() {
io;
int n, a[N];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int x = a[0];
for (int i = 1; i < n; i++) {
x = __gcd(x, a[i]);
}
if (x != 1) {
cout << "not coprime" << endl;
return 0;
}
map<int, int> mp;
for (int i = 0; i < n; i++) {
for (int j = 2; j * j <= a[i]; j++) {
if (a[i] % j == 0) {
if (mp[j]) {
cout << "setwise coprime";
return 0;
}
mp[j]++;
while (a[i] % j == 0)
a[i] /= j;
}
}
if (a[i] != 1) {
if (mp[a[i]]) {
cout << "setwise coprime";
return 0;
}
mp[a[i]]++;
}
}
cout << "pairwise coprime";
}
| #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pii pair<int, int>
#define F first
#define S second
#define ll long long
#define io \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 1000005;
const int mod = 1e9 + 7;
int main() {
io;
int n, a[N];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int x = a[0];
for (int i = 1; i < n; i++) {
x = __gcd(x, a[i]);
}
if (x != 1) {
cout << "not coprime" << endl;
return 0;
}
map<int, int> mp;
for (int i = 0; i < n; i++) {
for (int j = 2; j * j <= a[i]; j++) {
if (a[i] % j == 0) {
if (mp[j]) {
cout << "setwise coprime";
return 0;
}
mp[j]++;
while (a[i] % j == 0)
a[i] /= j;
}
}
if (a[i] != 1) {
if (mp[a[i]]) {
cout << "setwise coprime";
return 0;
}
mp[a[i]]++;
}
}
cout << "pairwise coprime";
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
bool IsPrime(long long n) {
if (n == 1)
return false;
for (long long i = 2; i * i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}
vector<long long> EnumDivisors(long long n) {
vector<long long> res;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
sort(res.begin(), res.end());
return res;
}
vector<pair<long long, long long>> PrimeFactorize(long long n) {
vector<pair<long long, long long>> res;
long long a = 0;
long long b = 0;
for (long long i = 2; i * i <= n; i++) {
a = 0;
if (n % i == 0) {
if (IsPrime(i)) {
while (n % i == 0) {
n /= i;
a++;
}
res.push_back(make_pair(i, a));
}
}
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
int main() {
int n;
const int max_n = 1e6;
long long a[max_n + 1];
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> list(n, 0);
bool flag1 = 0;
bool flag2 = 0;
for (int i = 0; i < n; i++) {
vector<pair<long long, long long>> res;
res = PrimeFactorize(a[i]);
for (int j = 0; j < res.size(); j++) {
int num = res[j].first;
if (list[num] > 0)
flag1 = 1;
list[num]++;
}
}
for (int i = 0; i < n; i++) {
if (list[i] == n)
flag2 = 1;
}
string ans = "not coprime";
if (flag2 == 0)
ans = "setwise coprime";
if (flag1 == 0)
ans = "pairwise coprime";
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
bool IsPrime(long long n) {
if (n == 1)
return false;
for (long long i = 2; i * i < n; i++) {
if (n % i == 0)
return false;
}
return true;
}
vector<long long> EnumDivisors(long long n) {
vector<long long> res;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
sort(res.begin(), res.end());
return res;
}
vector<pair<long long, long long>> PrimeFactorize(long long n) {
vector<pair<long long, long long>> res;
long long a = 0;
long long b = 0;
for (long long i = 2; i * i <= n; i++) {
a = 0;
if (n % i == 0) {
if (IsPrime(i)) {
while (n % i == 0) {
n /= i;
a++;
}
res.push_back(make_pair(i, a));
}
}
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
int main() {
int n;
const int max_n = 1e6;
long long a[max_n + 1];
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> list(max_n + 1, 0);
bool flag1 = 0;
bool flag2 = 0;
for (int i = 0; i < n; i++) {
vector<pair<long long, long long>> res;
res = PrimeFactorize(a[i]);
for (int j = 0; j < res.size(); j++) {
int num = res[j].first;
if (list[num] > 0)
flag1 = 1;
list[num]++;
}
}
for (int i = 0; i < n; i++) {
if (list[i] == n)
flag2 = 1;
}
string ans = "not coprime";
if (flag2 == 0)
ans = "setwise coprime";
if (flag1 == 0)
ans = "pairwise coprime";
cout << ans << endl;
return 0;
} | replace | 71 | 72 | 71 | 72 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N> string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cout << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cout << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
const unsigned long long Mod = 1000000000 + 7;
typedef unsigned long long ull;
const ull maxA = 100005;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ull n;
cin >> n;
vector<ull> v(n), cnt(maxA, 0);
for (int i = 0; i < n; i++) {
cin >> v[i];
cnt[v[i]] += 1;
}
bool is_pair = true;
for (int i = 2; i < maxA; i++) {
int foo = 0;
for (int j = i; j < maxA; j += i) {
foo += cnt[j];
}
if (foo > 1) {
is_pair = false;
break;
}
if (!is_pair) {
break;
}
}
if (is_pair) {
cout << "pairwise coprime";
return 0;
}
auto gcd = [&](ull a, ull b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
};
ull g = v[0];
for (int i = 1; i < n; i++) {
g = gcd(g, v[i]);
}
if (g == 1) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N> string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cout << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cout << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
const unsigned long long Mod = 1000000000 + 7;
typedef unsigned long long ull;
const ull maxA = 1000006;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ull n;
cin >> n;
vector<ull> v(n), cnt(maxA, 0);
for (int i = 0; i < n; i++) {
cin >> v[i];
cnt[v[i]] += 1;
}
bool is_pair = true;
for (int i = 2; i < maxA; i++) {
int foo = 0;
for (int j = i; j < maxA; j += i) {
foo += cnt[j];
}
if (foo > 1) {
is_pair = false;
break;
}
if (!is_pair) {
break;
}
}
if (is_pair) {
cout << "pairwise coprime";
return 0;
}
auto gcd = [&](ull a, ull b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
};
ull g = v[0];
for (int i = 1; i < n; i++) {
g = gcd(g, v[i]);
}
if (g == 1) {
cout << "setwise coprime";
} else {
cout << "not coprime";
}
return 0;
}
| replace | 81 | 82 | 81 | 82 | 0 | |
p02574 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair<ll, ll>
#define nl "\n"
const int L = 1000006;
ll spf[L + 10];
map<ll, ll> x;
ll soe() {
ll i, j;
for (i = 1; i <= L; i++)
spf[i] = i;
for (i = 2; i * i <= L; i++) {
if (spf[i] == i) {
for (j = i * i; j <= L; j += i) {
if (spf[j] == j)
spf[j] = i;
}
}
}
}
vector<ll> factorise(ll x) {
vector<ll> v;
while (x != 1) {
v.pb(spf[x]);
x = x / spf[x];
}
return v;
}
int main() {
ios_base::sync_with_stdio(false);
ll n, i;
soe();
cin >> n;
ll a[n + 2];
for (i = 0; i < n; i++)
cin >> a[i];
ll gcd = a[0];
for (i = 1; i < n; i++)
gcd = __gcd(gcd, a[i]);
// for(i=1;i<L;i++)
// {
// factorise(i);
// }
for (i = 0; i < n; i++) {
vector<ll> sub = factorise(a[i]);
for (auto y : sub) {
x[y]++;
}
}
ll ff = 0;
for (i = 0; i < n; i++) {
vector<ll> sub = factorise(a[i]);
map<ll, ll> subb;
for (auto it : sub)
subb[it]++;
ll f = 0;
for (auto y : subb) {
ll p = x[y.ff] - y.ss;
if (p != 0) {
f = 1;
break;
}
}
if (f == 1) {
ff = 1;
break;
}
}
if (ff == 0)
cout << "pairwise coprime";
else if (gcd == 1)
cout << "setwise coprime";
else
cout << "not coprime";
cout << nl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair<ll, ll>
#define nl "\n"
const int L = 1000006;
ll spf[L + 10];
map<ll, ll> x;
void soe() {
ll i, j;
for (i = 1; i <= L; i++)
spf[i] = i;
for (i = 2; i * i <= L; i++) {
if (spf[i] == i) {
for (j = i * i; j <= L; j += i) {
if (spf[j] == j)
spf[j] = i;
}
}
}
}
vector<ll> factorise(ll x) {
vector<ll> v;
while (x != 1) {
v.pb(spf[x]);
x = x / spf[x];
}
return v;
}
int main() {
ios_base::sync_with_stdio(false);
ll n, i;
soe();
cin >> n;
ll a[n + 2];
for (i = 0; i < n; i++)
cin >> a[i];
ll gcd = a[0];
for (i = 1; i < n; i++)
gcd = __gcd(gcd, a[i]);
// for(i=1;i<L;i++)
// {
// factorise(i);
// }
for (i = 0; i < n; i++) {
vector<ll> sub = factorise(a[i]);
for (auto y : sub) {
x[y]++;
}
}
ll ff = 0;
for (i = 0; i < n; i++) {
vector<ll> sub = factorise(a[i]);
map<ll, ll> subb;
for (auto it : sub)
subb[it]++;
ll f = 0;
for (auto y : subb) {
ll p = x[y.ff] - y.ss;
if (p != 0) {
f = 1;
break;
}
}
if (f == 1) {
ff = 1;
break;
}
}
if (ff == 0)
cout << "pairwise coprime";
else if (gcd == 1)
cout << "setwise coprime";
else
cout << "not coprime";
cout << nl;
return 0;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p02574 | Python | Runtime Error | from math import gcd
n = int(input())
a = list(map(int, input().split()))
# 解説AC(a*loga)
ans = 0
cnt = [0] * (max(a) + 1)
for ai in a:
ans = gcd(ans, ai)
cnt[ai] += 1
if ans != 1:
print("not coprime")
elif any(sum(cnt[i::i]) > 1 for i in range(max(a) + 1)):
print("setwise coprime")
else:
print("pairwise coprime")
| from math import gcd
n = int(input())
a = list(map(int, input().split()))
# 解説AC(a*loga)
ans = 0
cnt = [0] * (max(a) + 1)
for ai in a:
ans = gcd(ans, ai)
cnt[ai] += 1
if ans != 1:
print("not coprime")
elif any(sum(cnt[i::i]) > 1 for i in range(2, max(a) + 1)):
print("setwise coprime")
else:
print("pairwise coprime")
| replace | 14 | 15 | 14 | 15 | ValueError: slice step cannot be zero | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02574/Python/s213124389.py", line 15, in <module>
elif any(sum(cnt[i::i]) > 1 for i in range(max(a) + 1)):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02574/Python/s213124389.py", line 15, in <genexpr>
elif any(sum(cnt[i::i]) > 1 for i in range(max(a) + 1)):
ValueError: slice step cannot be zero
|
p02575 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ls (p << 1)
#define rs (p << 1 | 1)
#define mid (l + r) / 2
#define rep(i, l, r) for (int i = l; i <= r; ++i)
typedef long long ll;
const int N = 800000 + 5;
struct tree {
int min, tag;
} t[N];
int n, m, a, b, fir;
int read() {
char c;
int x = 0, f = 1;
c = getchar();
while (c > '9' || c < '0') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
void lazy(int p, int k) { t[p].min = t[p].tag = k; }
void down(int p, int l, int r) {
if (!t[p].tag)
return;
lazy(ls, t[p].tag), lazy(rs, t[p].tag + mid - l + 1);
t[p].tag = 0;
}
void update(int p, int l, int r, int x, int y, int k) {
down(p, l, r);
if (l >= x && r <= y) {
lazy(p, k);
return;
}
if (mid >= x)
update(ls, l, mid, x, y, k);
if (mid < y)
update(rs, mid + 1, r, x, y, k + max(0, mid - max(l, x) + 1));
t[p].min = min(t[ls].min, t[rs].min);
}
int query(int p, int l, int r, int x, int y) {
if (l >= x && r <= y)
return t[p].min;
down(p, l, r);
if (mid >= x)
return query(ls, l, mid, x, y);
else
return query(rs, mid + 1, r, x, y);
}
int main() {
n = read(), m = read();
rep(i, 1, n) {
a = read(), b = read();
fir = (a == 1 ? m + 1 : query(1, 1, m, a - 1, a - 1) + 1);
update(1, 1, m, a, b, fir);
printf("%d\n", t[1].min >= m + 1 ? -1 : t[1].min + i);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ls (p << 1)
#define rs (p << 1 | 1)
#define mid (l + r) / 2
#define rep(i, l, r) for (int i = l; i <= r; ++i)
typedef long long ll;
const int N = 80000000 + 5;
struct tree {
int min, tag;
} t[N];
int n, m, a, b, fir;
int read() {
char c;
int x = 0, f = 1;
c = getchar();
while (c > '9' || c < '0') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
void lazy(int p, int k) { t[p].min = t[p].tag = k; }
void down(int p, int l, int r) {
if (!t[p].tag)
return;
lazy(ls, t[p].tag), lazy(rs, t[p].tag + mid - l + 1);
t[p].tag = 0;
}
void update(int p, int l, int r, int x, int y, int k) {
down(p, l, r);
if (l >= x && r <= y) {
lazy(p, k);
return;
}
if (mid >= x)
update(ls, l, mid, x, y, k);
if (mid < y)
update(rs, mid + 1, r, x, y, k + max(0, mid - max(l, x) + 1));
t[p].min = min(t[ls].min, t[rs].min);
}
int query(int p, int l, int r, int x, int y) {
if (l >= x && r <= y)
return t[p].min;
down(p, l, r);
if (mid >= x)
return query(ls, l, mid, x, y);
else
return query(rs, mid + 1, r, x, y);
}
int main() {
n = read(), m = read();
rep(i, 1, n) {
a = read(), b = read();
fir = (a == 1 ? m + 1 : query(1, 1, m, a - 1, a - 1) + 1);
update(1, 1, m, a, b, fir);
printf("%d\n", t[1].min >= m + 1 ? -1 : t[1].min + i);
}
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02575 | C++ | Time Limit Exceeded | #include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return 0;
}
using P = pair<int, int>;
const int INF = 1 << 30;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int H, W;
cin >> H >> W;
vector<int> A(H), B(H);
rep(i, 0, H) {
cin >> A[i] >> B[i];
--A[i];
}
set<P> path;
multiset<int> dist;
rep(i, 0, W) {
path.emplace(i, i);
dist.insert(0);
}
rep(i, 0, H) {
vector<P> buf;
for (auto itr = path.lower_bound(P(A[i], 0)); (*itr).first < B[i]; ++itr) {
buf.push_back(*itr);
}
int max_start = -INF;
P max_path;
for (auto &p : buf) {
path.erase(p);
dist.erase(dist.find(p.first - p.second));
if (chmax(max_start, p.second)) {
max_path = p;
}
}
if (max_start > -INF) {
path.emplace(B[i], max_path.second);
dist.insert(B[i] == W ? INF : B[i] - max_path.second);
}
cout << (*dist.begin() == INF ? -1 : *dist.begin() + i + 1) << endl;
}
return 0;
} | #include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return 0;
}
using P = pair<int, int>;
const int INF = 1 << 30;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int H, W;
cin >> H >> W;
vector<int> A(H), B(H);
rep(i, 0, H) {
cin >> A[i] >> B[i];
--A[i];
}
set<P> path;
multiset<int> dist;
rep(i, 0, W) {
path.emplace(i, i);
dist.insert(0);
}
rep(i, 0, H) {
vector<P> buf;
for (auto itr = path.lower_bound(P(A[i], 0));
itr != path.end() && (*itr).first < B[i]; ++itr) {
buf.push_back(*itr);
}
int max_start = -INF;
P max_path;
for (auto &p : buf) {
path.erase(p);
dist.erase(dist.find(p.first - p.second));
if (chmax(max_start, p.second)) {
max_path = p;
}
}
if (max_start > -INF) {
path.emplace(B[i], max_path.second);
dist.insert(B[i] == W ? INF : B[i] - max_path.second);
}
cout << (*dist.begin() == INF ? -1 : *dist.begin() + i + 1) << endl;
}
return 0;
} | replace | 46 | 47 | 46 | 48 | TLE | |
p02575 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define N 200020
const int inf = 0x3f3f3f3f;
struct tree {
int l, r, min, tag;
} t[N << 2];
int a[N], b[N];
int n, m;
int ls(int cur) { return cur << 1; }
int rs(int cur) { return cur << 1 | 1; }
void lazy(int cur, int k) {
t[cur].tag = k;
t[cur].min = k;
}
void pushdown(int cur) {
if (!t[cur].tag)
return;
int mid = (t[cur].l + t[cur].r) >> 1;
lazy(ls(cur), t[cur].tag);
lazy(rs(cur), t[cur].tag + mid - t[cur].l + 1);
t[cur].tag = 0;
return;
}
void build(int cur, int l, int r) {
t[cur].l = l;
t[cur].r = r;
t[cur].min = t[cur].tag = 0;
if (l == r)
return;
int mid = (l + r) >> 1;
build(ls(cur), l, mid);
build(rs(cur), mid + 1, r);
return;
}
void update(int cur, int ul, int ur, int k) {
// cout<<cur<<' '<<t[cur].l<<' '<<t[cur].r<<endl;
pushdown(cur);
if (t[cur].l >= ul && t[cur].r <= ur) {
lazy(cur, k);
return;
}
int mid = (t[cur].l + t[cur].r) >> 1;
if (mid >= ul)
update(ls(cur), ul, ur, k);
if (mid < ur)
update(rs(cur), ul, ur, k + max(0, (mid - max(t[cur].l, ul) + 1)));
t[cur].min = min(t[ls(cur)].min, t[rs(cur)].min);
return;
}
int query(int cur, int ql, int qr) {
if (t[cur].l >= ql && t[cur].r <= qr)
return t[cur].min;
pushdown(cur);
int mid = (t[cur].l + t[cur].r) >> 1;
int res = inf;
if (mid >= ql)
res = min(res, query(ls(cur), ql, qr));
if (mid < qr)
res = min(res, query(rs(cur), ql, qr));
return res;
}
void init() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i], &b[i]);
return;
}
void solve() {
build(1, 1, m);
for (int i = 1; i <= n; i++) {
// cout<<a[i]<<' '<<b[i]<<endl;
int k = (a[i] == 1) ? (m + 1) : query(1, a[i] - 1, a[i] - 1) + 1;
// cout<<k<<endl;
update(1, a[i], b[i], k);
if (t[1].min >= m + 1)
printf("-1\n");
else
printf("%d\n", t[1].min + i);
}
return;
}
int main() {
init();
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define N 200020
const int inf = 0x3f3f3f3f;
struct tree {
int l, r, min, tag;
} t[N << 3];
int a[N], b[N];
int n, m;
int ls(int cur) { return cur << 1; }
int rs(int cur) { return cur << 1 | 1; }
void lazy(int cur, int k) {
t[cur].tag = k;
t[cur].min = k;
}
void pushdown(int cur) {
if (!t[cur].tag)
return;
int mid = (t[cur].l + t[cur].r) >> 1;
lazy(ls(cur), t[cur].tag);
lazy(rs(cur), t[cur].tag + mid - t[cur].l + 1);
t[cur].tag = 0;
return;
}
void build(int cur, int l, int r) {
t[cur].l = l;
t[cur].r = r;
t[cur].min = t[cur].tag = 0;
if (l == r)
return;
int mid = (l + r) >> 1;
build(ls(cur), l, mid);
build(rs(cur), mid + 1, r);
return;
}
void update(int cur, int ul, int ur, int k) {
// cout<<cur<<' '<<t[cur].l<<' '<<t[cur].r<<endl;
pushdown(cur);
if (t[cur].l >= ul && t[cur].r <= ur) {
lazy(cur, k);
return;
}
int mid = (t[cur].l + t[cur].r) >> 1;
if (mid >= ul)
update(ls(cur), ul, ur, k);
if (mid < ur)
update(rs(cur), ul, ur, k + max(0, (mid - max(t[cur].l, ul) + 1)));
t[cur].min = min(t[ls(cur)].min, t[rs(cur)].min);
return;
}
int query(int cur, int ql, int qr) {
if (t[cur].l >= ql && t[cur].r <= qr)
return t[cur].min;
pushdown(cur);
int mid = (t[cur].l + t[cur].r) >> 1;
int res = inf;
if (mid >= ql)
res = min(res, query(ls(cur), ql, qr));
if (mid < qr)
res = min(res, query(rs(cur), ql, qr));
return res;
}
void init() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d%d", &a[i], &b[i]);
return;
}
void solve() {
build(1, 1, m);
for (int i = 1; i <= n; i++) {
// cout<<a[i]<<' '<<b[i]<<endl;
int k = (a[i] == 1) ? (m + 1) : query(1, a[i] - 1, a[i] - 1) + 1;
// cout<<k<<endl;
update(1, a[i], b[i], k);
if (t[1].min >= m + 1)
printf("-1\n");
else
printf("%d\n", t[1].min + i);
}
return;
}
int main() {
init();
solve();
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02575 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <vector>
#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
using namespace std;
double start_moment = 0;
double get_runtime() { return 1.0 * clock() / CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime() { cout << fixed << setprecision(5) << get_runtime() << '\n'; }
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> void read(vector<T> &a, ll n) {
T x;
a.clear();
for (ll i = 0; i < n; i++) {
cin >> x;
a.pb(x);
}
}
template <class T> void write(vector<T> &a) {
for (T x : a)
cout << x << ' ';
cout << '\n';
}
const int N = 200005;
int w, h;
int val[N];
set<int>::iterator it;
set<int> pos;
set<pii> st;
vector<int> to_er;
int main() {
// ios_base::sync_with_stdio(0);
// freopen("INPUT.txt","r",stdin);
// freopen("OUTPUT.txt", "w", stdout);
scanf("%d %d", &h, &w);
for (int i = 1; i <= w; i++) {
val[i] = 1;
pos.insert(i);
st.insert(mp(val[i], i));
}
for (int j = 0; j < h; j++) {
int a, b;
scanf("%d %d", &a, &b);
int mn = 1000000000;
it = lower_bound(all(pos), a);
to_er.clear();
while (it != pos.end() && *it <= b) {
to_er.pb(*it);
it++;
}
for (int i = 0; i < to_er.size(); i++) {
int vv = val[to_er[i]];
val[to_er[i]] = -1;
if (b != w)
mn = min(vv + (b + 1) - to_er[i], mn);
st.erase(mp(vv, to_er[i]));
pos.erase(to_er[i]);
}
if (mn != 1000000000) {
if (val[b + 1] == -1) {
val[b + 1] = mn;
st.insert(mp(val[b + 1], b + 1));
pos.insert(b + 1);
} else if (val[b + 1] > mn) {
st.erase(mp(val[b + 1], b + 1));
val[b + 1] = mn;
st.insert(mp(val[b + 1], b + 1));
pos.insert(b + 1);
}
}
if (st.size()) {
int res = (*st.begin()).f;
printf("%d\n", res + j);
} else
printf("-1\n");
}
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <vector>
#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
using namespace std;
double start_moment = 0;
double get_runtime() { return 1.0 * clock() / CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime() { cout << fixed << setprecision(5) << get_runtime() << '\n'; }
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> void read(vector<T> &a, ll n) {
T x;
a.clear();
for (ll i = 0; i < n; i++) {
cin >> x;
a.pb(x);
}
}
template <class T> void write(vector<T> &a) {
for (T x : a)
cout << x << ' ';
cout << '\n';
}
const int N = 200005;
int w, h;
int val[N];
set<int>::iterator it;
set<int> pos;
set<pii> st;
vector<int> to_er;
int main() {
// ios_base::sync_with_stdio(0);
// freopen("INPUT.txt","r",stdin);
// freopen("OUTPUT.txt", "w", stdout);
scanf("%d %d", &h, &w);
for (int i = 1; i <= w; i++) {
val[i] = 1;
pos.insert(i);
st.insert(mp(val[i], i));
}
for (int j = 0; j < h; j++) {
int a, b;
scanf("%d %d", &a, &b);
int mn = 1000000000;
it = pos.lower_bound(a);
to_er.clear();
while (it != pos.end() && *it <= b) {
to_er.pb(*it);
it++;
}
for (int i = 0; i < to_er.size(); i++) {
int vv = val[to_er[i]];
val[to_er[i]] = -1;
if (b != w)
mn = min(vv + (b + 1) - to_er[i], mn);
st.erase(mp(vv, to_er[i]));
pos.erase(to_er[i]);
}
if (mn != 1000000000) {
if (val[b + 1] == -1) {
val[b + 1] = mn;
st.insert(mp(val[b + 1], b + 1));
pos.insert(b + 1);
} else if (val[b + 1] > mn) {
st.erase(mp(val[b + 1], b + 1));
val[b + 1] = mn;
st.insert(mp(val[b + 1], b + 1));
pos.insert(b + 1);
}
}
if (st.size()) {
int res = (*st.begin()).f;
printf("%d\n", res + j);
} else
printf("-1\n");
}
}
| replace | 83 | 84 | 83 | 84 | TLE | |
p02575 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, m, dis[101010];
set<int> st;
multiset<int> sstt;
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
st.insert(i);
sstt.insert(0);
}
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
a--;
set<int>::iterator it = st.lower_bound(a), it1;
int mn = 1e9 + 1e5;
while (it != st.end() && *it <= b) {
int x = *it;
mn = min(mn, dis[x] + b - x);
it1 = it;
it1++;
st.erase(it);
it = it1;
sstt.erase(sstt.find(dis[x]));
dis[x] = 1e9 + 1e5;
}
if (b != m && mn != 1e9 + 1e5) {
dis[b] = mn;
st.insert(b);
sstt.insert(mn);
}
if (st.empty()) {
cout << "-1\n";
} else {
cout << *sstt.begin() + i + 1 << endl;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, m, dis[202020];
set<int> st;
multiset<int> sstt;
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
st.insert(i);
sstt.insert(0);
}
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
a--;
set<int>::iterator it = st.lower_bound(a), it1;
int mn = 1e9 + 1e5;
while (it != st.end() && *it <= b) {
int x = *it;
mn = min(mn, dis[x] + b - x);
it1 = it;
it1++;
st.erase(it);
it = it1;
sstt.erase(sstt.find(dis[x]));
dis[x] = 1e9 + 1e5;
}
if (b != m && mn != 1e9 + 1e5) {
dis[b] = mn;
st.insert(b);
sstt.insert(mn);
}
if (st.empty()) {
cout << "-1\n";
} else {
cout << *sstt.begin() + i + 1 << endl;
}
}
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02575 | C++ | Runtime Error | // 22:30 -
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)
typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;
const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;
struct SegTree {
static const int M = N * 4;
int mn[M], mx[M], d[M], lazy[M];
void Tag(int o, int L, int R, int val) {
mn[o] = mx[o] = val;
d[o] = val - R;
lazy[o] = val;
}
void Pushdown(int o, int L, int R) {
if (lazy[o] == 0)
return;
int M = (L + R) / 2;
Tag(lch, L, M, lazy[o]);
Tag(rch, M + 1, R, lazy[o]);
lazy[o] = 0;
}
void Maintain(int o) {
mx[o] = max(mx[lch], mx[rch]);
mn[o] = min(mn[lch], mn[rch]);
d[o] = min(d[lch], d[rch]);
}
void Build(int o, int L, int R) {
if (L == R) {
mx[o] = mn[o] = L;
return;
}
int M = (L + R) / 2;
Build(lch, L, M);
Build(rch, M + 1, R);
Maintain(o);
}
void Modify(int o, int L, int R, int qL, int qR, int val) {
if (qL <= mn[o] && mx[o] <= qR) {
Tag(o, L, R, val);
return;
}
Pushdown(o, L, R);
int M = (L + R) / 2;
if (qL <= mx[lch])
Modify(lch, L, M, qL, qR, val);
if (mn[rch] <= qR)
Modify(rch, M + 1, R, qL, qR, val);
Maintain(o);
}
int Query() { return d[1]; }
};
SegTree seg;
int a[N], b[N];
int main() {
ios::sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i] >> b[i];
seg.Build(1, 1, m);
for (int i = 1; i <= n; i++) {
int r = b[i] == m ? INF : b[i] + 1;
seg.Modify(1, 1, m, a[i], b[i], r);
int ans = seg.Query();
if (ans >= m)
cout << -1 << endl;
else
cout << ans + i << endl;
}
return 0;
}
| // 22:30 -
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)
typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;
const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;
struct SegTree {
static const int M = N * 4;
int mn[M], mx[M], d[M], lazy[M];
void Tag(int o, int L, int R, int val) {
mn[o] = mx[o] = val;
d[o] = val - R;
lazy[o] = val;
}
void Pushdown(int o, int L, int R) {
if (lazy[o] == 0)
return;
int M = (L + R) / 2;
Tag(lch, L, M, lazy[o]);
Tag(rch, M + 1, R, lazy[o]);
lazy[o] = 0;
}
void Maintain(int o) {
mx[o] = max(mx[lch], mx[rch]);
mn[o] = min(mn[lch], mn[rch]);
d[o] = min(d[lch], d[rch]);
}
void Build(int o, int L, int R) {
if (L == R) {
mx[o] = mn[o] = L;
return;
}
int M = (L + R) / 2;
Build(lch, L, M);
Build(rch, M + 1, R);
Maintain(o);
}
void Modify(int o, int L, int R, int qL, int qR, int val) {
if (qL <= mn[o] && mx[o] <= qR) {
Tag(o, L, R, val);
return;
}
if (mx[o] < qL || qR < mn[o])
return;
Pushdown(o, L, R);
int M = (L + R) / 2;
if (qL <= mx[lch])
Modify(lch, L, M, qL, qR, val);
if (mn[rch] <= qR)
Modify(rch, M + 1, R, qL, qR, val);
Maintain(o);
}
int Query() { return d[1]; }
};
SegTree seg;
int a[N], b[N];
int main() {
ios::sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> a[i] >> b[i];
seg.Build(1, 1, m);
for (int i = 1; i <= n; i++) {
int r = b[i] == m ? INF : b[i] + 1;
seg.Modify(1, 1, m, a[i], b[i], r);
int ans = seg.Query();
if (ans >= m)
cout << -1 << endl;
else
cout << ans + i << endl;
}
return 0;
}
| insert | 57 | 57 | 57 | 59 | 0 | |
p02575 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template <typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int x) { return (x > 0) - (x < 0); }
int gcd(int a, int b) {
while (b) {
swap(a %= b, b);
}
return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int cdiv(int a, int b) { return (a - 1 + b) / b; }
template <typename T> void fin(T mes) {
cout << mes << endl;
exit(0);
}
template <typename T, typename U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, typename U> bool chmin(T &a, const U &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
os << "(" << rhs.first << ", " << rhs.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
os << "{";
for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
os << *itr << (next(itr) != rhs.end() ? ", " : "");
}
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
os << "{";
for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
os << *itr << (next(itr) != rhs.end() ? ", " : "");
}
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
os << "{";
for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
os << *itr << (next(itr) != rhs.end() ? ", " : "");
}
os << "}";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &rhs) {
os << "{";
for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
os << *itr << (next(itr) != rhs.end() ? ", " : "");
}
os << "}";
return os;
}
struct setup {
static constexpr int PREC = 20;
setup() {
cout << fixed << setprecision(PREC);
cerr << fixed << setprecision(PREC);
};
} setup;
template <typename M> struct lazy_segment_tree {
using T = typename M::T;
using E = typename M::E;
int n;
std::vector<T> data;
std::vector<E> lazy;
lazy_segment_tree(int n)
: n(n), data(n << 1, M::id_T()), lazy(n << 1, M::id_E()) {}
lazy_segment_tree(const std::vector<T> &src)
: n(src.size()), data(n << 1), lazy(n << 1, M::id_E()) {
std::copy(src.begin(), src.end(), data.begin() + n);
for (int i = n - 1; i > 0; i--) {
data[i] = M::op_TT(data[i << 1 | 0], data[i << 1 | 1]);
}
}
void propagate(int i) {
if (i < 1) {
return;
}
data[i] = M::op_TE(data[i], lazy[i]);
if (i < n) {
lazy[i << 1 | 0] = M::op_EE(lazy[i << 1 | 0], lazy[i]);
lazy[i << 1 | 1] = M::op_EE(lazy[i << 1 | 1], lazy[i]);
}
lazy[i] = M::id_E();
}
void add(int l, int r, const E &x) {
l += n, r += n - 1;
for (int i = std::__lg(r); i > 0; i--) {
propagate(l >> i);
propagate(r >> i);
}
auto apply = [&](int i) { lazy[i] = M::op_EE(lazy[i], x), propagate(i); };
for (int i = l, j = r + 1; i < j; i >>= 1, j >>= 1) {
if (i & 1) {
apply(i++);
}
if (j & 1) {
apply(--j);
}
}
while (l >>= 1, r >>= 1) {
data[l] = M::op_TT(M::op_TE(data[l << 1 | 0], lazy[l << 1 | 0]),
M::op_TE(data[l << 1 | 1], lazy[l << 1 | 1]));
data[r] = M::op_TT(M::op_TE(data[r << 1 | 0], lazy[r << 1 | 0]),
M::op_TE(data[r << 1 | 1], lazy[r << 1 | 1]));
}
}
T get_sum(int l, int r) {
l += n, r += n - 1;
for (int i = std::__lg(r); i > 0; i--) {
propagate(l >> i), propagate(r >> i);
}
T a = M::id_T(), b = M::id_T();
for (r++; l < r; l >>= 1, r >>= 1) {
if (l & 1) {
propagate(l), a = M::op_TT(a, data[l++]);
}
if (r & 1) {
propagate(--r), b = M::op_TT(data[r], b);
}
}
return M::op_TT(a, b);
}
};
struct rminq_and_ruq {
using T = pint;
using E = int;
static T id_T() { return {LLONG_MAX, 0}; };
static E id_E() { return -1; };
static T op_TT(const T &a, const T &b) {
if (a.first - a.second < b.first - b.second) {
return a;
} else {
return b;
}
}
static E op_EE(const E &a, const E &b) { return b == id_E() ? a : b; }
static T op_TE(const T &a, const E &b) {
return b == id_E() ? a : pint(b, a.second);
}
};
template <typename F>
long long discrete_binary_search(long long ok, long long ng, F is_ok) {
while (abs(ok - ng) > 1) {
long long mid = (ok + ng) / 2;
(is_ok(mid) ? ok : ng) = mid;
}
return ok;
}
signed main() {
int H, W;
cin >> H >> W;
vpint src(W);
rep(i, W) { src[i] = {i, i}; }
lazy_segment_tree<rminq_and_ruq> lst(src);
vint A(H), B(H);
rep(i, H) {
cin >> A[i] >> B[i], A[i]--, B[i]--;
int l = discrete_binary_search(
W, -1, [&](int x) { return A[i] <= lst.get_sum(x, x + 1).first; });
int r = discrete_binary_search(
W, -1, [&](int x) { return B[i] + 1 <= lst.get_sum(x, x + 1).first; });
if (B[i] == W - 1) {
lst.add(l, r, LLONG_MAX);
} else {
lst.add(l, r, B[i] + 1);
}
pint res = lst.get_sum(0, W);
if (res.first == LLONG_MAX) {
cout << -1 << endl;
} else {
cout << res.first - res.second + i + 1 << endl;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template <typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int x) { return (x > 0) - (x < 0); }
int gcd(int a, int b) {
while (b) {
swap(a %= b, b);
}
return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int cdiv(int a, int b) { return (a - 1 + b) / b; }
template <typename T> void fin(T mes) {
cout << mes << endl;
exit(0);
}
template <typename T, typename U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, typename U> bool chmin(T &a, const U &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
os << "(" << rhs.first << ", " << rhs.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
os << "{";
for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
os << *itr << (next(itr) != rhs.end() ? ", " : "");
}
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
os << "{";
for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
os << *itr << (next(itr) != rhs.end() ? ", " : "");
}
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
os << "{";
for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
os << *itr << (next(itr) != rhs.end() ? ", " : "");
}
os << "}";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &rhs) {
os << "{";
for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
os << *itr << (next(itr) != rhs.end() ? ", " : "");
}
os << "}";
return os;
}
struct setup {
static constexpr int PREC = 20;
setup() {
cout << fixed << setprecision(PREC);
cerr << fixed << setprecision(PREC);
};
} setup;
template <typename M> struct lazy_segment_tree {
using T = typename M::T;
using E = typename M::E;
int n;
std::vector<T> data;
std::vector<E> lazy;
lazy_segment_tree(int n)
: n(n), data(n << 1, M::id_T()), lazy(n << 1, M::id_E()) {}
lazy_segment_tree(const std::vector<T> &src)
: n(src.size()), data(n << 1), lazy(n << 1, M::id_E()) {
std::copy(src.begin(), src.end(), data.begin() + n);
for (int i = n - 1; i > 0; i--) {
data[i] = M::op_TT(data[i << 1 | 0], data[i << 1 | 1]);
}
}
void propagate(int i) {
if (i < 1) {
return;
}
data[i] = M::op_TE(data[i], lazy[i]);
if (i < n) {
lazy[i << 1 | 0] = M::op_EE(lazy[i << 1 | 0], lazy[i]);
lazy[i << 1 | 1] = M::op_EE(lazy[i << 1 | 1], lazy[i]);
}
lazy[i] = M::id_E();
}
void add(int l, int r, const E &x) {
l += n, r += n - 1;
for (int i = std::__lg(r); i > 0; i--) {
propagate(l >> i);
propagate(r >> i);
}
auto apply = [&](int i) { lazy[i] = M::op_EE(lazy[i], x), propagate(i); };
for (int i = l, j = r + 1; i < j; i >>= 1, j >>= 1) {
if (i & 1) {
apply(i++);
}
if (j & 1) {
apply(--j);
}
}
while (l >>= 1, r >>= 1) {
data[l] = M::op_TT(M::op_TE(data[l << 1 | 0], lazy[l << 1 | 0]),
M::op_TE(data[l << 1 | 1], lazy[l << 1 | 1]));
data[r] = M::op_TT(M::op_TE(data[r << 1 | 0], lazy[r << 1 | 0]),
M::op_TE(data[r << 1 | 1], lazy[r << 1 | 1]));
}
}
T get_sum(int l, int r) {
l += n, r += n - 1;
for (int i = std::__lg(r); i > 0; i--) {
propagate(l >> i), propagate(r >> i);
}
T a = M::id_T(), b = M::id_T();
for (r++; l < r; l >>= 1, r >>= 1) {
if (l & 1) {
propagate(l), a = M::op_TT(a, data[l++]);
}
if (r & 1) {
propagate(--r), b = M::op_TT(data[r], b);
}
}
return M::op_TT(a, b);
}
};
struct rminq_and_ruq {
using T = pint;
using E = int;
static T id_T() { return {LLONG_MAX, 0}; };
static E id_E() { return -1; };
static T op_TT(const T &a, const T &b) {
if (a.first - a.second < b.first - b.second) {
return a;
} else {
return b;
}
}
static E op_EE(const E &a, const E &b) { return b == id_E() ? a : b; }
static T op_TE(const T &a, const E &b) {
return b == id_E() ? a : pint(b, a.second);
}
};
template <typename F>
long long discrete_binary_search(long long ok, long long ng, F is_ok) {
while (abs(ok - ng) > 1) {
long long mid = (ok + ng) / 2;
(is_ok(mid) ? ok : ng) = mid;
}
return ok;
}
signed main() {
int H, W;
cin >> H >> W;
vpint src(W);
rep(i, W) { src[i] = {i, i}; }
lazy_segment_tree<rminq_and_ruq> lst(src);
vint A(H), B(H);
rep(i, H) {
cin >> A[i] >> B[i], A[i]--, B[i]--;
int l = discrete_binary_search(
W - 1, -1, [&](int x) { return A[i] <= lst.get_sum(x, x + 1).first; });
int r = discrete_binary_search(
W, -1, [&](int x) { return B[i] + 1 <= lst.get_sum(x, x + 1).first; });
if (B[i] == W - 1) {
lst.add(l, r, LLONG_MAX);
} else {
lst.add(l, r, B[i] + 1);
}
pint res = lst.get_sum(0, W);
if (res.first == LLONG_MAX) {
cout << -1 << endl;
} else {
cout << res.first - res.second + i + 1 << endl;
}
}
}
| replace | 195 | 196 | 195 | 196 | TLE | |
p02575 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
// #define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
for (int i = 0; i < A.size(); i++)
os << A[i] << " ";
os << endl;
return os;
}
template <> ostream &operator<<(ostream &os, const vector<vector<int>> &A) {
int N = A.size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < A[i].size(); j++)
os << A[i][j] << " ";
os << endl;
}
return os;
}
typedef pair<int, int> pii;
typedef long long ll;
struct edge {
int from, to, d, c;
edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
from = _from;
to = _to;
d = _d;
c = _c;
}
bool operator<(const edge &rhs) const {
return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
}
};
struct aabb {
int x1, y1, x2, y2;
aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};
typedef vector<edge> edges;
typedef vector<edges> graph;
struct flow {
int to, cap, rev, cost;
flow(int to = 0, int cap = 0, int rev = 0, int cost = 0)
: to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector<vector<flow>> flows;
const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);
int pow2(int n) { return 1LL << n; }
template <typename T, typename U> bool chmin(T &x, const U &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T, typename U> bool chmax(T &x, const U &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
fill((T *)array, (T *)(array + N), val);
}
struct initializer {
initializer() { cout << fixed << setprecision(20); }
};
initializer _____;
template <class Monoid, class Action> struct LSegT {
int N;
vector<Monoid> node;
vector<Action> lazy;
Monoid UNITY_MONOID; // to be set------------------------
Action UNITY_ACTION; // to be set------------------------
Monoid merge(const Monoid &l, const Monoid &r) {
// to be set---------------------------------
// return l+r;
return;
}
LSegT(vector<Monoid> &A) {
int sz = A.size();
N = 1;
while (N < sz)
N <<= 1;
node.resize(2 * N - 1);
lazy.resize(2 * N - 1, 0);
rep(i, sz) node[i + N - 1] = A[i];
for (int i = N - 2; i >= 0; i--)
node[i] = merge(node[i * 2 + 1], node[i * 2 + 2]);
}
void reflect(int k, int l, int r) {
// to be set----------------------------------------
// node[k]+=lazy[k];
}
void add(Action &d, const Action &e) {
// to be set---------------------------------------
// d+=e;
}
void eval(int k, int l, int r) {
if (lazy[k] != UNITY_ACTION) {
reflect(k, l, r);
if (r - l > 1) {
add(lazy[2 * k + 1], lazy[k]);
add(lazy[2 * k + 2], lazy[k]);
// if p,use this
// add(lazy[2 * k + 1], lazy[k] / 2);
// add(lazy[2 * k + 2], lazy[k] / 2);
}
lazy[k] = UNITY_ACTION;
}
}
void set(int a, int b, Action x, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = N;
if (b <= l || r <= a)
eval(k, l, r);
else if (a <= l && r <= b) {
add(lazy[k], x);
// if p,use this
// add(lazy[k] , (r - l) * x);
eval(k, l, r);
} else {
eval(k, l, r);
set(a, b, x, 2 * k + 1, l, (l + r) / 2);
set(a, b, x, 2 * k + 2, (l + r) / 2, r);
node[k] = merge(node[2 * k + 1], node[2 * k + 2]);
}
}
Monoid get(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = N;
if (b <= l || r <= a)
return UNITY_MONOID;
eval(k, l, r);
if (a <= l && r <= b)
return node[k];
Monoid vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
Monoid vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
return node[k] = merge(vl, vr);
}
};
template <class Monoid> struct SegT {
// to be set--------------------------------------------------
const static Monoid UNITY = LINF; // UNITY=0
Monoid merge(const Monoid &a, const Monoid &b) {
return min(a, b); // a+b;
}
// kokomade----------------------------------------------------
vector<Monoid> container;
int n;
void update(int i, Monoid x) {
int ii = i + n - 1;
container[ii] = x;
while (ii > 0) {
ii = (ii - 1) / 2;
container[ii] = merge(container[2 * ii + 1], container[2 * ii + 2]);
}
}
Monoid get(int l, int r, int l2 = 0, int r2 = -1, int k = 0) {
if (r2 == -1)
r2 = n;
if (r2 <= l || r <= l2)
return UNITY;
if (l <= l2 && r2 <= r)
return container[k];
ll vl = get(l, r, l2, (l2 + r2) / 2, 2 * k + 1);
ll vr = get(l, r, (l2 + r2) / 2, r2, 2 * k + 2);
return merge(vl, vr);
}
void init(vector<Monoid> &A) {
n = 1;
while (n < A.size())
n <<= 1;
container = vector<Monoid>(2 * n - 1, 0);
for (int i = 0; i < A.size(); i++)
update(i, A[i]);
}
SegT(vector<Monoid> &A) { init(A); }
SegT(int _n) {
vector<Monoid> A(_n, UNITY);
init(A);
}
};
int N, M, K, T, Q, H, W;
signed main() {
cin >> H >> W;
vector<int> A(H), B(W);
rep(i, H) {
cin >> A[i] >> B[i];
--A[i];
--B[i];
}
vector<int> tmp(W, 0);
SegT<int> sgt(tmp);
map<int, int> m;
rep(i, W) m[i] = i;
vector<int> ans(H, LINF);
rep(i, H) {
auto it = m.lower_bound(A[i]);
int r = -1;
while (it != m.end() && it->first <= B[i]) {
sgt.update(it->second, LINF);
chmax(r, it->second);
// cerr << it->second << " " << it->first << endl;
it = m.erase(it);
}
// cerr << r << endl;
if (r != -1 && B[i] < W - 1) {
chmax(m[B[i] + 1], r);
sgt.update(m[B[i] + 1], B[i] - m[B[i] + 1] + 1);
}
// cerr << sgt.get(0, W) << endl;
// rep(j, W) cerr << sgt.get(j, j + 1) << " ";
// cout << endl;
ans[i] = sgt.get(0, W) + i + 1;
}
rep(i, H) {
if (ans[i] >= LINF)
ans[i] = -1;
cout << ans[i] << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
// #define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
for (int i = 0; i < A.size(); i++)
os << A[i] << " ";
os << endl;
return os;
}
template <> ostream &operator<<(ostream &os, const vector<vector<int>> &A) {
int N = A.size();
for (int i = 0; i < N; i++) {
for (int j = 0; j < A[i].size(); j++)
os << A[i][j] << " ";
os << endl;
}
return os;
}
typedef pair<int, int> pii;
typedef long long ll;
struct edge {
int from, to, d, c;
edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
from = _from;
to = _to;
d = _d;
c = _c;
}
bool operator<(const edge &rhs) const {
return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
}
};
struct aabb {
int x1, y1, x2, y2;
aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};
typedef vector<edge> edges;
typedef vector<edges> graph;
struct flow {
int to, cap, rev, cost;
flow(int to = 0, int cap = 0, int rev = 0, int cost = 0)
: to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector<vector<flow>> flows;
const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);
int pow2(int n) { return 1LL << n; }
template <typename T, typename U> bool chmin(T &x, const U &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T, typename U> bool chmax(T &x, const U &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
fill((T *)array, (T *)(array + N), val);
}
struct initializer {
initializer() { cout << fixed << setprecision(20); }
};
initializer _____;
template <class Monoid, class Action> struct LSegT {
int N;
vector<Monoid> node;
vector<Action> lazy;
Monoid UNITY_MONOID; // to be set------------------------
Action UNITY_ACTION; // to be set------------------------
Monoid merge(const Monoid &l, const Monoid &r) {
// to be set---------------------------------
// return l+r;
return;
}
LSegT(vector<Monoid> &A) {
int sz = A.size();
N = 1;
while (N < sz)
N <<= 1;
node.resize(2 * N - 1);
lazy.resize(2 * N - 1, 0);
rep(i, sz) node[i + N - 1] = A[i];
for (int i = N - 2; i >= 0; i--)
node[i] = merge(node[i * 2 + 1], node[i * 2 + 2]);
}
void reflect(int k, int l, int r) {
// to be set----------------------------------------
// node[k]+=lazy[k];
}
void add(Action &d, const Action &e) {
// to be set---------------------------------------
// d+=e;
}
void eval(int k, int l, int r) {
if (lazy[k] != UNITY_ACTION) {
reflect(k, l, r);
if (r - l > 1) {
add(lazy[2 * k + 1], lazy[k]);
add(lazy[2 * k + 2], lazy[k]);
// if p,use this
// add(lazy[2 * k + 1], lazy[k] / 2);
// add(lazy[2 * k + 2], lazy[k] / 2);
}
lazy[k] = UNITY_ACTION;
}
}
void set(int a, int b, Action x, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = N;
if (b <= l || r <= a)
eval(k, l, r);
else if (a <= l && r <= b) {
add(lazy[k], x);
// if p,use this
// add(lazy[k] , (r - l) * x);
eval(k, l, r);
} else {
eval(k, l, r);
set(a, b, x, 2 * k + 1, l, (l + r) / 2);
set(a, b, x, 2 * k + 2, (l + r) / 2, r);
node[k] = merge(node[2 * k + 1], node[2 * k + 2]);
}
}
Monoid get(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = N;
if (b <= l || r <= a)
return UNITY_MONOID;
eval(k, l, r);
if (a <= l && r <= b)
return node[k];
Monoid vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
Monoid vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
return node[k] = merge(vl, vr);
}
};
template <class Monoid> struct SegT {
// to be set--------------------------------------------------
const static Monoid UNITY = LINF; // UNITY=0
Monoid merge(const Monoid &a, const Monoid &b) {
return min(a, b); // a+b;
}
// kokomade----------------------------------------------------
vector<Monoid> container;
int n;
void update(int i, Monoid x) {
int ii = i + n - 1;
container[ii] = x;
while (ii > 0) {
ii = (ii - 1) / 2;
container[ii] = merge(container[2 * ii + 1], container[2 * ii + 2]);
}
}
Monoid get(int l, int r, int l2 = 0, int r2 = -1, int k = 0) {
if (r2 == -1)
r2 = n;
if (r2 <= l || r <= l2)
return UNITY;
if (l <= l2 && r2 <= r)
return container[k];
ll vl = get(l, r, l2, (l2 + r2) / 2, 2 * k + 1);
ll vr = get(l, r, (l2 + r2) / 2, r2, 2 * k + 2);
return merge(vl, vr);
}
void init(vector<Monoid> &A) {
n = 1;
while (n < A.size())
n <<= 1;
container = vector<Monoid>(2 * n - 1, 0);
for (int i = 0; i < A.size(); i++)
update(i, A[i]);
}
SegT(vector<Monoid> &A) { init(A); }
SegT(int _n) {
vector<Monoid> A(_n, UNITY);
init(A);
}
};
int N, M, K, T, Q, H, W;
signed main() {
cin >> H >> W;
vector<int> A(H), B(H);
rep(i, H) {
cin >> A[i] >> B[i];
--A[i];
--B[i];
}
vector<int> tmp(W, 0);
SegT<int> sgt(tmp);
map<int, int> m;
rep(i, W) m[i] = i;
vector<int> ans(H, LINF);
rep(i, H) {
auto it = m.lower_bound(A[i]);
int r = -1;
while (it != m.end() && it->first <= B[i]) {
sgt.update(it->second, LINF);
chmax(r, it->second);
// cerr << it->second << " " << it->first << endl;
it = m.erase(it);
}
// cerr << r << endl;
if (r != -1 && B[i] < W - 1) {
chmax(m[B[i] + 1], r);
sgt.update(m[B[i] + 1], B[i] - m[B[i] + 1] + 1);
}
// cerr << sgt.get(0, W) << endl;
// rep(j, W) cerr << sgt.get(j, j + 1) << " ";
// cout << endl;
ans[i] = sgt.get(0, W) + i + 1;
}
rep(i, H) {
if (ans[i] >= LINF)
ans[i] = -1;
cout << ans[i] << endl;
}
return 0;
} | replace | 226 | 227 | 226 | 227 | 0 | |
p02575 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
int main() {
int h, w;
cin >> h >> w;
VI a(h), b(h);
rep(i, h) {
cin >> a[i] >> b[i];
a[i]--;
}
multiset<int> num;
rep(i, w) num.insert(0);
VI dp(w);
set<int> alive;
rep(i, w) alive.insert(i);
rep(i, h) {
while (1) {
auto it = alive.lower_bound(a[i]);
if (it == alive.end() || *it >= b[i])
break;
int k = *it;
assert(num.find(dp[k]) != num.end());
alive.erase(k);
num.erase(num.find(dp[k]));
if (b[i] == w) {
;
} else if (alive.count(b[i]) == 0) {
alive.insert(b[i]);
dp[b[i]] = dp[k] + b[i] - k;
num.insert(dp[k] + b[i] - k);
} else {
if (dp[k] + b[i] - k < dp[b[i]]) {
num.erase(dp[b[i]]);
num.insert(dp[k] + b[i] - k);
dp[b[i]] = dp[k] + b[i] - k;
}
}
a[i] = k + 1;
}
if (num.empty())
cout << -1 << endl;
else
cout << *num.begin() + i + 1 << endl;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
int main() {
int h, w;
cin >> h >> w;
VI a(h), b(h);
rep(i, h) {
cin >> a[i] >> b[i];
a[i]--;
}
multiset<int> num;
rep(i, w) num.insert(0);
VI dp(w);
set<int> alive;
rep(i, w) alive.insert(i);
rep(i, h) {
while (1) {
auto it = alive.lower_bound(a[i]);
if (it == alive.end() || *it >= b[i])
break;
int k = *it;
assert(num.find(dp[k]) != num.end());
alive.erase(k);
num.erase(num.find(dp[k]));
if (b[i] == w) {
;
} else if (alive.count(b[i]) == 0) {
alive.insert(b[i]);
dp[b[i]] = dp[k] + b[i] - k;
num.insert(dp[k] + b[i] - k);
} else {
if (dp[k] + b[i] - k < dp[b[i]]) {
num.erase(num.find(dp[b[i]]));
num.insert(dp[k] + b[i] - k);
dp[b[i]] = dp[k] + b[i] - k;
}
}
a[i] = k + 1;
}
if (num.empty())
cout << -1 << endl;
else
cout << *num.begin() + i + 1 << endl;
}
} | replace | 41 | 42 | 41 | 42 | 0 | |
p02575 | C++ | Time Limit Exceeded | #include <stdio.h>
#include <string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c) {
static char buf[1 << 15], *ptr = buf;
if (ptr == buf + strlen(buf) || c == 0) {
fwrite(buf, 1, ptr - buf, stdout), ptr = buf;
}
*ptr++ = c;
}
static inline int IN(void) {
int x = 0, f = 0, c = getchar();
while (c < 48 || c > 57) {
f ^= c == 45, c = getchar();
}
while (c > 47 && c < 58) {
x = x * 10 + c - 48, c = getchar();
}
return f ? -x : x;
}
static inline void OUT(int a) {
if (a < 0)
PUT('-'), a = -a;
int d[40], i = 0;
do {
d[i++] = a % 10;
} while (a /= 10);
while (i--) {
PUT(d[i] + 48);
}
PUT('\n');
}
static inline int Min(int a, int b) { return a < b ? a : b; }
const int INF = 0x3f3f3f3f;
int M, seg[800002], tag[800002];
static inline void upt(int x) { seg[x] = Min(seg[x << 1], seg[x << 1 | 1]); }
static inline void nodeCover(int x, int l, int val) {
seg[x] = l - val;
tag[x] = val;
}
static inline void dnt(int x, int l, int r) {
if (tag[x]) {
int mid = (l + r) / 2;
nodeCover(x << 1, l, tag[x]);
nodeCover(x << 1 | 1, mid + 1, tag[x]);
tag[x] = 0;
}
}
static inline void segCover(int u, int v, int t, int x = 1, int l = 1,
int r = M) {
if (u <= l && r <= v) {
nodeCover(x, l, t);
return;
}
dnt(x, l, r);
int mid = (l + r) / 2;
if (u <= mid) {
segCover(u, v, t, x << 1, l, mid);
}
if (v > mid) {
segCover(u, v, t, x << 1 | 1, mid + 1, r);
}
upt(x);
}
static inline int segQuery(int p, int x = 1, int l = 1, int r = M) {
if (l == r) {
return p - seg[x];
}
dnt(x, l, r);
int mid = (l + r) / 2;
return p <= mid ? segQuery(p, x << 1, l, mid)
: segQuery(p, x << 1 | 1, mid + 1, r);
}
int main() {
int N = IN() + 1, count = 0, cur = 1, left, right;
M = IN();
while (N--) {
left = IN(), right = IN();
count++;
if (cur >= left && cur <= right)
segCover(cur, right, -INF), cur = right + 1;
else if (cur < left)
segCover(left, right, segQuery(left - 1));
if (cur > M) {
puts("");
while (N--) {
puts("-1");
}
return 0;
}
OUT(seg[1] + count);
}
} | #include <stdio.h>
#include <string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c) {
static char buf[1 << 15], *ptr = buf;
if (ptr == buf + strlen(buf) || c == 0) {
fwrite(buf, 1, ptr - buf, stdout), ptr = buf;
}
*ptr++ = c;
}
static inline int IN(void) {
int x = 0, f = 0, c = getchar();
while (c < 48 || c > 57) {
f ^= c == 45, c = getchar();
}
while (c > 47 && c < 58) {
x = x * 10 + c - 48, c = getchar();
}
return f ? -x : x;
}
static inline void OUT(int a) {
if (a < 0)
PUT('-'), a = -a;
int d[40], i = 0;
do {
d[i++] = a % 10;
} while (a /= 10);
while (i--) {
PUT(d[i] + 48);
}
PUT('\n');
}
static inline int Min(int a, int b) { return a < b ? a : b; }
const int INF = 0x3f3f3f3f;
int M, seg[800002], tag[800002];
static inline void upt(int x) { seg[x] = Min(seg[x << 1], seg[x << 1 | 1]); }
static inline void nodeCover(int x, int l, int val) {
seg[x] = l - val;
tag[x] = val;
}
static inline void dnt(int x, int l, int r) {
if (tag[x]) {
int mid = (l + r) / 2;
nodeCover(x << 1, l, tag[x]);
nodeCover(x << 1 | 1, mid + 1, tag[x]);
tag[x] = 0;
}
}
static inline void segCover(int u, int v, int t, int x = 1, int l = 1,
int r = M) {
if (u <= l && r <= v) {
nodeCover(x, l, t);
return;
}
dnt(x, l, r);
int mid = (l + r) / 2;
if (u <= mid) {
segCover(u, v, t, x << 1, l, mid);
}
if (v > mid) {
segCover(u, v, t, x << 1 | 1, mid + 1, r);
}
upt(x);
}
static inline int segQuery(int p, int x = 1, int l = 1, int r = M) {
if (l == r) {
return p - seg[x];
}
dnt(x, l, r);
int mid = (l + r) / 2;
return p <= mid ? segQuery(p, x << 1, l, mid)
: segQuery(p, x << 1 | 1, mid + 1, r);
}
int main() {
int N = IN() + 1, count = 0, cur = 1, left, right;
M = IN();
while (N--) {
left = IN(), right = IN();
count++;
if (cur >= left && cur <= right)
segCover(cur, right, -INF), cur = right + 1;
else if (cur < left)
segCover(left, right, segQuery(left - 1));
if (cur > M) {
puts("");
while (N--) {
puts("-1");
}
return 0;
}
OUT(seg[1] + count);
if (N == 1) {
return 0;
}
}
} | insert | 92 | 92 | 92 | 95 | TLE | |
p02575 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
void solve() {
int H, W;
cin >> H >> W;
const int inf = 1e9;
map<int, int> mp; // mp[今] = 最初の位置
multiset<int> diff; // mpで管理してる区間における 今 - 最初 の集合
for (int i = 0; i < W; i++) {
mp[i] = i;
diff.insert(0);
}
for (int i = 0; i < H; i++) {
// cerr << "mp: ";
// for(auto e : mp) {
// cerr << e << " ";
// }
// cerr << endl;
// cerr << "diff: ";
// for(auto e : diff) {
// cerr << e << " ";
// }
// cerr << endl;
int a, b;
cin >> a >> b;
a--; // 半開区間 [a, b)
auto it = mp.lower_bound(a);
while (it->first < b && it != mp.end()) {
if (mp.find(b) == mp.end() || it->second > mp.at(b)) {
if (b == W) {
if (diff.find(inf) == diff.end()) {
diff.insert(inf);
}
} else {
if (diff.find(b - mp.at(b)) != diff.end()) {
diff.erase(diff.lower_bound(b - mp.at(b)));
}
diff.insert(b - it->second);
}
mp[b] = it->second;
}
diff.erase(diff.lower_bound(it->first - it->second));
it = mp.erase(it);
}
if (*diff.begin() >= inf) {
cout << -1 << endl;
} else {
cout << *diff.begin() + i + 1 << endl;
}
}
// cerr << "mp: ";
// for(auto e : mp) {
// cerr << e << " ";
// }
// cerr << endl;
// cerr << "diff: ";
// for(auto e : diff) {
// cerr << e << " ";
// }
// cerr << endl;
}
int main() {
#ifdef LOCAL_ENV
cin.exceptions(ios::failbit);
#endif
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
}
| #include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
void solve() {
int H, W;
cin >> H >> W;
const int inf = 1e9;
map<int, int> mp; // mp[今] = 最初の位置
multiset<int> diff; // mpで管理してる区間における 今 - 最初 の集合
for (int i = 0; i < W; i++) {
mp[i] = i;
diff.insert(0);
}
for (int i = 0; i < H; i++) {
// cerr << "mp: ";
// for(auto e : mp) {
// cerr << e << " ";
// }
// cerr << endl;
// cerr << "diff: ";
// for(auto e : diff) {
// cerr << e << " ";
// }
// cerr << endl;
int a, b;
cin >> a >> b;
a--; // 半開区間 [a, b)
auto it = mp.lower_bound(a);
while (it->first < b && it != mp.end()) {
if (mp.find(b) == mp.end() || it->second > mp.at(b)) {
if (b == W) {
if (diff.find(inf) == diff.end()) {
diff.insert(inf);
}
} else {
if (mp.find(b) != mp.end() && diff.find(b - mp.at(b)) != diff.end()) {
diff.erase(diff.lower_bound(b - mp.at(b)));
}
diff.insert(b - it->second);
}
mp[b] = it->second;
}
diff.erase(diff.lower_bound(it->first - it->second));
it = mp.erase(it);
}
if (*diff.begin() >= inf) {
cout << -1 << endl;
} else {
cout << *diff.begin() + i + 1 << endl;
}
}
// cerr << "mp: ";
// for(auto e : mp) {
// cerr << e << " ";
// }
// cerr << endl;
// cerr << "diff: ";
// for(auto e : diff) {
// cerr << e << " ";
// }
// cerr << endl;
}
int main() {
#ifdef LOCAL_ENV
cin.exceptions(ios::failbit);
#endif
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
}
| replace | 63 | 64 | 63 | 64 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): map::at
|
p02575 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF = 1e9 + 7;
const ll LINF = 9223372036854775807;
const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ld EPS = 1e-10; // 微調整用(EPSより小さいと0と判定など)
int ii() {
int x;
if (scanf("%d", &x) == 1)
return x;
else
return 0;
}
long long il() {
long long x;
if (scanf("%lld", &x) == 1)
return x;
else
return 0;
}
string is() {
string x;
cin >> x;
return x;
}
char ic() {
char x;
cin >> x;
return x;
}
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v) \
{ \
cerr << #v << endl; \
for (const auto &xxx : v) { \
cout << xxx.first << " " << xxx.second << "\n"; \
} \
} // 動作未確認
void br() { putchar('\n'); }
// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define b_e(a) a.begin(), a.end() // sort(b_e(vec));
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define DREP(i, m, n) for (ll i = (ll)(m); i > (ll)(n); i--)
#define rep(i, n) REP(i, 0, n)
#define m_p(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 p_b push_back
#define SZ(x) ((ll)(x).size()) // size()がunsignedなのでエラー避けに
#define endk '\n'
// coutによるpairの出力(空白区切り)
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << " " << p.second << ")";
}
// coutによるvectorの出力(空白区切り)
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i];
if (i < len - 1)
s << " "; //"\t"に変えるとTabで見やすく区切る
}
return s;
}
// coutによる多次元vectorの出力(空白区切り)
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
// 最大値、最小値の更新。更新したor等しければtrueを返す
template <typename T> bool chmax(T &a, T b) { return (a = max(a, b)) == b; }
template <typename T> bool chmin(T &a, T b) { return (a = min(a, b)) == b; }
// 4近傍(上下左右) rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};
// -------- template end - //
// - library ------------- //
// --------- library end - //
int main() {
ll H, W;
cin >> H >> W;
// 現在見ている行に辿り着くときの <終点列の列番号, その列に行き着く始点列> の
// set ただし、不要な行は削除する 不要な行 :
// 例えば、ある行の処理をしたときに「2, 3, 4行目からスタートすると、それぞれ
// 4, 4, 4 行目
// に辿り着く」という状態になった時、その行から先を考える限りにおいては、2,
// 3行目からスタートするメリットは無い。このように「終点列が一致してしまったペアのうち、もっとも始点列の列番号が大きいペア」以外を削除する
set<pair<ll, ll>> goal_and_starts;
// goal_and_starts に格納されている各ペアの .first - .second を格納
// つまり 終点列 - 始点列 だから、「何回右に移動する必要があるか」を意味する
// これの最小値 + k が、k 行における答えとなる
// goal_and_starts
// でペアを削除(更新)するとき、ここの対応する値も削除(更新)する
multiset<ll> moves;
// 注) r が W-1
// であった場合、つまり盤の外側に押し出されてしまう(下の行に行けない)場合、解説では無限にするとあったが、この実装では、削除してしまうことにした
// k=0 つまり開始前においては、終点行 = 始点行
// moves の内容は、全て 0
rep(w, W) {
goal_and_starts.insert(m_p(w, w));
moves.insert(0);
}
// 各 k について set, multiset を管理しながら答えを出していく
// O(H*W) になりそうだが、区間が与えられる度に set
// の中身が減っていくので、解説のとおり計算量は大きくない
bool cannotreach =
false; // それ以降の行に辿り着けなくなったらこのフラグを立てる
REP(k, 1, H + 1) {
// k : 1 ~ H
ll l = il() - 1;
ll r = il() - 1; // 0-indexed
if (cannotreach) {
cout << -1 << endk;
continue;
}
// k-1 行で l 列目に辿り着くような始点列は、k 行で全て r+1
// 列目に辿り着いてしまう よって、現時点で goal_and_starts
// に入っているペアのうち、.first が l ~ r
// のペアは、最も後ろにある(最も始点列の列番号が大きい=右移動が少なくて済む)ものだけ残し、削除する
// l_it := [l, r]
// に辿り着くペアのうち、最も始点列が左側のもの(のイテレータ) r_it := [l,
// r] に辿り着くペアのうち、最も始点列が右側のもの の直後を指す
auto l_it = goal_and_starts.lower_bound(m_p(l, 0));
auto r_it = goal_and_starts.lower_bound(m_p(r + 1, 0));
if (l_it == goal_and_starts.end() || r_it == goal_and_starts.begin()) {
// 一つも条件を満たすペアが無い時
// この行の入力は何も影響を及ぼさないということなので、set, multiset
// に対する処理は何もしない
} else {
// [l, r]
// に辿り着くペアのうち、最も始点列が右側のもの「の直後」を指していたイテレータを、1つ前に戻す。これで
// [l, r] に辿り着くペアのうち最も始点列が右側のものを指すようになる
r_it--;
// ペア [l_it, r_it) を削除する
// ここですぐに set
// を操作し始めると添字が変わってしまうため、削除したいペアをリストアップ
vector<pair<ll, ll>> pairs_toerase;
vector<ll> moves_toerase;
while (l_it != r_it) {
pairs_toerase.push_back(*l_it);
moves_toerase.push_back((*l_it).first - (*l_it).second);
l_it++;
}
// k行目において r にいたペアは、k-1行目において r+1
// にいくことになるから、更新したペアを入れ直したあと、削除する r == W-1
// の場合は、k-1行目において [l, r]
// にいるとそもそも下の行に辿り着けないので、入れ直しはせず、ただ削除するだけ
pairs_toerase.push_back(*r_it);
moves_toerase.push_back((*r_it).first - (*r_it).second);
if (r != W - 1) {
goal_and_starts.insert(m_p(r + 1, (*r_it).second));
moves.insert((r + 1 - (*r_it).second));
}
// 削除の処理を行う
rep(i, SZ(pairs_toerase)) {
goal_and_starts.erase(pairs_toerase[i]);
// multiset は普通に .erase(key)
// をかけると重複する値も全部消してしまうので、イテレータを使う
auto it = moves.find(moves_toerase[i]);
if (it != moves.end()) {
moves.erase(it);
}
}
}
// これで、moves 内の最小値 + k が k 行における答えとなる
// ただし、set
// に要素が1つもなくなっていた場合、その行には到達不可能なので、残り全てで
// -1 を出力する
if (moves.size() == 0) {
cannotreach = true;
cout << -1 << endk;
} else {
cout << *(moves.begin()) + k << endk;
}
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF = 1e9 + 7;
const ll LINF = 9223372036854775807;
const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ld EPS = 1e-10; // 微調整用(EPSより小さいと0と判定など)
int ii() {
int x;
if (scanf("%d", &x) == 1)
return x;
else
return 0;
}
long long il() {
long long x;
if (scanf("%lld", &x) == 1)
return x;
else
return 0;
}
string is() {
string x;
cin >> x;
return x;
}
char ic() {
char x;
cin >> x;
return x;
}
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v) \
{ \
cerr << #v << endl; \
for (const auto &xxx : v) { \
cout << xxx.first << " " << xxx.second << "\n"; \
} \
} // 動作未確認
void br() { putchar('\n'); }
// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define b_e(a) a.begin(), a.end() // sort(b_e(vec));
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define DREP(i, m, n) for (ll i = (ll)(m); i > (ll)(n); i--)
#define rep(i, n) REP(i, 0, n)
#define m_p(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 p_b push_back
#define SZ(x) ((ll)(x).size()) // size()がunsignedなのでエラー避けに
#define endk '\n'
// coutによるpairの出力(空白区切り)
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << " " << p.second << ")";
}
// coutによるvectorの出力(空白区切り)
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i];
if (i < len - 1)
s << " "; //"\t"に変えるとTabで見やすく区切る
}
return s;
}
// coutによる多次元vectorの出力(空白区切り)
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
// 最大値、最小値の更新。更新したor等しければtrueを返す
template <typename T> bool chmax(T &a, T b) { return (a = max(a, b)) == b; }
template <typename T> bool chmin(T &a, T b) { return (a = min(a, b)) == b; }
// 4近傍(上下左右) rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};
// -------- template end - //
// - library ------------- //
// --------- library end - //
int main() {
ll H, W;
cin >> H >> W;
// 現在見ている行に辿り着くときの <終点列の列番号, その列に行き着く始点列> の
// set ただし、不要な行は削除する 不要な行 :
// 例えば、ある行の処理をしたときに「2, 3, 4行目からスタートすると、それぞれ
// 4, 4, 4 行目
// に辿り着く」という状態になった時、その行から先を考える限りにおいては、2,
// 3行目からスタートするメリットは無い。このように「終点列が一致してしまったペアのうち、もっとも始点列の列番号が大きいペア」以外を削除する
set<pair<ll, ll>> goal_and_starts;
// goal_and_starts に格納されている各ペアの .first - .second を格納
// つまり 終点列 - 始点列 だから、「何回右に移動する必要があるか」を意味する
// これの最小値 + k が、k 行における答えとなる
// goal_and_starts
// でペアを削除(更新)するとき、ここの対応する値も削除(更新)する
multiset<ll> moves;
// 注) r が W-1
// であった場合、つまり盤の外側に押し出されてしまう(下の行に行けない)場合、解説では無限にするとあったが、この実装では、削除してしまうことにした
// k=0 つまり開始前においては、終点行 = 始点行
// moves の内容は、全て 0
rep(w, W) {
goal_and_starts.insert(m_p(w, w));
moves.insert(0);
}
// 各 k について set, multiset を管理しながら答えを出していく
// O(H*W) になりそうだが、区間が与えられる度に set
// の中身が減っていくので、解説のとおり計算量は大きくない
bool cannotreach =
false; // それ以降の行に辿り着けなくなったらこのフラグを立てる
REP(k, 1, H + 1) {
// k : 1 ~ H
ll l = il() - 1;
ll r = il() - 1; // 0-indexed
if (cannotreach) {
cout << -1 << endk;
continue;
}
// k-1 行で l 列目に辿り着くような始点列は、k 行で全て r+1
// 列目に辿り着いてしまう よって、現時点で goal_and_starts
// に入っているペアのうち、.first が l ~ r
// のペアは、最も後ろにある(最も始点列の列番号が大きい=右移動が少なくて済む)ものだけ残し、削除する
// l_it := [l, r]
// に辿り着くペアのうち、最も始点列が左側のもの(のイテレータ) r_it := [l,
// r] に辿り着くペアのうち、最も始点列が右側のもの の直後を指す
auto l_it = goal_and_starts.lower_bound(m_p(l, 0));
auto r_it = goal_and_starts.lower_bound(m_p(r + 1, 0));
if (l_it == r_it) {
// 一つも条件を満たすペアが無い時(終点列の列番号が「全て l 未満」か「全て
// r+1 以上」) この行の入力は何も影響を及ぼさないということなので、set,
// multiset に対する処理は何もしない
} else {
// [l, r]
// に辿り着くペアのうち、最も始点列が右側のもの「の直後」を指していたイテレータを、1つ前に戻す。これで
// [l, r] に辿り着くペアのうち最も始点列が右側のものを指すようになる
r_it--;
// ペア [l_it, r_it) を削除する
// ここですぐに set
// を操作し始めると添字が変わってしまうため、削除したいペアをリストアップ
vector<pair<ll, ll>> pairs_toerase;
vector<ll> moves_toerase;
while (l_it != r_it) {
pairs_toerase.push_back(*l_it);
moves_toerase.push_back((*l_it).first - (*l_it).second);
l_it++;
}
// k行目において r にいたペアは、k-1行目において r+1
// にいくことになるから、更新したペアを入れ直したあと、削除する r == W-1
// の場合は、k-1行目において [l, r]
// にいるとそもそも下の行に辿り着けないので、入れ直しはせず、ただ削除するだけ
pairs_toerase.push_back(*r_it);
moves_toerase.push_back((*r_it).first - (*r_it).second);
if (r != W - 1) {
goal_and_starts.insert(m_p(r + 1, (*r_it).second));
moves.insert((r + 1 - (*r_it).second));
}
// 削除の処理を行う
rep(i, SZ(pairs_toerase)) {
goal_and_starts.erase(pairs_toerase[i]);
// multiset は普通に .erase(key)
// をかけると重複する値も全部消してしまうので、イテレータを使う
auto it = moves.find(moves_toerase[i]);
if (it != moves.end()) {
moves.erase(it);
}
}
}
// これで、moves 内の最小値 + k が k 行における答えとなる
// ただし、set
// に要素が1つもなくなっていた場合、その行には到達不可能なので、残り全てで
// -1 を出力する
if (moves.size() == 0) {
cannotreach = true;
cout << -1 << endk;
} else {
cout << *(moves.begin()) + k << endk;
}
}
} | replace | 162 | 166 | 162 | 166 | TLE | |
p02575 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
const int MAX_N = 1 << 20;
// セグメント木を持つグローバル配列
int nn, dat[2 * MAX_N - 1];
// 初期化
void init(int n_) {
// n_が小さいときの変な挙動を防ぐ
if (n_ < 10)
n_ = 10;
// 簡単のため要素数を2のべき乗に
nn = 1;
while (nn < n_)
nn *= 2;
// 全ての値をINT_MAXに
for (int i = 0; i < 2 * nn - 1; i++)
dat[i] = INT_MAX;
}
// k番目の値(0-indexed)をaに変更
void update(int k, int a) {
// 葉の接点
k += nn - 1;
dat[k] = a;
// 登りながら更新
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// [a,b)の最小値を求める
// 後ろのほうの引数は、計算の簡単のための引数。
// kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。
// したがって、外からはquery(a, b, 0, 0, nn)として呼ぶ。
int query(int a, int b, int k, int l, int r) {
// [a, b)と[l, r)が交差しなければ、INT_MAX
if (r <= a || b <= l)
return INT_MAX;
// [a, b)が[l, r)を完全に含んでいれば、この節点の値
if (a <= l && r <= b)
return dat[k];
else {
// そうでなければ、2つの子の最小値
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
int h, w;
cin >> h >> w;
init(w + 10);
set<int> se;
srep(i, 1, w + 1) {
update(i, 0);
se.insert(i);
}
int INF = 1001001001;
rep(i, h) {
int a, b;
scanf("%d%d", &a, &b);
auto ite = lower_bound(se.begin(), se.end(), a);
int mi = INF;
while (ite != se.end()) {
int x = *ite;
if (x > b + 1)
break;
int tmp = query(x, x + 1, 0, 0, nn);
tmp += b + 1 - x;
mi = min(mi, tmp);
update(x, INF);
ite = se.erase(ite);
}
if (mi < INF) {
update(b + 1, mi);
if (b < w)
se.insert(b + 1);
}
// cout << se.size() << endl;
int ans = query(1, w + 1, 0, 0, nn);
ans += i + 1;
if (ans >= INF)
ans = -1;
printf("%d\n", ans);
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
const int MAX_N = 1 << 20;
// セグメント木を持つグローバル配列
int nn, dat[2 * MAX_N - 1];
// 初期化
void init(int n_) {
// n_が小さいときの変な挙動を防ぐ
if (n_ < 10)
n_ = 10;
// 簡単のため要素数を2のべき乗に
nn = 1;
while (nn < n_)
nn *= 2;
// 全ての値をINT_MAXに
for (int i = 0; i < 2 * nn - 1; i++)
dat[i] = INT_MAX;
}
// k番目の値(0-indexed)をaに変更
void update(int k, int a) {
// 葉の接点
k += nn - 1;
dat[k] = a;
// 登りながら更新
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// [a,b)の最小値を求める
// 後ろのほうの引数は、計算の簡単のための引数。
// kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。
// したがって、外からはquery(a, b, 0, 0, nn)として呼ぶ。
int query(int a, int b, int k, int l, int r) {
// [a, b)と[l, r)が交差しなければ、INT_MAX
if (r <= a || b <= l)
return INT_MAX;
// [a, b)が[l, r)を完全に含んでいれば、この節点の値
if (a <= l && r <= b)
return dat[k];
else {
// そうでなければ、2つの子の最小値
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
int h, w;
cin >> h >> w;
init(w + 10);
set<int> se;
srep(i, 1, w + 1) {
update(i, 0);
se.insert(i);
}
int INF = 1001001001;
rep(i, h) {
int a, b;
scanf("%d%d", &a, &b);
auto ite = se.lower_bound(a);
int mi = INF;
while (ite != se.end()) {
int x = *ite;
if (x > b + 1)
break;
int tmp = query(x, x + 1, 0, 0, nn);
tmp += b + 1 - x;
mi = min(mi, tmp);
update(x, INF);
ite = se.erase(ite);
}
if (mi < INF) {
update(b + 1, mi);
if (b < w)
se.insert(b + 1);
}
// cout << se.size() << endl;
int ans = query(1, w + 1, 0, 0, nn);
ans += i + 1;
if (ans >= INF)
ans = -1;
printf("%d\n", ans);
}
return 0;
}
| replace | 85 | 86 | 85 | 86 | TLE | |
p02575 | C++ | Runtime Error | /*/ Author: kal013 /*/
// #pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class key, class value, class cmp = std::less<key>>
using ordered_map =
tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
size_t operator()(pair<int64_t, int64_t> Y) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM);
}
};
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << "]";
}
template <class T> istream &operator>>(istream &is, vector<T> &V) {
for (auto &e : V)
is >> e;
return is;
}
#ifdef __SIZEOF_INT128__
ostream &operator<<(ostream &os, __int128 T) {
const static long long N = (1'000'000'000'000'000'000);
if (T < 0) {
os << '-';
T *= -1;
}
unsigned long long b = T % N;
T /= N;
if (T == 0)
return os << b;
unsigned long long a = T % N;
T /= N;
if (T == 0) {
os << a;
__int128 mul = 10;
int cnt = 0;
while (mul * b < N && cnt < 17) {
os << '0';
mul *= 10;
++cnt;
}
return os << b;
}
os << ((long long)T);
__int128 mul = 10;
int cnt = 0;
while (mul * a < N && cnt < 17) {
os << '0';
mul *= 10;
++cnt;
}
os << a;
mul = 10;
cnt = 0;
while (mul * b < N && cnt < 17) {
os << '0';
mul *= 10;
++cnt;
}
return os << b;
}
istream &operator>>(istream &is, __int128 &T) {
string U;
is >> U;
T = 0;
size_t pos = 0;
int mul = 1;
if (U[pos] == '-') {
++pos;
mul *= -1;
}
for (; pos < U.size(); ++pos) {
T *= 10;
T += (U[pos] - '0');
}
T *= mul;
return is;
}
#endif
template <class T> ostream &operator<<(ostream &os, set<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class T> ostream &operator<<(ostream &os, unordered_set<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class T> ostream &operator<<(ostream &os, multiset<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class T> ostream &operator<<(ostream &os, ordered_set<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
os << "{ ";
for (auto m : M)
os << "(" << m.first << ":" << m.second << ") ";
return os << "}";
}
template <class L, class R, class chash = std::hash<R>>
ostream &operator<<(ostream &os, unordered_map<L, R, chash> M) {
os << "{ ";
for (auto m : M)
os << "(" << m.first << ":" << m.second << ") ";
return os << "}";
}
template <class L, class R, class chash = std::hash<R>>
ostream &operator<<(ostream &os, gp_hash_table<L, R, chash> M) {
os << "{ ";
for (auto m : M)
os << "(" << m.first << ":" << m.second << ") ";
return os << "}";
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...) 1
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l, long long r) {
uniform_int_distribution<int64_t> generator(l, r);
return generator(rng);
}
inline int64_t random_long() {
uniform_int_distribution<int64_t> generator(LLONG_MIN, LLONG_MAX);
return generator(rng);
}
/*/---------------------------Defines----------------------/*/
typedef vector<int> vi;
typedef pair<int, int> pii;
#define For(i, n) for (int i = 0; i < (int)n; ++i)
#define Rep(i, n) for (int i = 1; i <= (int)n; ++i)
#define ll long long
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(v) (v).begin(), (v).end()
/*/-----------------------Modular Arithmetic---------------/*/
const int mod = 1e9 + 7;
/*/-----------------------------Code begins----------------------------------/*/
#define int ll
const ll INF = 1e10;
const int N = 8e5 + 10;
ll seg[N], lazy[N];
#define M ((s + e) >> 1)
void build(int node, int s, int e) {
seg[node] = 0;
lazy[node] = 0;
if (s != e) {
build(2 * node, s, M);
build(2 * node + 1, M + 1, e);
}
}
void rmv(int node, int s, int e) {
if (lazy[node] == 0) {
return;
}
if (s != e) {
lazy[2 * node] = 1;
lazy[2 * node + 1] = 1;
seg[2 * node] = seg[node];
seg[2 * node + 1] = seg[node] + (M + 1 - s);
}
lazy[node] = 0;
}
void update(int node, int s, int e, int l, int r, ll v) {
rmv(node, s, e);
if (e < l || s > r) {
return;
}
if (l <= s && e <= r) {
seg[node] = v + (s - l);
lazy[node] = 1;
return;
}
update(2 * node, s, M, l, r, v);
update(2 * node + 1, M + 1, e, l, r, v);
seg[node] = min(seg[2 * node], seg[2 * node + 1]);
}
ll get(int node, int s, int e, ll l) {
rmv(node, s, e);
if (s == e) {
assert(s == l == e);
return seg[node];
}
if (l <= M) {
return get(2 * node, s, M, l);
}
return get(2 * node + 1, M + 1, e, l);
}
void solve() {
int h, w;
cin >> h >> w;
build(1, 1, w);
int off = 0;
for (int i = 0; i < h; ++i) {
int a, b;
cin >> a >> b;
++off;
ll st = INF;
if (a > 1) {
st = get(1, 1, w, a - 1) + 1;
}
update(1, 1, w, a, b, st);
rmv(1, 1, w);
// trace(seg[1] - INF);
if (seg[1] < INF) {
cout << seg[1] + off << endl;
} else {
cout << -1 << endl;
}
// for(int i = 1; i <= w; ++i){
// trace(i, get(1,1,w,i));
// }
}
}
#undef int
int main() {
// Use "set_name".max_load_factor(0.25);"set_name".reserve(512); with
// unordered set Or use gp_hash_table<X,null_type>
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << fixed << setprecision(25);
cerr << fixed << setprecision(10);
auto start = std::chrono::high_resolution_clock::now();
int t = 1;
// cin >> t;
while (t--) {
solve();
}
auto stop = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
// cerr << "Time taken : " << ((long double)duration.count())/((long double)
// 1e9) <<"s "<< endl;
}
| /*/ Author: kal013 /*/
// #pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class key, class value, class cmp = std::less<key>>
using ordered_map =
tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k) returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
size_t operator()(pair<int64_t, int64_t> Y) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM);
}
};
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V)
os << v << " ";
return os << "]";
}
template <class T> istream &operator>>(istream &is, vector<T> &V) {
for (auto &e : V)
is >> e;
return is;
}
#ifdef __SIZEOF_INT128__
ostream &operator<<(ostream &os, __int128 T) {
const static long long N = (1'000'000'000'000'000'000);
if (T < 0) {
os << '-';
T *= -1;
}
unsigned long long b = T % N;
T /= N;
if (T == 0)
return os << b;
unsigned long long a = T % N;
T /= N;
if (T == 0) {
os << a;
__int128 mul = 10;
int cnt = 0;
while (mul * b < N && cnt < 17) {
os << '0';
mul *= 10;
++cnt;
}
return os << b;
}
os << ((long long)T);
__int128 mul = 10;
int cnt = 0;
while (mul * a < N && cnt < 17) {
os << '0';
mul *= 10;
++cnt;
}
os << a;
mul = 10;
cnt = 0;
while (mul * b < N && cnt < 17) {
os << '0';
mul *= 10;
++cnt;
}
return os << b;
}
istream &operator>>(istream &is, __int128 &T) {
string U;
is >> U;
T = 0;
size_t pos = 0;
int mul = 1;
if (U[pos] == '-') {
++pos;
mul *= -1;
}
for (; pos < U.size(); ++pos) {
T *= 10;
T += (U[pos] - '0');
}
T *= mul;
return is;
}
#endif
template <class T> ostream &operator<<(ostream &os, set<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class T> ostream &operator<<(ostream &os, unordered_set<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class T> ostream &operator<<(ostream &os, multiset<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class T> ostream &operator<<(ostream &os, ordered_set<T> S) {
os << "{ ";
for (auto s : S)
os << s << " ";
return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
os << "{ ";
for (auto m : M)
os << "(" << m.first << ":" << m.second << ") ";
return os << "}";
}
template <class L, class R, class chash = std::hash<R>>
ostream &operator<<(ostream &os, unordered_map<L, R, chash> M) {
os << "{ ";
for (auto m : M)
os << "(" << m.first << ":" << m.second << ") ";
return os << "}";
}
template <class L, class R, class chash = std::hash<R>>
ostream &operator<<(ostream &os, gp_hash_table<L, R, chash> M) {
os << "{ ";
for (auto m : M)
os << "(" << m.first << ":" << m.second << ") ";
return os << "}";
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...) 1
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l, long long r) {
uniform_int_distribution<int64_t> generator(l, r);
return generator(rng);
}
inline int64_t random_long() {
uniform_int_distribution<int64_t> generator(LLONG_MIN, LLONG_MAX);
return generator(rng);
}
/*/---------------------------Defines----------------------/*/
typedef vector<int> vi;
typedef pair<int, int> pii;
#define For(i, n) for (int i = 0; i < (int)n; ++i)
#define Rep(i, n) for (int i = 1; i <= (int)n; ++i)
#define ll long long
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(v) (v).begin(), (v).end()
/*/-----------------------Modular Arithmetic---------------/*/
const int mod = 1e9 + 7;
/*/-----------------------------Code begins----------------------------------/*/
#define int ll
const ll INF = 1e10;
const int N = 8e5 + 10;
ll seg[N], lazy[N];
#define M ((s + e) >> 1)
void build(int node, int s, int e) {
seg[node] = 0;
lazy[node] = 0;
if (s != e) {
build(2 * node, s, M);
build(2 * node + 1, M + 1, e);
}
}
void rmv(int node, int s, int e) {
if (lazy[node] == 0) {
return;
}
if (s != e) {
lazy[2 * node] = 1;
lazy[2 * node + 1] = 1;
seg[2 * node] = seg[node];
seg[2 * node + 1] = seg[node] + (M + 1 - s);
}
lazy[node] = 0;
}
void update(int node, int s, int e, int l, int r, ll v) {
rmv(node, s, e);
if (e < l || s > r) {
return;
}
if (l <= s && e <= r) {
seg[node] = v + (s - l);
lazy[node] = 1;
return;
}
update(2 * node, s, M, l, r, v);
update(2 * node + 1, M + 1, e, l, r, v);
seg[node] = min(seg[2 * node], seg[2 * node + 1]);
}
ll get(int node, int s, int e, ll l) {
rmv(node, s, e);
if (s == e) {
return seg[node];
}
if (l <= M) {
return get(2 * node, s, M, l);
}
return get(2 * node + 1, M + 1, e, l);
}
void solve() {
int h, w;
cin >> h >> w;
build(1, 1, w);
int off = 0;
for (int i = 0; i < h; ++i) {
int a, b;
cin >> a >> b;
++off;
ll st = INF;
if (a > 1) {
st = get(1, 1, w, a - 1) + 1;
}
update(1, 1, w, a, b, st);
rmv(1, 1, w);
// trace(seg[1] - INF);
if (seg[1] < INF) {
cout << seg[1] + off << endl;
} else {
cout << -1 << endl;
}
// for(int i = 1; i <= w; ++i){
// trace(i, get(1,1,w,i));
// }
}
}
#undef int
int main() {
// Use "set_name".max_load_factor(0.25);"set_name".reserve(512); with
// unordered set Or use gp_hash_table<X,null_type>
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << fixed << setprecision(25);
cerr << fixed << setprecision(10);
auto start = std::chrono::high_resolution_clock::now();
int t = 1;
// cin >> t;
while (t--) {
solve();
}
auto stop = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
// cerr << "Time taken : " << ((long double)duration.count())/((long double)
// 1e9) <<"s "<< endl;
}
| delete | 257 | 258 | 257 | 257 | 0 | |
p02575 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n) for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)
using namespace std;
template <typename T> class SegTree {
public:
SegTree(int n, function<T(T, T)> operation, function<T(T, T)> update,
T identity = T()) {
int ne = 1;
while (ne < n) {
ne *= 2;
}
this->n_ = n;
this->ne_ = ne;
this->data_ = vector<T>(this->ne_ * 2, identity);
this->operation_ = operation;
this->update_ = update;
this->identity_ = identity;
}
const T &Val(int i) const { return this->data_[i + this->ne_ - 1]; }
void Update(int i, const T &v) {
int idx = i + this->ne_ - 1;
this->data_[idx] = this->update_(this->data_[idx], v);
while (idx != 0) {
idx = (idx - 1) / 2;
int lidx = idx * 2 + 1;
int ridx = idx * 2 + 2;
this->data_[idx] = this->operation_(this->data_[lidx], this->data_[ridx]);
}
}
T QueryOpen(int l, int r) const {
return this->QueryInternal(l, r, 0, this->ne_, 0);
}
T QueryClose(int l, int r) const { return QueryOpen(l, r + 1); }
private:
T QueryInternal(int l, int r, int lc, int rc, int idx) const {
if (l <= lc && rc <= r) {
return this->data_[idx];
}
if (rc <= l || r <= lc) {
return this->identity_;
}
int m = (lc + rc) / 2;
int lidx = idx * 2 + 1;
int ridx = idx * 2 + 2;
if (r <= m) {
return this->QueryInternal(l, r, lc, m, lidx);
} else if (m <= l) {
return this->QueryInternal(l, r, m, rc, ridx);
} else {
return this->operation_(this->QueryInternal(l, r, lc, m, lidx),
this->QueryInternal(l, r, m, rc, ridx));
}
}
size_t n_;
size_t ne_;
vector<T> data_;
function<T(T, T)> operation_;
function<T(T, T)> update_;
T identity_;
};
struct S {
int i;
int p;
int v;
};
auto cmp = [](const S &lhs, const S &rhs) { return lhs.p < rhs.p; };
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// cout << fixed << setprecision(20);
int h, w;
cin >> h >> w;
set<S, decltype(cmp)> values(cmp);
FOR_LE(i, 1, w) { values.insert({i, i, 0}); }
auto process = [](int lhs, int rhs) { return min(lhs, rhs); };
auto update = [](int lhs, int rhs) { return rhs; };
SegTree<int> st(w + 1, process, update);
st.Update(0, INT_MAX);
FOR_LT(i, 0, h) {
// cout << i << endl;
int a, b;
cin >> a >> b;
auto bit = values.lower_bound({0, a, 0});
auto eit = values.upper_bound({0, b + 1, 0});
// cout << a << " " << b << endl;
// cout << "bit " << bit->i << endl;
if (bit != eit) {
auto fit = eit;
fit--;
S s = *fit;
s.v += (b + 1 - s.p);
s.p = b + 1;
if (w < s.p) {
st.Update(s.i, INT_MAX);
} else {
// cout << "update : " << s.i << " " << s.v << endl;
st.Update(s.i, s.v);
}
while (bit != eit) {
// cout << "erase : " << bit->i << endl;
if (bit->i != s.i) {
st.Update(bit->i, INT_MAX);
}
bit = values.erase(bit);
}
values.insert(s);
// cout << "valuse" << endl;
for (auto &v : values) {
// cout << v.i << " " << v.p << " " << v.v << endl;
}
}
int ans = st.QueryClose(1, w);
if (ans == INT_MAX) {
cout << -1 << endl;
} else {
cout << ans + (i + 1) << endl;
}
}
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n) for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)
using namespace std;
template <typename T> class SegTree {
public:
SegTree(int n, function<T(T, T)> operation, function<T(T, T)> update,
T identity = T()) {
int ne = 1;
while (ne < n) {
ne *= 2;
}
this->n_ = n;
this->ne_ = ne;
this->data_ = vector<T>(this->ne_ * 2, identity);
this->operation_ = operation;
this->update_ = update;
this->identity_ = identity;
}
const T &Val(int i) const { return this->data_[i + this->ne_ - 1]; }
void Update(int i, const T &v) {
int idx = i + this->ne_ - 1;
this->data_[idx] = this->update_(this->data_[idx], v);
while (idx != 0) {
idx = (idx - 1) / 2;
int lidx = idx * 2 + 1;
int ridx = idx * 2 + 2;
this->data_[idx] = this->operation_(this->data_[lidx], this->data_[ridx]);
}
}
T QueryOpen(int l, int r) const {
return this->QueryInternal(l, r, 0, this->ne_, 0);
}
T QueryClose(int l, int r) const { return QueryOpen(l, r + 1); }
private:
T QueryInternal(int l, int r, int lc, int rc, int idx) const {
if (l <= lc && rc <= r) {
return this->data_[idx];
}
if (rc <= l || r <= lc) {
return this->identity_;
}
int m = (lc + rc) / 2;
int lidx = idx * 2 + 1;
int ridx = idx * 2 + 2;
if (r <= m) {
return this->QueryInternal(l, r, lc, m, lidx);
} else if (m <= l) {
return this->QueryInternal(l, r, m, rc, ridx);
} else {
return this->operation_(this->QueryInternal(l, r, lc, m, lidx),
this->QueryInternal(l, r, m, rc, ridx));
}
}
size_t n_;
size_t ne_;
vector<T> data_;
function<T(T, T)> operation_;
function<T(T, T)> update_;
T identity_;
};
struct S {
int i;
int p;
int v;
};
auto cmp = [](const S &lhs, const S &rhs) { return lhs.p < rhs.p; };
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// cout << fixed << setprecision(20);
int h, w;
cin >> h >> w;
set<S, decltype(cmp)> values(cmp);
FOR_LE(i, 1, w) { values.insert({i, i, 0}); }
auto process = [](int lhs, int rhs) { return min(lhs, rhs); };
auto update = [](int lhs, int rhs) { return rhs; };
SegTree<int> st(w + 1, process, update);
st.Update(0, INT_MAX);
FOR_LT(i, 0, h) {
// cout << i << endl;
int a, b;
cin >> a >> b;
auto bit = values.lower_bound({0, a, 0});
auto eit = values.upper_bound({0, b + 1, 0});
// cout << a << " " << b << endl;
// cout << "bit " << bit->i << endl;
if (bit != eit) {
auto fit = eit;
fit--;
S s = *fit;
s.v += (b + 1 - s.p);
s.p = b + 1;
if (w < s.p) {
st.Update(s.i, INT_MAX);
} else {
// cout << "update : " << s.i << " " << s.v << endl;
st.Update(s.i, s.v);
}
while (bit != eit) {
// cout << "erase : " << bit->i << endl;
if (bit->i != s.i) {
st.Update(bit->i, INT_MAX);
}
bit = values.erase(bit);
}
values.insert(s);
// cout << "valuse" << endl;
// for (auto& v : values) {
// cout << v.i << " " << v.p << " " << v.v << endl;
//}
}
int ans = st.QueryClose(1, w);
if (ans == INT_MAX) {
cout << -1 << endl;
} else {
cout << ans + (i + 1) << endl;
}
}
return 0;
} | replace | 155 | 158 | 155 | 158 | TLE | |
p02575 | C++ | Runtime Error | // #pragma GCC optimize ("O3","unroll-loops")
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <numeric>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define TEST \
{ IS_TEST = true; }
#define fi first
#define se second
#define pb(x) emplace_back(x)
#define pf(x) emplace_front(x)
#define emp(x) emplace(x)
#define mp(x, y) make_pair(x, y)
using namespace std;
using ll = int_fast64_t;
using v_b = vector<bool>;
using v_ll = vector<ll>;
using str = string;
using v_str = vector<string>;
using p_ll = pair<ll, ll>;
using vv_b = vector<v_b>;
using vv_ll = vector<v_ll>;
using vp_ll = vector<p_ll>;
using vvv_ll = vector<vv_ll>;
using vvp_ll = vector<vp_ll>;
using ld = long double;
using v_ld = vector<ld>;
using vv_ld = vector<v_ld>;
bool IS_TEST = false;
ll ll_min64 = 1LL << 63;
ll ll_max64 = ~ll_min64;
ll ll_min32 = 1LL << 31;
ll ll_max32 = ~ll_min32;
ll MOD = 1000000007;
/*displaying functions for debug*/
template <class T> void show2(const T &x) { cerr << x; }
template <class T1, class T2> void show2(const pair<T1, T2> &x) {
cerr << "{" << show2(x.first) << "," << show2(x.second) << "}";
}
template <class T> void show(const T &x) {
if (!IS_TEST)
return;
show2(x);
cerr << "\n";
}
template <class T> void v_show(const T &v, ll n = -1) {
if (!IS_TEST)
return;
auto itr = v.begin();
ll m = n;
while (itr != v.end() && m != 0) {
show2(*itr);
cerr << " ";
itr++;
m--;
}
cerr << "\n";
}
template <class T> void vv_show(const T &v, ll n = -1) {
if (!IS_TEST)
return;
cerr << "--------------------------------\n";
auto itr = v.begin();
ll m = n;
while (itr != v.end() && m != 0) {
v_show(*itr, n);
itr++;
m--;
}
cerr << "--------------------------------\n";
}
/*--------------------------------*/
/*loading integers*/
void load(ll &x1) { cin >> x1; }
void load(ll &x1, ll &x2) { cin >> x1 >> x2; }
void load(ll &x1, ll &x2, ll &x3) { cin >> x1 >> x2 >> x3; }
void load(ll &x1, ll &x2, ll &x3, ll &x4) { cin >> x1 >> x2 >> x3 >> x4; }
void v_load(ll n, v_ll &v1, ll head = 0, ll tail = 0, ll init = 0) {
ll m = n + head + tail;
v1.assign(m, init);
for (ll i = 0; i < n; i++) {
scanf("%lld", &v1[i + head]);
}
}
void v_load(ll n, v_ll &v1, v_ll &v2, ll head = 0, ll tail = 0, ll init = 0) {
ll m = n + head + tail;
v1.assign(m, init);
v2.assign(m, init);
for (ll i = 0; i < n; i++) {
scanf("%lld%lld", &v1[i + head], &v2[i + head]);
}
}
void v_load(ll n, v_ll &v1, v_ll &v2, v_ll &v3, ll head = 0, ll tail = 0,
ll init = 0) {
ll m = n + head + tail;
v1.assign(m, init);
v2.assign(m, init);
v3.assign(m, init);
for (ll i = 0; i < n; i++) {
scanf("%lld%lld%lld", &v1[i + head], &v2[i + head], &v3[i + head]);
}
}
void v_load(ll n, v_ll &v1, v_ll &v2, v_ll &v3, v_ll &v4, ll head = 0,
ll tail = 0, ll init = 0) {
ll m = n + head + tail;
v1.assign(m, init);
v2.assign(m, init);
v3.assign(m, init);
v4.assign(m, init);
for (ll i = 0; i < n; i++) {
scanf("%lld%lld%lld%lld", &v1[i + head], &v2[i + head], &v3[i + head],
&v4[i + head]);
}
}
/*--------------------------------*/
v_ll local_sort(ll x1 = ll_max64, ll x2 = ll_max64, ll x3 = ll_max64,
ll x4 = ll_max64) {
v_ll x{x1, x2, x3, x4};
sort(x.begin(), x.end());
return x;
}
ll max(ll x, ll y) { return x > y ? x : y; }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(v_ll::iterator b, v_ll::iterator e) {
ll ans = *b;
while (b < e) {
ans = max(ans, *b);
b++;
}
return ans;
}
ll argmax(v_ll::iterator b, v_ll::iterator e) {
ll ans = 0, cnt = 0, val = *b;
while (b < e) {
if (val < *b) {
ans = cnt;
val = *b;
}
cnt++;
b++;
}
return ans;
}
ll min(v_ll::iterator b, v_ll::iterator e) {
ll ans = *b;
while (b < e) {
ans = min(ans, *b);
b++;
}
return ans;
}
ll argmin(v_ll::iterator b, v_ll::iterator e) {
ll ans = 0, cnt = 0, val = *b;
while (b < e) {
if (val > *b) {
ans = cnt;
val = *b;
}
cnt++;
b++;
}
return ans;
}
ll sum(v_ll::iterator b, v_ll::iterator e) {
ll ans = 0;
while (b < e) {
ans += *b;
b++;
}
return ans;
}
template <class T> bool chmax(T &x, const T &y) {
if (x >= y)
return false;
x = y;
return true;
}
template <class T> bool chmin(T &x, const T &y) {
if (x <= y)
return false;
x = y;
return true;
}
template <class T> void quit(T x) {
cout << x << endl;
exit(0);
}
void yesno(bool x) { cout << (x ? "Yes" : "No") << endl; }
ll rup(ll x, ll y) { return (x - 1) / y + 1; }
ll rem(ll x, ll y) {
ll z = x % y;
return z >= 0 ? z : z + y;
}
template <typename T> v_ll index_sort(const vector<T> &ref) {
v_ll idx(ref.size());
iota(idx.begin(), idx.end(), 0);
sort(idx.begin(), idx.end(), [&](auto &x, auto &y) {
if (ref[x] < ref[y])
return true;
});
}
// setprecision(digit)
// sort(##.begin(),##.end(),[&](auto &x, auto &y){if (x<y) return true;});
// ll ok=0,ng=0; while(abs(ok-ng)>1){ll mid=(ok+ng)/2; (true?ok:ng)=mid;}
struct dat {
ll w, c;
dat(ll w, ll c) : w(w), c(c) {}
bool operator<(const dat &rhs) const { return w < rhs.w; }
};
int main() {
ll H, W;
v_ll A, B;
cin >> H >> W;
v_load(H, A, B);
for (ll i = 0; i < H; i++) {
A[i]--;
}
set<dat> sd;
multiset<ll> sl;
for (ll i = 0; i < W; i++) {
sd.insert(dat(i, 0));
sl.insert(0);
}
for (ll i = 0; i < H; i++) {
auto itr = sd.lower_bound(dat(A[i], 0));
dat d(B[i], 99999999);
while ((*itr).w <= B[i]) {
ll dict = (*itr).w + 1;
chmin(d.c, B[i] - (*itr).w + (*itr).c);
sl.erase(sl.lower_bound((*itr).c));
sd.erase(itr);
itr = sd.lower_bound(dat(dict, 0));
if (itr == sd.end())
break;
}
if (d.c < 99999999 && B[i] < W) {
sd.insert(d);
sl.insert(d.c);
}
/*
auto test=sd.begin();
cerr << "test " ;
while (test!=sd.end()){
cerr << (*test).w <<"," <<(*test).c << " ";
test++;
}cerr << endl;
*/
if (!sl.empty()) {
ll x = *(sl.begin());
cout << (x + i + 1) << "\n";
} else {
cout << -1 << "\n";
}
}
}
| // #pragma GCC optimize ("O3","unroll-loops")
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <functional>
#include <numeric>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define TEST \
{ IS_TEST = true; }
#define fi first
#define se second
#define pb(x) emplace_back(x)
#define pf(x) emplace_front(x)
#define emp(x) emplace(x)
#define mp(x, y) make_pair(x, y)
using namespace std;
using ll = int_fast64_t;
using v_b = vector<bool>;
using v_ll = vector<ll>;
using str = string;
using v_str = vector<string>;
using p_ll = pair<ll, ll>;
using vv_b = vector<v_b>;
using vv_ll = vector<v_ll>;
using vp_ll = vector<p_ll>;
using vvv_ll = vector<vv_ll>;
using vvp_ll = vector<vp_ll>;
using ld = long double;
using v_ld = vector<ld>;
using vv_ld = vector<v_ld>;
bool IS_TEST = false;
ll ll_min64 = 1LL << 63;
ll ll_max64 = ~ll_min64;
ll ll_min32 = 1LL << 31;
ll ll_max32 = ~ll_min32;
ll MOD = 1000000007;
/*displaying functions for debug*/
template <class T> void show2(const T &x) { cerr << x; }
template <class T1, class T2> void show2(const pair<T1, T2> &x) {
cerr << "{" << show2(x.first) << "," << show2(x.second) << "}";
}
template <class T> void show(const T &x) {
if (!IS_TEST)
return;
show2(x);
cerr << "\n";
}
template <class T> void v_show(const T &v, ll n = -1) {
if (!IS_TEST)
return;
auto itr = v.begin();
ll m = n;
while (itr != v.end() && m != 0) {
show2(*itr);
cerr << " ";
itr++;
m--;
}
cerr << "\n";
}
template <class T> void vv_show(const T &v, ll n = -1) {
if (!IS_TEST)
return;
cerr << "--------------------------------\n";
auto itr = v.begin();
ll m = n;
while (itr != v.end() && m != 0) {
v_show(*itr, n);
itr++;
m--;
}
cerr << "--------------------------------\n";
}
/*--------------------------------*/
/*loading integers*/
void load(ll &x1) { cin >> x1; }
void load(ll &x1, ll &x2) { cin >> x1 >> x2; }
void load(ll &x1, ll &x2, ll &x3) { cin >> x1 >> x2 >> x3; }
void load(ll &x1, ll &x2, ll &x3, ll &x4) { cin >> x1 >> x2 >> x3 >> x4; }
void v_load(ll n, v_ll &v1, ll head = 0, ll tail = 0, ll init = 0) {
ll m = n + head + tail;
v1.assign(m, init);
for (ll i = 0; i < n; i++) {
scanf("%lld", &v1[i + head]);
}
}
void v_load(ll n, v_ll &v1, v_ll &v2, ll head = 0, ll tail = 0, ll init = 0) {
ll m = n + head + tail;
v1.assign(m, init);
v2.assign(m, init);
for (ll i = 0; i < n; i++) {
scanf("%lld%lld", &v1[i + head], &v2[i + head]);
}
}
void v_load(ll n, v_ll &v1, v_ll &v2, v_ll &v3, ll head = 0, ll tail = 0,
ll init = 0) {
ll m = n + head + tail;
v1.assign(m, init);
v2.assign(m, init);
v3.assign(m, init);
for (ll i = 0; i < n; i++) {
scanf("%lld%lld%lld", &v1[i + head], &v2[i + head], &v3[i + head]);
}
}
void v_load(ll n, v_ll &v1, v_ll &v2, v_ll &v3, v_ll &v4, ll head = 0,
ll tail = 0, ll init = 0) {
ll m = n + head + tail;
v1.assign(m, init);
v2.assign(m, init);
v3.assign(m, init);
v4.assign(m, init);
for (ll i = 0; i < n; i++) {
scanf("%lld%lld%lld%lld", &v1[i + head], &v2[i + head], &v3[i + head],
&v4[i + head]);
}
}
/*--------------------------------*/
v_ll local_sort(ll x1 = ll_max64, ll x2 = ll_max64, ll x3 = ll_max64,
ll x4 = ll_max64) {
v_ll x{x1, x2, x3, x4};
sort(x.begin(), x.end());
return x;
}
ll max(ll x, ll y) { return x > y ? x : y; }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(v_ll::iterator b, v_ll::iterator e) {
ll ans = *b;
while (b < e) {
ans = max(ans, *b);
b++;
}
return ans;
}
ll argmax(v_ll::iterator b, v_ll::iterator e) {
ll ans = 0, cnt = 0, val = *b;
while (b < e) {
if (val < *b) {
ans = cnt;
val = *b;
}
cnt++;
b++;
}
return ans;
}
ll min(v_ll::iterator b, v_ll::iterator e) {
ll ans = *b;
while (b < e) {
ans = min(ans, *b);
b++;
}
return ans;
}
ll argmin(v_ll::iterator b, v_ll::iterator e) {
ll ans = 0, cnt = 0, val = *b;
while (b < e) {
if (val > *b) {
ans = cnt;
val = *b;
}
cnt++;
b++;
}
return ans;
}
ll sum(v_ll::iterator b, v_ll::iterator e) {
ll ans = 0;
while (b < e) {
ans += *b;
b++;
}
return ans;
}
template <class T> bool chmax(T &x, const T &y) {
if (x >= y)
return false;
x = y;
return true;
}
template <class T> bool chmin(T &x, const T &y) {
if (x <= y)
return false;
x = y;
return true;
}
template <class T> void quit(T x) {
cout << x << endl;
exit(0);
}
void yesno(bool x) { cout << (x ? "Yes" : "No") << endl; }
ll rup(ll x, ll y) { return (x - 1) / y + 1; }
ll rem(ll x, ll y) {
ll z = x % y;
return z >= 0 ? z : z + y;
}
template <typename T> v_ll index_sort(const vector<T> &ref) {
v_ll idx(ref.size());
iota(idx.begin(), idx.end(), 0);
sort(idx.begin(), idx.end(), [&](auto &x, auto &y) {
if (ref[x] < ref[y])
return true;
});
}
// setprecision(digit)
// sort(##.begin(),##.end(),[&](auto &x, auto &y){if (x<y) return true;});
// ll ok=0,ng=0; while(abs(ok-ng)>1){ll mid=(ok+ng)/2; (true?ok:ng)=mid;}
struct dat {
ll w, c;
dat(ll w, ll c) : w(w), c(c) {}
bool operator<(const dat &rhs) const { return w < rhs.w; }
};
int main() {
ll H, W;
v_ll A, B;
cin >> H >> W;
v_load(H, A, B);
for (ll i = 0; i < H; i++) {
A[i]--;
}
set<dat> sd;
multiset<ll> sl;
for (ll i = 0; i < W; i++) {
sd.insert(dat(i, 0));
sl.insert(0);
}
for (ll i = 0; i < H; i++) {
auto itr = sd.lower_bound(dat(A[i], 0));
dat d(B[i], 99999999);
while (itr != sd.end() && (*itr).w <= B[i]) {
ll dict = (*itr).w + 1;
chmin(d.c, B[i] - (*itr).w + (*itr).c);
sl.erase(sl.lower_bound((*itr).c));
sd.erase(itr);
itr = sd.lower_bound(dat(dict, 0));
if (itr == sd.end())
break;
}
if (d.c < 99999999 && B[i] < W) {
sd.insert(d);
sl.insert(d.c);
}
/*
auto test=sd.begin();
cerr << "test " ;
while (test!=sd.end()){
cerr << (*test).w <<"," <<(*test).c << " ";
test++;
}cerr << endl;
*/
if (!sl.empty()) {
ll x = *(sl.begin());
cout << (x + i + 1) << "\n";
} else {
cout << -1 << "\n";
}
}
}
| replace | 258 | 259 | 258 | 259 | 0 | |
p02575 | C++ | Runtime Error | #include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000ll
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
ll power(ll x, ll y, ll md = inf) {
ll res = 1;
x %= md;
while (y) {
if (y & 1)
res = (res * x) % md;
x *= x;
if (x >= md)
x %= md;
y >>= 1;
}
return res;
}
using namespace std;
#define endl '\n'
#define int ll
signed main() {
fast;
int h, w;
cin >> h >> w;
pii v[100001];
for (int i = 0; i < h; i++)
cin >> v[i].f >> v[i].s;
map<int, int> mp;
for (int i = 1; i <= w; i++)
mp[i] = 0;
map<int, int> mini = {{0, w}};
for (int i = 0; i < h; i++) {
int l = v[i].f;
int r = v[i].s;
auto it = mp.lower_bound(l);
int mn = inf;
while (it != mp.end() && it->f <= r) {
mn = min(mn, r + 1 - (it->f) + (it->s));
auto it1 = it++;
mini[it1->s]--;
if (mini[it1->s] == 0)
mini.erase(it1->s);
mp.erase(it1);
}
if (r + 1 <= w && mn < inf) {
if (mp.count(r + 1) && mp[r + 1] > mn) {
mini[mp[r + 1]]--;
if (mini[mp[r + 1]] == 0)
mini.erase(mp[r + 1]);
mini[mn]++;
mp[r + 1] = mn;
} else if (!mp.count(r + 1)) {
mp[r + 1] = mn;
mini[mn]++;
}
}
if (mini.size())
cout << mini.begin()->f + i + 1 << endl;
else
cout << -1 << endl;
}
} | #include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000ll
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
ll power(ll x, ll y, ll md = inf) {
ll res = 1;
x %= md;
while (y) {
if (y & 1)
res = (res * x) % md;
x *= x;
if (x >= md)
x %= md;
y >>= 1;
}
return res;
}
using namespace std;
#define endl '\n'
#define int ll
signed main() {
fast;
int h, w;
cin >> h >> w;
pii v[200002];
for (int i = 0; i < h; i++)
cin >> v[i].f >> v[i].s;
map<int, int> mp;
for (int i = 1; i <= w; i++)
mp[i] = 0;
map<int, int> mini = {{0, w}};
for (int i = 0; i < h; i++) {
int l = v[i].f;
int r = v[i].s;
auto it = mp.lower_bound(l);
int mn = inf;
while (it != mp.end() && it->f <= r) {
mn = min(mn, r + 1 - (it->f) + (it->s));
auto it1 = it++;
mini[it1->s]--;
if (mini[it1->s] == 0)
mini.erase(it1->s);
mp.erase(it1);
}
if (r + 1 <= w && mn < inf) {
if (mp.count(r + 1) && mp[r + 1] > mn) {
mini[mp[r + 1]]--;
if (mini[mp[r + 1]] == 0)
mini.erase(mp[r + 1]);
mini[mn]++;
mp[r + 1] = mn;
} else if (!mp.count(r + 1)) {
mp[r + 1] = mn;
mini[mn]++;
}
}
if (mini.size())
cout << mini.begin()->f + i + 1 << endl;
else
cout << -1 << endl;
}
} | replace | 40 | 41 | 40 | 41 | 0 | |
p02575 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> class segtree {
private:
int n, sz, h;
vector<T> node, lazy;
vector<bool> lazyFlag;
void eval(int k) {
if (lazyFlag[k]) {
node[k] = lazy[k];
if (k < n) {
lazy[k * 2] = lazy[k * 2 + 1] = lazy[k];
lazyFlag[k * 2] = lazyFlag[k * 2 + 1] = true;
}
lazyFlag[k] = false;
}
}
public:
segtree(const vector<T> &v) : n(1), sz((int)v.size()), h(0) {
while (n < sz)
n *= 2, h++;
node.resize(2 * n, numeric_limits<T>::max());
lazy.resize(2 * n);
lazyFlag.resize(2 * n, false);
for (int i = 0; i < sz; i++)
node[i + n] = v[i];
for (int i = n - 1; i >= 1; i--)
node[i] = min(node[i * 2], node[i * 2 + 1]);
}
void range(int a, int b, T x, int k = 1, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k);
if (b <= l || r <= a)
return;
if (a <= l && r <= b) {
lazy[k] = x, lazyFlag[k] = true;
eval(k);
} else {
range(a, b, x, 2 * k, l, (l + r) / 2);
range(a, b, x, 2 * k + 1, (l + r) / 2, r);
node[k] = min(node[2 * k], node[2 * k + 1]);
}
}
T query(int a, int b) {
a += n, b += n - 1;
for (int i = h; i > 0; i--)
eval(a >> i), eval(b >> i);
b++;
T res1 = numeric_limits<T>::max(), res2 = numeric_limits<T>::max();
while (a < b) {
if (a & 1)
eval(a), res1 = min(res1, node[a++]);
if (b & 1)
eval(--b), res2 = min(res2, node[b]);
a >>= 1, b >>= 1;
}
return min(res1, res2);
}
void print() {
for (int i = 0; i < sz; i++)
cout << query(i, i + 1) << " ";
cout << endl;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> aa(n);
vector<int> bb(n);
rep(i, n) { bb[i] = -i; }
segtree<int> sg(aa);
segtree<int> sg2(bb);
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
int k = sg2.query(a, b + 1);
int nxt = k + (b + 1);
if (b < n - 1) {
if (sg.query(b + 1, b + 2) > nxt) {
sg.range(b + 1, b + 2, nxt);
sg2.range(b + 1, b + 2, nxt - (b + 1));
}
}
sg2.range(a, b + 1, inf);
sg.range(a, b + 1, inf);
int res = sg.query(0, n);
if (res >= inf - 1000000) {
cout << -1 << "\n";
} else {
cout << res + i + 1 << "\n";
}
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(), (x).end()
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> class segtree {
private:
int n, sz, h;
vector<T> node, lazy;
vector<bool> lazyFlag;
void eval(int k) {
if (lazyFlag[k]) {
node[k] = lazy[k];
if (k < n) {
lazy[k * 2] = lazy[k * 2 + 1] = lazy[k];
lazyFlag[k * 2] = lazyFlag[k * 2 + 1] = true;
}
lazyFlag[k] = false;
}
}
public:
segtree(const vector<T> &v) : n(1), sz((int)v.size()), h(0) {
while (n < sz)
n *= 2, h++;
node.resize(2 * n, numeric_limits<T>::max());
lazy.resize(2 * n);
lazyFlag.resize(2 * n, false);
for (int i = 0; i < sz; i++)
node[i + n] = v[i];
for (int i = n - 1; i >= 1; i--)
node[i] = min(node[i * 2], node[i * 2 + 1]);
}
void range(int a, int b, T x, int k = 1, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k);
if (b <= l || r <= a)
return;
if (a <= l && r <= b) {
lazy[k] = x, lazyFlag[k] = true;
eval(k);
} else {
range(a, b, x, 2 * k, l, (l + r) / 2);
range(a, b, x, 2 * k + 1, (l + r) / 2, r);
node[k] = min(node[2 * k], node[2 * k + 1]);
}
}
T query(int a, int b) {
a += n, b += n - 1;
for (int i = h; i > 0; i--)
eval(a >> i), eval(b >> i);
b++;
T res1 = numeric_limits<T>::max(), res2 = numeric_limits<T>::max();
while (a < b) {
if (a & 1)
eval(a), res1 = min(res1, node[a++]);
if (b & 1)
eval(--b), res2 = min(res2, node[b]);
a >>= 1, b >>= 1;
}
return min(res1, res2);
}
void print() {
for (int i = 0; i < sz; i++)
cout << query(i, i + 1) << " ";
cout << endl;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> m >> n;
vector<int> aa(n);
vector<int> bb(n);
rep(i, n) { bb[i] = -i; }
segtree<int> sg(aa);
segtree<int> sg2(bb);
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
int k = sg2.query(a, b + 1);
int nxt = k + (b + 1);
if (b < n - 1) {
if (sg.query(b + 1, b + 2) > nxt) {
sg.range(b + 1, b + 2, nxt);
sg2.range(b + 1, b + 2, nxt - (b + 1));
}
}
sg2.range(a, b + 1, inf);
sg.range(a, b + 1, inf);
int res = sg.query(0, n);
if (res >= inf - 1000000) {
cout << -1 << "\n";
} else {
cout << res + i + 1 << "\n";
}
}
return 0;
} | replace | 123 | 124 | 123 | 124 | 0 | |
p02575 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>
const int MAX_N = 1 << 17;
int n, dat[2 * MAX_N - 1];
void init(int n_) {
n = 1;
while (n < n_) {
n *= 2;
}
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = 0;
}
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) {
return INT_MAX;
}
if (a <= l && r <= b) {
return dat[k];
} else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
int h, w, a, b;
cin >> h >> w;
set<int> s;
for (int i = 1; i <= w; i++) {
s.insert(i);
}
n = w + 1;
init(n);
for (int i = 0; i < h; i++) {
cin >> a >> b;
if (b + 1 <= w && s.find(b + 1) == s.end()) {
set<int>::iterator it = s.upper_bound(b);
if (it != s.begin()) {
it--;
update(b + 1, b + 1 - *it + query(*it, *it + 1, 0, 0, n));
s.insert(b + 1);
}
}
while (s.lower_bound(a) != s.upper_bound(b)) {
update(*s.lower_bound(a), INT_MAX);
s.erase(s.lower_bound(a));
}
cout << (query(1, w + 1, 0, 0, n) == INT_MAX
? -1
: query(1, w + 1, 0, 0, n) + i + 1)
<< endl;
}
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>
const int MAX_N = 1 << 18;
int n, dat[2 * MAX_N - 1];
void init(int n_) {
n = 1;
while (n < n_) {
n *= 2;
}
for (int i = 0; i < 2 * n - 1; i++) {
dat[i] = 0;
}
}
void update(int k, int a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
int query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) {
return INT_MAX;
}
if (a <= l && r <= b) {
return dat[k];
} else {
int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
int main() {
int h, w, a, b;
cin >> h >> w;
set<int> s;
for (int i = 1; i <= w; i++) {
s.insert(i);
}
n = w + 1;
init(n);
for (int i = 0; i < h; i++) {
cin >> a >> b;
if (b + 1 <= w && s.find(b + 1) == s.end()) {
set<int>::iterator it = s.upper_bound(b);
if (it != s.begin()) {
it--;
update(b + 1, b + 1 - *it + query(*it, *it + 1, 0, 0, n));
s.insert(b + 1);
}
}
while (s.lower_bound(a) != s.upper_bound(b)) {
update(*s.lower_bound(a), INT_MAX);
s.erase(s.lower_bound(a));
}
cout << (query(1, w + 1, 0, 0, n) == INT_MAX
? -1
: query(1, w + 1, 0, 0, n) + i + 1)
<< endl;
}
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02575 | C++ | Time Limit Exceeded | #line 2 "header.hpp"
//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H
// template version 2.0
using namespace std;
#include <bits/stdc++.h>
// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) {
if ((a) < (b))
(a) = (b);
}
template <class T> inline void chmin(T &a, const T &b) {
if ((a) > (b))
(a) = (b);
}
template <typename X, typename T> auto make_table(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto make_table(X x, Y y, Z z, Zs... zs) {
auto cont = make_table(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) \
sort(all(x)); \
x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)
typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() {
assert(cin.eof() == 0);
int tmp;
cin >> tmp;
assert(cin.eof() == 1);
}
#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif
#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template <class T = ll> using vec = vector<T>;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
template <typename T, typename E> struct segment_tree_lazy { //{{{
// T: 値の型
// E: update作用素
using F = function<T(T, T)>;
using G = function<T(T, E)>;
using H = function<E(E, E)>;
int n, height;
F f; // 区間のマージ
G g; // 更新をどのように行うか
H h; // 複数の更新のまとめ方
T ti; // 値の単位元
E ei; // 恒等置換
vector<T> dat;
vector<E> laz;
segment_tree_lazy() {}
segment_tree_lazy(F f, G g, H h, T ti, E ei)
: f(f), g(g), h(h), ti(ti), ei(ei) {}
void init(int n_) { /*{{{*/
n = 1;
height = 0;
while (n < n_)
n <<= 1, height++;
dat.assign(2 * n, ti);
laz.assign(2 * n, ei);
} /*}}}*/
void build(const vector<T> &v) { /*{{{*/
int n_ = v.size();
init(n_);
for (int i = 0; i < n_; i++)
dat[n + i] = v[i];
for (int i = n - 1; i; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
} /*}}}*/
inline T reflect(int k) { /*{{{*/
return laz[k] == ei ? dat[k] : g(dat[k], laz[k]);
} /*}}}*/
inline void propagate(int k) { /*{{{*/
if (laz[k] == ei)
return;
laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k]);
laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]);
dat[k] = reflect(k);
laz[k] = ei;
} /*}}}*/
inline void thrust(int k) { /*{{{*/
for (int i = height; i; i--)
propagate(k >> i);
} /*}}}*/
inline void recalc(int k) { /*{{{*/
while (k >>= 1)
dat[k] = f(reflect((k << 1) | 0), reflect((k << 1) | 1));
} /*}}}*/
void update(int a, int b, E x) { /*{{{*/
if (a >= b)
return;
thrust(a += n);
thrust(b += n - 1);
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
laz[l] = h(laz[l], x), l++;
if (r & 1)
--r, laz[r] = h(laz[r], x);
}
recalc(a);
recalc(b);
} /*}}}*/
void set_val(int a, T x) { /*{{{*/
thrust(a += n);
dat[a] = x;
laz[a] = ei;
recalc(a);
} /*}}}*/
T query(int a, int b) { /*{{{*/
if (a >= b)
return ti;
thrust(a += n);
thrust(b += n - 1);
T vl = ti, vr = ti;
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
vl = f(vl, reflect(l++));
if (r & 1)
vr = f(reflect(--r), vr);
}
return f(vl, vr);
} /*}}}*/
template <typename C>
int find(int st, C &check, T &acc, int k, int l, int r) { /*{{{*/
if (l + 1 == r) {
acc = f(acc, reflect(k));
return check(acc) ? k - n : -1;
}
propagate(k);
int m = (l + r) >> 1;
if (m <= st)
return find(st, check, acc, (k << 1) | 1, m, r);
if (st <= l && !check(f(acc, dat[k]))) {
acc = f(acc, dat[k]);
return -1;
}
int vl = find(st, check, acc, (k << 1) | 0, l, m);
if (~vl)
return vl;
return find(st, check, acc, (k << 1) | 1, m, r);
} /*}}}*/
template <typename C> int find(int st, C &check) { /*{{{*/
T acc = ti;
return find(st, check, acc, 1, 0, n);
} /*}}}*/
}; //}}}
// Sample:
// -----------------------------------------------
// init
// * このコードはRSQに対応していないのでRSQをする場合は別のものを使用するように注意
// how to use
// rep(i, n) lseg.set_val(i, a[i]);
// lseg.update(l, r, x); // [l, r)
// lseg.query(l, r); // [l, r)
// -----------------------------------------------
int solve() {
ll h, w;
cin >> h >> w;
dump(h, w);
vl a(h), b(h);
rep(i, h) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
}
set<pll> st;
multiset<ll> ms;
rep(j, w) {
st.insert(mp(j, j)); // (current, start)
ms.insert(0);
}
st.insert(mp(w, -INF));
dump(st);
dump(ms);
rep(k, 0, h) {
cerrendl;
for (auto it = st.lb(mp(a[k], -1));;) {
if (it->first > b[k])
continue;
else if ((*next(it)).first > b[k]) {
auto nx = mp(b[k] + 1, it->second);
auto nv = b[k] + 1 - it->second;
ms.erase(ms.find(it->first - it->second));
it = st.erase(it);
if (b[k] + 1 < w) {
st.insert(nx);
ms.insert(nv);
}
break;
} else {
ms.erase(ms.find(it->first - it->second));
it = st.erase(it);
}
}
dump(st);
dump(ms, sz(ms));
cout << (sz(ms) == 0 ? -1 : *ms.begin() + k + 1) << endl;
}
return 0;
}
int main() { /*{{{*/
solve();
check_input();
return 0;
} /*}}}*/
| #line 2 "header.hpp"
//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H
// template version 2.0
using namespace std;
#include <bits/stdc++.h>
// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) {
if ((a) < (b))
(a) = (b);
}
template <class T> inline void chmin(T &a, const T &b) {
if ((a) > (b))
(a) = (b);
}
template <typename X, typename T> auto make_table(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto make_table(X x, Y y, Z z, Zs... zs) {
auto cont = make_table(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) \
sort(all(x)); \
x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)
typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() {
assert(cin.eof() == 0);
int tmp;
cin >> tmp;
assert(cin.eof() == 1);
}
#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif
#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template <class T = ll> using vec = vector<T>;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
template <typename T, typename E> struct segment_tree_lazy { //{{{
// T: 値の型
// E: update作用素
using F = function<T(T, T)>;
using G = function<T(T, E)>;
using H = function<E(E, E)>;
int n, height;
F f; // 区間のマージ
G g; // 更新をどのように行うか
H h; // 複数の更新のまとめ方
T ti; // 値の単位元
E ei; // 恒等置換
vector<T> dat;
vector<E> laz;
segment_tree_lazy() {}
segment_tree_lazy(F f, G g, H h, T ti, E ei)
: f(f), g(g), h(h), ti(ti), ei(ei) {}
void init(int n_) { /*{{{*/
n = 1;
height = 0;
while (n < n_)
n <<= 1, height++;
dat.assign(2 * n, ti);
laz.assign(2 * n, ei);
} /*}}}*/
void build(const vector<T> &v) { /*{{{*/
int n_ = v.size();
init(n_);
for (int i = 0; i < n_; i++)
dat[n + i] = v[i];
for (int i = n - 1; i; i--)
dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
} /*}}}*/
inline T reflect(int k) { /*{{{*/
return laz[k] == ei ? dat[k] : g(dat[k], laz[k]);
} /*}}}*/
inline void propagate(int k) { /*{{{*/
if (laz[k] == ei)
return;
laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k]);
laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]);
dat[k] = reflect(k);
laz[k] = ei;
} /*}}}*/
inline void thrust(int k) { /*{{{*/
for (int i = height; i; i--)
propagate(k >> i);
} /*}}}*/
inline void recalc(int k) { /*{{{*/
while (k >>= 1)
dat[k] = f(reflect((k << 1) | 0), reflect((k << 1) | 1));
} /*}}}*/
void update(int a, int b, E x) { /*{{{*/
if (a >= b)
return;
thrust(a += n);
thrust(b += n - 1);
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
laz[l] = h(laz[l], x), l++;
if (r & 1)
--r, laz[r] = h(laz[r], x);
}
recalc(a);
recalc(b);
} /*}}}*/
void set_val(int a, T x) { /*{{{*/
thrust(a += n);
dat[a] = x;
laz[a] = ei;
recalc(a);
} /*}}}*/
T query(int a, int b) { /*{{{*/
if (a >= b)
return ti;
thrust(a += n);
thrust(b += n - 1);
T vl = ti, vr = ti;
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
vl = f(vl, reflect(l++));
if (r & 1)
vr = f(reflect(--r), vr);
}
return f(vl, vr);
} /*}}}*/
template <typename C>
int find(int st, C &check, T &acc, int k, int l, int r) { /*{{{*/
if (l + 1 == r) {
acc = f(acc, reflect(k));
return check(acc) ? k - n : -1;
}
propagate(k);
int m = (l + r) >> 1;
if (m <= st)
return find(st, check, acc, (k << 1) | 1, m, r);
if (st <= l && !check(f(acc, dat[k]))) {
acc = f(acc, dat[k]);
return -1;
}
int vl = find(st, check, acc, (k << 1) | 0, l, m);
if (~vl)
return vl;
return find(st, check, acc, (k << 1) | 1, m, r);
} /*}}}*/
template <typename C> int find(int st, C &check) { /*{{{*/
T acc = ti;
return find(st, check, acc, 1, 0, n);
} /*}}}*/
}; //}}}
// Sample:
// -----------------------------------------------
// init
// * このコードはRSQに対応していないのでRSQをする場合は別のものを使用するように注意
// how to use
// rep(i, n) lseg.set_val(i, a[i]);
// lseg.update(l, r, x); // [l, r)
// lseg.query(l, r); // [l, r)
// -----------------------------------------------
int solve() {
ll h, w;
cin >> h >> w;
dump(h, w);
vl a(h), b(h);
rep(i, h) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
}
set<pll> st;
multiset<ll> ms;
rep(j, w) {
st.insert(mp(j, j)); // (current, start)
ms.insert(0);
}
st.insert(mp(w, -INF));
dump(st);
dump(ms);
rep(k, 0, h) {
cerrendl;
for (auto it = st.lb(mp(a[k], -1));;) {
if (it->first > b[k])
break;
else if ((*next(it)).first > b[k]) {
auto nx = mp(b[k] + 1, it->second);
auto nv = b[k] + 1 - it->second;
ms.erase(ms.find(it->first - it->second));
it = st.erase(it);
if (b[k] + 1 < w) {
st.insert(nx);
ms.insert(nv);
}
break;
} else {
ms.erase(ms.find(it->first - it->second));
it = st.erase(it);
}
}
dump(st);
dump(ms, sz(ms));
cout << (sz(ms) == 0 ? -1 : *ms.begin() + k + 1) << endl;
}
return 0;
}
int main() { /*{{{*/
solve();
check_input();
return 0;
} /*}}}*/
| replace | 246 | 247 | 246 | 247 | TLE | |
p02575 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(i, e) cerr << #i << ' ' << i << e
void debug(auto L, auto R) {
while (L < R)
cerr << *L << " \n"[L + 1 == R], ++L;
}
#else
#define DE(...) 0
void debug(...) {}
#endif
const int maxn = 200010, maxm = maxn + (maxn << 1), inf = 1e8;
int n, m;
map<pair<int, int>, int> id;
pair<int, int> to_loc[maxm];
int dp[maxm], cnt, rb[maxn], res[maxn], lb[maxn];
bool vis[maxm];
struct sgt {
int v[maxn << 1], sz;
void init(int ns = n + 1) {
sz = ns;
fill(v, v + sz + sz, inf);
}
void mo(int i, int val) { v[i] = min(v[i], val); }
int query(int i) {
int res = inf;
for (i += sz; i; i >>= 1)
res = min(res, v[i]);
return res;
}
void modify(int l, int r, int val) {
l += sz, r += sz;
for (; l < r; l >>= 1, r >>= 1) {
if (l & 1)
mo(l++, val);
if (r & 1)
mo(--r, val);
}
}
} tree;
// [u, len]
vector<pair<int, int>> edge[maxm];
map<pair<int, int>, int> Findnxt;
int create(int x, int y) {
if (id.count({x, y}))
return id[{x, y}];
assert(cnt < maxm);
to_loc[cnt] = {x, y};
return id[{x, y}] = cnt++;
}
vector<int> start;
void precal() {
tree.init(m);
tree.modify(0, m, n);
for (int i = n - 1; i >= 0; --i) {
if (rb[i] + 1 < m)
Findnxt[{i, rb[i] + 1}] = tree.query(rb[i] + 1);
tree.modify(lb[i], rb[i] + 1, i);
}
for (int i = 0; i < m; ++i)
if (i < lb[0] || i > rb[0])
Findnxt[{0, i}] = tree.query(i);
}
void build(int t) {
int x = 0, y = t, h = 0, now = create(x, y);
start.pb(now);
// DE(t, '\n');
while (x < n) {
// DE(x, ' '), DE(y, '\n');
// case one : go horizontal
int nx, ny;
if (y <= rb[x] && y >= lb[x])
nx = x, ny = rb[x] + 1;
else
assert(x == 0 || y == rb[x] + 1), assert(Findnxt.count({x, y})),
nx = Findnxt[{x, y}], ny = y;
// cerr << "X Y " << x << ' ' << y << '\n';
// cerr << "NX NY " << nx << ' ' << ny << '\n';
if (nx == x) {
if (ny >= m) {
// cerr << "No chance\n";
break;
}
int nxt = create(nx, rb[x] + 1);
edge[now].pb(nxt, rb[x] + 1 - y);
now = nxt, y = rb[x] + 1;
continue;
}
// case zero : go free
if (nx == n) {
edge[now].pb(create(nx, ny), 0);
break;
}
// case two : meet already exist
if (id.count({nx, ny})) {
// cerr << "Existed\n";
edge[now].pb(id[{nx, ny}], 0);
break;
}
// case three : meet not exist
int nxt = create(nx, ny);
edge[now].pb(nxt, 0);
now = nxt, x = nx;
}
// cerr << "Finish\n";
}
struct info {
int now, len;
bool operator()(const info &a, const info &b) const { return a.len > b.len; }
};
void dij() {
tree.init();
fill(dp, dp + cnt, inf);
priority_queue<info, vector<info>, info> pq;
for (int id : start) {
dp[id] = 0;
pq.push({id, 0});
}
while (pq.size()) {
auto [now, len] = pq.top();
pq.pop();
if (vis[now])
continue;
vis[now] = true;
auto [x, y] = to_loc[now];
// cerr << "X Y waste " << x << ' ' << y << ' ' << len << '\n';
for (auto [u, w] : edge[now]) {
auto [nx, ny] = to_loc[u];
tree.modify(x, nx + 1, len);
if (len + w < dp[u]) {
dp[u] = len + w;
pq.push({u, len + w});
}
}
}
for (int i = 1; i <= n; ++i) {
res[i] = tree.query(i);
if (res[i] == inf)
res[i] = -1;
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> lb[i] >> rb[i], --lb[i], --rb[i];
precal();
for (int i = 0; i < n; ++i)
build(i);
dij();
for (int i = 1; i <= n; ++i) {
// cout << res[i] << '\n';
if (res[i] == -1)
cout << -1 << '\n';
else
cout << res[i] + i << '\n';
}
}
| #include <bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(i, e) cerr << #i << ' ' << i << e
void debug(auto L, auto R) {
while (L < R)
cerr << *L << " \n"[L + 1 == R], ++L;
}
#else
#define DE(...) 0
void debug(...) {}
#endif
const int maxn = 200010, maxm = maxn + (maxn << 1), inf = 1e8;
int n, m;
map<pair<int, int>, int> id;
pair<int, int> to_loc[maxm];
int dp[maxm], cnt, rb[maxn], res[maxn], lb[maxn];
bool vis[maxm];
struct sgt {
int v[maxn << 1], sz;
void init(int ns = n + 1) {
sz = ns;
fill(v, v + sz + sz, inf);
}
void mo(int i, int val) { v[i] = min(v[i], val); }
int query(int i) {
int res = inf;
for (i += sz; i; i >>= 1)
res = min(res, v[i]);
return res;
}
void modify(int l, int r, int val) {
l += sz, r += sz;
for (; l < r; l >>= 1, r >>= 1) {
if (l & 1)
mo(l++, val);
if (r & 1)
mo(--r, val);
}
}
} tree;
// [u, len]
vector<pair<int, int>> edge[maxm];
map<pair<int, int>, int> Findnxt;
int create(int x, int y) {
if (id.count({x, y}))
return id[{x, y}];
assert(cnt < maxm);
to_loc[cnt] = {x, y};
return id[{x, y}] = cnt++;
}
vector<int> start;
void precal() {
tree.init(m);
tree.modify(0, m, n);
for (int i = n - 1; i >= 0; --i) {
if (rb[i] + 1 < m)
Findnxt[{i, rb[i] + 1}] = tree.query(rb[i] + 1);
tree.modify(lb[i], rb[i] + 1, i);
}
for (int i = 0; i < m; ++i)
if (i < lb[0] || i > rb[0])
Findnxt[{0, i}] = tree.query(i);
}
void build(int t) {
int x = 0, y = t, h = 0, now = create(x, y);
start.pb(now);
// DE(t, '\n');
while (x < n) {
// DE(x, ' '), DE(y, '\n');
// case one : go horizontal
int nx, ny;
if (y <= rb[x] && y >= lb[x])
nx = x, ny = rb[x] + 1;
else
assert(x == 0 || y == rb[x] + 1), assert(Findnxt.count({x, y})),
nx = Findnxt[{x, y}], ny = y;
// cerr << "X Y " << x << ' ' << y << '\n';
// cerr << "NX NY " << nx << ' ' << ny << '\n';
if (nx == x) {
if (ny >= m) {
// cerr << "No chance\n";
break;
}
int nxt = create(nx, rb[x] + 1);
edge[now].pb(nxt, rb[x] + 1 - y);
now = nxt, y = rb[x] + 1;
continue;
}
// case zero : go free
if (nx == n) {
edge[now].pb(create(nx, ny), 0);
break;
}
// case two : meet already exist
if (id.count({nx, ny})) {
// cerr << "Existed\n";
edge[now].pb(id[{nx, ny}], 0);
break;
}
// case three : meet not exist
int nxt = create(nx, ny);
edge[now].pb(nxt, 0);
now = nxt, x = nx;
}
// cerr << "Finish\n";
}
struct info {
int now, len;
bool operator()(const info &a, const info &b) const { return a.len > b.len; }
};
void dij() {
tree.init();
fill(dp, dp + cnt, inf);
priority_queue<info, vector<info>, info> pq;
for (int id : start) {
dp[id] = 0;
pq.push({id, 0});
}
while (pq.size()) {
auto [now, len] = pq.top();
pq.pop();
if (vis[now])
continue;
vis[now] = true;
auto [x, y] = to_loc[now];
// cerr << "X Y waste " << x << ' ' << y << ' ' << len << '\n';
for (auto [u, w] : edge[now]) {
auto [nx, ny] = to_loc[u];
tree.modify(x, nx + 1, len);
if (len + w < dp[u]) {
dp[u] = len + w;
pq.push({u, len + w});
}
}
}
for (int i = 1; i <= n; ++i) {
res[i] = tree.query(i);
if (res[i] == inf)
res[i] = -1;
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> lb[i] >> rb[i], --lb[i], --rb[i];
precal();
for (int i = 0; i < m; ++i)
build(i);
dij();
for (int i = 1; i <= n; ++i) {
// cout << res[i] << '\n';
if (res[i] == -1)
cout << -1 << '\n';
else
cout << res[i] + i << '\n';
}
}
| replace | 151 | 152 | 151 | 152 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.