QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#171173#7108. Couleurxianggui#AC ✓1478ms34448kbC++202.9kb2023-09-09 16:34:062023-09-09 16:34:54

Judging History

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

  • [2023-09-09 16:34:54]
  • 评测
  • 测评结果:AC
  • 用时:1478ms
  • 内存:34448kb
  • [2023-09-09 16:34:06]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#define mid (l+r)/2
using namespace std;
const int N = 100010;
int n, m, cnt;
int a[N], b[N], T[N];
int sum[N<<5], L[N<<5], R[N<<5];
struct node {
	int l,r;
	long long ans;
};
set<node> S;
multiset<long long> ansS;
bool operator < (const node &a,const node &b){
	return a.l<b.l||a.l==b.l&&a.r<b.r;
}
inline int build(int l, int r){
    int rt = ++ cnt;
    sum[rt] = 0;
    if (l < r){
        L[rt] = build(l, mid);
        R[rt] = build(mid+1, r);
    }
    return rt;
}
inline int update(int pre, int l, int r, int x){
    int rt = ++ cnt;
    L[rt] = L[pre]; R[rt] = R[pre]; sum[rt] = sum[pre]+1;
    if (l < r){
        if (x <= mid) L[rt] = update(L[pre], l, mid, x);
        else R[rt] = update(R[pre], mid+1, r, x);
    }
    return rt;
}
inline int query1(int u, int v, int l, int r, int val){
    if (l >= r) return 0;
    int x = sum[L[v]] - sum[L[u]];
    if (val > mid) return x + query1(R[u], R[v], mid+1, r, val);
    	else return query1(L[u], L[v], l, mid, val);
}
inline int query2(int u, int v, int l, int r, int val){
    if (l >= r) return sum[v] - sum[u];
    int x = sum[L[v]] - sum[L[u]];
    if (val > mid) return x + query2(R[u], R[v], mid+1, r, val);
    	else return query2(L[u], L[v], l, mid, val);
}
inline int getsum1(int x,int y,int z){ // < z
	if (x>y) return 0;
	return query1(T[x-1], T[y], 1, m, z);
}
inline int getsum2(int x,int y,int z){ // > z
	if (x>y) return 0;
	return (y-x+1)-query2(T[x-1], T[y], 1, m, z);
}
void solve(){
	S.clear();ansS.clear();
    scanf("%d",&n);m=0;cnt=0;
    for (int i = 1; i <= n; i ++){
        scanf("%d",&a[i]);
		m = max(m,a[i]);
    }
    T[0] = build(1, m);
    for (int i = 1; i <= n;i++)
        T[i] = update(T[i-1], 1, m, a[i]);
    long long ans=0,t=0;
    for (int i=1;i<=n;++i) ans+=getsum1(i+1,n,a[i]);
    printf("%lld",ans);ansS.insert(ans);
    S.insert((node){1,n,ans});
    for (int i=1;i<=n;++i){
    	scanf("%lld",&t); t=ans^t;
    	set<node>::iterator it=S.upper_bound((node){t,n+1,0});
		it--;S.erase(it);
    	int l=(*it).l,r=(*it).r;long long pre_ans=(*it).ans;
    	ansS.erase(ansS.find(pre_ans));
    	long long ans_1=0,ans_2=0,sum=0;
    	if (t-l<r-t){
    		for (int i=l;i<=t-1;++i) ans_1+=getsum1(i+1,t-1,a[i]),sum+=getsum1(t+1,r,a[i]);
    		sum+=getsum2(l,t-1,a[t])+getsum1(t+1,r,a[t]);
    		ans_2=pre_ans-ans_1-sum;
		} else {
			for (int i=t+1;i<=r;++i) ans_2+=getsum1(i+1,r,a[i]),sum+=getsum2(l,t-1,a[i]);
    		sum+=getsum2(l,t-1,a[t])+getsum1(t+1,r,a[t]);
    		ans_1=pre_ans-ans_2-sum;
		}
		ansS.insert(ans_1),ansS.insert(ans_2);ans=*ansS.rbegin();
		if (t>l) S.insert((node){l,t-1,ans_1});
		if (t<r) S.insert((node){t+1,r,ans_2});
		if (i!=n) printf(" %lld",ans);
	}
	puts("");
}
int main(){
	int T;scanf("%d",&T);
	while (T--) solve();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 10072kb

input:

3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10

output:

7 0 0 0 0
20 11 7 2 0 0 0 0 0 0
42 31 21 14 14 4 1 1 1 0 0 0 0 0 0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1478ms
memory: 34448kb

input:

11116
10
10 5 10 3 6 4 8 5 9 8
31 27 24 11 12 3 0 2 3 1
10
8 2 7 2 8 10 1 10 9 10
6 5 2 13 2 1 0 1 3 1
10
7 10 7 6 1 3 10 6 7 9
21 18 10 1 6 5 4 8 9 10
10
2 10 4 8 8 5 7 2 6 7
20 10 9 1 15 0 4 2 9 7
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10
1 2 3 4 5 6 7 8 9 10
6 3 5 2 7 10 9 1 4 8
10
1 10 1 3...

output:

21 18 16 12 10 6 4 1 1 0
12 12 10 10 4 4 4 2 1 0
20 16 9 5 3 3 3 0 0 0
22 14 8 8 5 5 2 1 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
19 12 7 4 4 2 2 1 0 0
20 18 8 3 1 1 0 0 0 0
45 21 21 10 3 3 3 0 0 0
17 11 8 2 1 1 1 0 0 0
13 4 1 0 0 0 0 0 0 0
29 27 22 15 9 7 4 3 1 0
26 16 9 2 1 1 1 1 1 0
0 0 0 0 0 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed