QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#753163#9731. Fuzzy RankingicesmokeRE 13ms31604kbC++172.7kb2024-11-16 11:35:582024-11-16 11:35:58

Judging History

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

  • [2024-11-25 12:28:53]
  • hack成功,自动添加数据
  • (/hack/1257)
  • [2024-11-16 11:35:58]
  • 评测
  • 测评结果:RE
  • 用时:13ms
  • 内存:31604kb
  • [2024-11-16 11:35:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long 

const int N = 2e5+5;

int n,m,q;
int col[N],dfn[N],low[N],st[N],idx;
vector<int>h[N],a[N],b[N],lx[N],rx[N];
stack<int>vex;

int cnt;

void tarjan(int u)
{
    cnt++;
    if(cnt>=1e8){
        cout<<"!!!\n";
        exit(0);
    }
    
    st[u] = 1;
    dfn[u] = low[u] = ++ idx;
    vex.push(u);
    for(int v:h[u]){
        if(!dfn[v]){
            tarjan(v);
            low[u] = min(low[u],low[v]);
        }else if(st[v]==1){
            low[u] = min(low[u],dfn[v]);
        }
    }
    if (dfn[u] == low[u])
    {
        col[u] = dfn[u];
        while(vex.size() && vex.top()!=u){
            col[vex.top()] = dfn[u];
            vex.pop();
        }
        vex.pop();
    }
    st[u] = 2;
}


void solve()
{
    cin>>n>>m>>q;
    for (int i = 1; i <= n; i ++ ){
        st[i] = dfn[i] = low[i] = 0;
        h[i].clear();
    }
    for (int i = 1; i <= m; i ++ ){
        a[i].resize(n+1);
        for (int j = 1; j <= n; j ++ ){
            cin>>a[i][j];
            if(j>1) h[a[i][j-1]].push_back(a[i][j]);
        }
    }
    idx = 0;
    for (int i = 1; i <= n; i ++ ){
        if(!dfn[i])
            tarjan(i);
    }
    for (int i = 1; i <= m; i ++ ){
        b[i].resize(n+1,0);
        lx[i].resize(n+1);
        rx[i].resize(n+1);
        for (int j = 1; j <= n; j ++ ){
            int k = j;
            while(k<=n && col[a[i][j]]==col[a[i][k]]){
                k++;
            }
            for(int j1=j;j1<k;j1++){
                lx[i][j1] = j;
                rx[i][j1] = k-1;
            }
            int len = k - j;
            b[i][k-1] = b[i][j-1] + len*(len-1)/2;
            j = k - 1;
        }
    }
    int ans = 0;
    while(q--){
        int id,l,r;
        cin>>id>>l>>r;
        id = (id + ans)%m + 1;
        l = (l + ans)%n + 1;
        r = (r + ans)%n + 1;
        if(l>n || r>n){
            cout<<"!!!!\n";
            exit(0);
        }
        if(col[a[id][l]]==col[a[id][r]]){
            int len = r - l + 1;
            ans = len * (len - 1) / 2;
        }else{
            ans = 0;
            int len1 = rx[id][l] - l + 1;
            int len2 = r - lx[id][r] + 1;
            ans += len1 * (len1 - 1) / 2;
            ans += len2 * (len2 - 1) / 2;
            ans += b[id][lx[id][r]-1] - b[id][rx[id][l]];
        }
        cout<<ans<<'\n';
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    
    int T;
    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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 31604kb

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: 13ms
memory: 31548kb

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