QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#718434 | #6434. Paimon Sorting | Unlimitedz | RE | 0ms | 0kb | C++17 | 2.4kb | 2024-11-06 20:30:54 | 2024-11-06 20:30:54 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
typedef long long ll;
const int maxv = 4e6 + 5;
typedef pair<ll, ll> pll;
typedef array<ll, 3> ar;
const ll lnf = 2e18;
const int inf=2e9;
// #define endl "\n"
int mod = 1e9 + 7;
template <typename T>
struct Fenwick {
int n;
std::vector<T> a;
Fenwick(int n_ = 0) {
init(n_);
}
void init(int n_) {
n = n_;
a.assign(n, T{});
}
void add(int x, const T &v) {
for (int i = x + 1; i <= n; i += i & -i) {
a[i - 1] = a[i - 1] + v;
}
}
T sum(int x) {
T ans{};
x++;
for (int i = x; i > 0; i -= i & -i) {
ans = ans + a[i - 1];
}
return ans;
}
T rangeSum(int l, int r) {
return sum(r) - sum(l);
}
int select(const T &k) {
int x = 0;
T cur{};
for (int i = 1 << std::__lg(n); i; i /= 2) {
if (x + i <= n && cur + a[x + i - 1] <= k) {
x += i;
cur = cur + a[x - 1];
}
}
return x;
}
};
void solve()
{
int n;
cin>>n;
vector<int> a(n+1);
for(int i=1;i<=n;i++) cin>>a[i];
Fenwick<int> t(n+5);
set<int> s;
int ans=0;
vector<int> p(n+5);
for(int i=1;i<=n;i++){
if(i==1){
// cout<<0<<" ";
p[i]=0;
s.insert(a[i]);
t.add(a[i],1);
}
else if(i==2){
if(a[i]>a[i-1]) ans=2;
if(a[i]<a[i-1]) ans=1;
p[i]=ans;
if(s.find(a[i])!=s.end()) continue;
t.add(a[i],1),s.insert(a[i]);
}
else{
int res=(int)s.size()-t.sum(a[i]);
if(res==0) res=2;
ans+=res;
p[i]=ans;
if(s.find(a[i])!=s.end()) continue;
t.add(a[i],1),s.insert(a[i]);
// cout<<ans<<" ";
}
}
// cout<<endl;
// for(int i=3;i<=n;i++){
// if(p[2]==2) p[i]--;
// }
for(int i=1;i<=n;i++) cout<<p[i]<<" ";
cout<<endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
system("pause");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
3 5 2 3 2 1 5 3 1 2 3 1 1
output:
0 2 3 5 7 0 2 4 0