QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#563717#6434. Paimon SortingAmiyaCastWA 210ms23108kbC++142.7kb2024-09-14 15:25:242024-09-14 15:25:24

Judging History

你现在查看的是最新测评结果

  • [2024-09-14 15:25:24]
  • 评测
  • 测评结果:WA
  • 用时:210ms
  • 内存:23108kb
  • [2024-09-14 15:25:24]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
const ll inf = 1145141919810;
using namespace std;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while (c<'0' || c>'9'){
        if (c=='-')  f=-1;
        c=getchar();
    }
    while (c>='0' && c<='9'){
        x=x*10+c-'0';
         c=getchar();
    }
    return x*f;
}
inline void print(ll x){
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + '0');
	return ;
}
inline void pprint(ll x){print(x); puts("");}
const int N = 2e5 + 7;
ll c[N], d[N], a[N], pos[N];
int n;
void add(int x, ll y){
	for(; x <= n; x += x & -x) c[x] += y;
}
ll ask(int x){
	ll res = 0;
	for(; x; x -= x & -x) res += c[x];
	return res;
}
struct Node{
	int l, r;
	ll add;
	ll sum;
}t[N << 2];
void build(int p, int l, int r){
	t[p] = Node{l, r};
	if(l == r) return ;
	const int mid = l + r >> 1;
	build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);
}
void up(int p){
	t[p].sum = t[p << 1].sum + t[p << 1 | 1].sum;
}
void down(int p){
	if(t[p].add){
		t[p << 1].sum += t[p].add, t[p << 1 | 1].sum += t[p].add;
		t[p << 1].add += t[p].add, t[p << 1 | 1].add += t[p].add;
		t[p].add = 0;
	}
}
void add(int p, int x, int y, ll k){
	int l = t[p].l, r = t[p].r;
	if(x <= l && r <= y){
		t[p].sum += k, t[p].add += k;
		return ;
	}
	down(p);
	const int mid = l + r >> 1;
	if(x <= mid) add(p << 1, x, y, k);
	if(y > mid) add(p << 1 | 1, x, y, k);
	up(p);
}

void slv(){
	build(1, 1, n);
	vector<ll> ans;
	ans.pb(0);
	
	ll maxn = a[1];
	if(ask(a[1]) - ask(a[1] - 1) == 0) add(a[1], 1);
	for(int i = 2; i <= n; ++i){
		if(pos[i] == 0) pos[i] = -1;
		else if(pos[i] == -1) pos[i] = i;
		if(ask(a[i]) - ask(a[i] - 1) == 0) add(a[i], 1);
		
		
		if(a[i] > maxn){//在第一轮做出改变
			add(1, 1, 1, 1);//第一个位置首先多进行一次交换
			add(1, i, i, 1);//最后一个位置会进行一次交换
            //下面进行修正
			if(pos[maxn] > 0){//第二次出现的位置都会多进行一次add
				add(1, pos[maxn], i - 1, 1);
			}
			maxn = a[i];
		}else{//一直轮不到他,那无所谓就仅仅是加一下自己的贡献就行
			ll tmp = ask(n) - ask(a[i]);//比a[i]大的有几个?
			add(1, i, i, tmp);//在这个地方正常进行交换
		}
		ans.pb(t[1].sum);
	}
	rep(i, 0, (int)ans.size() - 1){
		printf("%lld%c", ans[i], i == (int)ans.size() - 1 ? '\n' : ' ');
	}
}
int main(){
	int T = read();
	while(T--){
		n = read();
		rep(i, 1, n) a[i] = read();
		rep(i, 0, n + 1) c[i] = pos[i] = 0;
		rep(i, 0, n * 4 + 1) t[i] = Node{0, 0, 0, 0};
		slv();
	}
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9880kb

input:

3
5
2 3 2 1 5
3
1 2 3
1
1

output:

0 2 3 5 7
0 2 4
0

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 210ms
memory: 23108kb

input:

6107
19
10 13 8 8 11 18 12 9 15 19 6 13 11 11 17 9 14 2 18
12
1 8 10 2 10 2 6 1 5 9 5 7
16
14 4 2 15 12 14 10 3 2 9 15 4 12 9 5 15
10
3 2 5 6 7 8 6 1 6 4
18
6 5 12 12 11 2 10 10 5 10 13 15 13 10 17 7 11 2
1
1
2
1 1
3
2 1 2
17
11 15 3 10 7 15 15 10 5 17 3 3 14 13 11 11 2
3
2 2 3
7
6 1 7 5 3 5 1
7
2 1...

output:

0 2 4 6 7 9 11 16 17 19 28 31 36 41 43 51 55 67 68
0 2 4 6 6 8 10 14 17 18 22 25
0 1 3 5 7 8 11 16 22 26 26 31 33 37 42 42
0 1 3 5 7 9 11 17 19 23
0 1 3 3 4 8 10 12 16 18 20 22 23 27 29 35 39 48
0
0 0
0 1 1
0 2 4 6 9 9 9 11 15 17 23 29 31 34 38 42 51
0 0 2
0 1 3 5 8 10 14
0 1 3 4 6 9 9
0 1 1 3 5 9 1...

result:

wrong answer 5th lines differ - expected: '0 1 3 3 4 8 10 12 16 18 27 29 30 34 36 42 46 55', found: '0 1 3 3 4 8 10 12 16 18 20 22 23 27 29 35 39 48'