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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02730 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
string s, a, b;
int n, mid;
bool pal(string a) {
string b = a;
reverse(b.begin(), b.end());
if (b == a)
return true;
else
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> s;
n = s.length();
mid = n / 2;
a = s.substr(0, mid);
b = s.substr(mid + 1);
if (pal(s) and pal(a) and pal(b))
cout << "Yes";
else
cout << "No";
}
| #include <bits/stdc++.h>
using namespace std;
string s, a, b;
int n, mid;
bool pal(string a) {
string b = a;
reverse(b.begin(), b.end());
if (b == a)
return true;
else
return false;
}
int main() {
cin >> s;
n = s.length();
mid = n / 2;
a = s.substr(0, mid);
b = s.substr(mid + 1);
if (pal(s) and pal(a) and pal(b))
cout << "Yes";
else
cout << "No";
}
| delete | 16 | 22 | 16 | 16 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr: __pos (which is 1) > this->size() (which is 0)
|
p02730 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz \
ios::sync_with_stdio(0); \
cin.tie(0); \
ios_base::sync_with_stdio(0);
#define f(a, b, c) for (int a = b; a < c; a++)
using namespace std;
const ll mod = 1e9 + 7;
// ll fact[1000001]; ll inv[1000001];
// ll primes[100007];
// ll arr[1000007];
// ll modPower(ll b, ll p) {
// if (p == 0)
// return 1;
//
// ll halfpow = modPower(b, p / 2);
// ll toReturn = (halfpow * halfpow) % mod;
// if (p % 2)
// toReturn = (toReturn * b) % mod;
//
// return toReturn;
// }
//
// ll fastPower(ll b, ll p) {
// if (p == 0)
// return 1;
// ll ans = fastPower(b, p / 2);
// ans = (ans * ans);
// if (p % 2 != 0)
// ans = (ans * b);
// return ans;
// }
// ll GcdRecursive(ll a, ll b) {
// if (b == 0) return a;
// return GcdRecursive(b, a % b);
// }
// ll modLCM(ll a, ll b) {
// ll val = GcdRecursive(a, b);
// ll tmp = ((a % mod) * (b % mod)) % mod;
// ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
// return finalVal;
//
// }
// ll LCM(ll a, ll b) {
// return (a * b) / GcdRecursive(a, b);
// }
// void move1step(ll& a, ll& b, ll q) { // a and b by reference
// ll c = a - q * b;
// a = b;
// b = c;
// }
// ll GcdIterative(ll a, ll b) {
// while (b) move1step(a, b, a / b);
// return a;
// }
//
// void pre(ll n) {
//
// fact[0] = 1;
// inv[0] = 1;
//
// for (ll i = 1; i <= n; i++) {
// fact[i] = (i * fact[i - 1]) % mod;
// inv[i] = modPower(fact[i], mod - 2);
// arr[i] = modPower(i, mod - 2);
// }
// }
//
// ll npr(ll n, ll r) {
// return ((fact[n] * inv[n - r]) % mod);
// }
//
// ll ncr(ll n, ll r) {
// return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
// }
//
// void sieve(ll val) {
// memset(primes, 1, sizeof primes);
// primes[0] = primes[1] = false;
// for (int i = 2; i <= val; i++) {
// if (primes[i]) {
// for (int j = i * i; j <= val; j += i) {
// primes[j] = 0;
// }
// }
// }
//
// }
bool checkPalindrome(string s) {
f(i, 0, s.size() / 2) {
if (s[i] != s[s.size() - i - 1])
return false;
}
return true;
}
int main() {
MohamedMotaz;
string s;
cin >> s;
if (s.size() == 1)
return cout << "Yes", 0;
if (checkPalindrome(s) && checkPalindrome(s.substr(0, (s.size() - 1) / 2)) &&
checkPalindrome(s.substr((s.size() + 3) / 2 + 1, s.size())))
cout << "Yes";
else
cout << "No";
}
| #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz \
ios::sync_with_stdio(0); \
cin.tie(0); \
ios_base::sync_with_stdio(0);
#define f(a, b, c) for (int a = b; a < c; a++)
using namespace std;
const ll mod = 1e9 + 7;
// ll fact[1000001]; ll inv[1000001];
// ll primes[100007];
// ll arr[1000007];
// ll modPower(ll b, ll p) {
// if (p == 0)
// return 1;
//
// ll halfpow = modPower(b, p / 2);
// ll toReturn = (halfpow * halfpow) % mod;
// if (p % 2)
// toReturn = (toReturn * b) % mod;
//
// return toReturn;
// }
//
// ll fastPower(ll b, ll p) {
// if (p == 0)
// return 1;
// ll ans = fastPower(b, p / 2);
// ans = (ans * ans);
// if (p % 2 != 0)
// ans = (ans * b);
// return ans;
// }
// ll GcdRecursive(ll a, ll b) {
// if (b == 0) return a;
// return GcdRecursive(b, a % b);
// }
// ll modLCM(ll a, ll b) {
// ll val = GcdRecursive(a, b);
// ll tmp = ((a % mod) * (b % mod)) % mod;
// ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
// return finalVal;
//
// }
// ll LCM(ll a, ll b) {
// return (a * b) / GcdRecursive(a, b);
// }
// void move1step(ll& a, ll& b, ll q) { // a and b by reference
// ll c = a - q * b;
// a = b;
// b = c;
// }
// ll GcdIterative(ll a, ll b) {
// while (b) move1step(a, b, a / b);
// return a;
// }
//
// void pre(ll n) {
//
// fact[0] = 1;
// inv[0] = 1;
//
// for (ll i = 1; i <= n; i++) {
// fact[i] = (i * fact[i - 1]) % mod;
// inv[i] = modPower(fact[i], mod - 2);
// arr[i] = modPower(i, mod - 2);
// }
// }
//
// ll npr(ll n, ll r) {
// return ((fact[n] * inv[n - r]) % mod);
// }
//
// ll ncr(ll n, ll r) {
// return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
// }
//
// void sieve(ll val) {
// memset(primes, 1, sizeof primes);
// primes[0] = primes[1] = false;
// for (int i = 2; i <= val; i++) {
// if (primes[i]) {
// for (int j = i * i; j <= val; j += i) {
// primes[j] = 0;
// }
// }
// }
//
// }
bool checkPalindrome(string s) {
f(i, 0, s.size() / 2) {
if (s[i] != s[s.size() - i - 1])
return false;
}
return true;
}
int main() {
MohamedMotaz;
string s;
cin >> s;
if (s.size() == 1)
return cout << "Yes", 0;
if (checkPalindrome(s) && checkPalindrome(s.substr(0, (s.size() - 1) / 2)))
cout << "Yes";
else
cout << "No";
}
| replace | 111 | 113 | 111 | 112 | 0 | |
p02730 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
bool ispal(string s) {
int n = s.length();
for (int i = 0; i < n / 2; i++) {
if (s[i] != s[n - 1 - i])
return false;
}
return true;
}
int main() {
string S;
cin >> S;
int N = S.length();
if (ispal(S) && ispal(S.substr(0, (N - 1) / 2)) &&
ispal(S.substr((N + 3) / 2 + 1, (N - 3) / 2 + 1)))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
bool ispal(string s) {
int n = s.length();
for (int i = 0; i < n / 2; i++) {
if (s[i] != s[n - 1 - i])
return false;
}
return true;
}
int main() {
string S;
cin >> S;
int N = S.length();
if (ispal(S) && ispal(S.substr(0, (N - 1) / 2)) &&
ispal(S.substr((N + 3) / 2 - 1, (N - 3) / 2 + 1)))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p02730 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
bool isPalin(string S) {
for (int i = 0; i < S.length(); i++) {
if (S[i] != S[S.length() - i - 1]) {
return false;
}
}
return true;
}
int main(void) {
string S;
cin >> S;
int N = S.length();
bool strongPalindrome = true;
// 1st condition
if (!isPalin(S)) {
cout << "No" << endl;
return 0;
}
// 2nd condition
if (!isPalin(S.substr(0, (N - 1) / 2))) {
cout << "No" << endl;
return 0;
}
// 3rd condition
if (!isPalin(S.substr((N + 3) / 2 + 1))) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
bool isPalin(string S) {
for (int i = 0; i < S.length(); i++) {
if (S[i] != S[S.length() - i - 1]) {
return false;
}
}
return true;
}
int main(void) {
string S;
cin >> S;
int N = S.length();
bool strongPalindrome = true;
// 1st condition
if (!isPalin(S)) {
cout << "No" << endl;
return 0;
}
// 2nd condition
if (!isPalin(S.substr(0, (N - 1) / 2))) {
cout << "No" << endl;
return 0;
}
// 3rd condition
if (!isPalin(S.substr((N + 3) / 2 - 1))) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p02730 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define loop for (int i = 0; i < n; i++)
using namespace std;
string reverese(string n) {
string st = "";
for (int i = n.length() - 1; i >= 0; i--)
st += n[i];
return st;
}
int main() {
string k;
cin >> k;
int flag = 1;
int n = k.length();
if (n % 2 == 0)
flag = 1;
else if ((k.substr(0, n / 2) == reverese(k.substr(0, n / 2))) and
(k.substr(((n + 3) / 2) + 1, n) ==
reverese(k.substr((((n + 3) / 2) + 1), n))))
flag = 2;
if (flag == 2)
puts("Yes");
else
puts("No");
} | #include <bits/stdc++.h>
#define ll long long int
#define loop for (int i = 0; i < n; i++)
using namespace std;
string reverese(string n) {
string st = "";
for (int i = n.length() - 1; i >= 0; i--)
st += n[i];
return st;
}
int main() {
string k;
cin >> k;
int flag = 1;
int n = k.length();
if ((k.substr(0, n / 2) == reverese(k.substr(0, n / 2))) and
(k.substr(((n + 3) / 2) - 1, n - 1) ==
reverese(k.substr((((n + 3) / 2) - 1), n - 1))))
if (k == reverese(k))
flag = 2;
if (flag == 2)
puts("Yes");
else
puts("No");
} | replace | 15 | 21 | 15 | 20 | 0 | |
p02730 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
bool KBjudge(string x) {
string x_ = x;
reverse(x.begin(), x.end());
return (x_ == x);
}
int main() {
string S;
cin >> S;
int N = S.size();
if (KBjudge(S.substr(0, S.size()))) {
if (KBjudge(S.substr(0, (N - 1) / 2))) {
if (KBjudge(S.substr((N + 3) / 2 + 1, N - (N + 3) / 2))) {
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
bool KBjudge(string x) {
string x_ = x;
reverse(x.begin(), x.end());
return (x_ == x);
}
int main() {
string S;
cin >> S;
int N = S.size();
if (KBjudge(S.substr(0, S.size()))) {
if (KBjudge(S.substr(0, (N - 1) / 2))) {
if (KBjudge(S.substr((N + 3) / 2 - 1, N - (N + 3) / 2 + 2))) {
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02730 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)
int main() {
string s;
cin >> s;
for (int i = 0; i < s.length() / 2; ++i) {
if (s[i] != s[s.length() - i - 1]) {
cout << "No";
return 0;
}
}
int n = s.length();
string t(s.c_str(), s.c_str() + (n - 1) / 2);
for (int i = 0; i < t.length() / 2; ++i) {
if (t[i] != t[t.length() - i - 1]) {
cout << "No";
return 0;
}
}
string u(s.c_str() + (n + 3) / 2, s.c_str() - 1 + s.length());
for (int i = 0; i < u.length() / 2; ++i) {
if (u[i] != u[u.length() - i - 1]) {
cout << "No";
return 0;
}
}
cout << "Yes";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)
int main() {
string s;
cin >> s;
for (int i = 0; i < s.length() / 2; ++i) {
if (s[i] != s[s.length() - i - 1]) {
cout << "No";
return 0;
}
}
if (s.length() == 3) {
cout << "Yes";
return 0;
}
int n = s.length();
string t(s.c_str(), s.c_str() + (n - 1) / 2);
for (int i = 0; i < t.length() / 2; ++i) {
if (t[i] != t[t.length() - i - 1]) {
cout << "No";
return 0;
}
}
string u(s.c_str() + (n + 3) / 2, s.c_str() - 1 + s.length());
for (int i = 0; i < u.length() / 2; ++i) {
if (u[i] != u[u.length() - i - 1]) {
cout << "No";
return 0;
}
}
cout << "Yes";
return 0;
} | insert | 15 | 15 | 15 | 19 | 0 | |
p02730 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int N;
N = S.size();
int res = 0;
int check = 0;
for (int i = 0; i < N; i++) {
if (S.at(i) == S.at(N - 1 - i)) {
check = check + 0;
} else {
check = check + 1;
}
}
if (check == 0) {
res = res + 1;
}
int M = (N - 1) / 2;
int chec = 0;
for (int i = 0; i < M; i++) {
if (S.at(i) == S.at(M - 1 - i)) {
chec = chec + 0;
} else {
chec = chec + 1;
}
}
if (chec == 0) {
res = res + 1;
}
int L = (N + 3) / 2;
int che = 0;
for (int i = 0; i < L; i++) {
if (S.at(L + i) == S.at(N - 1 - i)) {
che = che + 0;
} else {
che = che + 1;
}
}
if (che == 0) {
res = res + 1;
}
if (res == 3) {
cout << "Yes";
}
if (res < 3) {
cout << "No";
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int N;
N = S.size();
int res = 0;
int check = 0;
for (int i = 0; i < N; i++) {
if (S.at(i) == S.at(N - 1 - i)) {
check = check + 0;
} else {
check = check + 1;
}
}
if (check == 0) {
res = res + 1;
}
int M = (N - 1) / 2;
int chec = 0;
for (int i = 0; i < M; i++) {
if (S.at(i) == S.at(M - 1 - i)) {
chec = chec + 0;
} else {
chec = chec + 1;
}
}
if (chec == 0) {
res = res + 1;
}
int L = (N + 3) / 2;
int che = 0;
for (int i = 0; i < N - L; i++) {
if (S.at(L + i - 1) == S.at(N - 1 - i)) {
che = che + 0;
} else {
che = che + 1;
}
}
if (che == 0) {
res = res + 1;
}
if (res == 3) {
cout << "Yes";
}
if (res < 3) {
cout << "No";
}
}
| replace | 34 | 36 | 34 | 36 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 7) >= this->size() (which is 7)
|
p02730 | C++ | Runtime Error | #include <algorithm>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(), s.end())
#define reverse(v) reverse(v.begin(), v.end());
#define Yes(ans) \
if (ans) \
cout << "Yes" << endl; \
else \
cout << "No" << endl;
#define YES(ans) \
if (ans) \
cout << "YES" << endl; \
else \
cout << "NO" << endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF UnionFind
#define rt0 return 0
constexpr auto mod = 1000000007;
// 辞書順はnext_permutation( begin( v ), end( v ) );やで!
// 2のn乗を求めるよ!!!
int ni(int n) {
if (n == 0)
return 1;
int x = ni(n / 2);
x *= x;
if (n % 2 == 1)
x *= 2;
return x;
}
// フィボナッチ数列のx番目を求めるよ!
llint f(int x, vector<llint> &s) {
if (x == 0)
return 0;
if (x == 1)
return 1;
if (s[x] != 0)
return s[x];
return s[x] = f(x - 1, s) + f(x - 2, s);
}
// aとbの最大公約数を求めるよ!
llint gcd(llint a, llint b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
return gcd(b, a % b);
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// mod. m での a の逆元 a^{-1} を計算するよ!
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
// aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
ll int ans = 1;
for (ll int i = 0; i < b; i++) {
ans *= a - i;
ans %= m;
}
for (ll int i = 1; i <= b; i++) {
ans *= modinv(i, m);
ans %= m;
}
return ans;
}
// m進数のn桁を全列挙やで
void dfs(int m, int n, int k, hei(int) a) {
stack<string> st;
st.push("");
while (!st.empty()) {
string now = st.top();
st.pop();
if (now.size() == n) {
cout << now << endl;
} else {
for (int i = m - 1; i >= 0; i--) {
string next = now + to_string(i);
st.push(next);
}
}
}
}
void press(vector<int> &v) { v.erase(unique((v).begin(), (v).end()), v.end()); }
void press(vector<char> &v) {
v.erase(unique((v).begin(), (v).end()), v.end());
}
llint min(llint a, llint b) {
if (a < b)
return a;
return b;
}
llint max(llint a, llint b) {
if (a < b)
swap(a, b);
return a;
}
llint p(int n) {
if (n == 1)
return 1;
return n * p(n - 1);
}
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化
for (int i = 0; i < N; i++)
par[i] = i;
}
int size(int a) { return par[root(a)]; }
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main() {
string s;
int ans = 0;
cin >> s;
string s1 = "", s2 = "";
rep(i, 0, s.size()) { s1 += s[s.size() - 1 - i]; }
if (s == s1)
ans++;
s1 = s.substr(0, (s.size() - 1) / 2);
rep(i, 0, s1.size()) { s2 += s1[s1.size() - 1 - i]; }
if (s1 == s2)
ans++;
s1 = s.substr(((s.size() + 3) / 2) + 1, s.size());
s2 = "";
rep(i, 0, s1.size()) { s2 += s1[s1.size() - 1 - i]; }
if (s1 == s2)
ans++;
Yes(ans == 3);
return 0;
} | #include <algorithm>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(), s.end())
#define reverse(v) reverse(v.begin(), v.end());
#define Yes(ans) \
if (ans) \
cout << "Yes" << endl; \
else \
cout << "No" << endl;
#define YES(ans) \
if (ans) \
cout << "YES" << endl; \
else \
cout << "NO" << endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF UnionFind
#define rt0 return 0
constexpr auto mod = 1000000007;
// 辞書順はnext_permutation( begin( v ), end( v ) );やで!
// 2のn乗を求めるよ!!!
int ni(int n) {
if (n == 0)
return 1;
int x = ni(n / 2);
x *= x;
if (n % 2 == 1)
x *= 2;
return x;
}
// フィボナッチ数列のx番目を求めるよ!
llint f(int x, vector<llint> &s) {
if (x == 0)
return 0;
if (x == 1)
return 1;
if (s[x] != 0)
return s[x];
return s[x] = f(x - 1, s) + f(x - 2, s);
}
// aとbの最大公約数を求めるよ!
llint gcd(llint a, llint b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
return gcd(b, a % b);
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// mod. m での a の逆元 a^{-1} を計算するよ!
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
// aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
ll int ans = 1;
for (ll int i = 0; i < b; i++) {
ans *= a - i;
ans %= m;
}
for (ll int i = 1; i <= b; i++) {
ans *= modinv(i, m);
ans %= m;
}
return ans;
}
// m進数のn桁を全列挙やで
void dfs(int m, int n, int k, hei(int) a) {
stack<string> st;
st.push("");
while (!st.empty()) {
string now = st.top();
st.pop();
if (now.size() == n) {
cout << now << endl;
} else {
for (int i = m - 1; i >= 0; i--) {
string next = now + to_string(i);
st.push(next);
}
}
}
}
void press(vector<int> &v) { v.erase(unique((v).begin(), (v).end()), v.end()); }
void press(vector<char> &v) {
v.erase(unique((v).begin(), (v).end()), v.end());
}
llint min(llint a, llint b) {
if (a < b)
return a;
return b;
}
llint max(llint a, llint b) {
if (a < b)
swap(a, b);
return a;
}
llint p(int n) {
if (n == 1)
return 1;
return n * p(n - 1);
}
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化
for (int i = 0; i < N; i++)
par[i] = i;
}
int size(int a) { return par[root(a)]; }
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
int main() {
string s;
int ans = 0;
cin >> s;
string s1 = "", s2 = "";
rep(i, 0, s.size()) { s1 += s[s.size() - 1 - i]; }
if (s == s1)
ans++;
s1 = s.substr(0, (s.size() - 1) / 2);
rep(i, 0, s1.size()) { s2 += s1[s1.size() - 1 - i]; }
if (s1 == s2)
ans++;
s1 = s.substr(((s.size() + 3) / 2) - 1, s.size());
s2 = "";
rep(i, 0, s1.size()) { s2 += s1[s1.size() - 1 - i]; }
if (s1 == s2)
ans++;
Yes(ans == 3);
return 0;
} | replace | 191 | 192 | 191 | 192 | 0 | |
p02731 | C++ | Runtime Error | //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//* vamsicool007 You are never wrong to do the right thing vamsicool007 *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#include <bits/stdc++.h>
using namespace std;
#define flash \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int N = 200005;
vector<int> vis(N);
vector<vector<int>> adj(N);
void dfs(int v) {
vis[v] = 1;
for (auto i : adj[v]) {
if (!vis[i]) {
dfs(i);
}
}
return;
}
bool isPrime(ll n) {
if (n < 2)
return false;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
return false;
}
}
return true;
}
ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); }
ll power(ll x, ll y) {
ll res = 1;
x = x;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res % mod;
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll max(ll a, ll b) {
ll ans = a > b ? a : b;
return ans;
}
ll min(ll a, ll b) {
ll ans = a < b ? a : b;
return ans;
}
int root(int a[], int i) {
while (a[i] != i) {
a[i] = a[a[i]];
i = a[i];
}
return i;
}
void unionn(int a[], int i, int j) {
int root_i = root(a, i);
int root_j = root(a, j);
a[root_i] = root_j;
return;
}
void fun() {
#ifndef ONLINE_JUDGE
freopen("infile.txt", "r", stdin);
freopen("oufile.txt", "w", stdout);
#endif
}
int fact(int n) {
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }
// Returns factorial of n
signed main() {
flash;
fun();
int t = 1;
// cin>>t;
while (t--) {
double l;
cin >> l;
l = l / 3;
l = l * l * l;
cout << setprecision(20) << l;
}
return 0;
} | //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//* vamsicool007 You are never wrong to do the right thing vamsicool007 *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#include <bits/stdc++.h>
using namespace std;
#define flash \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int N = 200005;
vector<int> vis(N);
vector<vector<int>> adj(N);
void dfs(int v) {
vis[v] = 1;
for (auto i : adj[v]) {
if (!vis[i]) {
dfs(i);
}
}
return;
}
bool isPrime(ll n) {
if (n < 2)
return false;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
return false;
}
}
return true;
}
ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); }
ll power(ll x, ll y) {
ll res = 1;
x = x;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res % mod;
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }
ll max(ll a, ll b) {
ll ans = a > b ? a : b;
return ans;
}
ll min(ll a, ll b) {
ll ans = a < b ? a : b;
return ans;
}
int root(int a[], int i) {
while (a[i] != i) {
a[i] = a[a[i]];
i = a[i];
}
return i;
}
void unionn(int a[], int i, int j) {
int root_i = root(a, i);
int root_j = root(a, j);
a[root_i] = root_j;
return;
}
void fun() {
#ifndef ONLINE_JUDGE
freopen("infile.txt", "r", stdin);
freopen("oufile.txt", "w", stdout);
#endif
}
int fact(int n) {
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }
// Returns factorial of n
signed main() {
flash;
// fun();
int t = 1;
// cin>>t;
while (t--) {
double l;
cin >> l;
l = l / 3;
l = l * l * l;
cout << setprecision(20) << l;
}
return 0;
} | replace | 99 | 100 | 99 | 100 | 0 | |
p02731 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int L;
cin >> L;
vector<double> p;
for (int i = 1; i < L - 1; i++) {
p.push_back((double)i * (L - i) * (L - i) / 4);
}
sort(p.begin(), p.end());
reverse(p.begin(), p.end());
cout << p.at(0) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int L;
cin >> L;
cout << fixed << setprecision(10) << (double)L * L * L / 27 << endl;
return 0;
}
| replace | 5 | 12 | 5 | 6 | 0 | |
p02731 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define mod 1e9 + 7;
#define INF 1e9 + 9;
#define ps(x, y) fixed << setprecision(y) << x
#define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int l;
cin >> l;
l = l * l * l;
double bb = (double)l / 27;
cout << ps(bb, 12) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mod 1e9 + 7;
#define INF 1e9 + 9;
#define ps(x, y) fixed << setprecision(y) << x
#define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
int l;
cin >> l;
l = l * l * l;
double bb = (double)l / 27;
cout << ps(bb, 12) << endl;
return 0;
} | replace | 14 | 16 | 14 | 16 | 0 | |
p02731 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int l;
int ans = 0;
for (int i = 1; i <= l; i++) {
int a = i;
for (int j = 1; j <= l; j++) {
int b = j;
int c = l - a - b;
if (c > 0) {
ans = max(ans, a * b * c);
}
}
}
cout << ans << "\n";
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
double l;
cin >> l;
double m = l / 3;
double ans = m * m * m;
printf("%.12f\n", ans);
return 0;
} | replace | 5 | 18 | 5 | 10 | TLE | |
p02731 | C++ | Runtime Error | // AnkitCode99 here....
// every ups and downs matter!
#include <bits/stdc++.h>
#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define pll pair<ll, ll>
#define pb push_back
// max xor btw range of two numbers..
#define max_XOR(a, b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(), v.end()
#define Ryuga \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define rep(i, a, b) for (long long int i = a; i < b; i++)
#define nrep(i, a, b) for (long long int i = a; i >= b; i--)
#define ceil(a, b) a / b + ((a % b == 0) ? 0 : 1)
using namespace std;
const ll sz = 100005;
const ll szz = 1000006;
int main() {
Ryuga;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("op.txt", "w", stdout);
#endif
ll L;
cin >> L;
cout << fixed << setprecision(12) << (L * L * L) / 27.0;
} // Goodbye... | // AnkitCode99 here....
// every ups and downs matter!
#include <bits/stdc++.h>
#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define pll pair<ll, ll>
#define pb push_back
// max xor btw range of two numbers..
#define max_XOR(a, b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(), v.end()
#define Ryuga \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define rep(i, a, b) for (long long int i = a; i < b; i++)
#define nrep(i, a, b) for (long long int i = a; i >= b; i--)
#define ceil(a, b) a / b + ((a % b == 0) ? 0 : 1)
using namespace std;
const ll sz = 100005;
const ll szz = 1000006;
int main() {
Ryuga;
ll L;
cin >> L;
cout << fixed << setprecision(12) << (L * L * L) / 27.0;
} // Goodbye... | delete | 31 | 36 | 31 | 31 | 0 | |
p02731 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
double l;
cin >> l;
double maxi = 0;
for (double i = 0; i <= l / 3; i += 0.001) {
for (double j = 0; j <= (l - i) / 2; j += 0.001) {
maxi = max(maxi, i * j * (l - i - j));
}
}
cout << maxi << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
double l;
cin >> l;
printf("%.12f\n", pow(l / 3, 3.0));
} | replace | 6 | 13 | 6 | 7 | TLE | |
p02731 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int // ranges from (0 - twice of long long int)
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define per(i, a, n) for (ll i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define mod 1000000007LL
#define llpair pair<ll, ll>
#define INF 1000000000000000000ll
#define np next_permutation
#define PI acos(-1)
#define deb(x) cout << #x << " " << x << endl;
// ALWAYS USE ll DATA TYPE FOR INTEGER(FASTER THAN INTEGER AS WELL AS SOMETIMES
// WITHOUT USE LONG UR ANSWER WILL NOT ACCEPTED) && DOUBLE FOR DECIMAL VALUE
template <typename T> // for removing front element from the vector
void pop_front(std::vector<T> &v) {
if (v.size() > 0) {
v.erase(v.begin());
}
}
template <
typename R> // for removing back element from the vector or can directly
void pop_back(std::vector<R> &v) // use vec.pop_back() function...
{
if (v.size() > 0) {
v.erase(v.begin() + v.size() - 1);
}
}
bool isprime(ll n) // IN O(sqrt(n))
{
if (n <= 1)
return false;
for (ll i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
vector<ll> factors(ll n) { // IN O(sqrt(n))
vll v;
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
v.pb(i);
if ((n / i) != i)
v.pb(n / i);
}
}
return v;
}
ll power(ll a, ll n) // using Binary Exponential in TC O(logn)
{ // Self Written By </ME> :)
ll res = 1;
while (1) {
if (n % 2) {
res = res * a;
n--;
}
if (n == 0)
break;
a = a * a;
n /= 2;
}
return res;
}
ll ts(ll arr[], int l, int r,
int x) // ternary search to find x in sorted array arr
{
while (l <= r) {
ll mid1 = l + (r - l) / 3;
ll mid2 = r - (r - l) / 3;
if (arr[mid1] == x || arr[mid2] == x)
return 1;
if (x < arr[mid1])
r = mid1 - 1;
else if (x > arr[mid2])
l = mid2 + 1;
else {
l = mid1 + 1;
r = mid2 - 1;
}
}
return -1;
}
bool f(string s, ll start, ll end) {
while (start <= end) {
if (s[start] != s[end])
return false;
start++;
end--;
}
return true;
}
int main() {
auto start = chrono::high_resolution_clock::now();
fio;
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
ll T = 1;
// cin>>T;
while (T--) {
double n;
cin >> n;
n = n / 3;
n = n * n * n;
cout << fixed << setprecision(12) << n;
}
auto finish = chrono::high_resolution_clock::now();
cerr << "Time elapsed: "
<< (chrono::duration<long double>(finish - start)).count() << "s\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int // ranges from (0 - twice of long long int)
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define per(i, a, n) for (ll i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define mod 1000000007LL
#define llpair pair<ll, ll>
#define INF 1000000000000000000ll
#define np next_permutation
#define PI acos(-1)
#define deb(x) cout << #x << " " << x << endl;
// ALWAYS USE ll DATA TYPE FOR INTEGER(FASTER THAN INTEGER AS WELL AS SOMETIMES
// WITHOUT USE LONG UR ANSWER WILL NOT ACCEPTED) && DOUBLE FOR DECIMAL VALUE
template <typename T> // for removing front element from the vector
void pop_front(std::vector<T> &v) {
if (v.size() > 0) {
v.erase(v.begin());
}
}
template <
typename R> // for removing back element from the vector or can directly
void pop_back(std::vector<R> &v) // use vec.pop_back() function...
{
if (v.size() > 0) {
v.erase(v.begin() + v.size() - 1);
}
}
bool isprime(ll n) // IN O(sqrt(n))
{
if (n <= 1)
return false;
for (ll i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
vector<ll> factors(ll n) { // IN O(sqrt(n))
vll v;
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
v.pb(i);
if ((n / i) != i)
v.pb(n / i);
}
}
return v;
}
ll power(ll a, ll n) // using Binary Exponential in TC O(logn)
{ // Self Written By </ME> :)
ll res = 1;
while (1) {
if (n % 2) {
res = res * a;
n--;
}
if (n == 0)
break;
a = a * a;
n /= 2;
}
return res;
}
ll ts(ll arr[], int l, int r,
int x) // ternary search to find x in sorted array arr
{
while (l <= r) {
ll mid1 = l + (r - l) / 3;
ll mid2 = r - (r - l) / 3;
if (arr[mid1] == x || arr[mid2] == x)
return 1;
if (x < arr[mid1])
r = mid1 - 1;
else if (x > arr[mid2])
l = mid2 + 1;
else {
l = mid1 + 1;
r = mid2 - 1;
}
}
return -1;
}
bool f(string s, ll start, ll end) {
while (start <= end) {
if (s[start] != s[end])
return false;
start++;
end--;
}
return true;
}
int main() {
auto start = chrono::high_resolution_clock::now();
fio;
ll T = 1;
// cin>>T;
while (T--) {
double n;
cin >> n;
n = n / 3;
n = n * n * n;
cout << fixed << setprecision(12) << n;
}
auto finish = chrono::high_resolution_clock::now();
cerr << "Time elapsed: "
<< (chrono::duration<long double>(finish - start)).count() << "s\n";
return 0;
}
| delete | 115 | 121 | 115 | 115 | 0 | Time elapsed: 0.000317968s
|
p02731 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vppll vector<pair<pll, pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll, ll>
#define fir first
#define sec second
#define _cin \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define fo(i, b) for (i = 0; i < b; i++)
#define repa(i, a, b) for (i = a; i < b; i++)
#define repb(i, a, b) for (i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18 + 1);
const long long int MIN = (ll)(-1e18 - 1);
const long long int mod = (ll)(1e9 + 7);
using namespace std;
ll max(ll a, ll b, ll c) { return max(max(a, b), c); }
ll min(ll a, ll b, ll c) { return min(min(a, b), c); }
ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
ll power(ll a, ll n) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
ll power_mod(ll a, ll n, ll mod_) {
ll p = 1;
while (n) {
if (n % 2) {
p = (p * a) % mod_;
}
n /= 2;
a = (a * a) % mod_;
}
return p % mod_;
}
/*Code Begins*/
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
_cin;
cout << setprecision(15);
ll mn = MAX, mx = MIN;
ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0;
ll x = 0, y = 0, fx, diff, tot = 0, l, r;
int TC = 1;
// cin >> TC;
while (TC--) {
cin >> n;
double d = (double)(n / 3.0);
double vol = d * d * d;
cout << vol;
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vppll vector<pair<pll, pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll, ll>
#define fir first
#define sec second
#define _cin \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define fo(i, b) for (i = 0; i < b; i++)
#define repa(i, a, b) for (i = a; i < b; i++)
#define repb(i, a, b) for (i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18 + 1);
const long long int MIN = (ll)(-1e18 - 1);
const long long int mod = (ll)(1e9 + 7);
using namespace std;
ll max(ll a, ll b, ll c) { return max(max(a, b), c); }
ll min(ll a, ll b, ll c) { return min(min(a, b), c); }
ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
ll power(ll a, ll n) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
ll power_mod(ll a, ll n, ll mod_) {
ll p = 1;
while (n) {
if (n % 2) {
p = (p * a) % mod_;
}
n /= 2;
a = (a * a) % mod_;
}
return p % mod_;
}
/*Code Begins*/
int main() {
_cin;
cout << setprecision(15);
ll mn = MAX, mx = MIN;
ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0;
ll x = 0, y = 0, fx, diff, tot = 0, l, r;
int TC = 1;
// cin >> TC;
while (TC--) {
cin >> n;
double d = (double)(n / 3.0);
double vol = d * d * d;
cout << vol;
}
return 0;
}
| replace | 55 | 60 | 55 | 56 | 0 | |
p02731 | Python | Runtime Error | f = int(input()) / 3.0
print("{.9f}".format(f * f * f))
| f = int(input()) / 3.0
print("{:.9f}".format(f * f * f))
| replace | 1 | 2 | 1 | 2 | AttributeError: 'float' object has no attribute '9f' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02731/Python/s178614375.py", line 2, in <module>
print("{.9f}".format(f * f * f))
AttributeError: 'float' object has no attribute '9f'
|
p02731 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 101010
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld", &s);
#define sout(s) printf("%lld\n", s);
#define in(s) cin >> s
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define vll vector<ll>
#define out(s) cout << s
#define outs(s, a) cout << s << a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define nfl(i, n) for (i = 0; i < n; i++)
#define sfl(i, s, e) for (i = s; i < e; i++)
#define ufl(i, n) for (i = n - 1; i >= 0; i--)
void solve() {
ld n;
in(n);
ld div = n / 3.0;
ld rem = n - 2 * div;
cout << fixed << setprecision(10) << rem * div * div << '\n';
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
clock_t t1 = clock();
gear_change;
ll test = 1;
// in(test);
while (test--) {
solve();
}
clock_t t2 = clock();
cerr << "Time elapsed:- " << (double)(t2 - t1) / CLOCKS_PER_SEC << '\n';
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 101010
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld", &s);
#define sout(s) printf("%lld\n", s);
#define in(s) cin >> s
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define vll vector<ll>
#define out(s) cout << s
#define outs(s, a) cout << s << a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define nfl(i, n) for (i = 0; i < n; i++)
#define sfl(i, s, e) for (i = s; i < e; i++)
#define ufl(i, n) for (i = n - 1; i >= 0; i--)
void solve() {
ld n;
in(n);
ld div = n / 3.0;
ld rem = n - 2 * div;
cout << fixed << setprecision(10) << rem * div * div << '\n';
}
int main() {
clock_t t1 = clock();
gear_change;
ll test = 1;
// in(test);
while (test--) {
solve();
}
clock_t t2 = clock();
cerr << "Time elapsed:- " << (double)(t2 - t1) / CLOCKS_PER_SEC << '\n';
} | delete | 32 | 35 | 32 | 32 | 0 | Time elapsed:- 0.000206
|
p02731 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define umap unordered_map
#define all(v) v.begin(), v.end()
#define st first
#define nd second
#define ln '\n'
#define MAX 1000000009
#define MOD 1000000007
#define N 105
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
long double d;
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> d;
d = (long double)d / 3;
cout << setprecision(32) << d * d * d;
} | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define umap unordered_map
#define all(v) v.begin(), v.end()
#define st first
#define nd second
#define ln '\n'
#define MAX 1000000009
#define MOD 1000000007
#define N 105
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
long double d;
int main() {
#ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> d;
d = (long double)d / 3;
cout << setprecision(32) << d * d * d;
} | replace | 18 | 20 | 18 | 20 | 0 | |
p02732 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#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 namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
map<int, int> mp;
vector<int> bn(n);
int a;
rep(i, n) {
cin >> a;
mp[a]++;
bn[i] = a;
}
for (int i = 0; i < n; i++) { // banするやつきめる
int cnt = 0;
for (auto p : mp) {
if (p.first == bn[i])
cnt += (p.second - 1) * (p.second - 2) / 2;
else
cnt += p.second * (p.second - 1) / 2;
}
cout << cnt << "\n";
}
return 0;
} | #include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#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 namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
map<int, int> mp;
vector<int> bn(n);
int a;
rep(i, n) {
cin >> a;
mp[a]++;
bn[i] = a;
}
int sum = 0;
for (auto p : mp) {
sum += p.second * (p.second - 1) / 2;
}
rep(i, n) {
int k = mp.at(bn[i]) - 1;
cout << sum - k << "\n";
}
return 0;
} | replace | 22 | 31 | 22 | 29 | TLE | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<ll, ll> P;
const int MAXN = 1e5 + 7;
const int LOG = 20;
const int INF = 0x3f3f3f3f;
int a[MAXN], cnt[MAXN], sum[MAXN], b[MAXN];
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
cnt[a[i]]++;
}
sort(b, b + n);
int tn = unique(b, b + n) - b;
int ans = 0;
for (int i = 0; i < tn; i++) {
sum[b[i]] = cnt[b[i]] * (cnt[b[i]] - 1) / 2;
ans += sum[b[i]];
}
for (int i = 0; i < n; i++) {
ans -= sum[a[i]];
cout << ans + (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2 << endl;
ans += sum[a[i]];
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int T;
T = 1;
while (T--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<ll, ll> P;
const int MAXN = 2e5 + 7;
const int LOG = 20;
const int INF = 0x3f3f3f3f;
int a[MAXN], cnt[MAXN], sum[MAXN], b[MAXN];
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
cnt[a[i]]++;
}
sort(b, b + n);
int tn = unique(b, b + n) - b;
int ans = 0;
for (int i = 0; i < tn; i++) {
sum[b[i]] = cnt[b[i]] * (cnt[b[i]] - 1) / 2;
ans += sum[b[i]];
}
for (int i = 0; i < n; i++) {
ans -= sum[a[i]];
cout << ans + (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2 << endl;
ans += sum[a[i]];
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int T;
T = 1;
while (T--) {
solve();
}
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02732 | C++ | Runtime Error | #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main() {
int N;
cin >> N;
vector<ll> A(N), B;
map<int, int> m, k;
for (int i = 0; i < N; i++) {
cin >> A[i];
m[A[i]]++;
}
{
int i = 0;
for (auto itr = m.begin(); itr != m.end(); itr++) {
B.push_back((*itr).second);
k[(*itr).first] = i;
i++;
}
}
vector<ll> C(B.size()), D(B.size(), 0), E(B.size(), 0);
for (int i = 0; i < N; i++) {
if (B[i] < 2)
C[i] = 0;
else
C[i] = B[i] * (B[i] - 1) / 2;
}
D[0] = C[0], E.back() = C.back();
for (int i = 0; i < D.size() - 1; i++) {
D[i + 1] = D[i] + C[i + 1];
}
for (int i = E.size() - 1; i >= 1; i--) {
E[i - 1] = E[i] + C[i - 1];
}
for (int i = 0; i < N; i++) {
ll ans = 0;
if (B[k[A[i]]] >= 3)
ans += (B[k[A[i]]] - 1) * (B[k[A[i]]] - 2) / 2;
if (k[A[i]] != 0)
ans += D[k[A[i]] - 1];
if (k[A[i]] != B.size() - 1)
ans += E[k[A[i]] + 1];
cout << ans << endl;
}
} | #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main() {
int N;
cin >> N;
vector<ll> A(N), B;
map<int, int> m, k;
for (int i = 0; i < N; i++) {
cin >> A[i];
m[A[i]]++;
}
{
int i = 0;
for (auto itr = m.begin(); itr != m.end(); itr++) {
B.push_back((*itr).second);
k[(*itr).first] = i;
i++;
}
}
vector<ll> C(B.size()), D(B.size(), 0), E(B.size(), 0);
for (int i = 0; i < B.size(); i++) {
if (B[i] < 2)
C[i] = 0;
else
C[i] = B[i] * (B[i] - 1) / 2;
}
D[0] = C[0], E.back() = C.back();
for (int i = 0; i < D.size() - 1; i++) {
D[i + 1] = D[i] + C[i + 1];
}
for (int i = E.size() - 1; i >= 1; i--) {
E[i - 1] = E[i] + C[i - 1];
}
for (int i = 0; i < N; i++) {
ll ans = 0;
if (B[k[A[i]]] >= 3)
ans += (B[k[A[i]]] - 1) * (B[k[A[i]]] - 2) / 2;
if (k[A[i]] != 0)
ans += D[k[A[i]] - 1];
if (k[A[i]] != B.size() - 1)
ans += E[k[A[i]] + 1];
cout << ans << endl;
}
} | replace | 30 | 31 | 30 | 31 | -6 | free(): invalid size
|
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int64_t ncr2(int64_t n);
int main(void) {
int64_t N;
int64_t total = 0;
cin >> N;
vector<int64_t> A(N);
vector<int64_t> B(100001, 0);
for (int64_t i = 0; i < N; i++) {
cin >> A[i];
B[A[i] - 1]++;
}
for (int64_t i = 0; i < B.size(); i++) {
total += ncr2(B[i]);
}
for (int64_t i = 0; i < N; i++) {
cout << total - ncr2(B[A[i] - 1]) + ncr2(B[A[i] - 1] - 1) << "\n";
}
return 0;
}
int64_t ncr2(int64_t n) {
if (n < 2)
return 0;
if (n == 2)
return 1;
return (n * (n - 1)) / 2;
}
| #include <bits/stdc++.h>
using namespace std;
int64_t ncr2(int64_t n);
int main(void) {
int64_t N;
int64_t total = 0;
cin >> N;
vector<int64_t> A(N);
vector<int64_t> B(200001, 0);
for (int64_t i = 0; i < N; i++) {
cin >> A[i];
B[A[i] - 1]++;
}
for (int64_t i = 0; i < B.size(); i++) {
total += ncr2(B[i]);
}
for (int64_t i = 0; i < N; i++) {
cout << total - ncr2(B[A[i] - 1]) + ncr2(B[A[i] - 1] - 1) << "\n";
}
return 0;
}
int64_t ncr2(int64_t n) {
if (n < 2)
return 0;
if (n == 2)
return 1;
return (n * (n - 1)) / 2;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02732 | Python | Time Limit Exceeded | from collections import defaultdict
def num_combinations(_n):
return _n * (_n - 1) // 2
if __name__ == "__main__":
n = int(input())
xs = [int(s) for s in input().split()]
freq = defaultdict(int)
for n in xs:
freq[n] += 1
res = 0
for k in range(len(xs)):
res = 0
for num in freq.keys():
res += num_combinations(freq[num] - (1 if xs[k] == num else 0))
print(res)
| from collections import defaultdict
def num_combinations(_n):
return _n * (_n - 1) // 2
if __name__ == "__main__":
n = int(input())
xs = [int(s) for s in input().split()]
freq = defaultdict(int)
for n in xs:
freq[n] += 1
total = sum([num_combinations(n) for n in freq.values()])
for x in xs:
print(total - (freq[x] - 1))
| replace | 15 | 22 | 15 | 18 | TLE | |
p02732 | Python | Runtime Error | import collections
import math
url = "https://atcoder.jp//contests/abc159/tasks/abc159_d"
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
input()
t = list(map(int, input().split()))
col = collections.Counter(t)
com = {}
al = 0
for key in col:
com[key] = combinations_count(col[key], 2)
al += com[key]
for v in t:
c = col[v] - 1
if c <= 1:
c = 0
else:
c = com[v] - c
tmp = (al - com[v]) + c
print(tmp)
if __name__ == "__main__":
main()
| import collections
import math
url = "https://atcoder.jp//contests/abc159/tasks/abc159_d"
def combinations_count(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
input()
t = list(map(int, input().split()))
col = collections.Counter(t)
com = {}
al = 0
for key in col:
if col[key] < 2:
com[key] = 0
else:
com[key] = combinations_count(col[key], 2)
al += com[key]
for v in t:
c = col[v] - 1
if c <= 1:
c = 0
else:
c = com[v] - c
tmp = (al - com[v]) + c
print(tmp)
if __name__ == "__main__":
main()
| replace | 17 | 18 | 17 | 21 | 0 | |
p02732 | Python | Time Limit Exceeded | from collections import Counter
def choose(n: int) -> int:
if n < 2:
return 0
else:
return (n * (n - 1)) // 2
N = int(input())
A = list(map(int, input().split()))
for k in range(N):
c = Counter(A[:k] + A[k + 1 :])
print(sum(map(choose, c.values())))
| from collections import Counter
def choose(n: int) -> int:
if n < 2:
return 0
else:
return (n * (n - 1)) // 2
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
d = {key: choose(value) for key, value in c.items()}
if len(d) > 1:
sum_d = sum(d.values())
for a in A:
print(sum_d - d[a] + choose(c[a] - 1))
else:
ans = choose(N - 1)
for _ in range(N):
print(ans)
| replace | 12 | 16 | 12 | 22 | TLE | |
p02732 | Python | Runtime Error | from collections import Counter
from scipy.special import comb
import numpy as np
N = int(input())
A = list(map(int, input().split()))
total = 0
answers = np.array([0] * (N + 1))
for number, appearance in Counter(A).items():
flat = comb(appearance, 2, exact=True)
minus_one = comb(appearance - 1, 2, exact=True)
total += flat
answers[number] = minus_one - flat
answers += total
print(*answers[A], sep="\n")
| from collections import Counter
from scipy.misc import comb
import numpy as np
N = int(input())
A = list(map(int, input().split()))
total = 0
answers = np.array([0] * (N + 1))
for number, appearance in Counter(A).items():
flat = comb(appearance, 2, exact=True)
minus_one = comb(appearance - 1, 2, exact=True)
total += flat
answers[number] = minus_one - flat
answers += total
print(*answers[A], sep="\n")
| replace | 1 | 2 | 1 | 2 | ModuleNotFoundError: No module named 'scipy' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02732/Python/s996070439.py", line 3, in <module>
from scipy.special import comb
ModuleNotFoundError: No module named 'scipy'
|
p02732 | Python | Runtime Error | N = int(input())
A = [int(a) for a in input().split()]
cnt = {}
total = 0
for a in A:
if a not in cnt:
cnt[a] = 0
cnt[a] += 1
for i in cnt.values():
total += i * (i - 1) // 2
for i in range(N):
print(total - (cnt[i] - 1))
| N = int(input())
A = [int(a) for a in input().split()]
cnt = {}
total = 0
for a in A:
if a not in cnt:
cnt[a] = 0
cnt[a] += 1
for i in cnt.values():
total += i * (i - 1) // 2
for a in A:
print(total - (cnt[a] - 1))
| replace | 13 | 15 | 13 | 15 | KeyError: 0 | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02732/Python/s071344434.py", line 15, in <module>
print(total - (cnt[i] - 1))
KeyError: 0
|
p02732 | Python | Time Limit Exceeded | N = int(input())
A = list(map(int, input().split()))
dictA = {}
for x in A:
dictA[x] = 0
for x1 in A:
dictA[x1] += 1
for x2 in A:
dictB = dictA.copy()
combisum = 0
dictB[x2] -= 1
for x3 in dictB.values():
combisum += x3 * (x3 - 1) // 2
print(combisum)
| N = int(input())
A = list(map(int, input().split()))
dictA = {}
for x in A:
dictA[x] = 0
for x1 in A:
dictA[x1] += 1
combisum = 0
for y in dictA.values():
combisum += y * (y - 1) // 2
for z in range(N):
print(combisum - dictA[A[z]] + 1)
| replace | 8 | 15 | 8 | 14 | TLE | |
p02732 | Python | Runtime Error | N = int(input())
A = list(map(int, input().split()))
m = [0] * N
for i in range(N):
m[A[i]] += 1
ans = 0
for i in range(len(m)):
ans += m[i] * (m[i] - 1) // 2
for i in range(N):
print(ans - m[A[i]] + 1)
| N = int(input())
A = list(map(int, input().split()))
m = [0] * (N + 1)
for i in range(N):
m[A[i]] += 1
ans = 0
for i in range(len(m)):
ans += m[i] * (m[i] - 1) // 2
for i in range(N):
print(ans - m[A[i]] + 1)
| replace | 3 | 4 | 3 | 4 | 0 | |
p02732 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define mod 1000000007 // 10^9+7
#define INF 1000000000000 // 10^12
#define F first
#define S second
#define P pair<int, int>
#define all(vec) vec.begin(), vec.end()
map<int, int> mp;
int a[300000];
int ans[300000];
int tri(int n) { return n * (n - 1) / 2; }
signed main() {
int n;
cin >> n;
rep(i, n) {
cin >> a[i];
mp[a[i]]++;
}
for (auto &x : mp) {
x.second--;
for (auto y : mp) {
ans[x.first] += tri(y.second);
}
x.second++;
}
rep(i, n) { cout << ans[a[i]] << endl; }
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define mod 1000000007 // 10^9+7
#define INF 1000000000000 // 10^12
#define F first
#define S second
#define P pair<int, int>
#define all(vec) vec.begin(), vec.end()
map<int, int> mp;
int a[300000];
int ans[300000];
int tri(int n) { return n * (n - 1) / 2; }
signed main() {
int n;
cin >> n;
rep(i, n) {
cin >> a[i];
mp[a[i]]++;
}
int cnt = 0;
for (auto x : mp) {
cnt += tri(x.second);
}
for (auto x : mp) {
int nor = tri(x.second);
int sma = tri(x.second - 1);
ans[x.first] = cnt - (nor - sma);
}
rep(i, n) { cout << ans[a[i]] << endl; }
return 0;
}
| replace | 22 | 28 | 22 | 30 | TLE | |
p02732 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<long long> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
vector<long long> Acnt(N + 1, 0);
for (auto x : A) {
Acnt.at(x) = count(A.begin(), A.end(), x);
}
long long s = 0;
for (int i = 1; i < N + 1; i++) {
if (Acnt.at(i) != 0) {
s = s + Acnt.at(i) * (Acnt.at(i) - 1) / 2;
}
}
for (auto Ak : A) {
long long ans = s - Acnt.at(Ak) + 1;
printf("%lld\n", ans);
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<long long> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
vector<long long> Acnt(N + 1, 0);
for (auto x : A) {
Acnt.at(x)++;
}
long long s = 0;
for (int i = 1; i < N + 1; i++) {
if (Acnt.at(i) != 0) {
s = s + Acnt.at(i) * (Acnt.at(i) - 1) / 2;
}
}
for (auto Ak : A) {
long long ans = s - Acnt.at(Ak) + 1;
printf("%lld\n", ans);
}
} | replace | 15 | 16 | 15 | 16 | TLE | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pp;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
super_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
tree_order_statistics_node_update>
multi_set;
#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i, n) for (ll i = 1; i <= n; ++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll << x)
const ll DIM = 1e5 + 7;
const ll INF = 1e9;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll A[DIM], cnt[DIM];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
forn(i, n) {
cin >> A[i];
cnt[A[i]]++;
}
ll sum = 0;
forn(i, n) { sum += cnt[i] * (cnt[i] - 1) / 2; }
forn(i, n) {
ll r = sum - cnt[A[i]] * (cnt[A[i]] - 1) / 2;
r += (cnt[A[i]] - 1) * (cnt[A[i]] - 2) / 2;
cout << r << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pp;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
super_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
tree_order_statistics_node_update>
multi_set;
#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i, n) for (ll i = 1; i <= n; ++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll << x)
const ll DIM = 2e5 + 7;
const ll INF = 1e9;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll A[DIM], cnt[DIM];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
forn(i, n) {
cin >> A[i];
cnt[A[i]]++;
}
ll sum = 0;
forn(i, n) { sum += cnt[i] * (cnt[i] - 1) / 2; }
forn(i, n) {
ll r = sum - cnt[A[i]] * (cnt[A[i]] - 1) / 2;
r += (cnt[A[i]] - 1) * (cnt[A[i]] - 2) / 2;
cout << r << endl;
}
return 0;
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p02732 | C++ | Runtime Error | #include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stdint.h>
#include <vector>
using namespace std;
#define int long long
#define INF 1001001001
int arr[200001];
int nChoosek(int n, int k) {
if (k > n)
return 0;
if (k * 2 > n)
k = n - k;
if (k == 0)
return 1;
int result = n;
for (int i = 2; i <= k; ++i) {
result *= (n - i + 1);
result /= i;
}
return result;
}
int32_t main() {
int N;
cin >> N;
vector<int> v(N);
for (int i = 1; i <= N; i++) {
int tmp;
cin >> tmp;
arr[tmp]++;
v[i] = tmp;
}
int sum = 0;
for (int i = 1; i <= N; i++) {
sum += nChoosek(arr[i], 2);
}
int ans = sum;
for (int i = 1; i <= N; i++) {
ans = sum;
ans -= nChoosek(arr[v[i]], 2);
ans += nChoosek(arr[v[i]] - 1, 2);
cout << ans << endl;
}
} | #include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stdint.h>
#include <vector>
using namespace std;
#define int long long
#define INF 1001001001
int arr[200001];
int nChoosek(int n, int k) {
if (k > n)
return 0;
if (k * 2 > n)
k = n - k;
if (k == 0)
return 1;
int result = n;
for (int i = 2; i <= k; ++i) {
result *= (n - i + 1);
result /= i;
}
return result;
}
int32_t main() {
int N;
cin >> N;
vector<int> v(N + 1);
for (int i = 1; i <= N; i++) {
int tmp;
cin >> tmp;
arr[tmp]++;
v[i] = tmp;
}
int sum = 0;
for (int i = 1; i <= N; i++) {
sum += nChoosek(arr[i], 2);
}
int ans = sum;
for (int i = 1; i <= N; i++) {
ans = sum;
ans -= nChoosek(arr[v[i]], 2);
ans += nChoosek(arr[v[i]] - 1, 2);
cout << ans << endl;
}
} | replace | 34 | 35 | 34 | 35 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod
const int N = 100001;
int freq[N];
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (auto &i : v) {
cin >> i;
freq[i]++;
}
int an = 0;
for (int i = 0; i <= n; i++) {
an += freq[i] * (freq[i] - 1) / 2;
}
int cur = 0;
for (int i = 0; i < n; i++) {
cur = an;
int nm = v[i];
cur -= freq[nm] * (freq[nm] - 1) / 2;
cur += (freq[nm] - 1) * (freq[nm] - 2) / 2;
cout << cur << "\n";
}
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod
const int N = 200001;
int freq[N];
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (auto &i : v) {
cin >> i;
freq[i]++;
}
int an = 0;
for (int i = 0; i <= n; i++) {
an += freq[i] * (freq[i] - 1) / 2;
}
int cur = 0;
for (int i = 0; i < n; i++) {
cur = an;
int nm = v[i];
cur -= freq[nm] * (freq[nm] - 1) / 2;
cur += (freq[nm] - 1) * (freq[nm] - 2) / 2;
cout << cur << "\n";
}
}
int32_t main() {
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02732 | C++ | Runtime Error | #pragma comment(linker, "/stack:16777216")
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
// #include"functions.h"
// #include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pff pair<float, float>
#define pdd pair<double, double>
#define psi pair<string, int>
#define pis pair<int, string>
#define ppi pair<pii, int>
#define pdi pair<pii, pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a, b) for (int a = 0; a < b; a++)
#define rep(a, b) for (int a = 0; a < b; a++)
#define forn(a, n) for (int a = 1; a <= n; a++)
#define forr(a, n) for (int a = n; a >= 1; a--)
#define repn(a, n, p) for (int a = 0; a < n; a += p)
#define repr(a, n) for (int a = n - 1; a >= 0; a--)
#define foreach(a, b) for (__typeof(b.begin()) a = b.begin(); a != b.end(); a++)
#define fillemp(a) memset(a, 0, sizeof(a))
#define fillinf(a) memset(a, 0x3f, sizeof(a))
#define frestream \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define stdf(a, b) \
freopen(a, "r", stdin); \
freopen(b, "w", stdout);
#define inputf(a) freopen(a, "r", stdin);
#define outputf(a) freopen(a, "w", stdout);
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;
int n;
int a[100010];
map<int, ll> f, m;
int main(int argc, char **argv) {
cin >> n;
rep(i, n) {
cin >> a[i];
f[a[i]]++;
}
ll sum = 0ll;
rep(j, n) {
int i = a[j];
if (m[i])
continue;
m[i] = (f[i] * (f[i] - 1ll)) / 2ll;
// cout<<m[i]<<" "<<i<<endl;
sum += m[i];
}
rep(i, n) {
ll ans = sum - (f[a[i]] * (f[a[i]] - 1ll)) / 2ll;
ans += ((f[a[i]] - 1ll) * (f[a[i]] - 2ll)) / 2ll;
cout << ans << endl;
}
return 0;
} | #pragma comment(linker, "/stack:16777216")
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
// #include"functions.h"
// #include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pff pair<float, float>
#define pdd pair<double, double>
#define psi pair<string, int>
#define pis pair<int, string>
#define ppi pair<pii, int>
#define pdi pair<pii, pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a, b) for (int a = 0; a < b; a++)
#define rep(a, b) for (int a = 0; a < b; a++)
#define forn(a, n) for (int a = 1; a <= n; a++)
#define forr(a, n) for (int a = n; a >= 1; a--)
#define repn(a, n, p) for (int a = 0; a < n; a += p)
#define repr(a, n) for (int a = n - 1; a >= 0; a--)
#define foreach(a, b) for (__typeof(b.begin()) a = b.begin(); a != b.end(); a++)
#define fillemp(a) memset(a, 0, sizeof(a))
#define fillinf(a) memset(a, 0x3f, sizeof(a))
#define frestream \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define stdf(a, b) \
freopen(a, "r", stdin); \
freopen(b, "w", stdout);
#define inputf(a) freopen(a, "r", stdin);
#define outputf(a) freopen(a, "w", stdout);
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;
int n;
ll a[200010];
ll f[200010], m[200010];
int main(int argc, char **argv) {
cin >> n;
rep(i, n) {
cin >> a[i];
f[a[i]]++;
}
ll sum = 0ll;
rep(j, n) {
int i = a[j];
if (m[i])
continue;
m[i] = (f[i] * (f[i] - 1ll)) / 2ll;
// cout<<m[i]<<" "<<i<<endl;
sum += m[i];
}
rep(i, n) {
ll ans = sum - (f[a[i]] * (f[a[i]] - 1ll)) / 2ll;
ans += ((f[a[i]] - 1ll) * (f[a[i]] - 2ll)) / 2ll;
cout << ans << endl;
}
return 0;
} | replace | 83 | 85 | 83 | 85 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T> inline void chkmax(T &x, T y) {
if (x < y)
x = y;
}
template <typename T> inline void chkmin(T &x, T y) {
if (x > y)
x = y;
}
inline int read() {
#define nc getchar()
int x = 0;
char c = nc;
while (c < 48)
c = nc;
while (c > 47)
x = (x << 3) + (x << 1) + (c ^ 48), c = nc;
return x;
#undef nc
}
typedef long long ll;
const int maxn = 1e5 + 10;
int n, a[maxn], cnt[maxn];
int main() {
cin >> n;
rep(i, 1, n) a[i] = read(), cnt[a[i]]++;
ll sum = 0;
rep(i, 1, n) sum += 1ll * cnt[i] * (cnt[i] - 1) / 2;
rep(i, 1, n) { printf("%lld\n", sum - cnt[a[i]] + 1); }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T> inline void chkmax(T &x, T y) {
if (x < y)
x = y;
}
template <typename T> inline void chkmin(T &x, T y) {
if (x > y)
x = y;
}
inline int read() {
#define nc getchar()
int x = 0;
char c = nc;
while (c < 48)
c = nc;
while (c > 47)
x = (x << 3) + (x << 1) + (c ^ 48), c = nc;
return x;
#undef nc
}
typedef long long ll;
const int maxn = 3e5 + 10;
int n, a[maxn], cnt[maxn];
int main() {
cin >> n;
rep(i, 1, n) a[i] = read(), cnt[a[i]]++;
ll sum = 0;
rep(i, 1, n) sum += 1ll * cnt[i] * (cnt[i] - 1) / 2;
rep(i, 1, n) { printf("%lld\n", sum - cnt[a[i]] + 1); }
return 0;
} | replace | 31 | 32 | 31 | 32 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
#define pll pair<ll, ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;
ll const N = 1e5 + 1;
void solve() {
ll n;
cin >> n;
vll a(n);
map<ll, ll> m;
for (int i = 0; i < n; i++) {
// ll a;
cin >> a[i];
m[a[i]]++;
}
vll v(N, 0), z(N, 0);
ll sum = 0;
for (auto itr = m.begin(); itr != m.end(); itr++) {
ll k = (*itr).ff;
ll p = m[k];
if (p >= 2) {
v[k] = (p * (p - 1)) / 2;
sum += v[k];
}
p--;
if (p >= 2) {
z[k] = (p * (p - 1)) / 2;
}
}
for (int i = 0; i < n; i++) {
cout << (sum - v[a[i]] + z[a[i]]) << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
typedef long long ll;
#define pll pair<ll, ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;
ll const N = 2e5 + 5;
void solve() {
ll n;
cin >> n;
vll a(n);
map<ll, ll> m;
for (int i = 0; i < n; i++) {
// ll a;
cin >> a[i];
m[a[i]]++;
}
vll v(N, 0), z(N, 0);
ll sum = 0;
for (auto itr = m.begin(); itr != m.end(); itr++) {
ll k = (*itr).ff;
ll p = m[k];
if (p >= 2) {
v[k] = (p * (p - 1)) / 2;
sum += v[k];
}
p--;
if (p >= 2) {
z[k] = (p * (p - 1)) / 2;
}
}
for (int i = 0; i < n; i++) {
cout << (sum - v[a[i]] + z[a[i]]) << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02732 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <float.h>
#include <time.h>
#define loop(i, start, end) for (i = (start); i <= (end); i++)
#define loopIterators(it, vec) for (it = (vec).begin(); it != (vec).end(); it++)
#define loopIteratorsRev(it, vec) \
for (it = (vec).rbegin(); it != (vec).rend(); it++)
#define loopRev(i, start, end) for (i = (start); i >= (end); i--)
#define FLASH \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define testCases(t) \
cin >> t; \
while (t--)
#define PN(n) cout << (n)
#define PN1(n) cout << (n) << " "
#define PN2(a, b) cout << (a) << " " << (b) << " "
#define PNN1(n) cout << (n) << endl
#define PNN2(a, b) cout << (a) << " " << (b) << endl
#define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define PrintArray(ar, n) \
for (i = 0; i < n; i++) \
cout << ar[i] << " "; \
cout << endl
#define PrintObject(ar, it) \
loopIterators(it, ar) cout << *it << " "; \
cout << endl
#define PrintMap(map, it) loopIterators(it, map) PNN2(it->first, it->second)
#define sz(a) sizeof(a)
#define IN1(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define ALL(s) s.begin(), s.end()
#define SWAP(a, b, c) \
c = a; \
a = b; \
b = c
#define STRSP(s) scanf("%[^\n]%*c", s)
#define ENTER PNN1("");
#define MOD7 1000000007
#define MOD9 10000009
#define MAX 1000000000
#define llPair std::pair<lli, lli>
#define iiPair std::pair<int, int>
// #define ONLINE_JUDGE
typedef long long int lli;
typedef long int li;
typedef unsigned long long int ulli;
typedef long double ld;
using namespace std;
int main(void) {
FLASH
#ifndef ONLINE_JUDGE
freopen("input-stream.txt", "r", stdin);
freopen("output-stream.txt", "w", stdout);
#endif
int n, i;
IN1(n);
int ar[n];
std::map<int, int> d;
loop(i, 0, n - 1) IN1(ar[i]);
loop(i, 0, n - 1)++ d[ar[i]];
lli total = 0LL;
for (auto cur : d)
total += 1LL * cur.second * (cur.second - 1) / 2;
// PNN1(total);
loop(i, 0, n - 1) {
lli now = d[ar[i]];
lli cur = total - 1LL * now * (now - 1) / 2;
--now;
cur += 1LL * now * (now - 1) / 2;
PNN1(cur);
}
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <float.h>
#include <time.h>
#define loop(i, start, end) for (i = (start); i <= (end); i++)
#define loopIterators(it, vec) for (it = (vec).begin(); it != (vec).end(); it++)
#define loopIteratorsRev(it, vec) \
for (it = (vec).rbegin(); it != (vec).rend(); it++)
#define loopRev(i, start, end) for (i = (start); i >= (end); i--)
#define FLASH \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define testCases(t) \
cin >> t; \
while (t--)
#define PN(n) cout << (n)
#define PN1(n) cout << (n) << " "
#define PN2(a, b) cout << (a) << " " << (b) << " "
#define PNN1(n) cout << (n) << endl
#define PNN2(a, b) cout << (a) << " " << (b) << endl
#define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define PrintArray(ar, n) \
for (i = 0; i < n; i++) \
cout << ar[i] << " "; \
cout << endl
#define PrintObject(ar, it) \
loopIterators(it, ar) cout << *it << " "; \
cout << endl
#define PrintMap(map, it) loopIterators(it, map) PNN2(it->first, it->second)
#define sz(a) sizeof(a)
#define IN1(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define ALL(s) s.begin(), s.end()
#define SWAP(a, b, c) \
c = a; \
a = b; \
b = c
#define STRSP(s) scanf("%[^\n]%*c", s)
#define ENTER PNN1("");
#define MOD7 1000000007
#define MOD9 10000009
#define MAX 1000000000
#define llPair std::pair<lli, lli>
#define iiPair std::pair<int, int>
#define ONLINE_JUDGE
typedef long long int lli;
typedef long int li;
typedef unsigned long long int ulli;
typedef long double ld;
using namespace std;
int main(void) {
FLASH
#ifndef ONLINE_JUDGE
freopen("input-stream.txt", "r", stdin);
freopen("output-stream.txt", "w", stdout);
#endif
int n, i;
IN1(n);
int ar[n];
std::map<int, int> d;
loop(i, 0, n - 1) IN1(ar[i]);
loop(i, 0, n - 1)++ d[ar[i]];
lli total = 0LL;
for (auto cur : d)
total += 1LL * cur.second * (cur.second - 1) / 2;
// PNN1(total);
loop(i, 0, n - 1) {
lli now = d[ar[i]];
lli cur = total - 1LL * now * (now - 1) / 2;
--now;
cur += 1LL * now * (now - 1) / 2;
PNN1(cur);
}
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
| replace | 63 | 64 | 63 | 64 | 0 | |
p02732 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<vector<long long>> ball_type_num(pow(10, 5), vector<long long>(2, 0));
for (int i = 0; i < n; i++) {
cin >> a[i];
ball_type_num[a[i]][0]++;
}
long long total = 0;
for (int i = 0; i < ball_type_num.size(); i++) {
if (ball_type_num[i][0] == 0) {
ball_type_num[i][1] = 0;
} else {
ball_type_num[i][1] = ball_type_num[i][0] - 1;
}
total += ball_type_num[i][0] * (ball_type_num[i][0] - 1) / 2;
// cout << ball_type_num[i][0] << " " << ball_type_num[i][1] << endl;
}
// cout << "total " << total << endl;
for (int i = 0; i < n; i++) {
cout << total - ball_type_num[a[i]][1] << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<vector<long long>> ball_type_num(2 * pow(10, 5),
vector<long long>(2, 0));
for (int i = 0; i < n; i++) {
cin >> a[i];
ball_type_num[a[i]][0]++;
}
long long total = 0;
for (int i = 0; i < ball_type_num.size(); i++) {
if (ball_type_num[i][0] == 0) {
ball_type_num[i][1] = 0;
} else {
ball_type_num[i][1] = ball_type_num[i][0] - 1;
}
total += ball_type_num[i][0] * (ball_type_num[i][0] - 1) / 2;
// cout << ball_type_num[i][0] << " " << ball_type_num[i][1] << endl;
}
// cout << "total " << total << endl;
for (int i = 0; i < n; i++) {
cout << total - ball_type_num[a[i]][1] << endl;
}
return 0;
} | replace | 15 | 16 | 15 | 17 | 0 | |
p02732 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;
#define K 2
#define LIMIT 20010
// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int cnt[LIMIT] = {0};
int main() {
int N;
cin >> N;
vector<int> v(N, 0);
int maxV = 0;
for (int i = 0; i < N; i++) {
cin >> v.at(i);
maxV = max(maxV, v.at(i));
cnt[v.at(i)]++;
}
ll sum = 0;
for (int i = 0; i <= maxV; ++i) {
sum += max(cnt[i] * (cnt[i] - 1LL) / K, 0LL);
}
for (auto i = v.begin(); i != v.end(); ++i) {
cout << sum - (max(cnt[*i] * (cnt[*i] - 1LL) / K, 0LL) -
max((cnt[*i] - 1LL) * (cnt[*i] - 2LL) / K, 0LL))
<< endl;
}
}
| #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;
#define K 2
#define LIMIT 200010
// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int cnt[LIMIT] = {0};
int main() {
int N;
cin >> N;
vector<int> v(N, 0);
int maxV = 0;
for (int i = 0; i < N; i++) {
cin >> v.at(i);
maxV = max(maxV, v.at(i));
cnt[v.at(i)]++;
}
ll sum = 0;
for (int i = 0; i <= maxV; ++i) {
sum += max(cnt[i] * (cnt[i] - 1LL) / K, 0LL);
}
for (auto i = v.begin(); i != v.end(); ++i) {
cout << sum - (max(cnt[*i] * (cnt[*i] - 1LL) / K, 0LL) -
max((cnt[*i] - 1LL) * (cnt[*i] - 2LL) / K, 0LL))
<< endl;
}
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a[20005];
map<int, int> mp;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
ans += mp[i] * (mp[i] - 1) / 2;
}
// cout << "ans:" << ans << endl;
for (int i = 0; i < n; i++) {
cout << ans - mp[a[i]] + 1 << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a[200005];
map<long long, long long> mp;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
ans += mp[i] * (mp[i] - 1) / 2;
}
// cout << "ans:" << ans << endl;
for (int i = 0; i < n; i++) {
cout << ans - mp[a[i]] + 1 << endl;
}
return 0;
}
| replace | 4 | 6 | 4 | 6 | 0 | |
p02732 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for (type i = a; i < b; i++)
typedef long long ll;
using namespace std;
int main(void) {
ll N, ans;
scanf("%lld", &N);
vector<ll> A(N);
map<ll, ll> mp;
REP(ll, i, 0, N) {
scanf("%lld", &A.at(i));
mp[A.at(i)]++;
}
REP(ll, i, 0, N) {
ll Num = A.at(i);
ans = 0;
for (auto &p : mp) {
if (Num == p.first) {
ans += (p.second - 1) * (p.second - 2) / 2;
} else {
ans += (p.second - 1) * p.second / 2;
}
}
printf("%lld\n", ans);
}
return 0;
} | #include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for (type i = a; i < b; i++)
typedef long long ll;
using namespace std;
int main(void) {
ll N, ans;
scanf("%lld", &N);
vector<ll> A(N);
map<ll, ll> mp;
REP(ll, i, 0, N) {
scanf("%lld", &A.at(i));
mp[A.at(i)]++;
}
for (auto &p : mp)
ans += (p.second - 1) * p.second / 2;
REP(ll, i, 0, N) { printf("%lld\n", ans - mp[A.at(i)] + 1); }
return 0;
} | replace | 16 | 28 | 16 | 19 | TLE | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll, ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef set<int> st;
typedef set<char> stc;
typedef vector<int>::iterator itr;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for (int i = 0; i < (b); i++)
#define f00(b) for (int j = 0; j < (b); j++)
#define f1(b) for (int i = 1; i <= (b); i++)
#define f11(b) for (int j = 1; j <= (b); j++)
#define f2(a, b) for (int i = (a); i <= (b); i++)
#define f22(a, b) for (int j = (a); j <= (b); j++)
#define sq(a) a *a
#define cu(a) (sq(a) * a)
#define sf1(a) scanf("%d", &a)
#define sf2(a, b) scanf("%d %d", &a, &b)
#define pf1(a) printf("%d\n", a)
#define pf2(a, b) printf("%d %d\n", a, b)
#define Last(i) ((i) & (-i))
const int mod = 1000000007;
const int maxn = (int)1e5 + 30;
const ll nnn = (ll)5e7 + 5;
const int inf = 1e9 + 9;
const ll INF = 1e18;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
ull a[maxn];
ull b[maxn];
ull n;
ull ans[maxn];
ull final = 0;
cin >> n;
memset(b, -1, sizeof(b));
f1(n) cin >> a[i], b[a[i]]++;
f1(n) {
// cout << i << ' ' << b[i] << ' ' << ((b[i] + 1) * b[i]) / 2 << endl;
if (b[i] > 0)
final += ((b[i] + 1) * b[i]) / 2;
}
f1(n) {
ull s = a[i];
ull ot = b[s] - 1;
// cout << s << ' ' << ot << ' ' << ( ((b[s] + 1) * b[s]) / 2 ) << ' ' <<
// (((ot + 1) * ot) / 2) << "\n";
cout << final - (((b[s] + 1) * b[s]) / 2) + (((ot + 1) * ot) / 2) << "\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll, ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef set<int> st;
typedef set<char> stc;
typedef vector<int>::iterator itr;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for (int i = 0; i < (b); i++)
#define f00(b) for (int j = 0; j < (b); j++)
#define f1(b) for (int i = 1; i <= (b); i++)
#define f11(b) for (int j = 1; j <= (b); j++)
#define f2(a, b) for (int i = (a); i <= (b); i++)
#define f22(a, b) for (int j = (a); j <= (b); j++)
#define sq(a) a *a
#define cu(a) (sq(a) * a)
#define sf1(a) scanf("%d", &a)
#define sf2(a, b) scanf("%d %d", &a, &b)
#define pf1(a) printf("%d\n", a)
#define pf2(a, b) printf("%d %d\n", a, b)
#define Last(i) ((i) & (-i))
const int mod = 1000000007;
const int maxn = (int)2e5 + 30;
const ll nnn = (ll)5e7 + 5;
const int inf = 1e9 + 9;
const ll INF = 1e18;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
ull a[maxn];
ull b[maxn];
ull n;
ull ans[maxn];
ull final = 0;
cin >> n;
memset(b, -1, sizeof(b));
f1(n) cin >> a[i], b[a[i]]++;
f1(n) {
// cout << i << ' ' << b[i] << ' ' << ((b[i] + 1) * b[i]) / 2 << endl;
if (b[i] > 0)
final += ((b[i] + 1) * b[i]) / 2;
}
f1(n) {
ull s = a[i];
ull ot = b[s] - 1;
// cout << s << ' ' << ot << ' ' << ( ((b[s] + 1) * b[s]) / 2 ) << ' ' <<
// (((ot + 1) * ot) / 2) << "\n";
cout << final - (((b[s] + 1) * b[s]) / 2) + (((ot + 1) * ot) / 2) << "\n";
}
return 0;
}
| replace | 39 | 40 | 39 | 40 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100005;
ll A[MAX_N], B[MAX_N];
int main() {
int N;
cin >> N;
rep(i, N) {
cin >> A[i];
A[i]--;
B[A[i]]++;
}
ll ans = 0;
rep(i, N) { ans += B[i] * (B[i] - 1) / 2; }
rep(i, N) { cout << ans - (B[A[i]] - 1) << endl; }
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 200005;
ll A[MAX_N], B[MAX_N];
int main() {
int N;
cin >> N;
rep(i, N) {
cin >> A[i];
A[i]--;
B[A[i]]++;
}
ll ans = 0;
rep(i, N) { ans += B[i] * (B[i] - 1) / 2; }
rep(i, N) { cout << ans - (B[A[i]] - 1) << endl; }
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02732 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
/*
__,.二ニ==- ニ.、_.
.,..‐ ⌒ ``'ァ-ニ、.
ィ'´. ´丶.、
.,ィ'´ `.x、..
.. /. 、\.
.ン′. ¬`""冖ーミト.
,r′. .ヘ、 `
ツ `、....
./´ ヘ
..... /. .〉.
´/.. .l
ィ . f..
.. .f ,d. l ′ 」 ,. ト !
. 〕../.f.. ′ .. | .} | |.
.!./..f.. / !- ナ丶п冖т ノー- . 〕 |.
|メ | | j , ┌. |〈. л`. /|.. ┤,..
...「...|. | ´ l. | j.L......ュ.L_└ヽ_|Y. メムw ょ | j.: |  ̄
. |. т〕<.ィ冖T冖.. г‐ `、 `, /┴¬..г ̄|.. .′ |
... | ... ),|.. ` リ 「_ノ.|| ` V |!{,「ll ´.」. 卜
. |.」 ′ ヽ └++〃.. ルwf カz′. |.
|..〕 「 .|
.l.|. ′. |
. .〕.. `! _.....ー:'' 」 ´ λ.
_「. , ┐_,、`~‐''"´ ィ .、 ヘ、
f :__..,二ュ.-i―'''^~´ 、\イ ヘ.`x
. / { j .~^
、/ 't.. 丿..
.../. ,x┐.. ∠∫
:^. /  ̄冖ー=zzュ┌ー―-- ∟,二..._. _,、.-ー.'l+~. .l`.
. У. ⌒冖‐-=._.. l「.「 ´ ̄」了 .,、-''^ 〉 ヽ_
_/.  ̄~'.ー-=.、_,..usァ.ー''" { \´
_ヰl'¬―- 、_ ( .\
*/
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;
ll mypow(ll x, ll n, ll mod = MOD) {
ll ret = 1;
while (n > 0) {
if (n & 1) {
ret = (ret * x) % mod;
}
x = (x * x) % mod;
n >>= 1;
}
return ret;
}
ll mygcd(ll a, ll b) {
if (b == 0)
return a;
return mygcd(b, a % b);
}
ll twoPow(ll shiftNum) { return (1LL << (shiftNum - 1)); }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<ll> a(n);
vector<ll> count(100001, 0);
for (auto &x : a) {
cin >> x;
count[x]++;
}
ll totalans = 0;
for (const auto x : count) {
totalans += (x * (x - 1)) / 2;
}
for (const auto x : a) {
cout << totalans - (count[x] * (count[x] - 1)) / 2 +
((count[x] - 1) * (count[x] - 2) / 2)
<< endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
/*
__,.二ニ==- ニ.、_.
.,..‐ ⌒ ``'ァ-ニ、.
ィ'´. ´丶.、
.,ィ'´ `.x、..
.. /. 、\.
.ン′. ¬`""冖ーミト.
,r′. .ヘ、 `
ツ `、....
./´ ヘ
..... /. .〉.
´/.. .l
ィ . f..
.. .f ,d. l ′ 」 ,. ト !
. 〕../.f.. ′ .. | .} | |.
.!./..f.. / !- ナ丶п冖т ノー- . 〕 |.
|メ | | j , ┌. |〈. л`. /|.. ┤,..
...「...|. | ´ l. | j.L......ュ.L_└ヽ_|Y. メムw ょ | j.: |  ̄
. |. т〕<.ィ冖T冖.. г‐ `、 `, /┴¬..г ̄|.. .′ |
... | ... ),|.. ` リ 「_ノ.|| ` V |!{,「ll ´.」. 卜
. |.」 ′ ヽ └++〃.. ルwf カz′. |.
|..〕 「 .|
.l.|. ′. |
. .〕.. `! _.....ー:'' 」 ´ λ.
_「. , ┐_,、`~‐''"´ ィ .、 ヘ、
f :__..,二ュ.-i―'''^~´ 、\イ ヘ.`x
. / { j .~^
、/ 't.. 丿..
.../. ,x┐.. ∠∫
:^. /  ̄冖ー=zzュ┌ー―-- ∟,二..._. _,、.-ー.'l+~. .l`.
. У. ⌒冖‐-=._.. l「.「 ´ ̄」了 .,、-''^ 〉 ヽ_
_/.  ̄~'.ー-=.、_,..usァ.ー''" { \´
_ヰl'¬―- 、_ ( .\
*/
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;
ll mypow(ll x, ll n, ll mod = MOD) {
ll ret = 1;
while (n > 0) {
if (n & 1) {
ret = (ret * x) % mod;
}
x = (x * x) % mod;
n >>= 1;
}
return ret;
}
ll mygcd(ll a, ll b) {
if (b == 0)
return a;
return mygcd(b, a % b);
}
ll twoPow(ll shiftNum) { return (1LL << (shiftNum - 1)); }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
vector<ll> a(n);
vector<ll> count(200001, 0);
for (auto &x : a) {
cin >> x;
count[x]++;
}
ll totalans = 0;
for (const auto x : count) {
totalans += (x * (x - 1)) / 2;
}
for (const auto x : a) {
cout << totalans - (count[x] * (count[x] - 1)) / 2 +
((count[x] - 1) * (count[x] - 2) / 2)
<< endl;
}
return 0;
} | replace | 88 | 89 | 88 | 89 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define LOOP(type, i, a, b) for (type i = a; i < b; i++)
typedef long long ll;
using namespace std;
int main() {
ll N, sum;
scanf("%lld", &N);
vector<ll> A(N), count(N);
LOOP(ll, i, 1, N + 1) count[i] = 0;
LOOP(ll, i, 0, N) {
scanf("%lld", &A[i]);
count[A[i]]++;
}
sum = 0;
LOOP(ll, i, 1, N + 1) sum += count[i] * (count[i] - 1) / 2;
LOOP(ll, i, 0, N) printf("%lld\n", sum - count[A[i]] + 1);
return 0;
}
| #include <bits/stdc++.h>
#define LOOP(type, i, a, b) for (type i = a; i < b; i++)
typedef long long ll;
using namespace std;
int main() {
ll N, sum;
scanf("%lld", &N);
vector<ll> A(N), count(N + 1);
LOOP(ll, i, 1, N + 1) count[i] = 0;
LOOP(ll, i, 0, N) {
scanf("%lld", &A[i]);
count[A[i]]++;
}
sum = 0;
LOOP(ll, i, 1, N + 1) sum += count[i] * (count[i] - 1) / 2;
LOOP(ll, i, 0, N) printf("%lld\n", sum - count[A[i]] + 1);
return 0;
}
| replace | 10 | 11 | 10 | 11 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main() {
int n, ary[20000];
cin >> n;
vector<ll> cnt(n + 1);
rep(i, n) {
cin >> ary[i];
cnt[ary[i]]++;
}
ll tmp = 0;
rep(i, n + 1) { tmp += cnt[i] * (cnt[i] - 1) / 2; }
rep(i, n) {
ll ans = tmp;
ll x = cnt[ary[i]];
ans -= x * (x - 1) / 2;
ans += (x - 1) * (x - 2) / 2;
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main() {
int n, ary[(int)2e+5];
cin >> n;
vector<ll> cnt(n + 1);
rep(i, n) {
cin >> ary[i];
cnt[ary[i]]++;
}
ll tmp = 0;
rep(i, n + 1) { tmp += cnt[i] * (cnt[i] - 1) / 2; }
rep(i, n) {
ll ans = tmp;
ll x = cnt[ary[i]];
ans -= x * (x - 1) / 2;
ans += (x - 1) * (x - 2) / 2;
cout << ans << endl;
}
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MAX 100001
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
map<ll, ll> m;
map<ll, pair<ll, ll>> mpp;
ll arr[MAX];
ll n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
m[arr[i]]++;
}
for (int i = 0; i < n; i++) {
ll temp = m[arr[i]];
ll co1 = temp * (temp - 1) * 0.5;
ll co2 = (temp - 1) * (temp - 2) * 0.5;
mpp[arr[i]] = make_pair(co1, co2);
}
// for(auto a: mpp){
// cout<<a.first<<" "<<a.second.first<<" "<<a.second.second<<endl;
// }
ll sum1;
sum1 = 0;
for (auto a : mpp) {
sum1 += a.second.first;
}
for (int i = 0; i < n; i++) {
ll e = sum1 - mpp[arr[i]].first + mpp[arr[i]].second;
cout << e << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define MAX 1000000
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
map<ll, ll> m;
map<ll, pair<ll, ll>> mpp;
ll arr[MAX];
ll n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
m[arr[i]]++;
}
for (int i = 0; i < n; i++) {
ll temp = m[arr[i]];
ll co1 = temp * (temp - 1) * 0.5;
ll co2 = (temp - 1) * (temp - 2) * 0.5;
mpp[arr[i]] = make_pair(co1, co2);
}
// for(auto a: mpp){
// cout<<a.first<<" "<<a.second.first<<" "<<a.second.second<<endl;
// }
ll sum1;
sum1 = 0;
for (auto a : mpp) {
sum1 += a.second.first;
}
for (int i = 0; i < n; i++) {
ll e = sum1 - mpp[arr[i]].first + mpp[arr[i]].second;
cout << e << endl;
}
return 0;
} | replace | 1 | 2 | 1 | 2 | 0 | |
p02732 | C++ | Runtime Error | /*<---------------------------CONCEPTS LEARNT------------------------------>
<-------------------------------------------------------------------------->
_ __ _ _____ _____ _____
___ _ _| |__ ___ / _|_ __ ___ __ _| | __ |___ |___ |___ |
/ __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ / / / / / / /
| (__| |_| | |_) | __/ _| | | __/ (_| | < / / / / / /
\___|\__,_|_.__/ \___|_| |_| \___|\__,_|_|\_\ /_/ /_/ /_/
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
typedef unordered_map<ll, ll> umap;
// #pragma GCC optimize "trapv"
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define For(i, n) for (int i = 0; i < (ll)n; i++)
#define Rev(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, n) for (int i = 1; i <= n; ++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(), (v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a, b) make_pair(a, b)
#define pf(n) cout << n << "\n"
#define pff(n) cout << n << " ";
long const M = 1e9 + 7;
const long mxN = 1e5 + 2;
const long mxNN = 1e6 + 2;
ll a[mxN];
void solve() {
ll n;
cin >> n;
map<ll, ll> m;
For(i, n) {
cin >> a[i];
m[a[i]]++;
}
ll ans = 0;
for (auto x : m) {
ans += x.S * (x.S - 1) / 2;
}
// cout << ans << endl ;
For(i, n) {
ll c = m[a[i]];
ll temp;
temp = ans - c * (c - 1) / 2;
c--;
temp += c * (c - 1) / 2;
cout << temp << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
// ll t ; cin >> t ; while(t--)solve();
return 0;
}
| /*<---------------------------CONCEPTS LEARNT------------------------------>
<-------------------------------------------------------------------------->
_ __ _ _____ _____ _____
___ _ _| |__ ___ / _|_ __ ___ __ _| | __ |___ |___ |___ |
/ __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ / / / / / / /
| (__| |_| | |_) | __/ _| | | __/ (_| | < / / / / / /
\___|\__,_|_.__/ \___|_| |_| \___|\__,_|_|\_\ /_/ /_/ /_/
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
typedef unordered_map<ll, ll> umap;
// #pragma GCC optimize "trapv"
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define For(i, n) for (int i = 0; i < (ll)n; i++)
#define Rev(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, n) for (int i = 1; i <= n; ++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(), (v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a, b) make_pair(a, b)
#define pf(n) cout << n << "\n"
#define pff(n) cout << n << " ";
long const M = 1e9 + 7;
const long mxN = 2e5 + 2;
const long mxNN = 1e6 + 2;
ll a[mxN];
void solve() {
ll n;
cin >> n;
map<ll, ll> m;
For(i, n) {
cin >> a[i];
m[a[i]]++;
}
ll ans = 0;
for (auto x : m) {
ans += x.S * (x.S - 1) / 2;
}
// cout << ans << endl ;
For(i, n) {
ll c = m[a[i]];
ll temp;
temp = ans - c * (c - 1) / 2;
c--;
temp += c * (c - 1) / 2;
cout << temp << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
// ll t ; cin >> t ; while(t--)solve();
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p02732 | C++ | Time Limit Exceeded | /*
--------DO NOT COPY I REQUEST YOU PLEASE--------
AUTHOR : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com
___ _ _ __ _ _ ____ __ _ _
/ __)( )_( ) /__\ ( \( )( _ \ /__\ ( \( )
( (__ ) _ ( /(__)\ ) ( )(_) )/(__)\ ) (
\___)(_) (_)(__)(__)(_)\_)(____/(__)(__)(_)\_)
/*
A ^ (B ^ C) % M = (A ^ y ) % M
where y = (B ^ C)%(M-1)
//
\
a^(m-1) ≡ 1 (mod m)
If we multiply both sides with a-1, we get
a^(-1) ≡ a^(m-2)(mod m)
*/
#include <bits/stdc++.h>
using namespace std;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#include <cstdio>
#define MAX 7000005
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <unordered_map>
#define ll long long
#define ld long double
#define lli long long int
#define pb push_back
#define INF 1000000000
#define mod 1000000007
#define MOD 1000000007
// #define mp make_pair
#define loop(i, n) for (lli i = 0; i < n; i++)
#define loopitr(xt, vec) for (auto xt : vec)
#define FOR(i, a, b) for (lli i = a; i < b; i += 1)
#define loop_rev(i, n) for (lli i = n - 1; i >= 0; i--)
#define FOR_REV(i, a, b) for (lli i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define sz(x) int(x.size())
#define pii pair<int, int>
#define F first
#define S second
#define mii map<lli, lli>
#define vi vector<lli>
#define seti set<lli>
#define itr ::iterator it
#define WL(t) while (t--)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (a / gcd(a, b)) * b
#define abs(x) ((x < 0) ? -(x) : x)
#define print(x) printf("%lli\n", x);
#define print2(x, y) printf("%lli %lli\n", x, y);
#define print3(x, y, z) printf("%lli %lli %lli\n", x, y, z);
#define scan(x) scanf("%lld", &x);
#define scan2(x, y) scanf("%lld %lld", &x, &y);
#define scan3(x, y, z) scanf("%lld %lld %lld", &x, &y, &z);
#define scanarr(a, n) \
for (lli i = 0; i < n; i++) \
cin >> a[i];
#define scanvector(a, n) \
for (lli i = 0; i < n; i++) { \
lli x; \
cin >> x; \
a.push_back(x); \
}
#define printarr(a, n) \
for (lli i = 0; i < n; i++) \
printf("%lli ", a[i]); \
printf("\n");
#define printvector(vec) \
for (auto xt : vec) \
cout << xt << " "; \
cout << "\n";
#define printset(st) \
for (auto xt : st) \
cout << xt << " "; \
cout << "\n";
#define FD(N) fixed << setprecision(N)
#define endl '\n'
#define deb(x) cout << #x << " " << x << endl;
lli find_mod(string s) {
lli i, x = 0;
for (i = 0; i < s.length(); i++)
x = (x * 10 + s[i] - '0') % MOD;
return x;
}
lli prime[MAX + 1];
void sieve1() { // prime or not
for (int i = 0; i <= MAX; i++)
prime[i] = 1;
prime[0] = prime[1] = 0;
for (lli i = 4; i <= MAX; i += 2)
prime[i] = 0;
for (int p = 3; p * p <= MAX; p += 2) {
if (prime[p] == 1)
for (int i = p * 2; i <= MAX; i += p) {
prime[i] = 0;
}
}
}
int min_prime_div_of_n[MAX + 1];
void sieve2() { // smallest prime factor which divide a no.
memset(min_prime_div_of_n, 0, sizeof(min_prime_div_of_n));
min_prime_div_of_n[0] = min_prime_div_of_n[1] = 1;
for (int i = 2; i * i <= MAX; i++) {
if (min_prime_div_of_n[i] == 0) {
for (int j = i * 2; j < MAX; j += i) {
if (min_prime_div_of_n[j] == 0) {
min_prime_div_of_n[j] = i;
// cout<<min_prime_div_of_n[i]<<" ";}
}
}
}
}
for (int i = 2; i <= MAX; i++)
if (min_prime_div_of_n[i] == 0)
min_prime_div_of_n[i] = i;
// If the number is prime then it's // smallest prime factor is the number //
// itself
}
int max_prime_div_of_n[MAX + 1];
void sieve3() { // maximum prime factor which divide a no.
sieve1();
memset(max_prime_div_of_n, 0,
sizeof(max_prime_div_of_n)); // 0 stands for is_prime
max_prime_div_of_n[0] = max_prime_div_of_n[1] = 1;
for (int i = 2; i * i <= MAX; i++) {
if (max_prime_div_of_n[i] == 0) {
for (int j = i * 2; j < MAX; j += i) {
if (max_prime_div_of_n[j] == 0 || ((j % i) == 0 && prime[i] == 1)) {
max_prime_div_of_n[j] = i;
}
}
}
}
for (int i = 2; i <= 100; i++)
// If the number is prime then it's largest prime factor is the number
// itself
if (max_prime_div_of_n[i] == 0)
max_prime_div_of_n[i] = i;
// cout<<max_prime_div_of_n[i]<<" ";
}
lli sum_prime_fac[1000001];
void sieve4() { // prime or not
sum_prime_fac[1000001] = {0};
for (lli i = 2; i <= 1000000; i++) {
if (!sum_prime_fac[i]) {
for (lli j = i; j <= 1000000; j += i)
sum_prime_fac[j] += i;
}
}
}
bool is_even(lli n) { return (!(n & 2)); }
bool is_odd(lli n) { return (n & 2); }
/*bool isPower(lli n)
{
// Find Log n in different bases
// and check if the value is an
// integer
float f=log(n)/log(2);
if (((f - (int)f) == 0.0) && prime[int(f)]==1)
return true;
for (lli x=3; x<=sqrt(n); x+=2) {
f = log(n) / log(x);
if (((f - (int)f) == 0.0) && prime[int(f)]==1 && prime[x]==1 )
return true;
}
return false;
}
*/
// memset(array_name , initialized value , sizeof(data_type_of_array))
lli sum(lli n) {
lli sum = 0;
while (n) {
sum += n % 10;
n /= 10;
}
return sum;
}
bool isPrime(lli n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n == 5)
return true;
if ((n % 2 == 0) || (n % 3 == 0) || (n % 5 == 0))
return false;
for (lli i = 5; i * i <= n; i += 6)
if ((n % i == 0) || (n % (i + 2) == 0))
return false;
return true;
}
lli reversenum(lli x) {
lli num = 0;
while (x > 0) {
num = num * 10 + x % 10;
x = x / 10;
}
return num;
}
bool ispalindrome(string s) {
string q = s;
reverse(q.begin(), q.end());
return (s == q);
}
bool isvowel(char x) {
return (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u');
}
/*inline void fastRead(lli &x) {
register int c = getchar_unlocked();
x = 0;
int neg = 0;
for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());
if(c=='-'){
neg = 1;
c = getchar_unlocked();}
for(; c>47 && c<58 ; c = getchar_unlocked()){x = (x<<1) + (x<<3) + c
- 48;} if(neg){ x = -x;}
}*/
lli mceil(lli a, lli b) {
if (a % b == 0)
return (a / b);
else
return (a / b + 1);
}
lli mfloor(lli a, lli b) { return (a / b); }
lli sumarr(lli a[], lli n) {
lli sum = 0;
loop(i, n) sum += a[i];
return sum;
}
ll modmullong(ll a, ll b) {
ll res = 0;
a %= mod;
while (b) {
if (b & 1)
res = (res + a) % mod;
a = (2 * a) % mod;
b >>= 1;
}
return res;
}
ll modmul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll modadd(ll a, ll b) { return ((a % mod) + (b % mod) + mod) % mod; }
ll modsub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
lli fastexpo(lli a, lli b) {
a = a % mod;
lli ans = 1;
while (b) {
if (b & 1)
ans = (ans * 1ll * a) % mod;
a = (a * 1ll * a) % mod;
b = b / 2;
}
return ans;
}
lli findmax(lli a[], lli x, lli y) {
lli maxi = -1;
for (lli i = x; i <= y; i++)
maxi = max(maxi, a[i]);
return maxi;
}
lli phi[MAX];
void euler_phi() { // euler totient function
loop(i, MAX - 1) phi[i + 1] = i + 1;
for (lli p = 2; p < MAX; p++) {
if (phi[p] == p) {
phi[p] = p - 1;
for (lli i = 2 * p; i < MAX; i += p)
phi[i] = (phi[i] / p) * (p - 1);
}
}
}
lli myphi(lli n) {
lli result = n;
for (lli p = 2; p * p <= n; ++p) {
if (n % p == 0) {
while (n % p == 0)
n /= p;
result -= result / p;
}
}
if (n > 1)
result -= result / n;
return result;
}
void prime_factorise(lli n, map<lli, lli> &mp) {
while (n % 2 == 0) {
mp[2]++;
n /= 2;
}
for (lli i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
mp[i]++;
n /= i;
}
}
if (n > 1)
mp[n]++;
}
// Returns largest power of p that divides n!
lli largestPower(lli n, lli p) {
lli total = 0;
// Calculate x = n/p + n/(p^2) + n/(p^3) + ....
while (n) {
n /= p;
total += n;
}
return total;
}
lli fact[100001];
void facto() {
fact[0] = 1;
for (lli i = 1; i <= 100000; i++)
fact[i] = modmul(fact[i - 1], i);
}
void finddiv(lli n, seti &st) {
for (lli i = 1; i * i <= n; i++) {
if (n % i == 0) {
st.insert(i);
st.insert(n / i);
}
}
}
lli findncr(lli n, lli r) {
if (n < r)
return 0;
else {
r = min(r, n - r);
lli a = 1, b = 1;
for (lli i = 0; i < r; i++) {
a = (a * (n - i)) % mod;
b = (b * (i + 1)) % mod;
}
a = modmul(a, fastexpo(b, mod - 2));
return a;
}
}
void chandan1() { return; }
void chandan2() {
loop(i, 10) { lli x = 1; }
return (chandan1());
}
bool f(string s, lli se, lli e) {
e--;
while (se < e) {
if (s[se] != s[e])
return false;
se++;
e--;
}
return true;
}
int main() {
fastIO lli t = 1;
// cin>>t;
while (t--) {
lli n;
cin >> n;
lli a[n];
mii mp;
loop(i, n) {
cin >> a[i];
mp[a[i]]++;
}
mii mpu;
lli sum = 0;
for (auto xt : mp) {
// cout<<xt.F<<"--\n";
for (auto it : mp) {
if (it.F == xt.F)
sum += ((it.S - 1) * (it.S - 2)) / 2;
else
sum += ((it.S) * (it.S - 1)) / 2;
}
// sum=0;
mpu[xt.F] = sum;
sum = 0;
}
loop(i, n) { cout << mpu[a[i]] << "\n"; }
}
return 0;
}
| /*
--------DO NOT COPY I REQUEST YOU PLEASE--------
AUTHOR : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com
___ _ _ __ _ _ ____ __ _ _
/ __)( )_( ) /__\ ( \( )( _ \ /__\ ( \( )
( (__ ) _ ( /(__)\ ) ( )(_) )/(__)\ ) (
\___)(_) (_)(__)(__)(_)\_)(____/(__)(__)(_)\_)
/*
A ^ (B ^ C) % M = (A ^ y ) % M
where y = (B ^ C)%(M-1)
//
\
a^(m-1) ≡ 1 (mod m)
If we multiply both sides with a-1, we get
a^(-1) ≡ a^(m-2)(mod m)
*/
#include <bits/stdc++.h>
using namespace std;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#include <cstdio>
#define MAX 7000005
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <unordered_map>
#define ll long long
#define ld long double
#define lli long long int
#define pb push_back
#define INF 1000000000
#define mod 1000000007
#define MOD 1000000007
// #define mp make_pair
#define loop(i, n) for (lli i = 0; i < n; i++)
#define loopitr(xt, vec) for (auto xt : vec)
#define FOR(i, a, b) for (lli i = a; i < b; i += 1)
#define loop_rev(i, n) for (lli i = n - 1; i >= 0; i--)
#define FOR_REV(i, a, b) for (lli i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define sz(x) int(x.size())
#define pii pair<int, int>
#define F first
#define S second
#define mii map<lli, lli>
#define vi vector<lli>
#define seti set<lli>
#define itr ::iterator it
#define WL(t) while (t--)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (a / gcd(a, b)) * b
#define abs(x) ((x < 0) ? -(x) : x)
#define print(x) printf("%lli\n", x);
#define print2(x, y) printf("%lli %lli\n", x, y);
#define print3(x, y, z) printf("%lli %lli %lli\n", x, y, z);
#define scan(x) scanf("%lld", &x);
#define scan2(x, y) scanf("%lld %lld", &x, &y);
#define scan3(x, y, z) scanf("%lld %lld %lld", &x, &y, &z);
#define scanarr(a, n) \
for (lli i = 0; i < n; i++) \
cin >> a[i];
#define scanvector(a, n) \
for (lli i = 0; i < n; i++) { \
lli x; \
cin >> x; \
a.push_back(x); \
}
#define printarr(a, n) \
for (lli i = 0; i < n; i++) \
printf("%lli ", a[i]); \
printf("\n");
#define printvector(vec) \
for (auto xt : vec) \
cout << xt << " "; \
cout << "\n";
#define printset(st) \
for (auto xt : st) \
cout << xt << " "; \
cout << "\n";
#define FD(N) fixed << setprecision(N)
#define endl '\n'
#define deb(x) cout << #x << " " << x << endl;
lli find_mod(string s) {
lli i, x = 0;
for (i = 0; i < s.length(); i++)
x = (x * 10 + s[i] - '0') % MOD;
return x;
}
lli prime[MAX + 1];
void sieve1() { // prime or not
for (int i = 0; i <= MAX; i++)
prime[i] = 1;
prime[0] = prime[1] = 0;
for (lli i = 4; i <= MAX; i += 2)
prime[i] = 0;
for (int p = 3; p * p <= MAX; p += 2) {
if (prime[p] == 1)
for (int i = p * 2; i <= MAX; i += p) {
prime[i] = 0;
}
}
}
int min_prime_div_of_n[MAX + 1];
void sieve2() { // smallest prime factor which divide a no.
memset(min_prime_div_of_n, 0, sizeof(min_prime_div_of_n));
min_prime_div_of_n[0] = min_prime_div_of_n[1] = 1;
for (int i = 2; i * i <= MAX; i++) {
if (min_prime_div_of_n[i] == 0) {
for (int j = i * 2; j < MAX; j += i) {
if (min_prime_div_of_n[j] == 0) {
min_prime_div_of_n[j] = i;
// cout<<min_prime_div_of_n[i]<<" ";}
}
}
}
}
for (int i = 2; i <= MAX; i++)
if (min_prime_div_of_n[i] == 0)
min_prime_div_of_n[i] = i;
// If the number is prime then it's // smallest prime factor is the number //
// itself
}
int max_prime_div_of_n[MAX + 1];
void sieve3() { // maximum prime factor which divide a no.
sieve1();
memset(max_prime_div_of_n, 0,
sizeof(max_prime_div_of_n)); // 0 stands for is_prime
max_prime_div_of_n[0] = max_prime_div_of_n[1] = 1;
for (int i = 2; i * i <= MAX; i++) {
if (max_prime_div_of_n[i] == 0) {
for (int j = i * 2; j < MAX; j += i) {
if (max_prime_div_of_n[j] == 0 || ((j % i) == 0 && prime[i] == 1)) {
max_prime_div_of_n[j] = i;
}
}
}
}
for (int i = 2; i <= 100; i++)
// If the number is prime then it's largest prime factor is the number
// itself
if (max_prime_div_of_n[i] == 0)
max_prime_div_of_n[i] = i;
// cout<<max_prime_div_of_n[i]<<" ";
}
lli sum_prime_fac[1000001];
void sieve4() { // prime or not
sum_prime_fac[1000001] = {0};
for (lli i = 2; i <= 1000000; i++) {
if (!sum_prime_fac[i]) {
for (lli j = i; j <= 1000000; j += i)
sum_prime_fac[j] += i;
}
}
}
bool is_even(lli n) { return (!(n & 2)); }
bool is_odd(lli n) { return (n & 2); }
/*bool isPower(lli n)
{
// Find Log n in different bases
// and check if the value is an
// integer
float f=log(n)/log(2);
if (((f - (int)f) == 0.0) && prime[int(f)]==1)
return true;
for (lli x=3; x<=sqrt(n); x+=2) {
f = log(n) / log(x);
if (((f - (int)f) == 0.0) && prime[int(f)]==1 && prime[x]==1 )
return true;
}
return false;
}
*/
// memset(array_name , initialized value , sizeof(data_type_of_array))
lli sum(lli n) {
lli sum = 0;
while (n) {
sum += n % 10;
n /= 10;
}
return sum;
}
bool isPrime(lli n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n == 5)
return true;
if ((n % 2 == 0) || (n % 3 == 0) || (n % 5 == 0))
return false;
for (lli i = 5; i * i <= n; i += 6)
if ((n % i == 0) || (n % (i + 2) == 0))
return false;
return true;
}
lli reversenum(lli x) {
lli num = 0;
while (x > 0) {
num = num * 10 + x % 10;
x = x / 10;
}
return num;
}
bool ispalindrome(string s) {
string q = s;
reverse(q.begin(), q.end());
return (s == q);
}
bool isvowel(char x) {
return (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u');
}
/*inline void fastRead(lli &x) {
register int c = getchar_unlocked();
x = 0;
int neg = 0;
for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());
if(c=='-'){
neg = 1;
c = getchar_unlocked();}
for(; c>47 && c<58 ; c = getchar_unlocked()){x = (x<<1) + (x<<3) + c
- 48;} if(neg){ x = -x;}
}*/
lli mceil(lli a, lli b) {
if (a % b == 0)
return (a / b);
else
return (a / b + 1);
}
lli mfloor(lli a, lli b) { return (a / b); }
lli sumarr(lli a[], lli n) {
lli sum = 0;
loop(i, n) sum += a[i];
return sum;
}
ll modmullong(ll a, ll b) {
ll res = 0;
a %= mod;
while (b) {
if (b & 1)
res = (res + a) % mod;
a = (2 * a) % mod;
b >>= 1;
}
return res;
}
ll modmul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll modadd(ll a, ll b) { return ((a % mod) + (b % mod) + mod) % mod; }
ll modsub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
lli fastexpo(lli a, lli b) {
a = a % mod;
lli ans = 1;
while (b) {
if (b & 1)
ans = (ans * 1ll * a) % mod;
a = (a * 1ll * a) % mod;
b = b / 2;
}
return ans;
}
lli findmax(lli a[], lli x, lli y) {
lli maxi = -1;
for (lli i = x; i <= y; i++)
maxi = max(maxi, a[i]);
return maxi;
}
lli phi[MAX];
void euler_phi() { // euler totient function
loop(i, MAX - 1) phi[i + 1] = i + 1;
for (lli p = 2; p < MAX; p++) {
if (phi[p] == p) {
phi[p] = p - 1;
for (lli i = 2 * p; i < MAX; i += p)
phi[i] = (phi[i] / p) * (p - 1);
}
}
}
lli myphi(lli n) {
lli result = n;
for (lli p = 2; p * p <= n; ++p) {
if (n % p == 0) {
while (n % p == 0)
n /= p;
result -= result / p;
}
}
if (n > 1)
result -= result / n;
return result;
}
void prime_factorise(lli n, map<lli, lli> &mp) {
while (n % 2 == 0) {
mp[2]++;
n /= 2;
}
for (lli i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
mp[i]++;
n /= i;
}
}
if (n > 1)
mp[n]++;
}
// Returns largest power of p that divides n!
lli largestPower(lli n, lli p) {
lli total = 0;
// Calculate x = n/p + n/(p^2) + n/(p^3) + ....
while (n) {
n /= p;
total += n;
}
return total;
}
lli fact[100001];
void facto() {
fact[0] = 1;
for (lli i = 1; i <= 100000; i++)
fact[i] = modmul(fact[i - 1], i);
}
void finddiv(lli n, seti &st) {
for (lli i = 1; i * i <= n; i++) {
if (n % i == 0) {
st.insert(i);
st.insert(n / i);
}
}
}
lli findncr(lli n, lli r) {
if (n < r)
return 0;
else {
r = min(r, n - r);
lli a = 1, b = 1;
for (lli i = 0; i < r; i++) {
a = (a * (n - i)) % mod;
b = (b * (i + 1)) % mod;
}
a = modmul(a, fastexpo(b, mod - 2));
return a;
}
}
void chandan1() { return; }
void chandan2() {
loop(i, 10) { lli x = 1; }
return (chandan1());
}
bool f(string s, lli se, lli e) {
e--;
while (se < e) {
if (s[se] != s[e])
return false;
se++;
e--;
}
return true;
}
int main() {
fastIO lli t = 1;
// cin>>t;
while (t--) {
lli n;
cin >> n;
lli a[n];
mii mp;
loop(i, n) {
cin >> a[i];
mp[a[i]]++;
}
mii mpu;
lli sum = 0;
for (auto it : mp) {
sum += ((it.S) * (it.S - 1)) / 2;
// cout<<it.S<<endl;
}
// cout<<endl<<sum<<"\n\n";
loop(i, n) {
// cout<<mp[a[i]]<<" ";
cout << sum + 1 - mp[a[i]] << "\n";
}
}
return 0;
}
| replace | 443 | 456 | 443 | 452 | TLE | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define fori(i, a, b, c) for (int i = (int)(a); i <= (int)(b); i += (int)(c))
#define ford(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define MOD 998244353
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef long long lol;
typedef vector<lol> vlol;
ifstream in("input");
const int NR = 3e3 + 5;
lol a[NR], ap[NR], n, sol;
bool used[NR];
int main() {
ios::sync_with_stdio(false);
int i;
cin >> n;
fori(i, 1, n, 1) {
cin >> a[i];
ap[a[i]]++;
}
fori(i, 1, n, 1) if (!used[a[i]]) sol += ap[a[i]] * (ap[a[i]] - 1) / 2,
used[a[i]] = 1;
fori(i, 1, n, 1) cout << sol - ap[a[i]] * (ap[a[i]] - 1) / 2 +
(ap[a[i]] - 2) * (ap[a[i]] - 1) / 2
<< '\n';
}
| #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define fori(i, a, b, c) for (int i = (int)(a); i <= (int)(b); i += (int)(c))
#define ford(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define MOD 998244353
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef long long lol;
typedef vector<lol> vlol;
ifstream in("input");
const int NR = 2e5 + 5;
lol a[NR], ap[NR], n, sol;
bool used[NR];
int main() {
ios::sync_with_stdio(false);
int i;
cin >> n;
fori(i, 1, n, 1) {
cin >> a[i];
ap[a[i]]++;
}
fori(i, 1, n, 1) if (!used[a[i]]) sol += ap[a[i]] * (ap[a[i]] - 1) / 2,
used[a[i]] = 1;
fori(i, 1, n, 1) cout << sol - ap[a[i]] * (ap[a[i]] - 1) / 2 +
(ap[a[i]] - 2) * (ap[a[i]] - 1) / 2
<< '\n';
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02732 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <string>
#define mem(x) memset(x, 0, sizeof(x))
#define sca(x) scanf("%lld", &x)
#define scaa(x, y) scanf("%lld%lld", &x, &y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi = acos(-1);
const double eps = 1e-6;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<char, char> pcc;
const ll mod = 998244353;
int main() {
ll n;
ll a[100005];
ll v[100005];
mem(v);
sca(n);
for (int i = 0; i < n; i++) {
sca(a[i]);
v[a[i]]++;
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
if (v[i])
ans += (v[i] * (v[i] - 1)) / 2ll;
}
for (int i = 0; i < n; i++) {
ll tt = ans - v[a[i]] + 1;
printf("%lld\n", tt);
}
} | #include <algorithm>
#include <bits/stdc++.h>
#include <string>
#define mem(x) memset(x, 0, sizeof(x))
#define sca(x) scanf("%lld", &x)
#define scaa(x, y) scanf("%lld%lld", &x, &y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi = acos(-1);
const double eps = 1e-6;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<char, char> pcc;
const ll mod = 998244353;
int main() {
ll n;
ll a[200005];
ll v[200005];
mem(v);
sca(n);
for (int i = 0; i < n; i++) {
sca(a[i]);
v[a[i]]++;
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
if (v[i])
ans += (v[i] * (v[i] - 1)) / 2ll;
}
for (int i = 0; i < n; i++) {
ll tt = ans - v[a[i]] + 1;
printf("%lld\n", tt);
}
} | replace | 18 | 20 | 18 | 20 | 0 | |
p02732 | C++ | Runtime Error | // Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) \
{ \
cerr << "\033[32;1m" << #x << " -> "; \
err(x); \
}
void err() { cerr << "\033[39;0m" << endl; }
template <typename T, typename... A> void err(T a, A... x) {
cerr << a << ' ';
err(x...);
}
#else
#define dbg(...)
#endif
#define sz(x) ((int)x.size())
typedef long long LL;
const int N = 1e5 + 50;
int cnt[N];
int n;
int a[N];
int main(int argc, char const *argv[]) {
// code
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
++cnt[a[i]];
}
LL ans = 0;
for (int i = 1; i <= n; ++i) {
ans += 1LL * cnt[i] * (cnt[i] - 1) / 2;
}
for (int i = 0; i < n; ++i) {
printf("%lld\n", ans - cnt[a[i]] + 1);
}
return 0;
}
| // Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) \
{ \
cerr << "\033[32;1m" << #x << " -> "; \
err(x); \
}
void err() { cerr << "\033[39;0m" << endl; }
template <typename T, typename... A> void err(T a, A... x) {
cerr << a << ' ';
err(x...);
}
#else
#define dbg(...)
#endif
#define sz(x) ((int)x.size())
typedef long long LL;
const int N = 2e5 + 50;
int cnt[N];
int n;
int a[N];
int main(int argc, char const *argv[]) {
// code
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
++cnt[a[i]];
}
LL ans = 0;
for (int i = 1; i <= n; ++i) {
ans += 1LL * cnt[i] * (cnt[i] - 1) / 2;
}
for (int i = 0; i < n; ++i) {
printf("%lld\n", ans - cnt[a[i]] + 1);
}
return 0;
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 100001
int main() {
ll n;
cin >> n;
ll c[MAX] = {0};
ll a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
c[a[i]]++;
}
ll s = 0;
for (int i = 1; i <= n; ++i) {
s = s + (c[i] * (c[i] - 1)) / 2;
}
for (int i = 0; i < n; ++i) {
cout << (s - c[a[i]] + 1) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 200001
int main() {
ll n;
cin >> n;
ll c[MAX] = {0};
ll a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
c[a[i]]++;
}
ll s = 0;
for (int i = 1; i <= n; ++i) {
s = s + (c[i] * (c[i] - 1)) / 2;
}
for (int i = 0; i < n; ++i) {
cout << (s - c[a[i]] + 1) << endl;
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02732 | C++ | Runtime Error | #pragma GCC optimize("O3")
#pragma GCC target("avx")
// #include<bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
if (ci - cn == cm) {
fread_unlocked(cn, 1, cm, stdin);
ci = cn;
}
return *ci++;
}
inline int getint() {
int A = 0;
if (ci - cn + 16 > cm)
while ((ct = getcha()) >= '0')
A = A * 10 + ct - '0';
else
while ((ct = *ci++) >= '0')
A = A * 10 + ct - '0';
return A;
}
char dn[2400000], *di = dn;
const int MAX = 200000;
class shuturyoku_unko {
public:
char C[MAX * 6 + 10];
char *K[MAX + 10];
constexpr shuturyoku_unko() : C(), K() {
auto di = C + 1;
C[0] = '0';
K[1] = di;
rep1(i, MAX) {
int X = i;
int keta = 0;
char c[10] = {};
while (X) {
*(c + keta) = '0' + X % 10;
X /= 10;
keta++;
}
for (int j = keta - 1; j >= 0; j--)
*di++ = (*(c + j));
K[i + 1] = di;
}
}
} f;
inline void putint(ll X) {
int ue = X / 100000;
if (ue) {
for (auto i = f.K[ue]; i < f.K[ue + 1]; i++)
*di++ = *i;
int sita = X - ue * 100000ll;
rep(i, 5 - (f.K[sita + 1] - f.K[sita])) *di++ = '0';
for (auto i = f.K[sita]; i < f.K[sita + 1]; i++)
*di++ = *i;
} else
for (auto i = f.K[X]; i < f.K[X + 1]; i++)
*di++ = *i;
*di++ = '\n';
}
int A[200000];
int B[200010];
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
int N = getint();
ll kotae = 0;
rep(i, N) kotae += B[(A[i] = getint())]++;
rep(i, N) putint(kotae - B[A[i]] + 1);
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} | #pragma GCC optimize("O3")
#pragma GCC target("avx")
// #include<bits/stdc++.h>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
if (ci - cn == cm) {
fread_unlocked(cn, 1, cm, stdin);
ci = cn;
}
return *ci++;
}
inline int getint() {
int A = 0;
if (ci - cn + 16 > cm)
while ((ct = getcha()) >= '0')
A = A * 10 + ct - '0';
else
while ((ct = *ci++) >= '0')
A = A * 10 + ct - '0';
return A;
}
char dn[2400000], *di = dn;
const int MAX = 200000;
class shuturyoku_unko {
public:
char C[MAX * 6 + 10];
char *K[MAX + 10];
constexpr shuturyoku_unko() : C(), K() {
auto di = C + 1;
C[0] = '0';
K[0] = C;
K[1] = di;
rep1(i, MAX) {
int X = i;
int keta = 0;
char c[10] = {};
while (X) {
*(c + keta) = '0' + X % 10;
X /= 10;
keta++;
}
for (int j = keta - 1; j >= 0; j--)
*di++ = (*(c + j));
K[i + 1] = di;
}
}
} f;
inline void putint(ll X) {
int ue = X / 100000;
if (ue) {
for (auto i = f.K[ue]; i < f.K[ue + 1]; i++)
*di++ = *i;
int sita = X - ue * 100000ll;
rep(i, 5 - (f.K[sita + 1] - f.K[sita])) *di++ = '0';
for (auto i = f.K[sita]; i < f.K[sita + 1]; i++)
*di++ = *i;
} else
for (auto i = f.K[X]; i < f.K[X + 1]; i++)
*di++ = *i;
*di++ = '\n';
}
int A[200000];
int B[200010];
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
int N = getint();
ll kotae = 0;
rep(i, N) kotae += B[(A[i] = getint())]++;
rep(i, N) putint(kotae - B[A[i]] + 1);
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} | insert | 49 | 49 | 49 | 50 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MAX_N 100000
using namespace std;
string s;
int n;
bool pal(int st, int dr) {
for (int i = st, j = dr; i < j; i++, j--) {
if (s[i] != s[j])
return 0;
}
return 1;
}
int a[MAX_N + 1];
int ap[MAX_N + 1];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
ap[a[i]]++;
}
long long rez = 0;
for (int i = 1; i <= n; i++)
rez = rez + 1LL * ap[i] * (ap[i] - 1) / 2;
for (int i = 1; i <= n; i++) {
long long ant = rez;
int x = a[i];
rez = rez - 1LL * ap[x] * (ap[x] - 1) / 2;
rez = rez + 1LL * (ap[x] - 1) * (ap[x] - 2) / 2;
cout << rez << "\n";
rez = ant;
}
return 0;
}
| #include <bits/stdc++.h>
#define MAX_N 200000
using namespace std;
string s;
int n;
bool pal(int st, int dr) {
for (int i = st, j = dr; i < j; i++, j--) {
if (s[i] != s[j])
return 0;
}
return 1;
}
int a[MAX_N + 1];
int ap[MAX_N + 1];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
ap[a[i]]++;
}
long long rez = 0;
for (int i = 1; i <= n; i++)
rez = rez + 1LL * ap[i] * (ap[i] - 1) / 2;
for (int i = 1; i <= n; i++) {
long long ant = rez;
int x = a[i];
rez = rez - 1LL * ap[x] * (ap[x] - 1) / 2;
rez = rez + 1LL * (ap[x] - 1) * (ap[x] - 2) / 2;
cout << rez << "\n";
rez = ant;
}
return 0;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d", &x);
#define scs(x) scanf("%s", x);
#define scl(x) scanf("%lld", &x);
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define dep(i, s, e) for (int i = s; i >= e; --i)
typedef long long ll;
using namespace std;
ll a[100005], b[100005];
int main() {
ll n, cou = 0;
scl(n);
rep(i, 1, n) {
scl(a[i]);
b[a[i]]++;
}
rep(i, 1, n) if (b[i] >= 2) cou += b[i] * (b[i] - 1) / 2;
rep(i, 1, n) {
ll v = cou;
cou -= b[a[i]] * (b[a[i]] - 1) / 2;
b[a[i]]--;
if (b[a[i]] > 0)
cou += b[a[i]] * (b[a[i]] - 1) / 2;
pf("%lld\n", cou);
cou = v;
b[a[i]]++;
}
} | #include <bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d", &x);
#define scs(x) scanf("%s", x);
#define scl(x) scanf("%lld", &x);
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define dep(i, s, e) for (int i = s; i >= e; --i)
typedef long long ll;
using namespace std;
ll a[200005], b[200005];
int main() {
ll n, cou = 0;
scl(n);
rep(i, 1, n) {
scl(a[i]);
b[a[i]]++;
}
rep(i, 1, n) if (b[i] >= 2) cou += b[i] * (b[i] - 1) / 2;
rep(i, 1, n) {
ll v = cou;
cou -= b[a[i]] * (b[a[i]] - 1) / 2;
b[a[i]]--;
if (b[a[i]] > 0)
cou += b[a[i]] * (b[a[i]] - 1) / 2;
pf("%lld\n", cou);
cou = v;
b[a[i]]++;
}
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vppll vector<pair<pll, pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll, ll>
#define fir first
#define sec second
#define _cin \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define fo(i, b) for (i = 0; i < b; i++)
#define repa(i, a, b) for (i = a; i < b; i++)
#define repb(i, a, b) for (i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18 + 1);
const long long int MIN = (ll)(-1e18 - 1);
const long long int mod = (ll)(1e9 + 7);
using namespace std;
ll max(ll a, ll b, ll c) { return max(max(a, b), c); }
ll min(ll a, ll b, ll c) { return min(min(a, b), c); }
ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
ll power(ll a, ll n) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
ll power_mod(ll a, ll n, ll mod_) {
ll p = 1;
while (n) {
if (n % 2) {
p = (p * a) % mod_;
}
n /= 2;
a = (a * a) % mod_;
}
return p % mod_;
}
/*Code Begins*/
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
_cin;
cout << setprecision(15);
ll mn = MAX, mx = MIN;
ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0;
ll x = 0, y = 0, fx, diff, tot = 0, l, r;
int TC = 1;
// cin >> TC;
while (TC--) {
cin >> n;
vll a(n);
mapll f;
tot = 0;
fo(i, n) {
cin >> a[i];
f[a[i]]++;
}
for (auto p : f) {
tie(x, y) = p;
tot += y * (y - 1) / 2;
}
vll dp(n);
fo(i, n) {
dp[i] =
tot - f[a[i]] * (f[a[i]] - 1) / 2 + (f[a[i]] - 1) * (f[a[i]] - 2) / 2;
}
fo(i, n) cout << dp[i] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vppll vector<pair<pll, pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll, ll>
#define fir first
#define sec second
#define _cin \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define fo(i, b) for (i = 0; i < b; i++)
#define repa(i, a, b) for (i = a; i < b; i++)
#define repb(i, a, b) for (i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18 + 1);
const long long int MIN = (ll)(-1e18 - 1);
const long long int mod = (ll)(1e9 + 7);
using namespace std;
ll max(ll a, ll b, ll c) { return max(max(a, b), c); }
ll min(ll a, ll b, ll c) { return min(min(a, b), c); }
ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
ll power(ll a, ll n) {
ll p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
ll power_mod(ll a, ll n, ll mod_) {
ll p = 1;
while (n) {
if (n % 2) {
p = (p * a) % mod_;
}
n /= 2;
a = (a * a) % mod_;
}
return p % mod_;
}
/*Code Begins*/
int main() {
_cin;
cout << setprecision(15);
ll mn = MAX, mx = MIN;
ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0;
ll x = 0, y = 0, fx, diff, tot = 0, l, r;
int TC = 1;
// cin >> TC;
while (TC--) {
cin >> n;
vll a(n);
mapll f;
tot = 0;
fo(i, n) {
cin >> a[i];
f[a[i]]++;
}
for (auto p : f) {
tie(x, y) = p;
tot += y * (y - 1) / 2;
}
vll dp(n);
fo(i, n) {
dp[i] =
tot - f[a[i]] * (f[a[i]] - 1) / 2 + (f[a[i]] - 1) * (f[a[i]] - 2) / 2;
}
fo(i, n) cout << dp[i] << endl;
}
return 0;
}
| replace | 55 | 60 | 55 | 56 | 0 | |
p02732 | C++ | Runtime Error | #define _GLIBCXX_DEBUG // TLEの原因になるので注意!!!!!!!!!!!
#include <bits/stdc++.h>
#include <cmath>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
deque<int> deq;
#define fi first
#define se second
// #define int long long
// cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある
ll N, M, H, W, K, Q, A, B;
string S;
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
// const ll INF = 1LL << 60;
// typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
if (b > a) {
a = b;
return true;
}
return false;
}
bool chmn(int &a, int b) {
if (b < a) {
a = b;
return true;
}
return false;
}
int main() {
ll n;
cin >> n;
multiset<ll> S;
ll b[n];
rep(i, n) {
ll a;
cin >> a;
b[i] = a;
S.insert(a);
}
ll tot = 0;
ll d[20005];
rep(i, 20001) {
ll m = S.count(i);
d[i] = m;
tot += m * (m - 1) / 2;
}
rep(i, n) {
ll ans = tot;
ll e = d[b[i]];
ans -= (e - 1) * e / 2;
ans += (e - 1) * (e - 2) / 2;
cout << ans << endl;
}
return 0;
}
| #define _GLIBCXX_DEBUG // TLEの原因になるので注意!!!!!!!!!!!
#include <bits/stdc++.h>
#include <cmath>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
deque<int> deq;
#define fi first
#define se second
// #define int long long
// cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある
ll N, M, H, W, K, Q, A, B;
string S;
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
// const ll INF = 1LL << 60;
// typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
if (b > a) {
a = b;
return true;
}
return false;
}
bool chmn(int &a, int b) {
if (b < a) {
a = b;
return true;
}
return false;
}
int main() {
ll n;
cin >> n;
multiset<ll> S;
ll b[n];
rep(i, n) {
ll a;
cin >> a;
b[i] = a;
S.insert(a);
}
ll tot = 0;
ll d[200005];
rep(i, 200001) {
ll m = S.count(i);
d[i] = m;
tot += m * (m - 1) / 2;
}
rep(i, n) {
ll ans = tot;
ll e = d[b[i]];
ans -= (e - 1) * e / 2;
ans += (e - 1) * (e - 2) / 2;
cout << ans << endl;
}
return 0;
}
| replace | 67 | 69 | 67 | 69 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb push_back
#define mp make_pair
#define INF (int)1e9
#define cBits(x) __builtin_popcount(x)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) a / gcd(a, b) * b
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORr(i, a, b) for (int i = a; i >= b; i--)
#define MAX3(a, b, c) max(a, max(b, c))
#define MIN3(a, b, c) min(a, min(b, c))
#define eachTest \
int t; \
cin >> t; \
while (t--) \
solve();
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
const int MOD = 1000000007;
void solve() { ; }
int main() {
fastio;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// eachTest
ll n;
cin >> n;
vector<ll> arr(n);
map<ll, ll> same;
FOR(i, 0, n) {
cin >> arr[i];
same[arr[i]]++;
}
ll temp;
ll total = 0;
for (auto v : same) {
temp = v.second;
total += temp * (temp - 1) / 2;
}
FOR(i, 0, n) { cout << total - same[arr[i]] + 1 << "\n"; }
return 0;
}
| #include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb push_back
#define mp make_pair
#define INF (int)1e9
#define cBits(x) __builtin_popcount(x)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) a / gcd(a, b) * b
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORr(i, a, b) for (int i = a; i >= b; i--)
#define MAX3(a, b, c) max(a, max(b, c))
#define MIN3(a, b, c) min(a, min(b, c))
#define eachTest \
int t; \
cin >> t; \
while (t--) \
solve();
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
typedef pair<int, int> PII;
const int MOD = 1000000007;
void solve() { ; }
int main() {
fastio;
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
// eachTest
ll n;
cin >> n;
vector<ll> arr(n);
map<ll, ll> same;
FOR(i, 0, n) {
cin >> arr[i];
same[arr[i]]++;
}
ll temp;
ll total = 0;
for (auto v : same) {
temp = v.second;
total += temp * (temp - 1) / 2;
}
FOR(i, 0, n) { cout << total - same[arr[i]] + 1 << "\n"; }
return 0;
}
| replace | 32 | 36 | 32 | 36 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long ans = 0;
int n, a[100100], cnt[100100];
inline long long cal(int x) { return 1ll * x * (x - 1) / 2; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", a + i), cnt[a[i]]++;
for (int i = 1; i <= n; i++)
ans += cal(cnt[i]);
for (int i = 1; i <= n; i++)
printf("%lld\n", ans - cal(cnt[a[i]]) + cal(cnt[a[i]] - 1));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long ans = 0;
int n, a[200100], cnt[200100];
inline long long cal(int x) { return 1ll * x * (x - 1) / 2; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", a + i), cnt[a[i]]++;
for (int i = 1; i <= n; i++)
ans += cal(cnt[i]);
for (int i = 1; i <= n; i++)
printf("%lld\n", ans - cal(cnt[a[i]]) + cal(cnt[a[i]] - 1));
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
int fact(int n);
int nCr(int n, int r) {
if (n < r) {
return 0;
}
return fact(n) / (fact(r) * fact(n - r));
}
// Returns factorial of n
int fact(int n) {
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
int32_t main() {
int n;
cin >> n;
int a[n];
map<int, int> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
m[a[i]] += 1;
}
int sum = 0;
map<int, int>::iterator itr;
map<int, int> self;
for (itr = m.begin(); itr != m.end(); ++itr) {
int key = itr->first;
int val = itr->second;
int x = (val * (val - 1)) / 2;
sum += x;
self.insert(pair<int, int>(key, x));
}
map<int, int> ans;
for (int i = 0; i < n; i++) {
int selph = self[a[i]];
int ekum = m[a[i]] - 1;
int nc = nCr(ekum, 2);
int result = sum - selph + nc;
ans[a[i]] = result;
}
// for (itr = ans.begin(); itr != ans.end(); ++itr) {
// cout << itr -> first << " " << itr -> second << endl;
// }
for (int i = 0; i < n; i++) {
cout << ans[a[i]] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
int fact(int n);
int nCr(int n, int r) {
if (n < r) {
return 0;
}
return fact(n) / (fact(r) * fact(n - r));
}
// Returns factorial of n
int fact(int n) {
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
int32_t main() {
int n;
cin >> n;
int a[n];
map<int, int> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
m[a[i]] += 1;
}
int sum = 0;
map<int, int>::iterator itr;
map<int, int> self;
for (itr = m.begin(); itr != m.end(); ++itr) {
int key = itr->first;
int val = itr->second;
int x = (val * (val - 1)) / 2;
sum += x;
self.insert(pair<int, int>(key, x));
}
map<int, int> ans;
for (int i = 0; i < n; i++) {
int selph = self[a[i]];
int ekum = m[a[i]] - 1;
// int nc = nCr(ekum, 2);
int nc = (ekum * (ekum - 1)) / 2;
int result = sum - selph + nc;
ans[a[i]] = result;
}
// for (itr = ans.begin(); itr != ans.end(); ++itr) {
// cout << itr -> first << " " << itr -> second << endl;
// }
for (int i = 0; i < n; i++) {
cout << ans[a[i]] << endl;
}
} | replace | 54 | 55 | 54 | 57 | 0 | |
p02732 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool palin(string s) {
int n = s.length();
for (int i = 0; i <= n / 2; i++) {
if (s[i] != s[n - i - 1])
return false;
}
return true;
}
int main() {
// your code goes here
int n;
cin >> n;
int a[n];
vector<ll> cnt(n + 1, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
for (int k = 1; k <= n; k++) {
cnt[a[k - 1]]--;
ll sum = 0;
for (int i = 1; i <= n; i++) {
if (cnt[i] > 0)
sum += (cnt[i] * (cnt[i] - 1)) / 2;
}
cout << sum << "\n";
cnt[a[k - 1]]++;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool palin(string s) {
int n = s.length();
for (int i = 0; i <= n / 2; i++) {
if (s[i] != s[n - i - 1])
return false;
}
return true;
}
int main() {
// your code goes here
int n;
cin >> n;
int a[n];
vector<ll> cnt(n + 1, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
// vector<ll>res(n+1,0);
ll sum = 0;
for (int i = 1; i <= n; i++) {
if (cnt[i] > 0)
sum += (cnt[i] * (cnt[i] - 1)) / 2;
}
for (int k = 0; k < n; k++) {
ll ans = 0;
ans = sum - (cnt[a[k]] * (cnt[a[k]] - 1)) / 2;
if (cnt[a[k]] > 2)
ans += ((cnt[a[k]] - 1) * (cnt[a[k]] - 2)) / 2;
cout << ans << "\n";
}
return 0;
}
| replace | 23 | 32 | 23 | 36 | TLE | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int N;
vector<long long> A(100010, 0);
vector<long long> NA(100010, 0);
long long SA = 0;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
++NA[A[i]];
}
for (int i = 1; i <= N; i++)
SA += NA[i] * (NA[i] - 1) / 2;
/*x番目のボールの番号はA[i]、個数はNA[A[i]]*/
for (int i = 0; i < N; i++)
cout << SA - NA[A[i]] + 1 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int N;
vector<long long> A(200010, 0);
vector<long long> NA(200010, 0);
long long SA = 0;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
++NA[A[i]];
}
for (int i = 1; i <= N; i++)
SA += NA[i] * (NA[i] - 1) / 2;
/*x番目のボールの番号はA[i]、個数はNA[A[i]]*/
for (int i = 0; i < N; i++)
cout << SA - NA[A[i]] + 1 << endl;
return 0;
}
| replace | 4 | 6 | 4 | 6 | 0 | |
p02732 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
map<int, ll> mp;
set<int> s;
int a[100010];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
mp[a[i]]++;
}
ll cnt = 0;
for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
ll k = mp[*it];
cnt += k * (k - 1) / 2;
}
for (int i = 0; i < n; i++) {
cout << cnt - mp[a[i]] + 1 << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
map<int, ll> mp;
set<int> s;
int a[200010];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i]);
mp[a[i]]++;
}
ll cnt = 0;
for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
ll k = mp[*it];
cnt += k * (k - 1) / 2;
}
for (int i = 0; i < n; i++) {
cout << cnt - mp[a[i]] + 1 << endl;
}
return 0;
} | replace | 27 | 28 | 27 | 28 | 0 | |
p02732 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define pb push_back
#define ll long long
using namespace std;
int A[100001], nums[100000];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
A[x]++;
nums[i] = x;
}
ll total = 0;
for (int i = 1; i <= n; i++) {
ll val = A[i];
total += val * (val - 1);
}
total /= 2;
for (int i = 0; i < n; i++) {
int rem = A[nums[i]];
if (rem == 0)
rem = 0;
else
rem--;
cout << (total - rem) << "\n";
}
return 0;
}
| #include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define pb push_back
#define ll long long
using namespace std;
int A[200001], nums[200000];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
A[x]++;
nums[i] = x;
}
ll total = 0;
for (int i = 1; i <= n; i++) {
ll val = A[i];
total += val * (val - 1);
}
total /= 2;
for (int i = 0; i < n; i++) {
int rem = A[nums[i]];
if (rem == 0)
rem = 0;
else
rem--;
cout << (total - rem) << "\n";
}
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02732 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define DBG(x) cerr << #x << “ = ” << (x) << endl
#define Rep(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
Long n;
cin >> n;
map<Long, Long> m;
vector<Long> v;
Rep(i, 0, n) {
Long a;
cin >> a;
m[a]++;
v.pb(a);
}
Long resp = 0;
for (auto x : m) {
resp += x.second * (x.second - 1) / 2;
}
Rep(i, 0, n) {
for (auto x : m) {
if (v[i] == x.first) {
cout << resp - (x.second - 1) << '\n';
}
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define DBG(x) cerr << #x << “ = ” << (x) << endl
#define Rep(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
Long n;
cin >> n;
map<Long, Long> m;
vector<Long> v;
Rep(i, 0, n) {
Long a;
cin >> a;
m[a]++;
v.pb(a);
}
Long resp = 0;
for (auto x : m) {
resp += x.second * (x.second - 1) / 2;
}
Rep(i, 0, n) { cout << resp - (m[v[i]] - 1) << '\n'; }
return 0;
} | replace | 26 | 33 | 26 | 27 | TLE | |
p02732 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<long long, long long> mp;
vector<long long> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i) {
mp[a[i]]++;
}
for (int k = 0; k < n; ++k) {
mp[a[k]]--;
long long sum = 0;
for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
sum += ((itr->second) * (itr->second - 1) / 2);
}
cout << sum << endl;
mp[a[k]]++;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<long long, long long> mp;
vector<long long> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i) {
mp[a[i]]++;
}
long long sum = 0;
for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
sum += ((itr->second) * (itr->second - 1) / 2);
}
for (int i = 0; i < n; ++i) {
cout << sum - (mp[a[i]] - 1) << endl;
}
return 0;
} | replace | 13 | 21 | 13 | 19 | TLE | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll cnt[114514], a[114514];
int main() {
ll n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans += cnt[i] * (cnt[i] - 1) / 2;
}
for (int i = 0; i < n; i++) {
cout << ans - cnt[a[i]] * (cnt[a[i]] - 1) / 2 +
(cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2
<< endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll cnt[214514], a[214514];
int main() {
ll n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i]]++;
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans += cnt[i] * (cnt[i] - 1) / 2;
}
for (int i = 0; i < n; i++) {
cout << ans - cnt[a[i]] * (cnt[a[i]] - 1) / 2 +
(cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2
<< endl;
}
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02732 | C++ | Runtime Error | /******************************************
* AUTHOR : Dharmveer Jakhar *
* Handle : dvjakhar *
* INSTITUTION : IIT (BHU) Varanasi *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define mod 1000000007
#define dd double
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define debug(x) cout << (#x) << " is " << (x) << endl
#define lb(arr, n, x) lower_bound(arr, arr + n, x) - arr
#define ub(arr, n, x) upper_bound(arr, arr + n, x) - arr
#define endl "\n"
#define PI 3.14159265358979323846 /* pi */
#define sqr(x) (x) * (x)
#define all(v) ((v).begin()), ((v).end())
#define degreesToRadians(angleDegrees) \
(angleDegrees * PI / 180.0) // Converts degrees to radians.
#define radiansToDegrees(angleRadians) \
(angleRadians * 180.0 / PI) // Converts radians to degrees.
typedef long long ll;
typedef long double ld;
// Calculation of (x^y)%mm
ll mod_exp(ll x, ll y, ll mm) {
if (y == 0)
return (1);
else if (y % 2 == 0)
return (mod_exp((x * x) % mm, y / 2, mm));
else
return ((x * mod_exp((x * x) % mm, (y - 1) / 2, mm)) % mm);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
std::vector<int> v;
rep(i, n) {
int x;
cin >> x;
v.pb(x);
}
std::map<int, ll> map;
for (auto x : v)
map[x]++;
ll ans = 0;
for (auto y : map) {
ans += (y.S) * ((y.S) - 1) / 2;
}
for (int i = 0; i < n; i++) {
cout << ans - (map[v[i]] - 1) << endl;
}
return 0;
} | /******************************************
* AUTHOR : Dharmveer Jakhar *
* Handle : dvjakhar *
* INSTITUTION : IIT (BHU) Varanasi *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define mod 1000000007
#define dd double
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define debug(x) cout << (#x) << " is " << (x) << endl
#define lb(arr, n, x) lower_bound(arr, arr + n, x) - arr
#define ub(arr, n, x) upper_bound(arr, arr + n, x) - arr
#define endl "\n"
#define PI 3.14159265358979323846 /* pi */
#define sqr(x) (x) * (x)
#define all(v) ((v).begin()), ((v).end())
#define degreesToRadians(angleDegrees) \
(angleDegrees * PI / 180.0) // Converts degrees to radians.
#define radiansToDegrees(angleRadians) \
(angleRadians * 180.0 / PI) // Converts radians to degrees.
typedef long long ll;
typedef long double ld;
// Calculation of (x^y)%mm
ll mod_exp(ll x, ll y, ll mm) {
if (y == 0)
return (1);
else if (y % 2 == 0)
return (mod_exp((x * x) % mm, y / 2, mm));
else
return ((x * mod_exp((x * x) % mm, (y - 1) / 2, mm)) % mm);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
std::vector<int> v;
rep(i, n) {
int x;
cin >> x;
v.pb(x);
}
std::map<int, ll> map;
for (auto x : v)
map[x]++;
ll ans = 0;
for (auto y : map) {
ans += (y.S) * ((y.S) - 1) / 2;
}
for (int i = 0; i < n; i++) {
cout << ans - (map[v[i]] - 1) << endl;
}
return 0;
} | delete | 46 | 53 | 46 | 46 | 0 | |
p02732 | C++ | Time Limit Exceeded | #include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>
using ll = long long;
using namespace std;
int main(void) {
ll n, a, sum = 0, one = 0;
map<ll, ll> m, m2;
vector<int> v;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
m[a]++;
}
for (auto j = m.begin(); j != m.end(); j++) {
one += (m[j->first] * ((m[j->first]) - 1)) / 2;
}
for (int i = 0; i < n; i++) {
sum = 0;
m2 = m;
m2[v[i]]--;
cout << one - m2[v[i]] << endl;
}
}
| #include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>
using ll = long long;
using namespace std;
int main(void) {
ll n, a, sum = 0, one = 0;
map<ll, ll> m, m2;
vector<int> v;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
m[a]++;
}
for (auto j = m.begin(); j != m.end(); j++) {
one += (m[j->first] * ((m[j->first]) - 1)) / 2;
}
for (int i = 0; i < n; i++) {
sum = 0;
// m2=m;
m[v[i]]--;
cout << one - m[v[i]] << endl;
m[v[i]]++;
}
}
| replace | 26 | 29 | 26 | 30 | TLE | |
p02732 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end() // 昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9 + 7;
typedef long long ll; // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI; // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII; // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP; // MP a;
typedef vector<pair<ll, ll>> PS;
template <class T, class U> // chmax(max, a);
bool chmax(T &a, U b) {
if (a <= b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> // chmin(min,a)
bool chmin(T &a, U b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T> // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
os << "{";
rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
os << "}";
return os;
}
// g++ -std=c++11 prac.cpp
int main() {
ll z = 0, k, n, m, h, w, ans = 0, sum = 0, Max = 1, Min = 1e9 + 1;
bool ok = false;
string s, t, r;
cin >> n;
VL a(n), b(n), c(n);
rep(i, n) {
cin >> a[i];
b[a[i]]++;
}
rep(i, 2 * 1e5) { sum = sum + (b[i] * (b[i] - 1) / 2); }
rep(i, n) {
ans = sum;
ans -= b[a[i]] * (b[a[i]] - 1) / 2;
ans += (b[a[i]] - 1) * (b[a[i]] - 2) / 2;
cout << ans << endl;
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end() // 昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9 + 7;
typedef long long ll; // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI; // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII; // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP; // MP a;
typedef vector<pair<ll, ll>> PS;
template <class T, class U> // chmax(max, a);
bool chmax(T &a, U b) {
if (a <= b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> // chmin(min,a)
bool chmin(T &a, U b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T> // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
os << "{";
rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
os << "}";
return os;
}
// g++ -std=c++11 prac.cpp
int main() {
ll z = 0, k, n, m, h, w, ans = 0, sum = 0, Max = 1, Min = 1e9 + 1;
bool ok = false;
string s, t, r;
cin >> n;
VL a(n), b(2 * 1e5 - 1), c(n);
rep(i, n) {
cin >> a[i];
b[a[i]]++;
}
rep(i, 2 * 1e5) { sum = sum + (b[i] * (b[i] - 1) / 2); }
rep(i, n) {
ans = sum;
ans -= b[a[i]] * (b[a[i]] - 1) / 2;
ans += (b[a[i]] - 1) * (b[a[i]] - 2) / 2;
cout << ans << endl;
}
return 0;
} | replace | 54 | 55 | 54 | 55 | -11 | |
p02732 | C++ | Runtime Error | // #include "pch.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define ll long long
#define fri(n) for (i = 0; i < (n); i++)
#define frj(n) for (j = 0; j < (n); i++)
#define min(p, q) ((p) < (q) ? (p) : (q))
#define max(p, q) ((p) > (q) ? (p) : (q))
#define INF 1000000000000000000 // 10^18
#define INFINT 2000000001 // 2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)
#define int ll
using namespace std;
signed main(void) {
// 変数の宣言
int n, m;
int h, w;
static int a[100010];
static int b[100010];
char s[110];
double Ld;
// よく使う変数
int i, j, k, l;
int flag = 0;
int ans = 0;
int count = 0;
int temp = 0;
int temp1 = 0;
int temp2 = 0;
int temp3 = 0;
static int vec[100010];
int max = 0;
int min = INFINT;
int len = 0;
int sum = 0;
int ok = 0;
int ng = 0;
char dummy;
static char stemp[100010];
// データの読み込み
scanf("%lld", &n);
// scanf_s("%lld",&n);
// scanf("%s",&s);
// scanf_s("%s",&s,110);
/* //scanf("%c",&dummy);
scanf_s("%c",&dummy);
for(i=0;i<n;i++){
// scanf("%c",&s[i]);
scanf_s("%c",&s[i]);
}*/
for (i = 0; i < n; i++) {
scanf("%lld", &a[i]);
// scanf_s("%lld",&a[i]);
}
// printf("nは%dです\n", n);
// printf("データの読み込み終了\n");
// 実際の処理
// clock_t start=clock();
for (i = 0; i <= n; i++) {
b[i] = 0;
}
for (i = 0; i < n; i++) {
b[a[i]]++;
}
ans = 0;
for (i = 1; i <= n; i++) {
ans = ans + b[i] * (b[i] - 1) / 2;
}
for (i = 0; i < n; i++) {
temp = ans - b[a[i]] + 1;
if (b[a[i]] == 0)
temp--;
printf("%lld\n", temp);
}
// clock_t end=clock();
// printf("計算部分終了\n");
// 出力
// printf("%d",(d[i-1][j-1]+1)/2);
// printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
// printf("結果の出力終了\n");
return 0;
}
| // #include "pch.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define ll long long
#define fri(n) for (i = 0; i < (n); i++)
#define frj(n) for (j = 0; j < (n); i++)
#define min(p, q) ((p) < (q) ? (p) : (q))
#define max(p, q) ((p) > (q) ? (p) : (q))
#define INF 1000000000000000000 // 10^18
#define INFINT 2000000001 // 2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)
#define int ll
using namespace std;
signed main(void) {
// 変数の宣言
int n, m;
int h, w;
static int a[200010];
static int b[200010];
char s[110];
double Ld;
// よく使う変数
int i, j, k, l;
int flag = 0;
int ans = 0;
int count = 0;
int temp = 0;
int temp1 = 0;
int temp2 = 0;
int temp3 = 0;
static int vec[100010];
int max = 0;
int min = INFINT;
int len = 0;
int sum = 0;
int ok = 0;
int ng = 0;
char dummy;
static char stemp[100010];
// データの読み込み
scanf("%lld", &n);
// scanf_s("%lld",&n);
// scanf("%s",&s);
// scanf_s("%s",&s,110);
/* //scanf("%c",&dummy);
scanf_s("%c",&dummy);
for(i=0;i<n;i++){
// scanf("%c",&s[i]);
scanf_s("%c",&s[i]);
}*/
for (i = 0; i < n; i++) {
scanf("%lld", &a[i]);
// scanf_s("%lld",&a[i]);
}
// printf("nは%dです\n", n);
// printf("データの読み込み終了\n");
// 実際の処理
// clock_t start=clock();
for (i = 0; i <= n; i++) {
b[i] = 0;
}
for (i = 0; i < n; i++) {
b[a[i]]++;
}
ans = 0;
for (i = 1; i <= n; i++) {
ans = ans + b[i] * (b[i] - 1) / 2;
}
for (i = 0; i < n; i++) {
temp = ans - b[a[i]] + 1;
if (b[a[i]] == 0)
temp--;
printf("%lld\n", temp);
}
// clock_t end=clock();
// printf("計算部分終了\n");
// 出力
// printf("%d",(d[i-1][j-1]+1)/2);
// printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
// printf("結果の出力終了\n");
return 0;
}
| replace | 37 | 39 | 37 | 39 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define mx 200005
#define ll long long
ll arr[mx] = {0};
ll contribute[mx] = {0};
int in[mx];
int main() {
ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, a;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a;
arr[a]++;
in[i] = a;
}
ll sum = 0;
for (int i = 1; i <= n; i++) {
if (arr[i]) {
ll add = arr[i];
add *= (add - 1);
add /= 2;
sum += add;
contribute[i] += add;
}
}
for (int i = 1; i <= n; i++) {
ll cont = contribute[in[i]];
ll ans = sum - cont;
ll add = arr[in[i]] - 1;
add *= (add - 1);
add /= 2;
ans += add;
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define mx 200005
#define ll long long
ll arr[mx] = {0};
ll contribute[mx] = {0};
int in[mx];
int main() {
ios_base::sync_with_stdio(0);
int n, a;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a;
arr[a]++;
in[i] = a;
}
ll sum = 0;
for (int i = 1; i <= n; i++) {
if (arr[i]) {
ll add = arr[i];
add *= (add - 1);
add /= 2;
sum += add;
contribute[i] += add;
}
}
for (int i = 1; i <= n; i++) {
ll cont = contribute[in[i]];
ll ans = sum - cont;
ll add = arr[in[i]] - 1;
add *= (add - 1);
add /= 2;
ans += add;
cout << ans << endl;
}
}
| replace | 9 | 13 | 9 | 10 | -11 | |
p02732 | C++ | Runtime Error | ///*
// 正在播放《フリージア》
// 1:21 ━━━━━━●───── 5:35
// ? ? ?? ? ?
//```````'`...```````''`````````````'````````````````'`.`''
//```````''..`';;'```''```'''''''''''''`````````````````'':
//.````''''':;;!!:````'````'''''''''''``````````````````'':
//``''''''':;;;;;'```'``````''```````````____________```'':
//`````````:;;!;'```````````'```````'```| 所以说 |'``'':
//```````'|$&$%:````````````'```````````|不要停下来啊|''''':
//````'''!$&&&|'```````````'''::''::''''/ (指AC) |':'':::
//````'':|&&&$!'`````'''''''::.....`;!;'/_________|''``'::
// ....'|&&@$!'........```:!;'....`:;:```````````````````'
//..````;$&&&$!:''``````'':|%%!::;|%$$!::::::::''::::::::::
//``````!&&@&&|:'````````':|$$$$$$$$$|:':::::::::::::::::::
//`````:%&@@@@@@@@&&&@@@@&&&&@@@@@@@&&&|::::::::':::::::::;
//`````.```':|$@@@@@@@@@@@@@@@@@@@@@@@@###@@&&$|;:::'::::::
//````````````';|$&@@@@@@@@@###@@@@@@########@@@@$!''''::::
//`````````..````:|%$@@@@@#########@#########@@@@&!''''::::
//`````````````````:|&########################@@@$;::::::::
//``````````````````:!$@########################@%;:::'::::
//``````````..``````':|&#######################@@&!''''''::
//''''::'''`.`''''''':|@#######################@@&|:'`.`';!
//:::::::::``'''''';%@######################@@##@@&!::'';;;
//::;::::::`.''''';%@@@@####################$%@##@@%;:'':;!
//:;;;;::::``':;%@@@#########################&%&##@@|:'';;!
//;;!;;;;;;'`::;%@#############################@@##@$!'';!!
//;;;;;;;;:``':::::;|$@############################@$!'`;!!
//::;;;;;;:'`'::::::;!$@#######################&&@$$$;``:;;
//`````````..````````'|@#####################$;!$$$&@@|''':
//'''''''''''''':'''''|@#########@&@##########@@####@@&%|!!
//''''''''':'''::'':''!&########&!|&@##########&&####&%|!||
//:::::'''::::::::::::!&########|:;|$@#########@&###&%||||!
//:::::::'''''':::::::!&#######@!:;!!$@########@$&##@%||||!
//
// だからよ...止まるじゃねえぞ
// */
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
// #define ll long long
const int N = 1e6 + 10;
#define PII pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) (int)(x).size()
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, m, t;
#define __i __int128
// ll mod = 1e9+7;
string manacher(string s) {
if (s.size() < 2)
return s;
string t;
t += '$';
for (int i = 0; i < s.size(); i++)
t += '#' + s[i];
t += '@';
int num = t.size();
int p[num];
int id = 0, mx = 0;
int maxl = -1;
int index = 0;
for (int j = 1; j < num - 1; j++) {
p[j] = mx > j ? min(p[2 * id - j], mx - j) : 1;
while (t[j + p[j]] == t[j - p[j]])
p[j]++;
if (mx < p[j] + j) {
mx = p[j] + j;
id = j;
}
if (maxl < p[j] + 1) {
maxl = p[j] - 1;
index = j;
}
}
int start = (index - maxl) / 2;
// cout <<start<<endl;
return s.substr(start, start + maxl);
}
int ar[100010];
int br[100010];
vector<int> v[100010];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
map<ll, ll> mp;
for (int i = 1; i <= n; i++)
cin >> ar[i], mp[ar[i]]++;
map<ll, ll> mm;
ll sum = 0;
for (auto it : mp)
sum += (it.second) * (it.second - 1) / 2;
for (int i = 1; i <= n; i++) {
cout << sum - (mp[ar[i]] - 1) << endl;
}
return 0;
}
| ///*
// 正在播放《フリージア》
// 1:21 ━━━━━━●───── 5:35
// ? ? ?? ? ?
//```````'`...```````''`````````````'````````````````'`.`''
//```````''..`';;'```''```'''''''''''''`````````````````'':
//.````''''':;;!!:````'````'''''''''''``````````````````'':
//``''''''':;;;;;'```'``````''```````````____________```'':
//`````````:;;!;'```````````'```````'```| 所以说 |'``'':
//```````'|$&$%:````````````'```````````|不要停下来啊|''''':
//````'''!$&&&|'```````````'''::''::''''/ (指AC) |':'':::
//````'':|&&&$!'`````'''''''::.....`;!;'/_________|''``'::
// ....'|&&@$!'........```:!;'....`:;:```````````````````'
//..````;$&&&$!:''``````'':|%%!::;|%$$!::::::::''::::::::::
//``````!&&@&&|:'````````':|$$$$$$$$$|:':::::::::::::::::::
//`````:%&@@@@@@@@&&&@@@@&&&&@@@@@@@&&&|::::::::':::::::::;
//`````.```':|$@@@@@@@@@@@@@@@@@@@@@@@@###@@&&$|;:::'::::::
//````````````';|$&@@@@@@@@@###@@@@@@########@@@@$!''''::::
//`````````..````:|%$@@@@@#########@#########@@@@&!''''::::
//`````````````````:|&########################@@@$;::::::::
//``````````````````:!$@########################@%;:::'::::
//``````````..``````':|&#######################@@&!''''''::
//''''::'''`.`''''''':|@#######################@@&|:'`.`';!
//:::::::::``'''''';%@######################@@##@@&!::'';;;
//::;::::::`.''''';%@@@@####################$%@##@@%;:'':;!
//:;;;;::::``':;%@@@#########################&%&##@@|:'';;!
//;;!;;;;;;'`::;%@#############################@@##@$!'';!!
//;;;;;;;;:``':::::;|$@############################@$!'`;!!
//::;;;;;;:'`'::::::;!$@#######################&&@$$$;``:;;
//`````````..````````'|@#####################$;!$$$&@@|''':
//'''''''''''''':'''''|@#########@&@##########@@####@@&%|!!
//''''''''':'''::'':''!&########&!|&@##########&&####&%|!||
//:::::'''::::::::::::!&########|:;|$@#########@&###&%||||!
//:::::::'''''':::::::!&#######@!:;!!$@########@$&##@%||||!
//
// だからよ...止まるじゃねえぞ
// */
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
// #define ll long long
const int N = 1e6 + 10;
#define PII pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) (int)(x).size()
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, m, t;
#define __i __int128
// ll mod = 1e9+7;
string manacher(string s) {
if (s.size() < 2)
return s;
string t;
t += '$';
for (int i = 0; i < s.size(); i++)
t += '#' + s[i];
t += '@';
int num = t.size();
int p[num];
int id = 0, mx = 0;
int maxl = -1;
int index = 0;
for (int j = 1; j < num - 1; j++) {
p[j] = mx > j ? min(p[2 * id - j], mx - j) : 1;
while (t[j + p[j]] == t[j - p[j]])
p[j]++;
if (mx < p[j] + j) {
mx = p[j] + j;
id = j;
}
if (maxl < p[j] + 1) {
maxl = p[j] - 1;
index = j;
}
}
int start = (index - maxl) / 2;
// cout <<start<<endl;
return s.substr(start, start + maxl);
}
int ar[200010];
int br[100010];
vector<int> v[100010];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
map<ll, ll> mp;
for (int i = 1; i <= n; i++)
cin >> ar[i], mp[ar[i]]++;
map<ll, ll> mm;
ll sum = 0;
for (auto it : mp)
sum += (it.second) * (it.second - 1) / 2;
for (int i = 1; i <= n; i++) {
cout << sum - (mp[ar[i]] - 1) << endl;
}
return 0;
}
| replace | 101 | 102 | 101 | 102 | 0 | |
p02732 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
using namespace std;
int n;
int a[100005], num[100005], sum;
int cal(int x) { return x * (x - 1) / 2; }
signed main() {
scanf("%lld", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]), num[a[i]]++;
for (int i = 1; i <= n; i++)
sum += cal(num[i]);
for (int i = 1; i <= n; i++)
printf("%lld\n", sum - cal(num[a[i]]) + cal(num[a[i]] - 1));
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
using namespace std;
int n;
int a[1000005], num[1000005], sum;
int cal(int x) { return x * (x - 1) / 2; }
signed main() {
scanf("%lld", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]), num[a[i]]++;
for (int i = 1; i <= n; i++)
sum += cal(num[i]);
for (int i = 1; i <= n; i++)
printf("%lld\n", sum - cal(num[a[i]]) + cal(num[a[i]] - 1));
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long mp[30005] = {0};
signed main() {
long long n;
cin >> n;
long long a[n + 5];
set<long long> st;
for (long long i = 0; i < n; ++i) {
/* code */
cin >> a[i];
st.insert(a[i]);
mp[a[i]]++;
}
long long sum = 0;
for (long long ele : st) {
long long temp = (mp[ele] * (mp[ele] - 1)) / 2;
long long zero = 0;
sum += (max(zero, temp));
}
for (long long i = 0; i < n; i++) {
cout << sum - (mp[a[i]] - 1) << '\n';
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long mp[300005] = {0};
signed main() {
long long n;
cin >> n;
long long a[n + 5];
set<long long> st;
for (long long i = 0; i < n; ++i) {
/* code */
cin >> a[i];
st.insert(a[i]);
mp[a[i]]++;
}
long long sum = 0;
for (long long ele : st) {
long long temp = (mp[ele] * (mp[ele] - 1)) / 2;
long long zero = 0;
sum += (max(zero, temp));
}
for (long long i = 0; i < n; i++) {
cout << sum - (mp[a[i]] - 1) << '\n';
}
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02732 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647; // int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
ll n;
cin >> n;
unordered_map<ll, ll> m;
vector<ll> v(n);
rep(i, n) {
int in;
cin >> in;
v[i] = in;
m[in]++;
}
unordered_map<ll, ll> memo;
for (int i = 1; i <= n; i++) {
ll ans = 0;
if (memo.find(v.at(i - 1)) == memo.end()) {
for (auto a : m) {
if (a.first == v.at(i - 1)) {
ans += (a.second - 1) * (a.second - 2) / 2;
} else {
ans += a.second * (a.second - 1) / 2;
}
}
cout << ans << endl;
memo[v.at(i - 1)] = ans;
} else {
cout << memo.at(v.at(i - 1)) << endl;
}
}
return 0;
}
/*
やっほい!
やほほい!
+ *
∧∧ . ∧∞∧ *
* ヽ(=´ω`)人(´ω`*)ノ
.~( O x.) ( O)~ +
。* ∪ ∪
*/ | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647; // int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
ll n;
cin >> n;
unordered_map<ll, ll> m;
vector<ll> v(n);
rep(i, n) {
int in;
cin >> in;
v[i] = in;
m[in]++;
}
ll sum = 0;
for (auto a : m) {
sum += a.second * (a.second - 1) / 2;
}
for (int i = 0; i < n; i++) {
cout << sum - (m.at(v[i])) * (m.at(v[i]) - 1) / 2 +
(m.at(v[i]) - 1) * (m.at(v[i]) - 2) / 2
<< endl;
}
return 0;
}
/*
やっほい!
やほほい!
+ *
∧∧ . ∧∞∧ *
* ヽ(=´ω`)人(´ω`*)ノ
.~( O x.) ( O)~ +
。* ∪ ∪
*/ | replace | 19 | 35 | 19 | 27 | TLE | |
p02732 | C++ | Runtime Error |
#include "bits/stdc++.h"
#define MOD 1000000007
#define rep(i, N) for (int i = 0; i < N; i++)
#define ll long long
#define int long long
using namespace std;
class Fact {
public:
vector<ll> f;
Fact(ll n) {
f = vector<ll>(n + 1);
f[0] = 1;
f[1] = 1;
for (int i = 2; i <= n; i++)
f[i] = f[i - 1] * i;
}
ll get(ll n) { return f[n]; }
ll comb(ll n, ll r) { return get(n) / (get(n - r) * get(r)); }
};
signed main(void) {
int N;
cin >> N;
Fact f(N + 1);
vector<int> A(N), cnt(N);
int totComb = 0;
rep(i, N) {
cin >> A[i];
A[i]--;
cnt[A[i]]++;
}
rep(i, N) if (cnt[i] >= 2) totComb += f.comb(cnt[i], 2);
rep(i, N) { cout << totComb - (cnt[A[i]] - 1) << endl; }
return 0;
} |
#include "bits/stdc++.h"
#define MOD 1000000007
#define rep(i, N) for (int i = 0; i < N; i++)
#define ll long long
#define int long long
using namespace std;
class Fact {
public:
vector<ll> f;
Fact(ll n) {
f = vector<ll>(n + 1);
f[0] = 1;
f[1] = 1;
for (int i = 2; i <= n; i++)
f[i] = f[i - 1] * i;
}
ll get(ll n) { return f[n]; }
ll comb(ll n, ll r) { return get(n) / (get(n - r) * get(r)); }
};
signed main(void) {
int N;
cin >> N;
Fact f(N + 1);
vector<int> A(N), cnt(N);
int totComb = 0;
rep(i, N) {
cin >> A[i];
A[i]--;
cnt[A[i]]++;
}
rep(i, N) if (cnt[i] >= 2) totComb += (cnt[i] * (cnt[i] - 1)) / 2;
rep(i, N) { cout << totComb - (cnt[A[i]] - 1) << endl; }
return 0;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long a[N], b[N];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
long long sum = 0;
for (int i = 0; i < N; i++) {
sum += (b[i] * (b[i] - 1) / 2);
}
for (int i = 0; i < n; i++) {
cout << sum - b[a[i]] + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long a[N], b[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
long long sum = 0;
for (int i = 0; i < N; i++) {
sum += (b[i] * (b[i] - 1) / 2);
}
for (int i = 0; i < n; i++) {
cout << sum - b[a[i]] + 1 << endl;
}
return 0;
} | delete | 7 | 12 | 7 | 7 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
template <class T> void chmin(T &x, T y) {
if (x < y)
x = y;
}
template <class T> void chmax(T &x, T y) {
if (x > y)
x = y;
}
int N;
map<int, ll> mp;
int A[100010];
ll sum;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
mp[A[i]]++;
}
for (auto u : mp) {
ll cnt = u.second;
sum += cnt * (cnt - (ll)1) / (ll)2;
}
for (int i = 0; i < N; i++) {
ll c = mp[A[i]];
cout << sum - c + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
template <class T> void chmin(T &x, T y) {
if (x < y)
x = y;
}
template <class T> void chmax(T &x, T y) {
if (x > y)
x = y;
}
int N;
map<int, ll> mp;
int A[200010];
ll sum;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
mp[A[i]]++;
}
for (auto u : mp) {
ll cnt = u.second;
sum += cnt * (cnt - (ll)1) / (ll)2;
}
for (int i = 0; i < N; i++) {
ll c = mp[A[i]];
cout << sum - c + 1 << endl;
}
return 0;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p02732 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, a) for (auto &i : a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main();
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
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;
}
template <class T> using v = vector<T>;
template <class T> using vv = vector<v<T>>;
const int MOD = 1e9 + 7;
const long long INF = 1LL << 60;
signed _main() {
int N;
cin >> N;
v<int> A(N);
unordered_map<int, int> map;
rep(i, N) {
cin >> A[i];
map[A[i]]++;
}
rep(i, N) {
map[A[i]]--;
int ans = 0;
fore(j, map) { ans += j.second * (j.second - 1) / 2; }
cout << ans << endl;
map[A[i]]++;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, a) for (auto &i : a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main();
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
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;
}
template <class T> using v = vector<T>;
template <class T> using vv = vector<v<T>>;
const int MOD = 1e9 + 7;
const long long INF = 1LL << 60;
signed _main() {
int N;
cin >> N;
v<int> A(N);
unordered_map<int, int> map;
rep(i, N) {
cin >> A[i];
map[A[i]]++;
}
int ans = 0;
fore(j, map) { ans += j.second * (j.second - 1) / 2; }
rep(i, N) { cout << ans - map[A[i]] + 1 << endl; }
return 0;
}
| replace | 46 | 53 | 46 | 49 | TLE | |
p02732 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <vector>
#define REP(i, n, N) for (ll i = (n); i < (N); i++)
// #define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
using namespace std;
typedef long long ll;
const long long MOD = 1e9 + 7;
int main() {
ll n;
cin >> n;
vector<ll> a(n);
REP(i, 0, n) { cin >> a.at(i); }
vector<ll> comb(n + 1, 0);
vector<ll> comb_self(n + 1, 0);
vector<ll> copy = a;
sort(copy.begin(), copy.end());
ll count = 1;
ll tmp = copy.at(0);
REP(i, 0, n) {
if (i == 0) {
continue;
}
if (tmp != copy.at(i)) {
if (count >= 2) {
comb.at(tmp) = count * (count - 1) / 2;
comb_self.at(tmp) = (count - 2) * (count - 1) / 2;
}
tmp = copy.at(i);
count = 1;
} else {
count++;
}
}
if (count >= 2) {
comb.at(tmp) = count * (count - 1) / 2;
comb_self.at(tmp) = (count - 2) * (count - 1) / 2;
}
// ll sum = accumulate(comb.begin(), comb.end(), 0);
REP(i, 0, n) {
p(accumulate(comb.begin(), comb.end(), ll(0)) - comb.at(a.at(i)) +
comb_self.at(a.at(i)));
}
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <vector>
#define REP(i, n, N) for (ll i = (n); i < (N); i++)
// #define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout << (s) << endl
#define p2(a, b) cout << (a) << " " << (b) << endl
using namespace std;
typedef long long ll;
const long long MOD = 1e9 + 7;
int main() {
ll n;
cin >> n;
vector<ll> a(n);
REP(i, 0, n) { cin >> a.at(i); }
vector<ll> comb(n + 1, 0);
vector<ll> comb_self(n + 1, 0);
vector<ll> copy = a;
sort(copy.begin(), copy.end());
ll count = 1;
ll tmp = copy.at(0);
REP(i, 0, n) {
if (i == 0) {
continue;
}
if (tmp != copy.at(i)) {
if (count >= 2) {
comb.at(tmp) = count * (count - 1) / 2;
comb_self.at(tmp) = (count - 2) * (count - 1) / 2;
}
tmp = copy.at(i);
count = 1;
} else {
count++;
}
}
if (count >= 2) {
comb.at(tmp) = count * (count - 1) / 2;
comb_self.at(tmp) = (count - 2) * (count - 1) / 2;
}
ll sum = accumulate(comb.begin(), comb.end(), 0LL);
REP(i, 0, n) { p(sum - comb.at(a.at(i)) + comb_self.at(a.at(i))); }
} | replace | 53 | 58 | 53 | 55 | TLE | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for (ll i = 0; i < t; i++)
#define bs(a, x) binary_search(a.begin(), a.end(), x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int, int>
#define umpl unordered_map<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 1000000007
#define N 10000000
#define all(a) a.begin(), a.end()
#define point pair<ll, ll>
const int inf = 100000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM = 100005;
inline ll mul(ll a, ll b) { return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b) {
ll c = a - b;
if (c < 0)
c += mod;
return c;
}
inline ll add(ll a, ll b) {
ll c = a + b;
if (c >= mod)
c -= mod;
return c;
}
inline ll max(ll a, ll b) { return a > b ? a : b; }
inline ll min(ll a, ll b) { return a < b ? a : b; }
struct hash_pair {
template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
ll dp[100005][2];
ll binomialCoeff(ll n, ll k) {
ll C[k + 1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (ll i = 1; i <= n; i++) {
for (ll j = min(i, k); j > 0; j--)
C[j] = C[j] + C[j - 1];
dp[i][k] = C[k];
}
return dp[n][k] = C[k];
}
int main() {
fio;
ll n;
cin >> n;
vl a(n);
f(n) cin >> a[i];
umpl mp;
f(n) mp[a[i]]++;
ll ans = 0;
memset(dp, 0, sizeof(dp));
binomialCoeff(n, 2);
for (auto i = mp.begin(); i != mp.end(); i++) {
ans = ans + dp[i->second][2];
}
for (ll i = 0; i < n; i++) {
ll ele = a[i];
ll temp = ans;
temp = temp - dp[mp[a[i]]][2];
temp = temp + dp[mp[a[i]] - 1][2];
cout << temp << "\n";
}
}
| #include <bits/stdc++.h>
using namespace std;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for (ll i = 0; i < t; i++)
#define bs(a, x) binary_search(a.begin(), a.end(), x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int, int>
#define umpl unordered_map<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 1000000007
#define N 10000000
#define all(a) a.begin(), a.end()
#define point pair<ll, ll>
const int inf = 100000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM = 100005;
inline ll mul(ll a, ll b) { return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b) {
ll c = a - b;
if (c < 0)
c += mod;
return c;
}
inline ll add(ll a, ll b) {
ll c = a + b;
if (c >= mod)
c -= mod;
return c;
}
inline ll max(ll a, ll b) { return a > b ? a : b; }
inline ll min(ll a, ll b) { return a < b ? a : b; }
struct hash_pair {
template <class T1, class T2> size_t operator()(const pair<T1, T2> &p) const {
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
ll dp[200005][3];
ll binomialCoeff(ll n, ll k) {
ll C[k + 1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (ll i = 1; i <= n; i++) {
for (ll j = min(i, k); j > 0; j--)
C[j] = C[j] + C[j - 1];
dp[i][k] = C[k];
}
return dp[n][k] = C[k];
}
int main() {
fio;
ll n;
cin >> n;
vl a(n);
f(n) cin >> a[i];
umpl mp;
f(n) mp[a[i]]++;
ll ans = 0;
memset(dp, 0, sizeof(dp));
binomialCoeff(n, 2);
for (auto i = mp.begin(); i != mp.end(); i++) {
ans = ans + dp[i->second][2];
}
for (ll i = 0; i < n; i++) {
ll ele = a[i];
ll temp = ans;
temp = temp - dp[mp[a[i]]][2];
temp = temp + dp[mp[a[i]] - 1][2];
cout << temp << "\n";
}
}
| replace | 52 | 53 | 52 | 53 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100010;
ll n, a[N], num[N];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i], num[a[i]]++;
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans += (num[i] - 1) * num[i] / 2;
// cout<<num[i]<<endl;
}
// cout<<ans<<endl;
for (int i = 0; i < n; i++)
cout << ans - num[a[i]] + 1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
ll n, a[N], num[N];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i], num[a[i]]++;
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans += (num[i] - 1) * num[i] / 2;
// cout<<num[i]<<endl;
}
// cout<<ans<<endl;
for (int i = 0; i < n; i++)
cout << ans - num[a[i]] + 1 << endl;
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02732 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define inf 1000000000000000000
#define ll long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
#define pair(A, B) make_pair(A, B)
using namespace std;
typedef pair<int, int> pi;
typedef pair<pair<int, int>, int> pii;
void perform() {
ll b[100001] = {0};
ll d[100001] = {0};
int n;
cin >> n;
ll arr[n];
ll totalDP = 0;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
b[t]++;
arr[i] = t;
totalDP -= d[t];
d[t] = (b[t] * (b[t] - 1)) / 2;
totalDP += d[t];
}
for (int i = 0; i < n; i++) {
ll ans = totalDP;
if (totalDP && b[arr[i]] - 1 > 0) {
ans -= d[arr[i]];
ans += ((b[arr[i]] - 1) * (b[arr[i]] - 2)) / 2;
}
cout << ans << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1; // cin >> t;
while (t--) {
perform();
}
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define inf 1000000000000000000
#define ll long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
#define pair(A, B) make_pair(A, B)
using namespace std;
typedef pair<int, int> pi;
typedef pair<pair<int, int>, int> pii;
void perform() {
ll b[200001] = {0};
ll d[200001] = {0};
int n;
cin >> n;
ll arr[n];
ll totalDP = 0;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
b[t]++;
arr[i] = t;
totalDP -= d[t];
d[t] = (b[t] * (b[t] - 1)) / 2;
totalDP += d[t];
}
for (int i = 0; i < n; i++) {
ll ans = totalDP;
if (totalDP && b[arr[i]] - 1 > 0) {
ans -= d[arr[i]];
ans += ((b[arr[i]] - 1) * (b[arr[i]] - 2)) / 2;
}
cout << ans << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1; // cin >> t;
while (t--) {
perform();
}
}
| replace | 23 | 25 | 23 | 25 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long con(long long n) { return n * (n - 1) / 2; }
int main() {
long long N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
vector<int> cnt(N);
for (int i = 0; i < N; i++)
cnt.at(A.at(i))++;
long long sum = 0;
for (int i = 0; i < N; i++) {
sum += con(cnt.at(i));
}
for (int i = 0; i < N; i++) {
long long ans = sum - con(cnt.at(A.at(i))) + con(cnt.at(A.at(i)) - 1);
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long con(long long n) { return n * (n - 1) / 2; }
int main() {
long long N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
A.at(i)--;
}
vector<int> cnt(N);
for (int i = 0; i < N; i++)
cnt.at(A.at(i))++;
long long sum = 0;
for (int i = 0; i < N; i++) {
sum += con(cnt.at(i));
}
for (int i = 0; i < N; i++) {
long long ans = sum - con(cnt.at(A.at(i))) + con(cnt.at(A.at(i)) - 1);
cout << ans << endl;
}
return 0;
}
| insert | 11 | 11 | 11 | 12 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n;
int a[N];
int occ[N];
long long ans;
int main() {
// freopen("in.in" , "r" , stdin);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
ans += occ[a[i]]++;
}
for (int i = 0; i < n; i++) {
ans -= --occ[a[i]];
cout << ans << "\n";
ans += occ[a[i]]++;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n;
int a[N];
int occ[N];
long long ans;
int main() {
// freopen("in.in" , "r" , stdin);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
ans += occ[a[i]]++;
}
for (int i = 0; i < n; i++) {
ans -= --occ[a[i]];
cout << ans << "\n";
ans += occ[a[i]]++;
}
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02732 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
int A[100000];
int cnt[100000];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
A[i]--;
}
for (int i = 0; i < N; i++) {
cnt[i] = 0;
}
for (int i = 0; i < N; i++) {
cnt[A[i]] += 1;
}
long long ans = 0;
for (int i = 0; i < N; i++) {
ans += (long long)cnt[i] * (cnt[i] - 1) / 2;
}
for (int i = 0; i < N; i++) {
if (cnt[A[i]] > 1) {
cout << ans - cnt[A[i]] + 1 << "\n";
} else {
cout << ans << "\n";
}
}
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
int A[200000];
int cnt[200000];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
A[i]--;
}
for (int i = 0; i < N; i++) {
cnt[i] = 0;
}
for (int i = 0; i < N; i++) {
cnt[A[i]] += 1;
}
long long ans = 0;
for (int i = 0; i < N; i++) {
ans += (long long)cnt[i] * (cnt[i] - 1) / 2;
}
for (int i = 0; i < N; i++) {
if (cnt[A[i]] > 1) {
cout << ans - cnt[A[i]] + 1 << "\n";
} else {
cout << ans << "\n";
}
}
} | replace | 17 | 19 | 17 | 19 | 0 | |
p02732 | C++ | Runtime Error | #include <iostream>
#include <set>
using namespace std;
const int maxn = 1e5 + 50;
long long a[maxn], cnt[maxn];
set<int> temp;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
cnt[a[i]]++;
}
long long ans = 0;
for (int i = 1; i <= n; ++i) {
if (cnt[i])
ans += (cnt[i] - 1) * cnt[i] / 2;
}
for (int i = 1; i <= n; ++i)
cout << ans - cnt[a[i]] + 1 << endl;
} | #include <iostream>
#include <set>
using namespace std;
const int maxn = 2e5 + 50;
long long a[maxn], cnt[maxn];
set<int> temp;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
cnt[a[i]]++;
}
long long ans = 0;
for (int i = 1; i <= n; ++i) {
if (cnt[i])
ans += (cnt[i] - 1) * cnt[i] / 2;
}
for (int i = 1; i <= n; ++i)
cout << ans - cnt[a[i]] + 1 << endl;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02732 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
ll N;
ll A[100005];
ll cnt[100005];
ll calc(ll n) { return n * (n - 1) / 2; }
int main() {
cin >> N;
ll a;
for (int i = 0; i < N; i++) {
cin >> A[i];
A[i]--;
cnt[A[i]]++;
}
ll sum = 0;
for (int i = 0; i < N; i++) {
sum += calc(cnt[i]);
}
for (int i = 0; i < N; i++) {
cout << sum - cnt[A[i]] + 1 << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
ll N;
ll A[200005];
ll cnt[200005];
ll calc(ll n) { return n * (n - 1) / 2; }
int main() {
cin >> N;
ll a;
for (int i = 0; i < N; i++) {
cin >> A[i];
A[i]--;
cnt[A[i]]++;
}
ll sum = 0;
for (int i = 0; i < N; i++) {
sum += calc(cnt[i]);
}
for (int i = 0; i < N; i++) {
cout << sum - cnt[A[i]] + 1 << endl;
}
return 0;
} | replace | 15 | 17 | 15 | 17 | 0 | |
p02732 | C++ | Runtime Error | // made by capeta160
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define etm \
cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define doub long double
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pll pair<long long int, long long int>
#define vpl vector<pll>
#define vll vector<ll>
#define vb vector<bool>
#define vvbb vector<vb>
#define vi vector<int>
#define mi map<int, int>
#define mull map<ull, ull>
#define stp setprecision(20)
#define N 100005
#define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
#define MOD 1000000007
#define ld long double
#define inf 1e18
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vvpll vector<vector<pair<ll, ll>>>
#define vvll vector<vector<ll>>
#define vvii vector<vector<int>>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define test \
ll T; \
cin >> T; \
while (T--)
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define show(w, size) \
for (ll i = 0; i < size; i++) \
cout << w[i] << " ";
#define print(a) cout << a << "\n";
#define pqll priority_queue<ll>
#define mset(dp, no) memset(dp, no, sizeof(dp))
#define umll unordered_map<ll, ll>
#define mll map<ll, ll>
#define input(a, n) \
ll I; \
rep(I, 0, n - 1, 1) cin >> a[I];
#define countbit __builtin_popcount // Number of set bits .
#define fbo(k) find_by_order // K-th element in a set (counting from zero) .
#define ook(k) order_of_key // Number of items strictly smaller than k .
#define lb lower_bound
#define up upper_bound
#define in insert
// #define db(x) cout <<#x<<": "<<x<<'\n';
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << '\n';
}
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...);
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll isPrime(ll n) {
ll p = (ll)sqrt(n);
rep(i, 2, p, 1) if (n % i == 0) return 0;
return 1;
} // reuturn 1 if prime
ll pow(ll b, ll e) {
if (e == 0)
return 1;
else if (e % 2 == 0) {
ll a = pow(b, e / 2);
return a * a;
} else {
ll a = pow(b, e / 2);
return b * a * a;
}
}
ll powm(ll x, ll y, ll m = MOD) {
x = x % m;
ll res = 1;
while (y) {
if (y & 1)
res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
ll ceil(long double a) {
ll b = a;
if (a == b) {
return b;
} else {
return b + 1;
}
}
ll floor(long double a) {
ll b = a;
return b;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll a, ll m) { return powm(a, m - 2, m); }
bool issq(ll n) {
ll p = sqrt(n);
return p * p == n;
}
vll prime; // if i==prime[i] then prime otherwise smallest prime factor of that
// number
void sieve(ll n) {
prime.resize(n + 1, 1);
prime[0] = 0, prime[1] = 0;
for (ll i = 2; i * i <= n; i++)
if (prime[i])
for (ll j = i * i; j <= n; j += i)
prime[j] = 0;
}
ll extended_GCD(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
ll mulInv(ll a, ll mod = 26) {
ll x, y;
extended_GCD(a, mod, x, y);
if (x < 0)
x += mod;
return x;
}
ll find(ll num[], ll rem[], ll k, ll prod) {
// Compute product of all numbers
ll result = 0;
// Apply above formula
for (ll i = 0; i < k; i++) {
ll pp = prod / num[i];
result += rem[i] * mulInv(pp, num[i]) * pp;
}
return result % prod;
}
ll nCr(ll n, ll k) {
ll res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate value of
// [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (ll i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
class DSU {
public:
vll parent, size;
public:
DSU(ll n) {
parent.resize(n + 1);
size.resize(n + 1);
for (ll i = 1; i <= n; i++) {
parent[i] = i;
size[i] = 1;
}
}
public:
ll find_set(ll x) {
if (parent[x] == x) {
return x;
}
return parent[x] = find_set(parent[x]);
}
public:
void union_set(ll x, ll y) {
x = find_set(x);
y = find_set(y);
if (x != y) {
parent[y] = x;
}
}
};
bool cmp(pair<ll, ll> &p1, pair<ll, ll> &p2) {
if (p1.fi == p2.fi) {
return p1.se > p2.se;
}
return p1.fi > p2.fi;
}
bool isPalindrome(string s) {
ll i, j;
for (i = 0, j = s.length() - 1; i <= j; i++, j--) {
if (s[i] != s[j]) {
return 0;
}
}
return 1;
}
ll ToInt(char ch) { return ch - '0'; }
char ToChar(ll a) { return a + '0'; }
bool isSubSeq(string str1, string str2, ll m, ll n) {
// Base Cases
if (m == 0)
return true;
if (n == 0)
return false;
// If last characters of two strings are matching
if (str1[m - 1] == str2[n - 1])
return isSubSeq(str1, str2, m - 1, n - 1);
// If last characters are not matching
return isSubSeq(str1, str2, m, n - 1);
}
void printVectorPair(vpll v) {
for (ll i = 0; i < v.size(); i++) {
cout << v[i].fi << " " << v[i].se << "\n";
}
}
void modBigNumber(string num, ll m) {
// Store the modulus of big number
vector<int> vec;
ll mod = 0;
// Do step by step division
for (int i = 0; i < num.size(); i++) {
int digit = num[i] - '0';
mod = mod * 10 + digit;
int quo = mod / m;
if ((vec.size() != 0) || (quo != 0)) // to remove initiale zeros
vec.push_back(quo);
mod = mod % m;
}
// cout << "\nRemainder : " << mod << "\n";
// cout << "Quotient : ";rep(i,0,vec.size()-1,1)cout<<vec[i];cout<<"\n";
return;
}
struct SegmentTree {
ll n;
vll v;
SegmentTree(ll size) {
n = 4 * size + 1;
v.resize(n, 0);
}
void build(ll ar[], ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] = ar[ipos];
else {
ll mid = (ipos + fpos) / 2;
build(ar, ipos, mid, pos * 2);
build(ar, mid + 1, fpos, pos * 2 + 1);
v[pos] = v[pos * 2] + v[pos * 2 + 1];
}
}
void update(ll index, ll val, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] += val;
else {
v[pos] += val;
ll mid = (ipos + fpos) / 2;
if (mid >= index)
update(index, val, ipos, mid, pos * 2);
else
update(index, val, mid + 1, fpos, pos * 2 + 1);
}
}
ll get_sum(ll l, ll r, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return 0;
if (l > r)
return 0;
ll mid = (ipos + fpos) / 2;
if ((l == ipos) && (r == fpos))
return v[pos];
else
return get_sum(l, min(mid, r), ipos, mid, pos * 2) +
get_sum(max(mid + 1, l), r, mid + 1, fpos, pos * 2 + 1);
}
};
struct BIT {
vector<ll> bitree;
ll n;
BIT(ll n) {
this->n = n;
bitree.resize(n + 1, 0);
}
void update(ll idx, ll val) {
idx++;
while (idx <= n) {
bitree[idx] += val;
idx += idx & (-idx);
}
}
ll Sum(ll idx) {
ll sum = 0;
idx++;
while (idx > 0) {
sum += bitree[idx];
idx -= idx & (-idx);
}
return sum;
}
};
ll sumofdigits(ll a) {
ll val = 0;
while (a > 0) {
val += a % 10;
a /= 10;
}
return val;
}
int main() {
fastio;
ll n;
cin >> n;
vll arr(n);
vll pre(1e5 + 5, 0);
rep(i, 0, n - 1, 1) {
cin >> arr[i];
pre[arr[i]]++;
}
ll ans = 1;
rep(i, 1, n, 1) {
if (pre[i] != 0 and pre[i] != 1) {
ans += (pre[i] * (pre[i] - 1)) / 2;
}
}
rep(i, 0, n - 1, 1) { cout << (ans - pre[arr[i]]) << endl; }
return 0;
} | // made by capeta160
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define etm \
cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define doub long double
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pll pair<long long int, long long int>
#define vpl vector<pll>
#define vll vector<ll>
#define vb vector<bool>
#define vvbb vector<vb>
#define vi vector<int>
#define mi map<int, int>
#define mull map<ull, ull>
#define stp setprecision(20)
#define N 100005
#define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
#define MOD 1000000007
#define ld long double
#define inf 1e18
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vvpll vector<vector<pair<ll, ll>>>
#define vvll vector<vector<ll>>
#define vvii vector<vector<int>>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define test \
ll T; \
cin >> T; \
while (T--)
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define show(w, size) \
for (ll i = 0; i < size; i++) \
cout << w[i] << " ";
#define print(a) cout << a << "\n";
#define pqll priority_queue<ll>
#define mset(dp, no) memset(dp, no, sizeof(dp))
#define umll unordered_map<ll, ll>
#define mll map<ll, ll>
#define input(a, n) \
ll I; \
rep(I, 0, n - 1, 1) cin >> a[I];
#define countbit __builtin_popcount // Number of set bits .
#define fbo(k) find_by_order // K-th element in a set (counting from zero) .
#define ook(k) order_of_key // Number of items strictly smaller than k .
#define lb lower_bound
#define up upper_bound
#define in insert
// #define db(x) cout <<#x<<": "<<x<<'\n';
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << '\n';
}
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...);
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll isPrime(ll n) {
ll p = (ll)sqrt(n);
rep(i, 2, p, 1) if (n % i == 0) return 0;
return 1;
} // reuturn 1 if prime
ll pow(ll b, ll e) {
if (e == 0)
return 1;
else if (e % 2 == 0) {
ll a = pow(b, e / 2);
return a * a;
} else {
ll a = pow(b, e / 2);
return b * a * a;
}
}
ll powm(ll x, ll y, ll m = MOD) {
x = x % m;
ll res = 1;
while (y) {
if (y & 1)
res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
ll ceil(long double a) {
ll b = a;
if (a == b) {
return b;
} else {
return b + 1;
}
}
ll floor(long double a) {
ll b = a;
return b;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll a, ll m) { return powm(a, m - 2, m); }
bool issq(ll n) {
ll p = sqrt(n);
return p * p == n;
}
vll prime; // if i==prime[i] then prime otherwise smallest prime factor of that
// number
void sieve(ll n) {
prime.resize(n + 1, 1);
prime[0] = 0, prime[1] = 0;
for (ll i = 2; i * i <= n; i++)
if (prime[i])
for (ll j = i * i; j <= n; j += i)
prime[j] = 0;
}
ll extended_GCD(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
ll mulInv(ll a, ll mod = 26) {
ll x, y;
extended_GCD(a, mod, x, y);
if (x < 0)
x += mod;
return x;
}
ll find(ll num[], ll rem[], ll k, ll prod) {
// Compute product of all numbers
ll result = 0;
// Apply above formula
for (ll i = 0; i < k; i++) {
ll pp = prod / num[i];
result += rem[i] * mulInv(pp, num[i]) * pp;
}
return result % prod;
}
ll nCr(ll n, ll k) {
ll res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate value of
// [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (ll i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
class DSU {
public:
vll parent, size;
public:
DSU(ll n) {
parent.resize(n + 1);
size.resize(n + 1);
for (ll i = 1; i <= n; i++) {
parent[i] = i;
size[i] = 1;
}
}
public:
ll find_set(ll x) {
if (parent[x] == x) {
return x;
}
return parent[x] = find_set(parent[x]);
}
public:
void union_set(ll x, ll y) {
x = find_set(x);
y = find_set(y);
if (x != y) {
parent[y] = x;
}
}
};
bool cmp(pair<ll, ll> &p1, pair<ll, ll> &p2) {
if (p1.fi == p2.fi) {
return p1.se > p2.se;
}
return p1.fi > p2.fi;
}
bool isPalindrome(string s) {
ll i, j;
for (i = 0, j = s.length() - 1; i <= j; i++, j--) {
if (s[i] != s[j]) {
return 0;
}
}
return 1;
}
ll ToInt(char ch) { return ch - '0'; }
char ToChar(ll a) { return a + '0'; }
bool isSubSeq(string str1, string str2, ll m, ll n) {
// Base Cases
if (m == 0)
return true;
if (n == 0)
return false;
// If last characters of two strings are matching
if (str1[m - 1] == str2[n - 1])
return isSubSeq(str1, str2, m - 1, n - 1);
// If last characters are not matching
return isSubSeq(str1, str2, m, n - 1);
}
void printVectorPair(vpll v) {
for (ll i = 0; i < v.size(); i++) {
cout << v[i].fi << " " << v[i].se << "\n";
}
}
void modBigNumber(string num, ll m) {
// Store the modulus of big number
vector<int> vec;
ll mod = 0;
// Do step by step division
for (int i = 0; i < num.size(); i++) {
int digit = num[i] - '0';
mod = mod * 10 + digit;
int quo = mod / m;
if ((vec.size() != 0) || (quo != 0)) // to remove initiale zeros
vec.push_back(quo);
mod = mod % m;
}
// cout << "\nRemainder : " << mod << "\n";
// cout << "Quotient : ";rep(i,0,vec.size()-1,1)cout<<vec[i];cout<<"\n";
return;
}
struct SegmentTree {
ll n;
vll v;
SegmentTree(ll size) {
n = 4 * size + 1;
v.resize(n, 0);
}
void build(ll ar[], ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] = ar[ipos];
else {
ll mid = (ipos + fpos) / 2;
build(ar, ipos, mid, pos * 2);
build(ar, mid + 1, fpos, pos * 2 + 1);
v[pos] = v[pos * 2] + v[pos * 2 + 1];
}
}
void update(ll index, ll val, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] += val;
else {
v[pos] += val;
ll mid = (ipos + fpos) / 2;
if (mid >= index)
update(index, val, ipos, mid, pos * 2);
else
update(index, val, mid + 1, fpos, pos * 2 + 1);
}
}
ll get_sum(ll l, ll r, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return 0;
if (l > r)
return 0;
ll mid = (ipos + fpos) / 2;
if ((l == ipos) && (r == fpos))
return v[pos];
else
return get_sum(l, min(mid, r), ipos, mid, pos * 2) +
get_sum(max(mid + 1, l), r, mid + 1, fpos, pos * 2 + 1);
}
};
struct BIT {
vector<ll> bitree;
ll n;
BIT(ll n) {
this->n = n;
bitree.resize(n + 1, 0);
}
void update(ll idx, ll val) {
idx++;
while (idx <= n) {
bitree[idx] += val;
idx += idx & (-idx);
}
}
ll Sum(ll idx) {
ll sum = 0;
idx++;
while (idx > 0) {
sum += bitree[idx];
idx -= idx & (-idx);
}
return sum;
}
};
ll sumofdigits(ll a) {
ll val = 0;
while (a > 0) {
val += a % 10;
a /= 10;
}
return val;
}
int main() {
fastio;
ll n;
cin >> n;
vll arr(n);
vll pre(2 * 1e5 + 5, 0);
rep(i, 0, n - 1, 1) {
cin >> arr[i];
pre[arr[i]]++;
}
ll ans = 1;
rep(i, 1, n, 1) {
if (pre[i] != 0 and pre[i] != 1) {
ans += (pre[i] * (pre[i] - 1)) / 2;
}
}
rep(i, 0, n - 1, 1) { cout << (ans - pre[arr[i]]) << endl; }
return 0;
} | replace | 364 | 365 | 364 | 365 | 0 | |
p02732 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
ll A[100010];
ll cnt[100010];
int main() {
int N;
cin >> N;
ll ans = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
ans += cnt[A[i]];
cnt[A[i]]++;
}
for (int i = 0; i < N; i++) {
cout << ans - cnt[A[i]] + 1 << endl;
}
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
ll A[200010];
ll cnt[200010];
int main() {
int N;
cin >> N;
ll ans = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
ans += cnt[A[i]];
cnt[A[i]]++;
}
for (int i = 0; i < N; i++) {
cout << ans - cnt[A[i]] + 1 << endl;
}
} | replace | 16 | 18 | 16 | 18 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i <= m; i++)
#define read(n) cin >> n;
#define write(n) cout << n;
using namespace std;
const int N = 1e5 + 5;
int n, cnt[N], x[N];
ll sum = 0;
int main() {
cin >> n;
rep(i, n) cin >> x[i], cnt[x[i]]++;
rep(i, n + 1) sum += 1ll * cnt[i] * (cnt[i] - 1) / 2;
// cout<<sum<<"\n";
rep(j, n) {
ll ans = sum;
int i = x[j];
if (cnt[i] != 0) {
ans = ans - 1ll * cnt[i] * (cnt[i] - 1) / 2 +
1ll * (cnt[i] - 1) * (cnt[i] - 2) / 2;
}
cout << ans << "\n";
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i <= m; i++)
#define read(n) cin >> n;
#define write(n) cout << n;
using namespace std;
const int N = 2e5 + 5;
int n, cnt[N], x[N];
ll sum = 0;
int main() {
cin >> n;
rep(i, n) cin >> x[i], cnt[x[i]]++;
rep(i, n + 1) sum += 1ll * cnt[i] * (cnt[i] - 1) / 2;
// cout<<sum<<"\n";
rep(j, n) {
ll ans = sum;
int i = x[j];
if (cnt[i] != 0) {
ans = ans - 1ll * cnt[i] * (cnt[i] - 1) / 2 +
1ll * (cnt[i] - 1) * (cnt[i] - 2) / 2;
}
cout << ans << "\n";
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int cnt[100010], a[100010];
int main() {
int n, c = 0;
ll ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int k;
cin >> a[i];
// if(cnt[a[i]]==0)c++;
cnt[a[i]]++;
}
for (int i = 1; i <= n; i++) {
if (cnt[i]) {
ans += cnt[i] * (cnt[i] - 1) / 2;
}
}
for (int i = 0; i < n; i++) {
ans -= cnt[a[i]] * (cnt[a[i]] - 1) / 2;
cnt[a[i]]--;
// ans+=cnt[a[i]]*(cnt[a[i]]-1)/2;
cout << ans + cnt[a[i]] * (cnt[a[i]] - 1) / 2 << '\n';
cnt[a[i]]++;
ans += cnt[a[i]] * (cnt[a[i]] - 1) / 2;
}
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
ll cnt[200010], a[200010];
int main() {
int n, c = 0;
ll ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int k;
cin >> a[i];
// if(cnt[a[i]]==0)c++;
cnt[a[i]]++;
}
for (int i = 1; i <= n; i++) {
if (cnt[i]) {
ans += cnt[i] * (cnt[i] - 1) / 2;
}
}
for (int i = 0; i < n; i++) {
ans -= cnt[a[i]] * (cnt[a[i]] - 1) / 2;
cnt[a[i]]--;
// ans+=cnt[a[i]]*(cnt[a[i]]-1)/2;
cout << ans + cnt[a[i]] * (cnt[a[i]] - 1) / 2 << '\n';
cnt[a[i]]++;
ans += cnt[a[i]] * (cnt[a[i]] - 1) / 2;
}
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define endl '\n'
// pair<int, int> *p=new pair<int, int>[n];
// std::vector<pair<int,int>> vp;
// v.push_back(make_pair(x,y))
// pair<int, int> p[1000001];
// string *s=new string [n];
// int freq[e];
// freq[a[i]-'a']++; freq[a[i]]++;
using namespace std;
ll n, t, m, c, x, y, sum, mx, mn, avg, pos, dif, j, dis;
map<ll, ll> mp;
bool vis[(int)1e5];
bool isPrime(int x) {
for (int i = 2; i * i <= x; i++)
if (x % i == 0)
return false;
return true;
}
int main(void) {
SpeeD cin >> n;
ll *a = new ll[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
for (int i = 0; i < n; i++) {
if (!vis[a[i]])
m += (mp[a[i]] * (mp[a[i]] - 1)) / 2;
vis[a[i]] = true;
}
for (int i = 0; i < n; i++) {
cout << m - mp[a[i]] + 1 << endl;
}
}
| #include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define endl '\n'
// pair<int, int> *p=new pair<int, int>[n];
// std::vector<pair<int,int>> vp;
// v.push_back(make_pair(x,y))
// pair<int, int> p[1000001];
// string *s=new string [n];
// int freq[e];
// freq[a[i]-'a']++; freq[a[i]]++;
using namespace std;
ll n, t, m, c, x, y, sum, mx, mn, avg, pos, dif, j, dis;
map<ll, ll> mp;
bool vis[(int)1e9];
bool isPrime(int x) {
for (int i = 2; i * i <= x; i++)
if (x % i == 0)
return false;
return true;
}
int main(void) {
SpeeD cin >> n;
ll *a = new ll[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
for (int i = 0; i < n; i++) {
if (!vis[a[i]])
m += (mp[a[i]] * (mp[a[i]] - 1)) / 2;
vis[a[i]] = true;
}
for (int i = 0; i < n; i++) {
cout << m - mp[a[i]] + 1 << endl;
}
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02732 | C++ | Runtime Error | /* ***********************************************
Author :taciturnity
Created Time :2020/2/21 8:23:51
File Name :TEST.cpp
************************************************ */
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i, x, y) for (int i = x; i <= y; ++i)
#define fori(i, x, y) for (int i = x; i >= y; --i)
#define bug puts("--------------")
#define out(x) cout << x << '\n';
inline char gc() {
char op[2];
scanf("%s", op);
return op[0];
}
const int N = 1e5 + 10;
const double eps = 0.00000001;
const ll mod = 1e9 + 7;
using namespace std;
ll read() {
ll x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
map<int, int> hap;
int a[N];
int main() {
int n = read();
rep(i, 1, n) a[i] = read(), hap[a[i]]++;
ll ans = 0;
for (auto p = hap.begin(); p != hap.end(); ++p) {
ll d = p->second;
ans += (d - 1) * d / 2;
}
rep(i, 1, n) {
ll d = hap[a[i]];
ll tmp = ans;
tmp -= d * (d - 1) / 2;
d--;
tmp += (d - 1) * d / 2;
cout << tmp << endl;
}
} | /* ***********************************************
Author :taciturnity
Created Time :2020/2/21 8:23:51
File Name :TEST.cpp
************************************************ */
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i, x, y) for (int i = x; i <= y; ++i)
#define fori(i, x, y) for (int i = x; i >= y; --i)
#define bug puts("--------------")
#define out(x) cout << x << '\n';
inline char gc() {
char op[2];
scanf("%s", op);
return op[0];
}
const int N = 2e5 + 10;
const double eps = 0.00000001;
const ll mod = 1e9 + 7;
using namespace std;
ll read() {
ll x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
map<int, int> hap;
int a[N];
int main() {
int n = read();
rep(i, 1, n) a[i] = read(), hap[a[i]]++;
ll ans = 0;
for (auto p = hap.begin(); p != hap.end(); ++p) {
ll d = p->second;
ans += (d - 1) * d / 2;
}
rep(i, 1, n) {
ll d = hap[a[i]];
ll tmp = ans;
tmp -= d * (d - 1) / 2;
d--;
tmp += (d - 1) * d / 2;
cout << tmp << endl;
}
} | replace | 30 | 31 | 30 | 31 | 0 | |
p02732 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, c) for (int i = 0; i < (int)c; ++i)
using llint = long long int;
using namespace std;
int main() {
int N;
map<llint, llint> mp;
vector<llint> A(N);
cin >> N;
rep(i, N) {
cin >> A[i];
mp[A[i]]++;
}
llint num = 0;
for (auto itr = mp.begin(); itr != mp.end(); itr++) {
llint seco = itr->second;
if (seco == 0)
continue;
else
num += seco * (seco - 1) / 2;
}
for (int i = 0; i < N; i++) {
if (mp[A[i]] < 2)
cout << num << endl;
else
cout << num - mp[A[i]] + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, c) for (int i = 0; i < (int)c; ++i)
using llint = long long int;
using namespace std;
int main() {
int N;
map<llint, llint> mp;
int A[200006];
cin >> N;
rep(i, N) {
cin >> A[i];
mp[A[i]]++;
}
llint num = 0;
for (auto itr = mp.begin(); itr != mp.end(); itr++) {
llint seco = itr->second;
if (seco == 0)
continue;
else
num += seco * (seco - 1) / 2;
}
for (int i = 0; i < N; i++) {
if (mp[A[i]] < 2)
cout << num << endl;
else
cout << num - mp[A[i]] + 1 << endl;
}
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.