QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#42850#4425. Cakefecto_elfilisWA 5968ms165888kbC++1.2kb2022-08-04 12:38:122022-08-04 12:38:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-04 12:38:14]
  • 评测
  • 测评结果:WA
  • 用时:5968ms
  • 内存:165888kb
  • [2022-08-04 12:38:12]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=500010;
int t,n,a[N],b[N],c[N],fw[N],hd[N];
ll ans;
vector <int> v[N];
map <pair<int,int>,int> mp;
void modify (int x) {
	for (int i=x;i<=n;i+=(i&(-i))) {fw[i]++;}
}
int query (int x) {
	int res=0;
	for (int i=x;i;i-=(i&(-i))) {res+=fw[i];}
	return res;
}
int main () {
	scanf("%d",&t);
	for (int ii=1;ii<=t;ii++) {
		scanf("%d",&n);
		for (int i=1;i<=n;i++) {scanf("%d",&a[i]);fw[i]=0;}
		int tot=0;
		for (int i=1;i<=n;i++) {
			scanf("%d",&b[i]);
			if (i&1) {swap(a[i],b[i]);}
			if (mp.find(make_pair(a[i],b[i]))==mp.end()) {mp[make_pair(a[i],b[i])]=++tot;hd[tot]=0;v[tot].clear();}
			v[mp[make_pair(a[i],b[i])]].push_back(i);
		}
		for (int i=1;i<=n;i++) {scanf("%d",&a[i]);}
		int flg=1;
		for (int i=1;i<=n;i++) {
			scanf("%d",&b[i]);
			if (i&1) {swap(a[i],b[i]);}
			if (mp.find(make_pair(a[i],b[i]))==mp.end()) {flg=0;continue;}
			int tmp=mp[make_pair(a[i],b[i])];
			if (hd[tmp]>=v[tmp].size()) {flg=0;continue;}
			c[i]=v[tmp][hd[tmp]++];
		}
		if (!flg) {printf("-1\n");continue;}
		for (int i=1;i<=n;i++) {
			ans+=i-1-query(c[i]);
			modify(c[i]);
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 5968ms
memory: 165888kb

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
187568795381

result:

wrong answer 4th lines differ - expected: '62569045381', found: '187568795381'