QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#854342#9731. Fuzzy Rankingucup-team3474#WA 49ms52504kbC++233.8kb2025-01-11 23:51:242025-01-11 23:51:26

Judging History

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

  • [2025-01-11 23:51:26]
  • 评测
  • 测评结果:WA
  • 用时:49ms
  • 内存:52504kb
  • [2025-01-11 23:51:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std ;
const int N=5e5+10;
#define int long long
typedef long long ll;

typedef pair<int,int> PII;
vector<vector<int>> strongly_connected_components(const vector<vector<int>>& adj) {
  int n = adj.size();
vector<bool> done(n);
    vector<int> pos(n, -1), stack;
    vector<vector<int>> res;
    auto dfs = [&](auto& dfs, int u) -> int {
        int low = pos[u] = stack.size();
        stack.push_back(u);
        for (int v : adj[u])
            if (not done[v]) low = min(low, ~pos[v] ? pos[v] : dfs(dfs, v));
        if (low == pos[u]) {
            res.emplace_back(stack.begin() + low, stack.end());
            for (int v : res.back()) done[v] = true;
            stack.resize(low);
        }
        return low;
    };
    for (int i = 0; i < n; i += 1)
        if (not done[i]) dfs(dfs, i);
    reverse(res.begin(), res.end());
    return res;
}

map<int,int> mp[N];
multiset<int> se[N];
vector<ll> e[N],s[N];


void solve()
{
    int n , m , k ;
    cin>>n>>m>>k;
    vector<vector<int>> adj(n * m + n) ;
    auto add = [&](int u , int v)
    {
        u -= 1 , v -= 1 ;
        adj[u].push_back(v) ;
        // cout << u + 1 << ' ' << v + 1 << '\n' ;
    } ;
    for(int i=1;i<=m;i++){
        e[i].clear();
        s[i].clear();
        for(int j=0;j<=n;j++){
             e[i].push_back(0);
             s[i].push_back(0);
        }
    }
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            int res=(i-1)*n+j;
            if(j<n)  
            {
                add(res , res + 1) ;
            }
            int x;
            cin>>x;
            e[i][j]=x;
            x += n * m ;
            add(x , res) ;
            add(res , x) ;
        }
    }

    auto v = strongly_connected_components(adj) ;
    vector<int> id(n * m + n + 1) ; // 1-index
    int cnt = 0 ;
    for(auto u : v)
    {
        cnt += 1 ;
        for(auto x : u) id[x + 1] = cnt ;
    }
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            e[i][j]=id[n*m+e[i][j]];
        }
    }
    for(int i=1;i<=m;i++){
        se[i].clear();
        se[i].insert(0);
        mp[i].clear();
        mp[i][0]=0;
        int l=1,now=e[i][1];
        set<int> waa;
        for(int j=1;j<=n;j++){
            if(now!=e[i][j]){
                se[i].insert(l);
                mp[i][l]=j-1;
                ll len=j-l;
                len=len*(len-1)/2;
                
                assert(!waa.count(e[i][j-1]));
                waa.insert(e[i][j-1]);
                s[i][j]=len;
                l=j;
                now=e[i][j];
            }
            s[i][j]+=s[i][j-1];
        }
        se[i].insert(l);
        mp[i][l]=n;
        
                assert(!waa.count(e[i][n]));
        se[i].insert(n+1);
        mp[i][n+1]=n+1;
    }
    
    ll lastans=0;
    for(int c=1;c<=k;c++){
        ll id,l,r;
        cin>>id>>l>>r;
        id=(id+lastans)%m+1;
        l=(l+lastans)%n+1;
        r=(r+lastans)%n+1;
        if(e[id][l]==e[id][r]){
            lastans=(r-l+1)*(r-l)/2;
        }else{
            auto it1=se[id].upper_bound(l);
            auto it2=se[id].upper_bound(r);
            it2--;
            ll res1=*it1,res2=*it2;
            lastans=0;
            // res1--;
            lastans=(res1-l)*(res1-l-1)/2;
            lastans+=(r-res2+1)*(r-res2)/2;
            res2--;
            if(res1<=res2) lastans+=s[id][res2]-s[id][res1-1];
        }   
        cout<<lastans<<"\n";
    }


    // for(int i = 1 ; i <= n * m + n ; i ++) cout << id[i] << ' ' ; cout << '\n' ;
}
signed main()
{
    std::ios::sync_with_stdio(false) , cin.tie(0) ;

    int T = 1 ;
    cin >> T ;
    while (T --) solve() ;

    return 0 ;
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 50608kb

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: -100
Wrong Answer
time: 49ms
memory: 52504kb

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:

2
0
1
0
3
1
0
2
2
4
1
0
0
0
3
3
3
1
0
0
1
6
28
0
0
10
10
6
6
15
0
3
10
6
4
3
6
1
2
1
4
0
1
1
3
0
7
7
1
3
1
3
3
4
0
4
1
3
1
0
0
0
1
2
0
0
0
2
0
1
4
0
0
1
4
4
0
4
4
4
3
6
16
16
0
11
16
1
4
15
1
6
1
1
1
2
1
1
2
6
0
0
0
0
0
0
0
0
0
0
1
3
0
9
3
0
6
2
1
1
0
0
0
0
0
0
0
0
0
0
0
1
0
4
3
1
0
0
0
6
9
1
12
4
7...

result:

wrong answer 1st lines differ - expected: '1', found: '2'