QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749294#9731. Fuzzy RankingKir1sameTL 0ms0kbC++201.9kb2024-11-14 23:24:242024-11-14 23:24:25

Judging History

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

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

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
ll low[N],dfn[N],stk[N],in[N],col[N],top,cnt1,cnt,T,n,k,q;
vector<ll> l[N],r[N],v[N],g[N];vector<ll> s[N];
void dfs(int p)
{
	dfn[p]=low[p]=++cnt;
	stk[++top]=p;in[p]=true;
	for(int i=0;i<g[p].size();i++)
	{
		int to=g[p][i];
		if(!dfn[to])
		{
			dfs(to);
			low[p]=min(low[p],low[to]);
		}
		else
			if(in[to])
				low[p]=min(low[p],dfn[to]);
	}
	if(dfn[p]==low[p])
	{
		cnt1++;
		while(top&&stk[top+1]!=p)
		{
			col[stk[top]]=cnt1;
			in[stk[top--]]=false;
		}
	}
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d %d %d",&n,&k,&q);
		cnt1=cnt=0;top=0;
		for(int i=1;i<=k;i++)
			v[i]=vector(n+1,0ll),l[i]=vector(n+1,0ll),r[i]=vector(n+1,0ll),s[i]=vector(n+1,0ll);

		for(int i=0;i<=n+1;i++)  
			g[i].clear(),in[i]=false,col[i]=0,dfn[i]=0,low[i]=0,stk[i]=0;
		for(int i=1;i<=k;i++)
			for(int j=1;j<=n;j++)
			{
				scanf("%d",&v[i][j]);
				if(j>1)
					g[v[i][j-1]].push_back(v[i][j]);
			}
		for(int i=1;i<=n;i++)
			if(!dfn[i])
				dfs(i);
		for(int i=1;i<=k;i++)
		{
			ll num=0;
			for(int j=1;j<=n;j++)
			{
				if(j!=1 && col[v[i][j]]!=col[v[i][j-1]])
				{
					s[i][j-1]+=1ll*num*(num-1)/2;
					for(int x=j-1;x>=j-num;x--)
						r[i][x]=j-1,l[i][x]=j-num;
					num=0;
				}
				s[i][j]+=s[i][j-1];
				num++;
			}
			s[i][n]+=1ll*num*(num-1)/2;
			for(int x=n;x>=n-num+1;x--)
				r[i][x]=n,l[i][x]=n-num+1;
		}
		ll lasans=0;
		while(q--)
		{
			int id,l1,r1;ll ans=0;
			scanf("%d %d %d",&id,&l1,&r1);
			id=(id+lasans)%k+1;
			l1=(l1+lasans)%k+1;
			r1=(r1+lasans)%k+1;
			if(r[id][r1]==r[id][l1])
				ans=(1ll*(r1-l1)*(r1-l1+1)/2);
			else
				ans=1ll*(r[id][l1]-l1)*(r[id][l1]-l1+1)/2+1ll*(r1-l[id][r1]+1)*(r1-l[id][r1])/2+s[id][l[id][r1]-1]-s[id][r[id][l1]];
			printf("%lld\n",ans);
			lasans=ans;
		}
	}
}

详细

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:

0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result: