QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#202262#4425. CakeForever_Young#WA 3489ms106156kbC++231.8kb2023-10-05 21:10:552023-10-05 21:10:55

Judging History

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

  • [2023-10-05 21:10:55]
  • 评测
  • 测评结果:WA
  • 用时:3489ms
  • 内存:106156kb
  • [2023-10-05 21:10:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n;i>=1;i--)
#define mp make_pair
#define pb push_back
#define N 510000
int a[2][N],b[2][N],A[N],B[N];
vector<int> pos1[N],pos2[N];
int q[N];
map<pair<int,int>,int> dic;
int n;
int st[N];
int lowbit(int x)
{
	return x & (-x);
}
int getsum(int x)
{
	int ret=0;
	while (x)
	{
		ret+=st[x];
		x-=lowbit(x);
	}
	return ret;
}
void insert(int x,int k)
{
	while (x<=n)
	{
		st[x]+=k;
		x+=lowbit(x);
	}
}
int main()
{
	int T;
	cin>>T;
	while (T--)
	{
		scanf("%d",&n);
		rep(i,n)scanf("%d",&a[0][i]);
		rep(i,n)scanf("%d",&a[1][i]);
		rep(i,n)scanf("%d",&b[0][i]);
		rep(i,n)scanf("%d",&b[1][i]);
		rep(i,n)if (i%2==0)swap(a[0][i],a[1][i]);
		rep(i,n)if (i%2==0)swap(b[0][i],b[1][i]);
		dic.clear();
		int tot=0;
		for(int i=1;i<=n;i++)
		{
			if (dic.find(mp(a[0][i],a[1][i]))==dic.end())dic[mp(a[0][i],a[1][i])]=++tot;
			A[i]=dic[mp(a[0][i],a[1][i])];
		}
		//rep(i,n)cout<<A[i]<<" "; puts("");
		int flag=1;
		for(int i=1;i<=n;i++)
		{
			if (dic.find(mp(b[0][i],b[1][i]))==dic.end())
			{
				flag=0;
				break;
			}
			B[i]=dic[mp(b[0][i],b[1][i])];
		}
		//rep(i,n)cout<<B[i]<<" "; puts("");
		if (!flag){ puts("-1"); continue; }
		for(int i=1;i<=tot;i++)pos1[i].clear(),pos2[i].clear();
		for(int i=1;i<=n;i++)pos1[A[i]].pb(i),pos2[B[i]].pb(i);
		for(int i=1;i<=n;i++)
		{
			if (pos1[i].size()!=pos2[i].size()){ flag=0; break; }
			int cnt=pos1[i].size();
			for(int j=0;j<cnt;j++)q[pos1[i][j]]=pos2[i][j];
		}
		if (!flag){ puts("-1"); continue; }
		long long ans=0;
		for(int i=1;i<=n;i++)st[i]=0;
		for(int i=1;i<=n;i++)
		{
			ans=ans+i-1-getsum(q[i]);
			insert(q[i],1);
		}
		printf("%lld\n",ans);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2963ms
memory: 105860kb

input:

4
500000
471518156 319758862 812815356 520822448 129241996 461169933 796713727 608641317 281180101 953966756 749634941 274104949 996181952 88142916 998544672 125597509 991731126 974767231 338911715 674197249 167602044 682799026 226927279 703198907 216742488 8185420 94921423 690039818 859329736 45428...

output:

0
-1
124999750000
62569045381

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 3489ms
memory: 106156kb

input:

4
500000
413978977 447850293 802546055 289227062 321812178 97254226 380555063 167654142 874843339 349071516 10868808 93093321 996630037 33169052 99312773 335065051 278187197 94810404 643530967 947474510 63047182 573006260 8470509 116477506 251504796 899920047 806158195 452300674 859769748 489596554 ...

output:

62623368052
62486676013
62520737719
62506121292

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 882ms
memory: 44068kb

input:

9082
7
714942297 703160828 709363739 23094554 461254804 159017923 666590460
196100940 70571239 755082029 321718821 55663261 378527017 335969190
321718821 335969190 70571239 755082029 378527017 55663261 714942297
23094554 666590460 703160828 709363739 159017923 461254804 196100940
5
2 1 1 2 1
2 1 2 2...

output:

13
2
0
-1
0
1
10
3
0
6
0
10
15
1
2336
-1
-3
-1
-1
4
-1
15
0
3
45
15
3
4
0
20
-1
-1
10
-1
18
10
13
3
1
-1
0
4
6
5
-1
18
-1
-1
-1
7
-1
265147
-1
-616
0
-783
-1
-1
-1
-1
2210
-73
1
16
-1
-1
0
-1
0
0
5
5
14
3
7
-1
21
-5
8
11
0
32308741
-1
20
-1
0
-1
-1
-16033
6
2249
0
-1
0
55236
1053
1
-106
-1
-1
-182
0...

result:

wrong answer 2nd lines differ - expected: '5', found: '2'