QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#766557#9731. Fuzzy RankingLinxRE 1ms7668kbC++232.2kb2024-11-20 17:44:132024-11-20 17:44:14

Judging History

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

  • [2024-11-25 12:28:53]
  • hack成功,自动添加数据
  • (/hack/1257)
  • [2024-11-20 17:44:14]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:7668kb
  • [2024-11-20 17:44:13]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define log(x) (31^__builtin_clz(x))
#define lowbit(x) (x&-x)
#define pii pair<int,int>
using namespace std;
const int maxn=2e5+5;
vector<int>e[maxn],st;
int vis[maxn],inst[maxn],dfn[maxn],low[maxn],cnt;
int scc[maxn],siz[maxn],sc;
inline ll calc(int x){
	return 1ll*(x)*(x-1)/2;
}
void dfs(int x){
	low[x]=dfn[x]=++cnt;
	inst[x]=vis[x]=1;
	st.push_back(x);
	for(auto u:e[x]){
		if(!vis[u]){
			dfs(u);
			low[x]=min(low[x],low[u]);
		}
		else if(inst[u]){
			low[x]=min(low[x],dfn[u]);
		}
	}
	if(low[x]==dfn[x]){
		sc++;
		siz[sc]=0;
		while(1){
			int u=st.back();
			scc[u]=sc;
			siz[sc]++;
			st.pop_back();
			if(u==x)break;
		}
	}
	inst[x]=0;
}
void solve(){
	int n,k,q,rt;
	cin>>n>>k>>q;
	sc=cnt=0;
	vector<vector<int>>a(k+2,vector<int>(n+2));
	for(int i=1;i<=n;i++){
		vis[i]=scc[i]=0;
		e[i].clear();
	}
	for(int i=1;i<=k;i++){
		int las=0;
		for(int j=1;j<=n;j++){
			int x;
			cin>>x;
			a[i][j]=x;
			if(j==1)rt=x;
			if(j>1)e[las].push_back(x);
			las=x;
		}
	}
	dfs(rt);
	vector<vector<pii>>t(k+5);
	vector<vector<ll>>sum(k+5);
	for(int i=1;i<=k;i++){
		t[i]={{1,1}};
		sum[i]={0};
		for(int j=2;j<=n;j++){
			if(scc[a[i][j]]==scc[a[i][j-1]]){
				sum[i].back()+=t[i].back().second-t[i].back().first+1;
				t[i].back().second++;
			}
			else{
				t[i].push_back({j,j});
				sum[i].push_back(0);
			}
		}
		t[i].push_back({n+1,n+1});
	}
	ll ans=0;
	for(int i=1;i<=q;i++){
		int id,l,r;
		cin>>id>>l>>r;
		id=(id+ans)%k+1;
		l=(l+ans)%n+1;
		r=(r+ans)%n+1;
		if(scc[a[id][l]]==scc[a[id][r]]){
			ans=1ll*(r-l+1)*(r-l)/2;
			cout<<ans<<"\n";
			continue;
		}
		int L=lower_bound(t[id].begin(),t[id].end(),(pii){l,0})-t[id].begin(),R=lower_bound(t[id].begin(),t[id].end(),(pii){r+1,0})-t[id].begin();
		R--;
		ans=sum[id][R-1]-sum[id][L];
		int siz1=t[i][L].second-l+1,siz2=r-t[i][R].first+1;
		ans+=calc(siz1)+calc(siz2);
		cout<<ans<<"\n";
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	cin>>t;
	while(t--)solve();
}
/*
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
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7668kb

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
Runtime Error

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:


result: