QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#879690#9731. Fuzzy Rankingfrankly6RE 12ms13780kbC++173.7kb2025-02-02 10:45:222025-02-02 10:45:23

Judging History

This is the latest submission verdict.

  • [2025-02-02 10:45:23]
  • Judged
  • Verdict: RE
  • Time: 12ms
  • Memory: 13780kb
  • [2025-02-02 10:45:22]
  • Submitted

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()
{
    // freopen("testdata.in","r",stdin);
    T=read();
    for(int time=1;time<=T;time++)
    {
        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;}
                int in=bel[r];
                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();
                        in=max(in,rk);
                    }
                    else break;
                }
                q.push({in,r});              
            }
            // if(time==216&&N==5) {cout << "col: "; for(int j=1;j<=N;j++) cout << find(bel[sc[i][j]]) << " "; cout << "\\";}
            // cout << "col: "; for(int j=1;j<=N;j++) cout << find(bel[sc[i][j]]) << " "; cout << '\n';
        }
        // if(time==216&&N==5) {for(int i=1;i<=K;i++) {for(int j=1;j<=N;j++) cout << sc[i][j] << " "; cout << " &&& ";}}
        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();
            l=(l+bef)%N+1; r=(r+bef)%N+1;
            int L=r-l+1;
            // if(time==216&&N==5) {cout << "col: "; for(int i=1;i<=N;i++) cout << col[i] << " "; 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;
                if(a0<0||l1<0||p<0) cout << "-1\n";
                // 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);
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 11856kb

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: 8ms
memory: 13780kb

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
1
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
1
3
2
4
0
3
4
4
4
4
0
0
1
1
2
0
0
1
2
1
1
0
0
1
4
3
0
4
4
1
3
6
16
16
0
11
16
1
4
15
1
4
2
0
0
2
0
1
2
4
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
9
1
9
4
...

result:

ok 20000 lines

Test #3:

score: 0
Accepted
time: 12ms
memory: 11852kb

input:

8000
5 5 10
3 5 2 4 1
3 2 5 4 1
3 5 2 4 1
3 5 2 4 1
3 5 2 4 1
1 1 1
4 1 3
1 0 3
4 2 3
1 0 1
3 2 3
1 2 3
3 0 2
1 1 3
1 1 2
5 5 10
5 3 1 2 4
3 5 1 2 4
5 3 1 2 4
3 5 1 2 4
5 3 1 2 4
0 0 1
2 0 1
4 1 2
1 3 4
2 0 1
4 3 3
1 4 4
1 3 4
0 0 4
0 0 3
5 5 10
2 3 4 1 5
5 1 4 3 2
1 3 4 2 5
2 3 4 1 5
5 1 3 4 2
1 2 ...

output:

0
1
1
0
0
0
0
1
0
1
1
0
0
0
1
0
0
0
1
0
3
0
3
1
0
3
1
6
1
0
0
0
0
0
0
0
0
0
0
0
1
1
2
1
0
3
0
0
3
0
1
0
0
0
0
0
0
1
0
0
6
1
0
6
0
3
3
3
0
0
3
3
6
1
10
1
3
0
1
0
3
1
0
0
1
0
1
1
1
2
0
0
0
0
0
0
0
0
0
0
0
0
3
1
3
3
1
3
1
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
0
1
6
0
6
6
1
1
1
0
1
1
0
0
1
0
0
0
3
0
1
1
0
2
3
3...

result:

ok 80000 lines

Test #4:

score: 0
Accepted
time: 9ms
memory: 11856kb

input:

8000
5 5 5
1 3 5 2 4
5 3 2 1 4
5 2 1 3 4
3 1 2 5 4
1 3 2 5 4
1 1 2
1 4 0
1 4 1
2 2 2
4 1 3
5 5 5
2 3 4 1 5
2 3 4 1 5
2 3 4 5 1
2 3 4 1 5
2 3 4 5 1
2 0 4
0 0 0
4 1 3
3 0 1
4 4 4
5 5 5
2 5 4 1 3
2 5 4 1 3
2 5 4 1 3
2 5 4 1 3
2 5 4 1 3
3 1 3
2 0 4
0 1 3
4 0 2
3 4 4
5 5 5
1 2 4 5 3
1 2 4 5 3
1 2 4 5 3
1...

output:

1
1
3
0
3
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
3
0
1
0
0
0
1
0
0
1
1
1
1
3
0
3
0
0
0
0
0
10
3
1
3
1
2
1
1
1
0
3
3
1
0
1
6
3
6
6
1
0
0
0
0
0
0
2
1
2
0
3
1
1
1
3
1
3
1
3
3
6
3
6
0
1
1
0
6
0
3
1
1
1
1
0
0
0
0
0
0
6
0
0
10
1
0
0
0
1
2
1
1
0
0
0
1
1
1
0
0
1
0
1
1
0
1
3
0
0
0
3
1
0
10
0
4
0
0
2...

result:

ok 40000 lines

Test #5:

score: -100
Runtime Error

input:

2000
1 100 100
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
25 0 0
9 0 0
80 0 0
37 0 0
18 0 0
24 0 0
5 0 0
87 0 0
50 0 0
63 0 0
53 0 0
62 0 0
37 ...

output:


result: