QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#786496#9731. Fuzzy Rankingqinsj#RE 15ms75224kbC++143.2kb2024-11-26 21:49:192024-11-26 21:49:20

Judging History

This is the latest submission verdict.

  • [2024-11-26 21:49:20]
  • Judged
  • Verdict: RE
  • Time: 15ms
  • Memory: 75224kb
  • [2024-11-26 21:49:19]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>

// #define db(args...) {\
//     string _s = #args;replace(_s.begin(), _s.end(), ',', ' ');\
//     stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout << '\n';}
// void err(istream_iterator<string> it){}
// template<typename T, typename... Args>
// void err(istream_iterator<string> it, T a, Args... args) {
//     cout << *it << " = " << a << ' ';
//     err(++it, args...);
// }
int n,k,q;
#define MAX 500005
vector<int> rk[MAX];
vector<int> e[MAX];
int dfn[MAX],low[MAX],sz;
int st[MAX],top;
int group[MAX],gr;
void tarjan(int x){
    dfn[x]=low[x]=++sz;
    st[++top]=x;
    for(auto y:e[x]){
        if(!dfn[y]){
            tarjan(y);
            low[x]=min(low[x],low[y]);
        }else if(!group[y]) low[x]=min(low[x],dfn[y]);
    }
    if(dfn[x]==low[x]){
        group[x]=++gr;
        while(st[top]!=x){
            group[st[top]]=gr;
            top--;
        }top--;
    }
}
void add(int x,int y){
    e[x].push_back(y);
}
#define ll long long
vector<ll> rgt[MAX],qz[MAX];
vector<int> pos[MAX],bk_rgt[MAX];
ll pw(ll x){
    return x*(x-1)/2;
}
void solve(){
    cin>>n>>k>>q;
    for(int i=1;i<=n;i++){
        e[i].clear();dfn[i]=low[i]=group[i]=0;
    }
    for(int i=1;i<=k;i++){
        rk[i].resize(n);
        for(int j=0;j<n;j++){
            cin>>rk[i][j];
            if(j) add(rk[i][j-1],rk[i][j]);
        }
    }sz=gr=0;
    for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i);
    //cout<<"mid"<<endl;
    //for(int i=1;i<=n;i++) cout<<group[i]<<" ";
    //cout<<endl;
    for(int i=1;i<=k;i++){
        rgt[i].resize(n);
        pos[i].resize(n);
        rgt[i][n-1]=n-1;
        for(int j=n-2;j>=0;j--){
            if(group[rk[i][j]]==group[rk[i][j+1]])
                rgt[i][j]=rgt[i][j+1]; 
            else rgt[i][j]=j;
        }
        //cout<<"rgt:"<<endl;
        //for(int j=0;j<n;j++) cout<<rgt[i][j]<<" ";
        //cout<<endl;
        int cnt=0;
        qz[i].clear();
        bk_rgt[i].clear();
        ll sm=0;
        for(int j=0;j<n;j++){
            pos[i][rgt[i][j]]=cnt++;
            bk_rgt[i].push_back(rgt[i][j]);
            sm+=pw(rgt[i][j]-j+1);
            //cout<<"FKKK:"<<j<<" "<<sm<<endl;
            qz[i].push_back(sm);
            j=rgt[i][j];
        }
    }
    ll ans=0;
    for(int i=1;i<=q;i++){
        ll id,l,r;
        cin>>id>>l>>r;
        id=(id+ans)%k+1;
        l=(l+ans)%n+1;r=(r+ans)%n+1;
        if(l>r) swap(l,r);
        l--,r--;
        //cout<<"query:"<<id<<" "<<l<<" "<<r<<endl;
        if(group[rk[id][l]]==group[rk[id][r]]){
            ans=pw(r-l+1);
        }else{
            int aa=pos[i][rgt[i][l]],bb=pos[i][rgt[i][r]];
            //cout<<"aa="<<aa<<" "<<bb<<endl;
            ans=qz[i][bb-1]-qz[i][aa];
            ans+=pw(rgt[i][l]-l+1);
            ans+=pw(r-bk_rgt[i][bb-1]);
        }
        cout<<ans<<"\n";
    }
}   
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}
/*
g++ f.cpp -std=c++20 -o f && ./f < in.txt > out.txt
*/

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 74132kb

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: 15ms
memory: 75224kb

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: -100
Runtime Error

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:


result: