QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#564703#7878. Matrix DistancesBird#RE 7ms28672kbC++14884b2024-09-15 13:35:282024-09-15 13:35:29

Judging History

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

  • [2024-09-15 13:35:29]
  • 评测
  • 测评结果:RE
  • 用时:7ms
  • 内存:28672kb
  • [2024-09-15 13:35:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int c[N][N],n,m;
vector<int> v[N][N];
long long ans;
struct BIT{
	long long sum[N];
	void add(int x,int val){
		for(;x<=n;x+=x&-x) sum[x]+=val;
	}
	long long qry(int x){
		long long res=0;
		for(;x;x-=x&-x) res+=sum[x];
		return res;
	}
}T[2];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++) cin>>c[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			v[c[i][j]][i].push_back(j);
	for(int i=1;i<=m;i++){
		int tot=0;
		long long num=0;
		for(int j=1;j<=n;j++){
			for(auto &x:v[i][j]){
				ans+=x*T[0].qry(x)-T[1].qry(x);
				ans+=T[1].qry(n)-T[1].qry(x)-x*(T[0].qry(n)-T[0].qry(x));
				ans+=1ll*tot*j-num;
				T[0].add(x,1);
				T[1].add(x,x);
				num+=j;tot++;
			}
		}
		for(int j=1;j<=n;j++) T[0].sum[j]=T[1].sum[j]=0;
	}
	cout<<ans*2;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 28672kb

input:

2 2
1 1
2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 28216kb

input:

4 4
1 3 2 4
2 1 2 3
1 3 3 2
3 2 1 4

output:

152

result:

ok 1 number(s): "152"

Test #3:

score: -100
Runtime Error

input:

1000 1000
227980299 227980299 227980299 227980299 227980299 776958596 227980299 227980299 227980299 227980299 227980299 227980299 227980299 227980299 227980299 227980299 776958596 227980299 227980299 329001637 227980299 227980299 227980299 329001637 227980299 227980299 227980299 227980299 227980299 ...

output:


result: