QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749511#9731. Fuzzy RankingyinyuqinTL 0ms0kbC++142.9kb2024-11-15 02:26:582024-11-15 02:26:59

Judging History

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

  • [2024-11-25 12:28:53]
  • hack成功,自动添加数据
  • (/hack/1257)
  • [2024-11-15 02:26:59]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-15 02:26:58]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0,f=1;char c=getchar();
	while(!(c>='0'&&c<='9')) {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
	return x*f;
}
const int maxn=4e5+5;
int num[maxn],p[maxn],cnt,times,scc_cnt;
int dfn[maxn],low[maxn];
vector<int> A[maxn],S1[maxn],S2[maxn],L[maxn],R[maxn];
stack<int> s;
struct node{
	int v,next;
}e[maxn];
void insert(int u,int v){
	cnt++;
	e[cnt].v=v;
	e[cnt].next=p[u];
	p[u]=cnt;
}
void dfs(int u){
	dfn[u]=low[u]=++times;
	s.push(u);
	for(int i=p[u];i!=-1;i=e[i].next){
		int v=e[i].v;
		if(dfn[v]==0){
			dfs(v);
			low[u]=min(low[u],low[v]);
		}else if(num[v]==0){
			low[u]=min(low[u],dfn[v]);
		}
	}
	if(dfn[u]==low[u]){
		scc_cnt++;
		while(1){
			int x=s.top();
			s.pop();
			num[x]=scc_cnt;
			if(x==u) break;
		}
	}
}
int Q1(int id,int l,int r){
//	cout<<l<<' '<<r<<endl;
	return S1[id][r]-S1[id][l-1];
}
int Q2(int id,int l,int r){
//	cout<<l<<' '<<r<<endl;
	return S2[id][r]-S2[id][l-1];
}
signed main(){
	freopen("F.in","r",stdin);
	int T=read();
	while(T--){
		int lstans=0;
		int n=read(),k=read(),q=read();
		cnt=scc_cnt=times=0;
		while(!s.empty()) s.pop();
		for(int i=0;i<=k+1;i++){
			A[i].clear();S1[i].clear();S2[i].clear();L[i].clear();R[i].clear();
		}
		for(int i=0;i<=n+1;i++) p[i]=-1,num[i]=0,dfn[i]=0,low[i]=0;
		for(int i=0;i<=k+1;i++){
			for(int j=0;j<=n+1;j++){
				A[i].push_back(0);
				S1[i].push_back(0);
				S2[i].push_back(0);
				L[i].push_back(0);
				R[i].push_back(0);
			}
		}
		for(int i=1;i<=k;i++){
			for(int j=1;j<=n;j++){
				int x=read();
				A[i][j]=x;
			}
			for(int j=2;j<=n;j++) insert(A[i][j-1],A[i][j]);
		}
		for(int i=1;i<=n;i++){
			if(!dfn[i]) dfs(i);
		}
		for(int i=1;i<=k;i++){
			for(int j=1;j<=n;j++){
				if(num[A[i][j]]==num[A[i][j-1]]) S1[i][j]=S1[i][j-1]+1;
				else S1[i][j]=0;
			}
			for(int j=n;j>=1;j--){
				if(num[A[i][j]]==num[A[i][j+1]]) S2[i][j]=S2[i][j+1]+1;
				else S2[i][j]=0;
			}
		}
		for(int i=1;i<=k;i++){
			int nowl=1,nowr=n;
			for(int j=1;j<=n;j++){
				if(S1[i][j]==0) nowl=j;
				L[i][j]=nowl;
			}
			for(int j=n;j>=1;j--){
				if(S2[i][j]==0) nowr=j;
				R[i][j]=nowr;
			}
		}
//		for(int i=1;i<=k;i++){
//			for(int j=1;j<=n;j++){
//				cout<<L[i][j]<<' ';
//			}cout<<endl;
//			for(int j=1;j<=n;j++){
//				cout<<R[i][j]<<' ';
//			}cout<<endl;
//			
//		}
		for(int i=1;i<=k;i++){
			for(int j=1;j<=n+1;j++){
				S1[i][j]+=S1[i][j-1];
				S2[i][j]+=S2[i][j-1];
			}
		}
		while(q--){
			int id=read(),l=read(),r=read();
//			cout<<id<<' '<<l<<' '<<r<<endl;
			id=(id+lstans)%k+1;
			l=(l+lstans)%n+1;
			r=(r+lstans)%n+1;
//			if(l>r) swap(l,r);
			if(L[id][l]==L[id][r]) lstans=(r-l+1)*(r-l)/2;
			else lstans=Q2(id,l,R[id][l])+Q1(id,R[id][l]+1,L[id][r]-1)+Q1(id,L[id][r],r);
			printf("%lld\n",lstans);
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

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:


result: