QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#879664 | #9731. Fuzzy Ranking | frankly6 | WA | 13ms | 13904kb | C++17 | 3.2kb | 2025-02-02 10:14:47 | 2025-02-02 10:14:48 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> PII;
const int MX=200020;
int T, N, K, Q;
int fa[MX], bel[MX], col[MX], num[MX], now[MX], ans[MX], rt[MX];
int read()
{
int r=0, f=1; char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
return r*f;
}
int find(int x){return x==fa[x]?fa[x]:fa[x]=find(fa[x]);}
void merge(int x, int y)
{
x=find(x); y=find(y);
if(x==y) return;
if(x>y) swap(x,y);
fa[y]=x;
}
priority_queue<PII> q;
signed main()
{
T=read();
while(T--)
{
N=read(); K=read(); Q=read();
vector<vi> sc(N+10,vi(K+10));
for(int i=1;i<=N;i++) fa[i]=i;
for(int i=1;i<=K;i++)
{
while(!q.empty()) q.pop();
for(int j=1;j<=N;j++)
{
sc[i][j]=read();
int r=sc[i][j];
if(i==1) {bel[r]=j; continue;}
while(!q.empty())
{
auto [rk,id]=q.top();
if(find(bel[r])<rk)
{
// cout << "r=" << r << ", bel=" << find(bel[r]) << ", id=" << id << ", rk=" << rk << '\n';
merge(bel[r],bel[id]), q.pop();
}
else break;
}
q.push({find(bel[r]),r});
}
// cout << "col: "; for(int j=1;j<=N;j++) cout << find(bel[sc[i][j]]) << " "; cout << '\n';
}
for(int i=1;i<=N;i++)
col[i]=find(bel[sc[1][i]]);
// cout << "col: "; for(int i=1;i<=N;i++) cout << col[i] << " "; cout << '\n';
for(int i=1;i<=N;i++) num[i]=now[i]=0;
for(int i=1,pre=0;i<=N;i++)
{
pre++; now[i]=pre;
if(col[i+1]!=col[i]) num[col[i]]=pre, pre=0, rt[col[i]]=i;
}
// cout << "rt: "; for(int i=1;i<=N;i++) cout << rt[col[i]] << " "; cout << '\n';
// cout << "now: "; for(int i=1;i<=N;i++) cout << now[i] << " "; cout << '\n';
for(int i=1,pre=0;i<=N;i++)
{
ans[i]=pre+now[i]*(now[i]-1)/2;
if(now[i]==num[col[i]]) pre=ans[i];
}
// cout << "ans: "; for(int i=1;i<=N;i++) cout << ans[i] << " "; cout << '\n';
int bef=0;
while(Q--)
{
int id=read(), l=read(), r=read();
id=(id+bef)%K+1;
l=(l+bef)%N+1;
r=(r+bef)%N+1;
int L=r-l+1;
// cout << "l=" << l << ", r=" << r << '\n';
if(col[r]==col[l]) bef=L*(L-1)/2;
else
{
int p=rt[col[l]];
int l1=num[col[l]]-now[l]+1;
int a0=l1*(l1-1)/2;
// cout << "ar=" << ans[r] << ", ap=" << ans[p] << ", a0=" << a0 << '\n';
bef=ans[r]-ans[p]+a0;
}
cout << bef << '\n';
}
for(int i=1;i<=N*K+5;i++) num[i]=now[i]=ans[i]=col[i]=fa[i]=bel[i]=rt[i]=0;
}
return (0-0);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 13904kb
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: 0
Accepted
time: 9ms
memory: 11864kb
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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
wrong answer 2151st lines differ - expected: '3', found: '0'