QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#759074#9731. Fuzzy Rankingfhq_treap#WA 10ms11868kbC++232.2kb2024-11-17 21:29:072024-11-17 21:29:08

Judging History

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

  • [2024-11-25 12:28:53]
  • hack成功,自动添加数据
  • (/hack/1257)
  • [2024-11-17 21:29:08]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:11868kb
  • [2024-11-17 21:29:07]
  • 提交

answer

#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<set>
using std::cin,std::cout;
int n,k,q,a[200010];
std::vector<int> v[200010];
int dfn[200010],low[200010],vis[200010],df,stk[200010],tp,col[200010],cnt;
void dfs(int x){
	dfn[x]=low[x]=++df,vis[x]=1;
	stk[++tp]=x;
	for(auto u:v[x])
		if(!vis[u]){
			dfs(u);
			low[x]=std::min(low[x],low[u]);
		}else if(vis[u]==1) low[x]=std::min(low[x],dfn[u]);
	if(dfn[x]==low[x]){
		++cnt;
		int u;
		do{
			u=stk[tp--];
			col[u]=cnt;
			vis[u]=2;
		}while(u!=x);
	}
}
int const B=448;
int c[450][200010],bel[200010],L[450],R[450],ct[200010];
long long f[450][450];
int query(int l,int r){
	long long ans=0;
	if(bel[l]==bel[r]){
		for(int i=l;i<=r;i++) ans+=ct[a[i]],++ct[a[i]];
		for(int i=l;i<=r;i++) ct[a[i]]=0;
	}else{
		ans=f[bel[l]+1][bel[r]-1];
		for(int i=l;i<=R[bel[l]];i++) ans+=ct[a[i]]+c[bel[r]-1][a[i]]-c[bel[l]][a[i]],++ct[a[i]];
		for(int i=L[bel[r]];i<=r;i++) ans+=ct[a[i]]+c[bel[r]-1][a[i]]-c[bel[l]][a[i]],++ct[a[i]];
		for(int i=l;i<=R[bel[l]];i++) ct[a[i]]=0;
		for(int i=L[bel[r]];i<=r;i++) ct[a[i]]=0;
	}
	return ans;
}
void solve(){
	cin>>n>>k>>q;
	for(int i=1;i<=n;i++) v[i].clear(),vis[i]=dfn[i]=low[i]=0;
	tp=cnt=df=0;
	for(int i=0;i<k;i++){
		int y=0;
		for(int j=0;j<n;j++){
			int x;
			cin>>x;
			a[i*n+j+1]=x;
			if(j) v[y].push_back(x);
			y=x;
		}
	}
	dfs(a[1]);
	int m=n*k;
	for(int i=1;i<=m;i++) a[i]=col[a[i]];
	//for(int i=1;i<=m;i++) cout<<a[i]<<" \n"[i==m];
	for(int i=1;i<=m;i++) bel[i]=i/B+1;
	for(int i=1;i<=m;i++) R[bel[i]]=i;
	for(int i=m;i;i--) L[bel[i]]=i;
	for(int i=1;i<=bel[n];i++){
		static int ct[200010];
		for(int j=1;j<=cnt;j++) ct[i]=0,c[i][j]=c[i-1][j];
		for(int j=L[i];j<=R[i];j++) c[i][a[j]]++;
		for(int j=i;j<=bel[n];j++){
			f[i][j]=f[i][j-1];
			for(int k=L[j];k<=R[j];k++) f[i][j]+=ct[a[k]],++ct[a[k]];
		}
	}
	while(q--){
		int id,l,r;
		cin>>id>>l>>r;
		static int lans=0;
		id=(id+lans)%k+1;
		l=(l+lans)%n+1;
		r=(r+lans)%n+1;
		cout<<(lans=query((id-1)*n+l,(id-1)*n+r))<<'\n';
	}
}
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11868kb

input:

2
5 2 2
1 2 3 4 5
5 4 3 2 1
1 0 2
1 2 1
5 3 3
1 2 3 4 5
1 3 2 4 5
1 2 3 5 4
0 0 2
0 2 3
1 0 3

output:

3
10
1
1
2

result:

ok 5 lines

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 11804kb

input:

2000
10 10 10
4 5 3 6 8 9 2 1 7 10
4 5 6 3 8 9 1 2 10 7
5 4 3 6 8 9 1 2 7 10
4 5 6 3 8 9 1 2 7 10
4 5 3 6 8 9 2 1 10 7
4 5 6 3 8 9 1 2 10 7
5 4 6 3 8 9 1 2 7 10
5 4 6 3 8 9 1 2 10 7
4 5 6 3 8 9 2 1 7 10
5 4 3 6 8 9 2 1 10 7
3 1 6
5 7 8
0 2 3
7 9 9
2 1 9
6 1 6
7 2 3
0 0 4
1 8 1
1 8 7
10 10 10
9 10 5 ...

output:

1
1
0
0
3
2
0
2
2
4
0
0
1
1
1
1
2
4
4
3
1
6
28
0
0
10
10
6
6
15
0
3
10
6
16
6
11
1
2
1
1
6
3
3
0
4
5
3
4
1
0
3
2
4
0
3
4
4
4
4
0
0
1
1
2
0
0
1
2
1
0
0
0
1
4
3
0
4
4
1
0
6
16
16
0
11
16
1
4
15
0
0
0
1
1
1
1
2
1
0
0
0
0
0
0
0
0
0
0
0
1
0
0
6
3
0
3
4
0
0
0
0
0
0
0
0
0
0
0
0
3
0
0
1
3
1
0
0
3
3
6
1
9
4
...

result:

wrong answer 11th lines differ - expected: '1', found: '0'