QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#742463#9731. Fuzzy RankingxuwbWA 15ms3764kbC++173.0kb2024-11-13 16:39:202024-11-13 16:39:21

Judging History

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

  • [2024-11-25 12:28:53]
  • hack成功,自动添加数据
  • (/hack/1257)
  • [2024-11-13 16:39:21]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3764kb
  • [2024-11-13 16:39:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct SCC {
    int n;
    std::vector<std::vector<int>> adj;
    std::vector<int> stk;
    std::vector<int> dfn, low, bel;
    int cur, cnt;

    SCC() {}
    SCC(int n) {
        init(n);
    }

    void init(int n) {
        this->n = n;
        adj.assign(n, {});
        dfn.assign(n, -1);
        low.resize(n);
        bel.assign(n, -1);
        stk.clear();
        cur = cnt = 0;
    }

    void addEdge(int u, int v) {
        adj[u].push_back(v);
    }

    void dfs(int x) {
        dfn[x] = low[x] = cur++;
        stk.push_back(x);

        for (auto y : adj[x]) {
            if (dfn[y] == -1) {
                dfs(y);
                low[x] = std::min(low[x], low[y]);
            } else if (bel[y] == -1) {
                low[x] = std::min(low[x], dfn[y]);
            }
        }

        if (dfn[x] == low[x]) {
            int y;
            do {
                y = stk.back();
                bel[y] = cnt;
                stk.pop_back();
            } while (y != x);
            cnt++;
        }
    }

    std::vector<int> work() {
        for (int i = 0; i < n; i++) {
            if (dfn[i] == -1) {
                dfs(i);
            }
        }
        return bel;
    }
};
void solve() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<vector<int>>a(k, vector<int>(n));
    SCC e(n);
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
            a[i][j]--;
            if (j)e.addEdge(a[i][j - 1], a[i][j]);
        }
    }
    vector<int>f = e.work();
    vector<ll>s(n + 1, 0);
    auto wk = [&](ll x) {
        return x * (x - 1) / 2;
    };
    int lasr = 0;
    set<int>stl, str;
    stl.insert(1);
    for (int i = 1; i <= n; i++) {
        s[i] = s[i - 1];
        if (i == n || f[a[0][i - 1]] != f[a[0][i]]) {
            if (i != n)stl.insert(i + 1);
            s[i] += wk(i - lasr);
            lasr = i;
            str.insert(i);
        }
    }
    ll res = 0;
    while (q--) {
        int l, r;
        cin >> l >> l >> r;
        l = (l + res) % n + 1;
        r = (r + res) % n + 1;
        ll tres = 0;
        auto it = stl.lower_bound(l);
        if (*it <= r) {
            tres += wk(*it - l);
            l = *it;
        }
        else {
            tres += wk(r - l + 1);
            l = r + 1;
        }
        if (l <= r) {
            auto it = str.upper_bound(r);
            if (it == str.begin()) {
                tres += wk(r - l + 1);
                l = r + 1;
            }
            else {
                it--;
                tres += wk(r - *it);
                r = *it;
            }
        }
        if (r >= l)tres += s[r] - s[l - 1];
        res = tres;
        cout << res << '\n';
    }
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

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

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
12
1
2
0
2
2
4
1
0
1
1
1
1
2
4
4
3
16
51
18
30
2
34
60
38
28
55
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
50
14
35
47
0
11
16
57
15
21
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
...

result:

wrong answer 4th lines differ - expected: '0', found: '12'