QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#185015#7108. Couleurucup-team1359AC ✓4040ms46280kbC++142.7kb2023-09-21 15:50:442023-09-21 15:50:45

Judging History

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

  • [2023-09-21 15:50:45]
  • 评测
  • 测评结果:AC
  • 用时:4040ms
  • 内存:46280kb
  • [2023-09-21 15:50:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace sgt {
	int sgt[2050000][3],sgtcnt;
	int newnode() {
		sgtcnt++;
		sgt[sgtcnt][0]=sgt[sgtcnt][1]=sgt[sgtcnt][2]=0;
		return sgtcnt;
	}
	void update(int p,int q,int s,int t,int x,int y) {
		sgt[q][0]=sgt[p][0];sgt[q][1]=sgt[p][1];sgt[q][2]=sgt[p][2]+y;
		if (s==t) return;
		int mid=(s+t)/2;
		if (x<=mid) {
			sgt[q][0]=newnode();
			update(sgt[p][0],sgt[q][0],s,mid,x,y);
		}
		else {
			sgt[q][1]=newnode();
			update(sgt[p][1],sgt[q][1],mid+1,t,x,y);
		}
	}
	int getsum(int p,int s,int t,int l,int r) {
		if (l>r) return 0;
		if ((l<=s)&&(t<=r)) return sgt[p][2];
		int mid=(s+t)/2;
		if (r<=mid) return getsum(sgt[p][0],s,mid,l,r);
		if (l>mid) return getsum(sgt[p][1],mid+1,t,l,r);
		return getsum(sgt[p][0],s,mid,l,r)+getsum(sgt[p][1],mid+1,t,l,r);
	}
}
int T,n,a[105000],rt[105000];
map<int,long long> mp;
multiset<long long,greater<long long> > ms;
set<int> st_getlarger;
set<int,greater<int> > st_getsmaller;
void split(int l,int r,int x) {
	long long tmp=mp[l-1];ms.erase(ms.find(tmp));
	long long ansx=sgt::getsum(rt[r],1,n,1,a[x]-1)-sgt::getsum(rt[x],1,n,1,a[x]-1)
	+sgt::getsum(rt[x-1],1,n,a[x]+1,n)-sgt::getsum(rt[l-1],1,n,a[x]+1,n);
	if (x-l<r-x) {
		long long newans=0,midans=ansx;
		for (int i=l;i<x;i++) {
			newans+=sgt::getsum(rt[i-1],1,n,a[i]+1,n)-sgt::getsum(rt[l-1],1,n,a[i]+1,n);
			midans+=sgt::getsum(rt[r],1,n,1,a[i]-1)-sgt::getsum(rt[x],1,n,1,a[i]-1);
		}
		mp[l-1]=newans;ms.insert(newans);
		mp[x]=tmp-newans-midans;ms.insert(tmp-newans-midans);
	} else {
		long long newans=0,midans=ansx;
		for (int i=x+1;i<=r;i++) {
			newans+=sgt::getsum(rt[r],1,n,1,a[i]-1)-sgt::getsum(rt[i],1,n,1,a[i]-1);
			midans+=sgt::getsum(rt[x-1],1,n,a[i]+1,n)-sgt::getsum(rt[l-1],1,n,a[i]+1,n);
		}
		mp[x]=newans;ms.insert(newans);
		mp[l-1]=tmp-newans-midans;ms.insert(tmp-newans-midans);
	}
}
int main() {
	scanf("%d",&T);
	while (T--) {
		scanf("%d",&n);
		sgt::sgtcnt=0;
		long long cur=0;
		for (int i=1;i<=n;i++) {
			scanf("%d",&a[i]);
			cur+=sgt::getsum(rt[i-1],1,n,a[i]+1,n);
			rt[i]=sgt::newnode();
			sgt::update(rt[i-1],rt[i],1,n,a[i],1);
		}
		mp.clear();ms.clear();st_getsmaller.clear();st_getlarger.clear();
		mp[0]=cur;ms.insert(cur);
		mp[n+1]=0;ms.insert(0);
		st_getsmaller.insert(0);st_getsmaller.insert(n+1);
		st_getlarger.insert(0);st_getlarger.insert(n+1);
		for (int i=1;i<=n;i++) {
			cur=*ms.begin();
			printf("%lld",cur);
			if (i<n) printf(" ");
			else printf("\n");
			long long x=0;
			scanf("%lld",&x);
			int y=(int)(x^cur);
			int l=*st_getsmaller.lower_bound(y),r=*st_getlarger.lower_bound(y);
			split(l+1,r-1,y);
			st_getsmaller.insert(y);st_getlarger.insert(y);
		}
	}
	return 0;
}

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

详细

Test #1:

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

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: 4040ms
memory: 46280kb

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