QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#233821 | #6434. Paimon Sorting | 8xin | Compile Error | / | / | C++14 | 7.3kb | 2023-11-01 00:22:42 | 2023-11-01 00:22:44 |
Judging History
answer
// #include <iostream>
// #include <cstdio>
// #include <algorithm>
// #include <cstring>
// #include <cmath>
// #include <vector>
// #include <queue>
// #include <map>
// #include <unordered_map>
// #include <bitset>
// #include <set>
// #include <stack>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define inf 0x3f3f3f3f
#define endl "\n"
#define pi acos(-1)
#define eps 1e-9
const ll mod = 1e9 + 7;
ll qpow(ll base, ll power) {
ll res = 1;
while (power > 0) {
if (power & 1)
res = base * res % mod;
power >>= 1;
base = base * base % mod;
}
return res;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
double dis(double x, double y, double x1, double y1) {
return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
}
ll dis1(ll x, ll y, ll z, ll x1, ll y1, ll z1) {
return (x - x1) * (x - x1) + (y - y1) * (y - y1) + (z - z1) * (z - z1);
}
int chaji(int x1, int x2, int y1, int y2) {
return x1 * y2 - x2 * y1;
}
const int N = 1e6 + 10;
int n;
int a[N];
int tr[N];
int vis[N];
int pos[N];
int lowbit(int x) {
return x & -x;
}
void add(int x, int d) {
for (int i = x; i <= n; i += lowbit(i)) {
tr[i] += d;
}
}
ll query(int x) {
int res = 0;
for (int i = x; i; i -= lowbit(i)) {
res += tr[i];
}
return res;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
ll ans = 0;
vis[a[1]] = 1;
add(a[1], 1);
if(n==1) cout << 0 << endl;
else cout << 0 << " ";
for (int i = 2; i <= n; i++) {
if (!vis[a[i]]) {
add(a[i], 1);
}
vis[a[i]] ++;
if(vis[a[i]]==2) pos[a[i]]=i;
if (a[1] < a[i]) {
ans ++;
if(vis[a[1]]>=2) ans+=i-pos[a[1]];
swap(a[1], a[i]);
}
ans += query(n) - query(a[i]);
cout << ans;
if(i!=n) cout << " ";
else cout << endl;
}
for (int i = 1; i <= n; i++)
tr[i] = 0, vis[i] = 0,pos[i]=0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
// scanf("%d",&t);
while (t--) {
//cout << "Case #" << ++cnt << ": ";
solve();
}
}// #include <iostream>
// #include <cstdio>
// #include <algorithm>
// #include <cstring>
// #include <cmath>
// #include <vector>
// #include <queue>
// #include <map>
// #include <unordered_map>
// #include <bitset>
// #include <set>
// #include <stack>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define inf 0x3f3f3f3f
#define endl "\n"
#define pi acos(-1)
#define eps 1e-9
const ll mod = 1e9 + 7;
ll qpow(ll base, ll power) {
ll res = 1;
while (power > 0) {
if (power & 1)
res = base * res % mod;
power >>= 1;
base = base * base % mod;
}
return res;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
double dis(double x, double y, double x1, double y1) {
return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
}
ll dis1(ll x, ll y, ll z, ll x1, ll y1, ll z1) {
return (x - x1) * (x - x1) + (y - y1) * (y - y1) + (z - z1) * (z - z1);
}
int chaji(int x1, int x2, int y1, int y2) {
return x1 * y2 - x2 * y1;
}
const int N = 1e6 + 10;
int n;
int a[N];
int tr[N];
int vis[N];
int pos[N];
int lowbit(int x) {
return x & -x;
}
void add(int x, int d) {
for (int i = x; i <= n; i += lowbit(i)) {
tr[i] += d;
}
}
ll query(int x) {
int res = 0;
for (int i = x; i; i -= lowbit(i)) {
res += tr[i];
}
return res;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
ll ans = 0;
vis[a[1]] = 1;
add(a[1], 1);
if(n==1) cout << 0 << endl;
else cout << 0 << " ";
for (int i = 2; i <= n; i++) {
if (!vis[a[i]]) {
add(a[i], 1);
}
vis[a[i]] ++;
if(vis[a[i]]==2) pos[a[i]]=i;
if (a[1] < a[i]) {
ans ++;
if(vis[a[1]]>=2) ans+=i-pos[a[1]];
swap(a[1], a[i]);
}
ans += query(n) - query(a[i]);
cout << ans;
if(i!=n) cout << " ";
else cout << endl;
}
for (int i = 1; i <= n; i++)
tr[i] = 0, vis[i] = 0,pos[i]=0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
// scanf("%d",&t);
while (t--) {
//cout << "Case #" << ++cnt << ": ";
solve();
}
}// #include <iostream>
// #include <cstdio>
// #include <algorithm>
// #include <cstring>
// #include <cmath>
// #include <vector>
// #include <queue>
// #include <map>
// #include <unordered_map>
// #include <bitset>
// #include <set>
// #include <stack>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define inf 0x3f3f3f3f
#define endl "\n"
#define pi acos(-1)
#define eps 1e-9
const ll mod = 1e9 + 7;
ll qpow(ll base, ll power) {
ll res = 1;
while (power > 0) {
if (power & 1)
res = base * res % mod;
power >>= 1;
base = base * base % mod;
}
return res;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
double dis(double x, double y, double x1, double y1) {
return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
}
ll dis1(ll x, ll y, ll z, ll x1, ll y1, ll z1) {
return (x - x1) * (x - x1) + (y - y1) * (y - y1) + (z - z1) * (z - z1);
}
int chaji(int x1, int x2, int y1, int y2) {
return x1 * y2 - x2 * y1;
}
const int N = 1e6 + 10;
int n;
int a[N];
int tr[N];
int vis[N];
int pos[N];
int lowbit(int x) {
return x & -x;
}
void add(int x, int d) {
for (int i = x; i <= n; i += lowbit(i)) {
tr[i] += d;
}
}
ll query(int x) {
int res = 0;
for (int i = x; i; i -= lowbit(i)) {
res += tr[i];
}
return res;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
ll ans = 0;
vis[a[1]] = 1;
add(a[1], 1);
if(n==1) cout << 0 << endl;
else cout << 0 << " ";
for (int i = 2; i <= n; i++) {
if (!vis[a[i]]) {
add(a[i], 1);
}
vis[a[i]] ++;
if(vis[a[i]]==2) pos[a[i]]=i;
if (a[1] < a[i]) {
ans ++;
if(vis[a[1]]>=2) ans+=i-pos[a[1]];
swap(a[1], a[i]);
}
ans += query(n) - query(a[i]);
cout << ans;
if(i!=n) cout << " ";
else cout << endl;
}
for (int i = 1; i <= n; i++)
tr[i] = 0, vis[i] = 0,pos[i]=0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
// scanf("%d",&t);
while (t--) {
//cout << "Case #" << ++cnt << ": ";
solve();
}
}
Details
answer.code:141:10: error: redefinition of ‘const long long int mod’ 141 | const ll mod = 1e9 + 7; | ^~~ answer.code:23:10: note: ‘const long long int mod’ previously defined here 23 | const ll mod = 1e9 + 7; | ^~~ answer.code:143:4: error: redefinition of ‘long long int qpow(long long int, long long int)’ 143 | ll qpow(ll base, ll power) { | ^~~~ answer.code:25:4: note: ‘long long int qpow(long long int, long long int)’ previously defined here 25 | ll qpow(ll base, ll power) { | ^~~~ answer.code:154:4: error: redefinition of ‘long long int gcd(long long int, long long int)’ 154 | ll gcd(ll a, ll b) { | ^~~ answer.code:36:4: note: ‘long long int gcd(long long int, long long int)’ previously defined here 36 | ll gcd(ll a, ll b) { | ^~~ answer.code:158:4: error: redefinition of ‘long long int lcm(long long int, long long int)’ 158 | ll lcm(ll a, ll b) { | ^~~ answer.code:40:4: note: ‘long long int lcm(long long int, long long int)’ previously defined here 40 | ll lcm(ll a, ll b) { | ^~~ answer.code:162:8: error: redefinition of ‘double dis(double, double, double, double)’ 162 | double dis(double x, double y, double x1, double y1) { | ^~~ answer.code:44:8: note: ‘double dis(double, double, double, double)’ previously defined here 44 | double dis(double x, double y, double x1, double y1) { | ^~~ answer.code:166:4: error: redefinition of ‘long long int dis1(long long int, long long int, long long int, long long int, long long int, long long int)’ 166 | ll dis1(ll x, ll y, ll z, ll x1, ll y1, ll z1) { | ^~~~ answer.code:48:4: note: ‘long long int dis1(long long int, long long int, long long int, long long int, long long int, long long int)’ previously defined here 48 | ll dis1(ll x, ll y, ll z, ll x1, ll y1, ll z1) { | ^~~~ answer.code:170:5: error: redefinition of ‘int chaji(int, int, int, int)’ 170 | int chaji(int x1, int x2, int y1, int y2) { | ^~~~~ answer.code:52:5: note: ‘int chaji(int, int, int, int)’ previously defined here 52 | int chaji(int x1, int x2, int y1, int y2) { | ^~~~~ answer.code:173:11: error: redefinition of ‘const int N’ 173 | const int N = 1e6 + 10; | ^ answer.code:55:11: note: ‘const int N’ previously defined here 55 | const int N = 1e6 + 10; | ^ answer.code:174:5: error: redefinition of ‘int n’ 174 | int n; | ^ answer.code:56:5: note: ‘int n’ previously declared here 56 | int n; | ^ answer.code:175:5: error: redefinition of ‘int a [1000010]’ 175 | int a[N]; | ^ answer.code:57:5: note: ‘int a [1000010]’ previously declared here 57 | int a[N]; | ^ answer.code:176:5: error: redefinition of ‘int tr [1000010]’ 176 | int tr[N]; | ^~ answer.code:58:5: note: ‘int tr [1000010]’ previously declared here 58 | int tr[N]; | ^~ answer.code:177:5: error: redefinition of ‘int vis [1000010]’ 177 | int vis[N]; | ^~~ answer.code:59:5: note: ‘int vis [1000010]’ previously declared here 59 | int vis[N]; | ^~~ answer.code:178:5: error: redefinition of ‘int pos [1000010]’ 178 | int pos[N]; | ^~~ answer.code:60:5: note: ‘int pos [1000010]’ previously declared here 60 | int pos[N]; | ^~~ answer.code:179:5: error: redefinition of ‘int lowbit(int)’ 179 | int lowbit(int x) { | ^~~~~~ answer.code:61:5: note: ‘int lowbit(int)’ previously defined here 61 | int lowbit(int x) { | ^~~~~~ answer.code:183:6: error: redefinition of ‘void add(int, int)’ 183 | void add(int x, int d) { | ^~~ answer.code:65:6: note: ‘void add(int, int)’ previously defined here 65 | void add(int x, int d) { | ^~~ answer.code:189:4: error: redefinition of ‘long long int query(int)’ 189 | ll query(int x) { | ^~~~~ answer.code:71:4: note: ‘long long int query(int)’ previously defined here 71 | ll query(int x) { | ^~~~~ answer.code:197:6: error: redefinition of ‘void solve()’ 197 | void solve() { | ^~~~~ answer.code:79:6: note: ‘void solve()’ previously defined here 79 | void solve() { | ^~~~~ answer.code:226:5: error: redefinition of ‘int main()’ 226 | int main() { | ^~~~ answer.code:108:5: note: ‘int main()’ previously defined here 108 | int main() { | ^~~~ answer.code:259:10: error: redefinition of ‘const long long int mod’ 259 | const ll mod = 1e9 + 7; | ^~~ answer.code:23:10: note: ‘const long long int mod’ previously defined here 23 | const ll mod = 1e9 + 7; | ^~~ answer.code:261:4: error: redefinition of ‘long long int qpow(long long int, long long int)’ 261 | ll qpow(ll base, ll power) { | ^~~~ answer.code:25:4: note: ‘long long int qpow(long long int, long long int)’ previously defined here 25 | ll qpow(ll base, ll power) { ...